Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 /**
5 * Make sure that pausing on exceptions works after reload.
6 */
8 const TAB_URL = EXAMPLE_URL + "doc_pause-exceptions.html";
10 let gTab, gDebuggee, gPanel, gDebugger;
11 let gFrames, gVariables, gPrefs, gOptions;
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;
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.");
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 }
42 function testPauseOnExceptionsAfterReload() {
43 let finished = waitForCaretAndScopes(gPanel, 19).then(() => {
44 info("Testing enabled pause-on-exceptions.");
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.");
51 let innerScope = gVariables.getScopeAtIndex(0);
52 let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
54 is(gFrames.itemCount, 1,
55 "Should have one frame.");
56 is(gVariables._store.length, 3,
57 "Should have three scopes.");
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>.");
64 let finished = waitForCaretAndScopes(gPanel, 26).then(() => {
65 info("Testing enabled pause-on-exceptions and resumed after pause.");
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.");
72 let innerScope = gVariables.getScopeAtIndex(0);
73 let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
75 is(gFrames.itemCount, 1,
76 "Should have one frame.");
77 is(gVariables._store.length, 3,
78 "Should have three scopes.");
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'.");
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.");
91 ok(true, "Frames were cleared, debugger didn't pause again.");
92 });
94 EventUtils.sendMouseEvent({ type: "mousedown" },
95 gDebugger.document.getElementById("resume"),
96 gDebugger);
98 return finished;
99 });
101 EventUtils.sendMouseEvent({ type: "mousedown" },
102 gDebugger.document.getElementById("resume"),
103 gDebugger);
105 return finished;
106 });
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 });
116 return finished;
117 }
119 function enablePauseOnExceptions() {
120 let deferred = promise.defer();
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.");
128 ok(true, "Pausing on exceptions was enabled.");
129 deferred.resolve();
130 });
132 gOptions._pauseOnExceptionsItem.setAttribute("checked", "true");
133 gOptions._togglePauseOnExceptions();
135 return deferred.promise;
136 }
138 function disablePauseOnExceptions() {
139 let deferred = promise.defer();
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.");
147 ok(true, "Pausing on exceptions was disabled.");
148 deferred.resolve();
149 });
151 gOptions._pauseOnExceptionsItem.setAttribute("checked", "false");
152 gOptions._togglePauseOnExceptions();
154 return deferred.promise;
155 }
157 function enableIgnoreCaughtExceptions() {
158 let deferred = promise.defer();
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.");
166 ok(true, "Ignore caught exceptions was enabled.");
167 deferred.resolve();
168 });
170 gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true");
171 gOptions._toggleIgnoreCaughtExceptions();
173 return deferred.promise;
174 }
176 function disableIgnoreCaughtExceptions() {
177 let deferred = promise.defer();
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.");
185 ok(true, "Ignore caught exceptions was disabled.");
186 deferred.resolve();
187 });
189 gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false");
190 gOptions._toggleIgnoreCaughtExceptions();
192 return deferred.promise;
193 }
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 });