|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that pausing on exceptions works. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_pause-exceptions.html"; |
|
9 |
|
10 let gTab, gDebuggee, gPanel, gDebugger; |
|
11 let gFrames, gVariables, gPrefs, gOptions; |
|
12 |
|
13 function test() { |
|
14 requestLongerTimeout(2); |
|
15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
16 gTab = aTab; |
|
17 gDebuggee = aDebuggee; |
|
18 gPanel = aPanel; |
|
19 gDebugger = gPanel.panelWin; |
|
20 gFrames = gDebugger.DebuggerView.StackFrames; |
|
21 gVariables = gDebugger.DebuggerView.Variables; |
|
22 gPrefs = gDebugger.Prefs; |
|
23 gOptions = gDebugger.DebuggerView.Options; |
|
24 |
|
25 is(gPrefs.pauseOnExceptions, false, |
|
26 "The pause-on-exceptions pref should be disabled by default."); |
|
27 isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true", |
|
28 "The pause-on-exceptions menu item should not be checked."); |
|
29 |
|
30 testPauseOnExceptionsDisabled() |
|
31 .then(enablePauseOnExceptions) |
|
32 .then(disableIgnoreCaughtExceptions) |
|
33 .then(testPauseOnExceptionsEnabled) |
|
34 .then(disablePauseOnExceptions) |
|
35 .then(enableIgnoreCaughtExceptions) |
|
36 .then(() => closeDebuggerAndFinish(gPanel)) |
|
37 .then(null, aError => { |
|
38 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
39 }); |
|
40 }); |
|
41 } |
|
42 |
|
43 function testPauseOnExceptionsDisabled() { |
|
44 let finished = waitForCaretAndScopes(gPanel, 26).then(() => { |
|
45 info("Testing disabled pause-on-exceptions."); |
|
46 |
|
47 is(gDebugger.gThreadClient.state, "paused", |
|
48 "Should only be getting stack frames while paused (1)."); |
|
49 ok(isCaretPos(gPanel, 26), |
|
50 "Should be paused on the debugger statement (1)."); |
|
51 |
|
52 let innerScope = gVariables.getScopeAtIndex(0); |
|
53 let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes; |
|
54 |
|
55 is(gFrames.itemCount, 1, |
|
56 "Should have one frame."); |
|
57 is(gVariables._store.length, 3, |
|
58 "Should have three scopes."); |
|
59 |
|
60 is(innerNodes[0].querySelector(".name").getAttribute("value"), "this", |
|
61 "Should have the right property name for 'this'."); |
|
62 is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>", |
|
63 "Should have the right property value for 'this'."); |
|
64 |
|
65 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { |
|
66 isnot(gDebugger.gThreadClient.state, "paused", |
|
67 "Should not be paused after resuming."); |
|
68 ok(isCaretPos(gPanel, 26), |
|
69 "Should be idle on the debugger statement."); |
|
70 |
|
71 ok(true, "Frames were cleared, debugger didn't pause again."); |
|
72 }); |
|
73 |
|
74 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
75 gDebugger.document.getElementById("resume"), |
|
76 gDebugger); |
|
77 |
|
78 return finished; |
|
79 }); |
|
80 |
|
81 EventUtils.sendMouseEvent({ type: "click" }, |
|
82 gDebuggee.document.querySelector("button"), |
|
83 gDebuggee); |
|
84 |
|
85 return finished; |
|
86 } |
|
87 |
|
88 function testPauseOnExceptionsEnabled() { |
|
89 let finished = waitForCaretAndScopes(gPanel, 19).then(() => { |
|
90 info("Testing enabled pause-on-exceptions."); |
|
91 |
|
92 is(gDebugger.gThreadClient.state, "paused", |
|
93 "Should only be getting stack frames while paused."); |
|
94 ok(isCaretPos(gPanel, 19), |
|
95 "Should be paused on the debugger statement."); |
|
96 |
|
97 let innerScope = gVariables.getScopeAtIndex(0); |
|
98 let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes; |
|
99 |
|
100 is(gFrames.itemCount, 1, |
|
101 "Should have one frame."); |
|
102 is(gVariables._store.length, 3, |
|
103 "Should have three scopes."); |
|
104 |
|
105 is(innerNodes[0].querySelector(".name").getAttribute("value"), "<exception>", |
|
106 "Should have the right property name for <exception>."); |
|
107 is(innerNodes[0].querySelector(".value").getAttribute("value"), "Error", |
|
108 "Should have the right property value for <exception>."); |
|
109 |
|
110 let finished = waitForCaretAndScopes(gPanel, 26).then(() => { |
|
111 info("Testing enabled pause-on-exceptions and resumed after pause."); |
|
112 |
|
113 is(gDebugger.gThreadClient.state, "paused", |
|
114 "Should only be getting stack frames while paused."); |
|
115 ok(isCaretPos(gPanel, 26), |
|
116 "Should be paused on the debugger statement."); |
|
117 |
|
118 let innerScope = gVariables.getScopeAtIndex(0); |
|
119 let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes; |
|
120 |
|
121 is(gFrames.itemCount, 1, |
|
122 "Should have one frame."); |
|
123 is(gVariables._store.length, 3, |
|
124 "Should have three scopes."); |
|
125 |
|
126 is(innerNodes[0].querySelector(".name").getAttribute("value"), "this", |
|
127 "Should have the right property name for 'this'."); |
|
128 is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>", |
|
129 "Should have the right property value for 'this'."); |
|
130 |
|
131 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { |
|
132 isnot(gDebugger.gThreadClient.state, "paused", |
|
133 "Should not be paused after resuming."); |
|
134 ok(isCaretPos(gPanel, 26), |
|
135 "Should be idle on the debugger statement."); |
|
136 |
|
137 ok(true, "Frames were cleared, debugger didn't pause again."); |
|
138 }); |
|
139 |
|
140 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
141 gDebugger.document.getElementById("resume"), |
|
142 gDebugger); |
|
143 |
|
144 return finished; |
|
145 }); |
|
146 |
|
147 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
148 gDebugger.document.getElementById("resume"), |
|
149 gDebugger); |
|
150 |
|
151 return finished; |
|
152 }); |
|
153 |
|
154 EventUtils.sendMouseEvent({ type: "click" }, |
|
155 gDebuggee.document.querySelector("button"), |
|
156 gDebuggee); |
|
157 |
|
158 return finished; |
|
159 } |
|
160 |
|
161 function enablePauseOnExceptions() { |
|
162 let deferred = promise.defer(); |
|
163 |
|
164 gDebugger.gThreadClient.addOneTimeListener("resumed", () => { |
|
165 is(gPrefs.pauseOnExceptions, true, |
|
166 "The pause-on-exceptions pref should now be enabled."); |
|
167 is(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true", |
|
168 "The pause-on-exceptions menu item should now be checked."); |
|
169 |
|
170 ok(true, "Pausing on exceptions was enabled."); |
|
171 deferred.resolve(); |
|
172 }); |
|
173 |
|
174 gOptions._pauseOnExceptionsItem.setAttribute("checked", "true"); |
|
175 gOptions._togglePauseOnExceptions(); |
|
176 |
|
177 return deferred.promise; |
|
178 } |
|
179 |
|
180 function disablePauseOnExceptions() { |
|
181 let deferred = promise.defer(); |
|
182 |
|
183 gDebugger.gThreadClient.addOneTimeListener("resumed", () => { |
|
184 is(gPrefs.pauseOnExceptions, false, |
|
185 "The pause-on-exceptions pref should now be disabled."); |
|
186 isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true", |
|
187 "The pause-on-exceptions menu item should now be unchecked."); |
|
188 |
|
189 ok(true, "Pausing on exceptions was disabled."); |
|
190 deferred.resolve(); |
|
191 }); |
|
192 |
|
193 gOptions._pauseOnExceptionsItem.setAttribute("checked", "false"); |
|
194 gOptions._togglePauseOnExceptions(); |
|
195 |
|
196 return deferred.promise; |
|
197 } |
|
198 |
|
199 function enableIgnoreCaughtExceptions() { |
|
200 let deferred = promise.defer(); |
|
201 |
|
202 gDebugger.gThreadClient.addOneTimeListener("resumed", () => { |
|
203 is(gPrefs.ignoreCaughtExceptions, true, |
|
204 "The ignore-caught-exceptions pref should now be enabled."); |
|
205 is(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true", |
|
206 "The ignore-caught-exceptions menu item should now be checked."); |
|
207 |
|
208 ok(true, "Ignore caught exceptions was enabled."); |
|
209 deferred.resolve(); |
|
210 }); |
|
211 |
|
212 gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true"); |
|
213 gOptions._toggleIgnoreCaughtExceptions(); |
|
214 |
|
215 return deferred.promise; |
|
216 } |
|
217 |
|
218 function disableIgnoreCaughtExceptions() { |
|
219 let deferred = promise.defer(); |
|
220 |
|
221 gDebugger.gThreadClient.addOneTimeListener("resumed", () => { |
|
222 is(gPrefs.ignoreCaughtExceptions, false, |
|
223 "The ignore-caught-exceptions pref should now be disabled."); |
|
224 isnot(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true", |
|
225 "The ignore-caught-exceptions menu item should now be unchecked."); |
|
226 |
|
227 ok(true, "Ignore caught exceptions was disabled."); |
|
228 deferred.resolve(); |
|
229 }); |
|
230 |
|
231 gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false"); |
|
232 gOptions._toggleIgnoreCaughtExceptions(); |
|
233 |
|
234 return deferred.promise; |
|
235 } |
|
236 |
|
237 registerCleanupFunction(function() { |
|
238 gTab = null; |
|
239 gDebuggee = null; |
|
240 gPanel = null; |
|
241 gDebugger = null; |
|
242 gFrames = null; |
|
243 gVariables = null; |
|
244 gPrefs = null; |
|
245 gOptions = null; |
|
246 }); |