browser/devtools/debugger/test/browser_dbg_breakpoints-pane.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:770455497ca3
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Bug 723071: Test adding a pane to display the list of breakpoints across
6 * all sources in the debuggee.
7 */
8
9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
10
11 function test() {
12 let gTab, gDebuggee, gPanel, gDebugger;
13 let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving;
14
15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
16 gTab = aTab;
17 gDebuggee = aDebuggee;
18 gPanel = aPanel;
19 gDebugger = gPanel.panelWin;
20 gEditor = gDebugger.DebuggerView.editor;
21 gSources = gDebugger.DebuggerView.Sources;
22 gBreakpoints = gDebugger.DebuggerController.Breakpoints;
23 gBreakpointsAdded = gBreakpoints._added;
24 gBreakpointsRemoving = gBreakpoints._removing;
25
26 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(performTest);
27 gDebuggee.firstCall();
28 });
29
30 let breakpointsAdded = 0;
31 let breakpointsDisabled = 0;
32 let breakpointsRemoved = 0;
33
34 function performTest() {
35 is(gDebugger.gThreadClient.state, "paused",
36 "Should only be getting stack frames while paused.");
37 is(gSources.itemCount, 2,
38 "Found the expected number of sources.");
39 is(gEditor.getText().indexOf("debugger"), 172,
40 "The correct source was loaded initially.");
41 is(gSources.selectedValue, gSources.values[1],
42 "The correct source is selected.");
43
44 is(gBreakpointsAdded.size, 0,
45 "No breakpoints currently added.");
46 is(gBreakpointsRemoving.size, 0,
47 "No breakpoints currently being removed.");
48 is(gEditor.getBreakpoints().length, 0,
49 "No breakpoints currently shown in the editor.");
50
51 ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
52 "_getAdded('foo', 3) returns falsey.");
53 ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
54 "_getRemoving('bar', 3) returns falsey.");
55
56 let breakpointsParent = gSources.widget._parent;
57 let breakpointsList = gSources.widget._list;
58
59 is(breakpointsParent.childNodes.length, 1, // one sources list
60 "Found junk in the breakpoints container.");
61 is(breakpointsList.childNodes.length, 1, // one sources group
62 "Found junk in the breakpoints container.");
63 is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0,
64 "No breakpoints should be visible at this point.");
65
66 addBreakpoints(true).then(() => {
67 is(breakpointsAdded, 3,
68 "Should have added 3 breakpoints so far.");
69 is(breakpointsDisabled, 0,
70 "Shouldn't have disabled anything so far.");
71 is(breakpointsRemoved, 0,
72 "Shouldn't have removed anything so far.");
73
74 is(breakpointsParent.childNodes.length, 1, // one sources list
75 "Found junk in the breakpoints container.");
76 is(breakpointsList.childNodes.length, 1, // one sources group
77 "Found junk in the breakpoints container.");
78 is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 3,
79 "3 breakpoints should be visible at this point.");
80
81 disableBreakpoints().then(() => {
82 is(breakpointsAdded, 3,
83 "Should still have 3 breakpoints added so far.");
84 is(breakpointsDisabled, 3,
85 "Should have 3 disabled breakpoints.");
86 is(breakpointsRemoved, 0,
87 "Shouldn't have removed anything so far.");
88
89 is(breakpointsParent.childNodes.length, 1, // one sources list
90 "Found junk in the breakpoints container.");
91 is(breakpointsList.childNodes.length, 1, // one sources group
92 "Found junk in the breakpoints container.");
93 is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
94 "Should have the same number of breakpoints in the pane.");
95 is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsDisabled,
96 "Should have the same number of disabled breakpoints.");
97
98 addBreakpoints().then(() => {
99 is(breakpointsAdded, 3,
100 "Should still have only 3 breakpoints added so far.");
101 is(breakpointsDisabled, 3,
102 "Should still have 3 disabled breakpoints.");
103 is(breakpointsRemoved, 0,
104 "Shouldn't have removed anything so far.");
105
106 is(breakpointsParent.childNodes.length, 1, // one sources list
107 "Found junk in the breakpoints container.");
108 is(breakpointsList.childNodes.length, 1, // one sources group
109 "Found junk in the breakpoints container.");
110 is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
111 "Since half of the breakpoints already existed, but disabled, " +
112 "only half of the added breakpoints are actually in the pane.");
113
114 removeBreakpoints().then(() => {
115 is(breakpointsRemoved, 3,
116 "Should have 3 removed breakpoints.");
117
118 is(breakpointsParent.childNodes.length, 1, // one sources list
119 "Found junk in the breakpoints container.");
120 is(breakpointsList.childNodes.length, 1, // one sources group
121 "Found junk in the breakpoints container.");
122 is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0,
123 "No breakpoints should be visible at this point.");
124
125 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
126 finalCheck();
127 closeDebuggerAndFinish(gPanel);
128 });
129
130 gDebugger.gThreadClient.resume();
131 });
132 });
133 });
134 });
135
136 function addBreakpoints(aIncrementFlag) {
137 let deferred = promise.defer();
138
139 gPanel.addBreakpoint({ url: gSources.selectedValue, line: 6 }).then(aClient => {
140 onBreakpointAdd(aClient, {
141 increment: aIncrementFlag,
142 line: 6,
143 text: "eval(\"debugger;\");"
144 });
145
146 gPanel.addBreakpoint({ url: gSources.selectedValue, line: 7 }).then(aClient => {
147 onBreakpointAdd(aClient, {
148 increment: aIncrementFlag,
149 line: 7,
150 text: "function foo() {}"
151 });
152
153 gPanel.addBreakpoint({ url: gSources.selectedValue, line: 9 }).then(aClient => {
154 onBreakpointAdd(aClient, {
155 increment: aIncrementFlag,
156 line: 9,
157 text: "foo();"
158 });
159
160 deferred.resolve();
161 });
162 });
163 });
164
165 return deferred.promise;
166 }
167
168 function disableBreakpoints() {
169 let deferred = promise.defer();
170
171 let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint");
172 info("Nodes to disable: " + breakpointsAdded.length);
173
174 is(nodes.length, breakpointsAdded,
175 "The number of nodes to disable is incorrect.");
176
177 for (let node of nodes) {
178 info("Disabling breakpoint: " + node.id);
179
180 let sourceItem = gSources.getItemForElement(node);
181 let breakpointItem = gSources.getItemForElement.call(sourceItem, node);
182 info("Found data: " + breakpointItem.attachment.toSource());
183
184 gSources.disableBreakpoint(breakpointItem.attachment).then(() => {
185 if (++breakpointsDisabled == breakpointsAdded) {
186 deferred.resolve();
187 }
188 });
189 }
190
191 return deferred.promise;
192 }
193
194 function removeBreakpoints() {
195 let deferred = promise.defer();
196
197 let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint");
198 info("Nodes to remove: " + breakpointsAdded.length);
199
200 is(nodes.length, breakpointsAdded,
201 "The number of nodes to remove is incorrect.");
202
203 for (let node of nodes) {
204 info("Removing breakpoint: " + node.id);
205
206 let sourceItem = gSources.getItemForElement(node);
207 let breakpointItem = gSources.getItemForElement.call(sourceItem, node);
208 info("Found data: " + breakpointItem.attachment.toSource());
209
210 gPanel.removeBreakpoint(breakpointItem.attachment).then(() => {
211 if (++breakpointsRemoved == breakpointsAdded) {
212 deferred.resolve();
213 }
214 });
215 }
216
217 return deferred.promise;
218 }
219
220 function onBreakpointAdd(aBreakpointClient, aTestData) {
221 if (aTestData.increment) {
222 breakpointsAdded++;
223 }
224
225 is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
226 aTestData.increment
227 ? "Should have added a breakpoint in the pane."
228 : "Should have the same number of breakpoints in the pane.");
229
230 let identifier = gBreakpoints.getIdentifier(aBreakpointClient.location);
231 let node = gDebugger.document.getElementById("breakpoint-" + identifier);
232 let line = node.getElementsByClassName("dbg-breakpoint-line")[0];
233 let text = node.getElementsByClassName("dbg-breakpoint-text")[0];
234 let check = node.querySelector("checkbox");
235
236 ok(node,
237 "Breakpoint element found successfully.");
238 is(line.getAttribute("value"), aTestData.line,
239 "The expected information wasn't found in the breakpoint element.");
240 is(text.getAttribute("value"), aTestData.text,
241 "The expected line text wasn't found in the breakpoint element.");
242 is(check.getAttribute("checked"), "true",
243 "The breakpoint enable checkbox is checked as expected.");
244 }
245 }
246
247 function finalCheck() {
248 is(gBreakpointsAdded.size, 0,
249 "No breakpoints currently added.");
250 is(gBreakpointsRemoving.size, 0,
251 "No breakpoints currently being removed.");
252 is(gEditor.getBreakpoints().length, 0,
253 "No breakpoints currently shown in the editor.");
254 }
255 }

mercurial