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

mercurial