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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial