|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Bug 740825: Test adding conditional breakpoints (with server-side support) |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html"; |
|
9 |
|
10 function test() { |
|
11 // Linux debug test slaves are a bit slow at this test sometimes. |
|
12 requestLongerTimeout(2); |
|
13 |
|
14 let gTab, gDebuggee, gPanel, gDebugger; |
|
15 let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving; |
|
16 |
|
17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
18 gTab = aTab; |
|
19 gDebuggee = aDebuggee; |
|
20 gPanel = aPanel; |
|
21 gDebugger = gPanel.panelWin; |
|
22 gEditor = gDebugger.DebuggerView.editor; |
|
23 gSources = gDebugger.DebuggerView.Sources; |
|
24 gBreakpoints = gDebugger.DebuggerController.Breakpoints; |
|
25 gBreakpointsAdded = gBreakpoints._added; |
|
26 gBreakpointsRemoving = gBreakpoints._removing; |
|
27 |
|
28 waitForSourceAndCaretAndScopes(gPanel, ".html", 17) |
|
29 .then(() => addBreakpoints()) |
|
30 .then(() => initialChecks()) |
|
31 .then(() => resumeAndTestBreakpoint(20)) |
|
32 .then(() => resumeAndTestBreakpoint(21)) |
|
33 .then(() => resumeAndTestBreakpoint(22)) |
|
34 .then(() => resumeAndTestBreakpoint(23)) |
|
35 .then(() => resumeAndTestBreakpoint(24)) |
|
36 .then(() => resumeAndTestBreakpoint(25)) |
|
37 .then(() => resumeAndTestBreakpoint(27)) |
|
38 .then(() => resumeAndTestBreakpoint(28)) |
|
39 .then(() => resumeAndTestBreakpoint(29)) |
|
40 .then(() => resumeAndTestNoBreakpoint()) |
|
41 .then(() => reloadActiveTab(gPanel, gDebugger.EVENTS.BREAKPOINT_SHOWN, 13)) |
|
42 .then(() => testAfterReload()) |
|
43 .then(() => closeDebuggerAndFinish(gPanel)) |
|
44 .then(null, aError => { |
|
45 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
46 }); |
|
47 |
|
48 gDebuggee.ermahgerd(); |
|
49 }); |
|
50 |
|
51 function addBreakpoints() { |
|
52 return promise.resolve(null) |
|
53 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
54 line: 18, |
|
55 condition: "undefined" |
|
56 })) |
|
57 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
58 line: 19, |
|
59 condition: "null" |
|
60 })) |
|
61 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
62 line: 20, |
|
63 condition: "42" |
|
64 })) |
|
65 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
66 line: 21, |
|
67 condition: "true" |
|
68 })) |
|
69 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
70 line: 22, |
|
71 condition: "'nasu'" |
|
72 })) |
|
73 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
74 line: 23, |
|
75 condition: "/regexp/" |
|
76 })) |
|
77 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
78 line: 24, |
|
79 condition: "({})" |
|
80 })) |
|
81 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
82 line: 25, |
|
83 condition: "(function() {})" |
|
84 })) |
|
85 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
86 line: 26, |
|
87 condition: "(function() { return false; })()" |
|
88 })) |
|
89 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
90 line: 27, |
|
91 condition: "a" |
|
92 })) |
|
93 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
94 line: 28, |
|
95 condition: "a !== undefined" |
|
96 })) |
|
97 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
98 line: 29, |
|
99 condition: "a !== null" |
|
100 })) |
|
101 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, |
|
102 line: 30, |
|
103 condition: "b" |
|
104 })); |
|
105 } |
|
106 |
|
107 function initialChecks() { |
|
108 is(gDebugger.gThreadClient.state, "paused", |
|
109 "Should only be getting stack frames while paused."); |
|
110 is(gSources.itemCount, 1, |
|
111 "Found the expected number of sources."); |
|
112 is(gEditor.getText().indexOf("ermahgerd"), 253, |
|
113 "The correct source was loaded initially."); |
|
114 is(gSources.selectedValue, gSources.values[0], |
|
115 "The correct source is selected."); |
|
116 |
|
117 is(gBreakpointsAdded.size, 13, |
|
118 "13 breakpoints currently added."); |
|
119 is(gBreakpointsRemoving.size, 0, |
|
120 "No breakpoints currently being removed."); |
|
121 is(gEditor.getBreakpoints().length, 13, |
|
122 "13 breakpoints currently shown in the editor."); |
|
123 |
|
124 ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), |
|
125 "_getAdded('foo', 3) returns falsey."); |
|
126 ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), |
|
127 "_getRemoving('bar', 3) returns falsey."); |
|
128 } |
|
129 |
|
130 function resumeAndTestBreakpoint(aLine) { |
|
131 let finished = waitForCaretUpdated(gPanel, aLine).then(() => testBreakpoint(aLine)); |
|
132 |
|
133 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
134 gDebugger.document.getElementById("resume"), |
|
135 gDebugger); |
|
136 |
|
137 return finished; |
|
138 } |
|
139 |
|
140 function resumeAndTestNoBreakpoint() { |
|
141 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { |
|
142 is(gSources.itemCount, 1, |
|
143 "Found the expected number of sources."); |
|
144 is(gEditor.getText().indexOf("ermahgerd"), 253, |
|
145 "The correct source was loaded initially."); |
|
146 is(gSources.selectedValue, gSources.values[0], |
|
147 "The correct source is selected."); |
|
148 |
|
149 ok(gSources.selectedItem, |
|
150 "There should be a selected source in the sources pane.") |
|
151 ok(!gSources._selectedBreakpointItem, |
|
152 "There should be no selected breakpoint in the sources pane.") |
|
153 is(gSources._conditionalPopupVisible, false, |
|
154 "The breakpoint conditional expression popup should not be shown."); |
|
155 |
|
156 is(gDebugger.document.querySelectorAll(".dbg-stackframe").length, 0, |
|
157 "There should be no visible stackframes."); |
|
158 is(gDebugger.document.querySelectorAll(".dbg-breakpoint").length, 13, |
|
159 "There should be thirteen visible breakpoints."); |
|
160 }); |
|
161 |
|
162 gDebugger.gThreadClient.resume(); |
|
163 |
|
164 return finished; |
|
165 } |
|
166 |
|
167 function testBreakpoint(aLine, aHighlightBreakpoint) { |
|
168 // Highlight the breakpoint only if required. |
|
169 if (aHighlightBreakpoint) { |
|
170 let finished = waitForCaretUpdated(gPanel, aLine).then(() => testBreakpoint(aLine)); |
|
171 gSources.highlightBreakpoint({ url: gSources.selectedValue, line: aLine }); |
|
172 return finished; |
|
173 } |
|
174 |
|
175 let selectedUrl = gSources.selectedValue; |
|
176 let selectedBreakpoint = gSources._selectedBreakpointItem; |
|
177 |
|
178 ok(selectedUrl, |
|
179 "There should be a selected item in the sources pane."); |
|
180 ok(selectedBreakpoint, |
|
181 "There should be a selected brekapoint in the sources pane."); |
|
182 |
|
183 is(selectedBreakpoint.attachment.url, selectedUrl, |
|
184 "The breakpoint on line " + aLine + " wasn't added on the correct source."); |
|
185 is(selectedBreakpoint.attachment.line, aLine, |
|
186 "The breakpoint on line " + aLine + " wasn't found."); |
|
187 is(!!selectedBreakpoint.attachment.disabled, false, |
|
188 "The breakpoint on line " + aLine + " should be enabled."); |
|
189 is(!!selectedBreakpoint.attachment.openPopup, false, |
|
190 "The breakpoint on line " + aLine + " should not have opened a popup."); |
|
191 is(gSources._conditionalPopupVisible, false, |
|
192 "The breakpoint conditional expression popup should not have been shown."); |
|
193 |
|
194 return gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => { |
|
195 is(aBreakpointClient.location.url, selectedUrl, |
|
196 "The breakpoint's client url is correct"); |
|
197 is(aBreakpointClient.location.line, aLine, |
|
198 "The breakpoint's client line is correct"); |
|
199 isnot(aBreakpointClient.condition, undefined, |
|
200 "The breakpoint on line " + aLine + " should have a conditional expression."); |
|
201 |
|
202 ok(isCaretPos(gPanel, aLine), |
|
203 "The editor caret position is not properly set."); |
|
204 }); |
|
205 } |
|
206 |
|
207 function testAfterReload() { |
|
208 let selectedUrl = gSources.selectedValue; |
|
209 let selectedBreakpoint = gSources._selectedBreakpointItem; |
|
210 |
|
211 ok(selectedUrl, |
|
212 "There should be a selected item in the sources pane after reload."); |
|
213 ok(!selectedBreakpoint, |
|
214 "There should be no selected brekapoint in the sources pane after reload."); |
|
215 |
|
216 return promise.resolve(null) |
|
217 .then(() => testBreakpoint(18, true)) |
|
218 .then(() => testBreakpoint(19, true)) |
|
219 .then(() => testBreakpoint(20, true)) |
|
220 .then(() => testBreakpoint(21, true)) |
|
221 .then(() => testBreakpoint(22, true)) |
|
222 .then(() => testBreakpoint(23, true)) |
|
223 .then(() => testBreakpoint(24, true)) |
|
224 .then(() => testBreakpoint(25, true)) |
|
225 .then(() => testBreakpoint(26, true)) |
|
226 .then(() => testBreakpoint(27, true)) |
|
227 .then(() => testBreakpoint(28, true)) |
|
228 .then(() => testBreakpoint(29, true)) |
|
229 .then(() => testBreakpoint(30, true)) |
|
230 .then(() => { |
|
231 is(gSources.itemCount, 1, |
|
232 "Found the expected number of sources."); |
|
233 is(gEditor.getText().indexOf("ermahgerd"), 253, |
|
234 "The correct source was loaded again."); |
|
235 is(gSources.selectedValue, gSources.values[0], |
|
236 "The correct source is selected."); |
|
237 |
|
238 ok(gSources.selectedItem, |
|
239 "There should be a selected source in the sources pane.") |
|
240 ok(gSources._selectedBreakpointItem, |
|
241 "There should be a selected breakpoint in the sources pane.") |
|
242 is(gSources._conditionalPopupVisible, false, |
|
243 "The breakpoint conditional expression popup should not be shown."); |
|
244 }); |
|
245 } |
|
246 } |