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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d4e940e1aec8
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Bug 723069: Test the debugger breakpoint API and connection to the
6 * source editor.
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 function performTest() {
31 is(gDebugger.gThreadClient.state, "paused",
32 "Should only be getting stack frames while paused.");
33 is(gSources.itemCount, 2,
34 "Found the expected number of sources.");
35 is(gEditor.getText().indexOf("debugger"), 172,
36 "The correct source was loaded initially.");
37 is(gSources.selectedValue, gSources.values[1],
38 "The correct source is selected.");
39
40 is(gBreakpointsAdded.size, 0,
41 "No breakpoints currently added.");
42 is(gBreakpointsRemoving.size, 0,
43 "No breakpoints currently being removed.");
44 is(gEditor.getBreakpoints().length, 0,
45 "No breakpoints currently shown in the editor.");
46
47 ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
48 "_getAdded('foo', 3) returns falsey.");
49 ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
50 "_getRemoving('bar', 3) returns falsey.");
51
52 is(gSources.values[1], gSources.selectedValue,
53 "The second source should be currently selected.");
54
55 info("Add the first breakpoint.");
56 let location = { url: gSources.selectedValue, line: 6 };
57 gEditor.once("breakpointAdded", onEditorBreakpointAddFirst);
58 gPanel.addBreakpoint(location).then(onBreakpointAddFirst);
59 }
60
61 let breakpointsAdded = 0;
62 let breakpointsRemoved = 0;
63 let editorBreakpointChanges = 0;
64
65 function onEditorBreakpointAddFirst(aEvent, aLine) {
66 editorBreakpointChanges++;
67
68 ok(aEvent,
69 "breakpoint1 added to the editor.");
70 is(aLine, 5,
71 "Editor breakpoint line is correct.");
72
73 is(gEditor.getBreakpoints().length, 1,
74 "editor.getBreakpoints().length is correct.");
75 }
76
77 function onBreakpointAddFirst(aBreakpointClient) {
78 breakpointsAdded++;
79
80 ok(aBreakpointClient,
81 "breakpoint1 added, client received.");
82 is(aBreakpointClient.location.url, gSources.selectedValue,
83 "breakpoint1 client url is correct.");
84 is(aBreakpointClient.location.line, 6,
85 "breakpoint1 client line is correct.");
86
87 ok(gBreakpoints._getAdded(aBreakpointClient.location),
88 "breakpoint1 client found in the list of added breakpoints.");
89 ok(!gBreakpoints._getRemoving(aBreakpointClient.location),
90 "breakpoint1 client found in the list of removing breakpoints.");
91
92 is(gBreakpointsAdded.size, 1,
93 "The list of added breakpoints holds only one breakpoint.");
94 is(gBreakpointsRemoving.size, 0,
95 "The list of removing breakpoints holds no breakpoint.");
96
97 gBreakpoints._getAdded(aBreakpointClient.location).then(aClient => {
98 is(aClient, aBreakpointClient,
99 "_getAdded() returns the correct breakpoint.");
100 });
101
102 is(gSources.values[1], gSources.selectedValue,
103 "The second source should be currently selected.");
104
105 info("Remove the first breakpoint.");
106 gEditor.once("breakpointRemoved", onEditorBreakpointRemoveFirst);
107 gPanel.removeBreakpoint(aBreakpointClient.location).then(onBreakpointRemoveFirst);
108 }
109
110 function onEditorBreakpointRemoveFirst(aEvent, aLine) {
111 editorBreakpointChanges++;
112
113 ok(aEvent,
114 "breakpoint1 removed from the editor.");
115 is(aLine, 5,
116 "Editor breakpoint line is correct.");
117
118 is(gEditor.getBreakpoints().length, 0,
119 "editor.getBreakpoints().length is correct.");
120 }
121
122 function onBreakpointRemoveFirst(aLocation) {
123 breakpointsRemoved++;
124
125 ok(aLocation,
126 "breakpoint1 removed");
127 is(aLocation.url, gSources.selectedValue,
128 "breakpoint1 removal url is correct.");
129 is(aLocation.line, 6,
130 "breakpoint1 removal line is correct.");
131
132 testBreakpointAddBackground();
133 }
134
135 function testBreakpointAddBackground() {
136 is(gBreakpointsAdded.size, 0,
137 "No breakpoints currently added.");
138 is(gBreakpointsRemoving.size, 0,
139 "No breakpoints currently being removed.");
140 is(gEditor.getBreakpoints().length, 0,
141 "No breakpoints currently shown in the editor.");
142
143 ok(!gBreakpoints._getAdded({ url: gSources.selectedValue, line: 6 }),
144 "_getAdded('gSources.selectedValue', 6) returns falsey.");
145 ok(!gBreakpoints._getRemoving({ url: gSources.selectedValue, line: 6 }),
146 "_getRemoving('gSources.selectedValue', 6) returns falsey.");
147
148 is(gSources.values[1], gSources.selectedValue,
149 "The second source should be currently selected.");
150
151 info("Add a breakpoint to the first source, which is not selected.");
152 let location = { url: gSources.values[0], line: 5 };
153 let options = { noEditorUpdate: true };
154 gEditor.on("breakpointAdded", onEditorBreakpointAddBackgroundTrap);
155 gPanel.addBreakpoint(location, options).then(onBreakpointAddBackground);
156 }
157
158 function onEditorBreakpointAddBackgroundTrap() {
159 // Trap listener: no breakpoint must be added to the editor when a
160 // breakpoint is added to a source that is not currently selected.
161 editorBreakpointChanges++;
162 ok(false, "breakpoint2 must not be added to the editor.");
163 }
164
165 function onBreakpointAddBackground(aBreakpointClient, aResponseError) {
166 breakpointsAdded++;
167
168 ok(aBreakpointClient,
169 "breakpoint2 added, client received");
170 is(aBreakpointClient.location.url, gSources.values[0],
171 "breakpoint2 client url is correct.");
172 is(aBreakpointClient.location.line, 5,
173 "breakpoint2 client line is correct.");
174
175 ok(gBreakpoints._getAdded(aBreakpointClient.location),
176 "breakpoint2 client found in the list of added breakpoints.");
177 ok(!gBreakpoints._getRemoving(aBreakpointClient.location),
178 "breakpoint2 client found in the list of removing breakpoints.");
179
180 is(gBreakpointsAdded.size, 1,
181 "The list of added breakpoints holds only one breakpoint.");
182 is(gBreakpointsRemoving.size, 0,
183 "The list of removing breakpoints holds no breakpoint.");
184
185 gBreakpoints._getAdded(aBreakpointClient.location).then(aClient => {
186 is(aClient, aBreakpointClient,
187 "_getAdded() returns the correct breakpoint.");
188 });
189
190 is(gSources.values[1], gSources.selectedValue,
191 "The second source should be currently selected.");
192
193 // Remove the trap listener.
194 gEditor.off("breakpointAdded", onEditorBreakpointAddBackgroundTrap);
195
196 info("Switch to the first source, which is not yet selected");
197 gEditor.once("breakpointAdded", onEditorBreakpointAddSwitch);
198 gEditor.once("change", onEditorTextChanged);
199 gSources.selectedIndex = 0;
200 }
201
202 function onEditorBreakpointAddSwitch(aEvent, aLine) {
203 editorBreakpointChanges++;
204
205 ok(aEvent,
206 "breakpoint2 added to the editor.");
207 is(aLine, 4,
208 "Editor breakpoint line is correct.");
209
210 is(gEditor.getBreakpoints().length, 1,
211 "editor.getBreakpoints().length is correct");
212 }
213
214 function onEditorTextChanged() {
215 // Wait for the actual text to be shown.
216 if (gEditor.getText() == gDebugger.L10N.getStr("loadingText"))
217 return void gEditor.once("change", onEditorTextChanged);
218
219 is(gEditor.getText().indexOf("debugger"), -1,
220 "The second source is no longer displayed.");
221 is(gEditor.getText().indexOf("firstCall"), 118,
222 "The first source is displayed.");
223
224 is(gSources.values[0], gSources.selectedValue,
225 "The first source should be currently selected.");
226
227 let window = gEditor.container.contentWindow;
228 executeSoon(() => window.mozRequestAnimationFrame(onReadyForClick));
229 }
230
231 function onReadyForClick() {
232 info("Remove the second breakpoint using the mouse.");
233 gEditor.once("breakpointRemoved", onEditorBreakpointRemoveSecond);
234
235 let iframe = gEditor.container;
236 let testWin = iframe.ownerDocument.defaultView;
237
238 // Flush the layout for the iframe.
239 info("rect " + iframe.contentDocument.documentElement.getBoundingClientRect());
240
241 let utils = testWin
242 .QueryInterface(Ci.nsIInterfaceRequestor)
243 .getInterface(Ci.nsIDOMWindowUtils);
244
245 let coords = gEditor.getCoordsFromPosition({ line: 4, ch: 0 });
246 let rect = iframe.getBoundingClientRect();
247 let left = rect.left + 10;
248 let top = rect.top + coords.top + 4;
249 utils.sendMouseEventToWindow("mousedown", left, top, 0, 1, 0, false, 0, 0);
250 utils.sendMouseEventToWindow("mouseup", left, top, 0, 1, 0, false, 0, 0);
251 }
252
253 function onEditorBreakpointRemoveSecond(aEvent, aLine) {
254 editorBreakpointChanges++;
255
256 ok(aEvent,
257 "breakpoint2 removed from the editor.");
258 is(aLine, 4,
259 "Editor breakpoint line is correct.");
260
261 is(gEditor.getBreakpoints().length, 0,
262 "editor.getBreakpoints().length is correct.");
263
264 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
265 finalCheck();
266 closeDebuggerAndFinish(gPanel);
267 });
268
269 gDebugger.gThreadClient.resume();
270 }
271
272 function finalCheck() {
273 is(gBreakpointsAdded.size, 0,
274 "No breakpoints currently added.");
275 is(gBreakpointsRemoving.size, 0,
276 "No breakpoints currently being removed.");
277 is(gEditor.getBreakpoints().length, 0,
278 "No breakpoints currently shown in the editor.");
279
280 ok(!gBreakpoints._getAdded({ url: gSources.values[0], line: 5 }),
281 "_getAdded('gSources.values[0]', 5) returns falsey.");
282 ok(!gBreakpoints._getRemoving({ url: gSources.values[0], line: 5 }),
283 "_getRemoving('gSources.values[0]', 5) returns falsey.");
284
285 ok(!gBreakpoints._getAdded({ url: gSources.values[1], line: 6 }),
286 "_getAdded('gSources.values[1]', 6) returns falsey.");
287 ok(!gBreakpoints._getRemoving({ url: gSources.values[1], line: 6 }),
288 "_getRemoving('gSources.values[1]', 6) returns falsey.");
289
290 ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
291 "_getAdded('foo', 3) returns falsey.");
292 ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
293 "_getRemoving('bar', 3) returns falsey.");
294
295 is(breakpointsAdded, 2,
296 "Correct number of breakpoints have been added.");
297 is(breakpointsRemoved, 1,
298 "Correct number of breakpoints have been removed.");
299 is(editorBreakpointChanges, 4,
300 "Correct number of editor breakpoint changes.");
301 }
302 }

mercurial