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