1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_pause-exceptions-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,246 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Make sure that pausing on exceptions works. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_pause-exceptions.html"; 1.12 + 1.13 +let gTab, gDebuggee, gPanel, gDebugger; 1.14 +let gFrames, gVariables, gPrefs, gOptions; 1.15 + 1.16 +function test() { 1.17 + requestLongerTimeout(2); 1.18 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.19 + gTab = aTab; 1.20 + gDebuggee = aDebuggee; 1.21 + gPanel = aPanel; 1.22 + gDebugger = gPanel.panelWin; 1.23 + gFrames = gDebugger.DebuggerView.StackFrames; 1.24 + gVariables = gDebugger.DebuggerView.Variables; 1.25 + gPrefs = gDebugger.Prefs; 1.26 + gOptions = gDebugger.DebuggerView.Options; 1.27 + 1.28 + is(gPrefs.pauseOnExceptions, false, 1.29 + "The pause-on-exceptions pref should be disabled by default."); 1.30 + isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true", 1.31 + "The pause-on-exceptions menu item should not be checked."); 1.32 + 1.33 + testPauseOnExceptionsDisabled() 1.34 + .then(enablePauseOnExceptions) 1.35 + .then(disableIgnoreCaughtExceptions) 1.36 + .then(testPauseOnExceptionsEnabled) 1.37 + .then(disablePauseOnExceptions) 1.38 + .then(enableIgnoreCaughtExceptions) 1.39 + .then(() => closeDebuggerAndFinish(gPanel)) 1.40 + .then(null, aError => { 1.41 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.42 + }); 1.43 + }); 1.44 +} 1.45 + 1.46 +function testPauseOnExceptionsDisabled() { 1.47 + let finished = waitForCaretAndScopes(gPanel, 26).then(() => { 1.48 + info("Testing disabled pause-on-exceptions."); 1.49 + 1.50 + is(gDebugger.gThreadClient.state, "paused", 1.51 + "Should only be getting stack frames while paused (1)."); 1.52 + ok(isCaretPos(gPanel, 26), 1.53 + "Should be paused on the debugger statement (1)."); 1.54 + 1.55 + let innerScope = gVariables.getScopeAtIndex(0); 1.56 + let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes; 1.57 + 1.58 + is(gFrames.itemCount, 1, 1.59 + "Should have one frame."); 1.60 + is(gVariables._store.length, 3, 1.61 + "Should have three scopes."); 1.62 + 1.63 + is(innerNodes[0].querySelector(".name").getAttribute("value"), "this", 1.64 + "Should have the right property name for 'this'."); 1.65 + is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>", 1.66 + "Should have the right property value for 'this'."); 1.67 + 1.68 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { 1.69 + isnot(gDebugger.gThreadClient.state, "paused", 1.70 + "Should not be paused after resuming."); 1.71 + ok(isCaretPos(gPanel, 26), 1.72 + "Should be idle on the debugger statement."); 1.73 + 1.74 + ok(true, "Frames were cleared, debugger didn't pause again."); 1.75 + }); 1.76 + 1.77 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.78 + gDebugger.document.getElementById("resume"), 1.79 + gDebugger); 1.80 + 1.81 + return finished; 1.82 + }); 1.83 + 1.84 + EventUtils.sendMouseEvent({ type: "click" }, 1.85 + gDebuggee.document.querySelector("button"), 1.86 + gDebuggee); 1.87 + 1.88 + return finished; 1.89 +} 1.90 + 1.91 +function testPauseOnExceptionsEnabled() { 1.92 + let finished = waitForCaretAndScopes(gPanel, 19).then(() => { 1.93 + info("Testing enabled pause-on-exceptions."); 1.94 + 1.95 + is(gDebugger.gThreadClient.state, "paused", 1.96 + "Should only be getting stack frames while paused."); 1.97 + ok(isCaretPos(gPanel, 19), 1.98 + "Should be paused on the debugger statement."); 1.99 + 1.100 + let innerScope = gVariables.getScopeAtIndex(0); 1.101 + let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes; 1.102 + 1.103 + is(gFrames.itemCount, 1, 1.104 + "Should have one frame."); 1.105 + is(gVariables._store.length, 3, 1.106 + "Should have three scopes."); 1.107 + 1.108 + is(innerNodes[0].querySelector(".name").getAttribute("value"), "<exception>", 1.109 + "Should have the right property name for <exception>."); 1.110 + is(innerNodes[0].querySelector(".value").getAttribute("value"), "Error", 1.111 + "Should have the right property value for <exception>."); 1.112 + 1.113 + let finished = waitForCaretAndScopes(gPanel, 26).then(() => { 1.114 + info("Testing enabled pause-on-exceptions and resumed after pause."); 1.115 + 1.116 + is(gDebugger.gThreadClient.state, "paused", 1.117 + "Should only be getting stack frames while paused."); 1.118 + ok(isCaretPos(gPanel, 26), 1.119 + "Should be paused on the debugger statement."); 1.120 + 1.121 + let innerScope = gVariables.getScopeAtIndex(0); 1.122 + let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes; 1.123 + 1.124 + is(gFrames.itemCount, 1, 1.125 + "Should have one frame."); 1.126 + is(gVariables._store.length, 3, 1.127 + "Should have three scopes."); 1.128 + 1.129 + is(innerNodes[0].querySelector(".name").getAttribute("value"), "this", 1.130 + "Should have the right property name for 'this'."); 1.131 + is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>", 1.132 + "Should have the right property value for 'this'."); 1.133 + 1.134 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { 1.135 + isnot(gDebugger.gThreadClient.state, "paused", 1.136 + "Should not be paused after resuming."); 1.137 + ok(isCaretPos(gPanel, 26), 1.138 + "Should be idle on the debugger statement."); 1.139 + 1.140 + ok(true, "Frames were cleared, debugger didn't pause again."); 1.141 + }); 1.142 + 1.143 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.144 + gDebugger.document.getElementById("resume"), 1.145 + gDebugger); 1.146 + 1.147 + return finished; 1.148 + }); 1.149 + 1.150 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.151 + gDebugger.document.getElementById("resume"), 1.152 + gDebugger); 1.153 + 1.154 + return finished; 1.155 + }); 1.156 + 1.157 + EventUtils.sendMouseEvent({ type: "click" }, 1.158 + gDebuggee.document.querySelector("button"), 1.159 + gDebuggee); 1.160 + 1.161 + return finished; 1.162 +} 1.163 + 1.164 +function enablePauseOnExceptions() { 1.165 + let deferred = promise.defer(); 1.166 + 1.167 + gDebugger.gThreadClient.addOneTimeListener("resumed", () => { 1.168 + is(gPrefs.pauseOnExceptions, true, 1.169 + "The pause-on-exceptions pref should now be enabled."); 1.170 + is(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true", 1.171 + "The pause-on-exceptions menu item should now be checked."); 1.172 + 1.173 + ok(true, "Pausing on exceptions was enabled."); 1.174 + deferred.resolve(); 1.175 + }); 1.176 + 1.177 + gOptions._pauseOnExceptionsItem.setAttribute("checked", "true"); 1.178 + gOptions._togglePauseOnExceptions(); 1.179 + 1.180 + return deferred.promise; 1.181 +} 1.182 + 1.183 +function disablePauseOnExceptions() { 1.184 + let deferred = promise.defer(); 1.185 + 1.186 + gDebugger.gThreadClient.addOneTimeListener("resumed", () => { 1.187 + is(gPrefs.pauseOnExceptions, false, 1.188 + "The pause-on-exceptions pref should now be disabled."); 1.189 + isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true", 1.190 + "The pause-on-exceptions menu item should now be unchecked."); 1.191 + 1.192 + ok(true, "Pausing on exceptions was disabled."); 1.193 + deferred.resolve(); 1.194 + }); 1.195 + 1.196 + gOptions._pauseOnExceptionsItem.setAttribute("checked", "false"); 1.197 + gOptions._togglePauseOnExceptions(); 1.198 + 1.199 + return deferred.promise; 1.200 +} 1.201 + 1.202 +function enableIgnoreCaughtExceptions() { 1.203 + let deferred = promise.defer(); 1.204 + 1.205 + gDebugger.gThreadClient.addOneTimeListener("resumed", () => { 1.206 + is(gPrefs.ignoreCaughtExceptions, true, 1.207 + "The ignore-caught-exceptions pref should now be enabled."); 1.208 + is(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true", 1.209 + "The ignore-caught-exceptions menu item should now be checked."); 1.210 + 1.211 + ok(true, "Ignore caught exceptions was enabled."); 1.212 + deferred.resolve(); 1.213 + }); 1.214 + 1.215 + gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true"); 1.216 + gOptions._toggleIgnoreCaughtExceptions(); 1.217 + 1.218 + return deferred.promise; 1.219 +} 1.220 + 1.221 +function disableIgnoreCaughtExceptions() { 1.222 + let deferred = promise.defer(); 1.223 + 1.224 + gDebugger.gThreadClient.addOneTimeListener("resumed", () => { 1.225 + is(gPrefs.ignoreCaughtExceptions, false, 1.226 + "The ignore-caught-exceptions pref should now be disabled."); 1.227 + isnot(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true", 1.228 + "The ignore-caught-exceptions menu item should now be unchecked."); 1.229 + 1.230 + ok(true, "Ignore caught exceptions was disabled."); 1.231 + deferred.resolve(); 1.232 + }); 1.233 + 1.234 + gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false"); 1.235 + gOptions._toggleIgnoreCaughtExceptions(); 1.236 + 1.237 + return deferred.promise; 1.238 +} 1.239 + 1.240 +registerCleanupFunction(function() { 1.241 + gTab = null; 1.242 + gDebuggee = null; 1.243 + gPanel = null; 1.244 + gDebugger = null; 1.245 + gFrames = null; 1.246 + gVariables = null; 1.247 + gPrefs = null; 1.248 + gOptions = null; 1.249 +});