browser/devtools/debugger/test/browser_dbg_pause-exceptions-02.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:c8c3b096a446
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 after reload.
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 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
15 gTab = aTab;
16 gDebuggee = aDebuggee;
17 gPanel = aPanel;
18 gDebugger = gPanel.panelWin;
19 gFrames = gDebugger.DebuggerView.StackFrames;
20 gVariables = gDebugger.DebuggerView.Variables;
21 gPrefs = gDebugger.Prefs;
22 gOptions = gDebugger.DebuggerView.Options;
23
24 is(gPrefs.pauseOnExceptions, false,
25 "The pause-on-exceptions pref should be disabled by default.");
26 isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
27 "The pause-on-exceptions menu item should not be checked.");
28
29 enablePauseOnExceptions()
30 .then(disableIgnoreCaughtExceptions)
31 .then(() => reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN))
32 .then(testPauseOnExceptionsAfterReload)
33 .then(disablePauseOnExceptions)
34 .then(enableIgnoreCaughtExceptions)
35 .then(() => closeDebuggerAndFinish(gPanel))
36 .then(null, aError => {
37 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
38 });
39 });
40 }
41
42 function testPauseOnExceptionsAfterReload() {
43 let finished = waitForCaretAndScopes(gPanel, 19).then(() => {
44 info("Testing enabled pause-on-exceptions.");
45
46 is(gDebugger.gThreadClient.state, "paused",
47 "Should only be getting stack frames while paused.");
48 ok(isCaretPos(gPanel, 19),
49 "Should be paused on the debugger statement.");
50
51 let innerScope = gVariables.getScopeAtIndex(0);
52 let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
53
54 is(gFrames.itemCount, 1,
55 "Should have one frame.");
56 is(gVariables._store.length, 3,
57 "Should have three scopes.");
58
59 is(innerNodes[0].querySelector(".name").getAttribute("value"), "<exception>",
60 "Should have the right property name for <exception>.");
61 is(innerNodes[0].querySelector(".value").getAttribute("value"), "Error",
62 "Should have the right property value for <exception>.");
63
64 let finished = waitForCaretAndScopes(gPanel, 26).then(() => {
65 info("Testing enabled pause-on-exceptions and resumed after pause.");
66
67 is(gDebugger.gThreadClient.state, "paused",
68 "Should only be getting stack frames while paused.");
69 ok(isCaretPos(gPanel, 26),
70 "Should be paused on the debugger statement.");
71
72 let innerScope = gVariables.getScopeAtIndex(0);
73 let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
74
75 is(gFrames.itemCount, 1,
76 "Should have one frame.");
77 is(gVariables._store.length, 3,
78 "Should have three scopes.");
79
80 is(innerNodes[0].querySelector(".name").getAttribute("value"), "this",
81 "Should have the right property name for 'this'.");
82 is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>",
83 "Should have the right property value for 'this'.");
84
85 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
86 isnot(gDebugger.gThreadClient.state, "paused",
87 "Should not be paused after resuming.");
88 ok(isCaretPos(gPanel, 26),
89 "Should be idle on the debugger statement.");
90
91 ok(true, "Frames were cleared, debugger didn't pause again.");
92 });
93
94 EventUtils.sendMouseEvent({ type: "mousedown" },
95 gDebugger.document.getElementById("resume"),
96 gDebugger);
97
98 return finished;
99 });
100
101 EventUtils.sendMouseEvent({ type: "mousedown" },
102 gDebugger.document.getElementById("resume"),
103 gDebugger);
104
105 return finished;
106 });
107
108 // Spin the event loop before causing the debuggee to pause, to allow
109 // this function to return first.
110 executeSoon(() => {
111 EventUtils.sendMouseEvent({ type: "click" },
112 gDebuggee.document.querySelector("button"),
113 gDebuggee.window);
114 });
115
116 return finished;
117 }
118
119 function enablePauseOnExceptions() {
120 let deferred = promise.defer();
121
122 gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
123 is(gPrefs.pauseOnExceptions, true,
124 "The pause-on-exceptions pref should now be enabled.");
125 is(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
126 "The pause-on-exceptions menu item should now be checked.");
127
128 ok(true, "Pausing on exceptions was enabled.");
129 deferred.resolve();
130 });
131
132 gOptions._pauseOnExceptionsItem.setAttribute("checked", "true");
133 gOptions._togglePauseOnExceptions();
134
135 return deferred.promise;
136 }
137
138 function disablePauseOnExceptions() {
139 let deferred = promise.defer();
140
141 gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
142 is(gPrefs.pauseOnExceptions, false,
143 "The pause-on-exceptions pref should now be disabled.");
144 isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
145 "The pause-on-exceptions menu item should now be unchecked.");
146
147 ok(true, "Pausing on exceptions was disabled.");
148 deferred.resolve();
149 });
150
151 gOptions._pauseOnExceptionsItem.setAttribute("checked", "false");
152 gOptions._togglePauseOnExceptions();
153
154 return deferred.promise;
155 }
156
157 function enableIgnoreCaughtExceptions() {
158 let deferred = promise.defer();
159
160 gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
161 is(gPrefs.ignoreCaughtExceptions, true,
162 "The ignore-caught-exceptions pref should now be enabled.");
163 is(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true",
164 "The ignore-caught-exceptions menu item should now be checked.");
165
166 ok(true, "Ignore caught exceptions was enabled.");
167 deferred.resolve();
168 });
169
170 gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true");
171 gOptions._toggleIgnoreCaughtExceptions();
172
173 return deferred.promise;
174 }
175
176 function disableIgnoreCaughtExceptions() {
177 let deferred = promise.defer();
178
179 gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
180 is(gPrefs.ignoreCaughtExceptions, false,
181 "The ignore-caught-exceptions pref should now be disabled.");
182 isnot(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true",
183 "The ignore-caught-exceptions menu item should now be unchecked.");
184
185 ok(true, "Ignore caught exceptions was disabled.");
186 deferred.resolve();
187 });
188
189 gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false");
190 gOptions._toggleIgnoreCaughtExceptions();
191
192 return deferred.promise;
193 }
194
195 registerCleanupFunction(function() {
196 gTab = null;
197 gDebuggee = null;
198 gPanel = null;
199 gDebugger = null;
200 gFrames = null;
201 gVariables = null;
202 gPrefs = null;
203 gOptions = null;
204 });

mercurial