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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_pause-exceptions-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,204 @@
     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 after reload.
     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 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.18 +    gTab = aTab;
    1.19 +    gDebuggee = aDebuggee;
    1.20 +    gPanel = aPanel;
    1.21 +    gDebugger = gPanel.panelWin;
    1.22 +    gFrames = gDebugger.DebuggerView.StackFrames;
    1.23 +    gVariables = gDebugger.DebuggerView.Variables;
    1.24 +    gPrefs = gDebugger.Prefs;
    1.25 +    gOptions = gDebugger.DebuggerView.Options;
    1.26 +
    1.27 +    is(gPrefs.pauseOnExceptions, false,
    1.28 +      "The pause-on-exceptions pref should be disabled by default.");
    1.29 +    isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
    1.30 +      "The pause-on-exceptions menu item should not be checked.");
    1.31 +
    1.32 +    enablePauseOnExceptions()
    1.33 +      .then(disableIgnoreCaughtExceptions)
    1.34 +      .then(() => reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN))
    1.35 +      .then(testPauseOnExceptionsAfterReload)
    1.36 +      .then(disablePauseOnExceptions)
    1.37 +      .then(enableIgnoreCaughtExceptions)
    1.38 +      .then(() => closeDebuggerAndFinish(gPanel))
    1.39 +      .then(null, aError => {
    1.40 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.41 +      });
    1.42 +  });
    1.43 +}
    1.44 +
    1.45 +function testPauseOnExceptionsAfterReload() {
    1.46 +  let finished = waitForCaretAndScopes(gPanel, 19).then(() => {
    1.47 +    info("Testing enabled pause-on-exceptions.");
    1.48 +
    1.49 +    is(gDebugger.gThreadClient.state, "paused",
    1.50 +      "Should only be getting stack frames while paused.");
    1.51 +    ok(isCaretPos(gPanel, 19),
    1.52 +      "Should be paused on the debugger statement.");
    1.53 +
    1.54 +    let innerScope = gVariables.getScopeAtIndex(0);
    1.55 +    let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
    1.56 +
    1.57 +    is(gFrames.itemCount, 1,
    1.58 +      "Should have one frame.");
    1.59 +    is(gVariables._store.length, 3,
    1.60 +      "Should have three scopes.");
    1.61 +
    1.62 +    is(innerNodes[0].querySelector(".name").getAttribute("value"), "<exception>",
    1.63 +      "Should have the right property name for <exception>.");
    1.64 +    is(innerNodes[0].querySelector(".value").getAttribute("value"), "Error",
    1.65 +      "Should have the right property value for <exception>.");
    1.66 +
    1.67 +    let finished = waitForCaretAndScopes(gPanel, 26).then(() => {
    1.68 +      info("Testing enabled pause-on-exceptions and resumed after pause.");
    1.69 +
    1.70 +      is(gDebugger.gThreadClient.state, "paused",
    1.71 +        "Should only be getting stack frames while paused.");
    1.72 +      ok(isCaretPos(gPanel, 26),
    1.73 +        "Should be paused on the debugger statement.");
    1.74 +
    1.75 +      let innerScope = gVariables.getScopeAtIndex(0);
    1.76 +      let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
    1.77 +
    1.78 +      is(gFrames.itemCount, 1,
    1.79 +        "Should have one frame.");
    1.80 +      is(gVariables._store.length, 3,
    1.81 +        "Should have three scopes.");
    1.82 +
    1.83 +      is(innerNodes[0].querySelector(".name").getAttribute("value"), "this",
    1.84 +        "Should have the right property name for 'this'.");
    1.85 +      is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>",
    1.86 +        "Should have the right property value for 'this'.");
    1.87 +
    1.88 +      let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
    1.89 +        isnot(gDebugger.gThreadClient.state, "paused",
    1.90 +          "Should not be paused after resuming.");
    1.91 +        ok(isCaretPos(gPanel, 26),
    1.92 +          "Should be idle on the debugger statement.");
    1.93 +
    1.94 +        ok(true, "Frames were cleared, debugger didn't pause again.");
    1.95 +      });
    1.96 +
    1.97 +      EventUtils.sendMouseEvent({ type: "mousedown" },
    1.98 +        gDebugger.document.getElementById("resume"),
    1.99 +        gDebugger);
   1.100 +
   1.101 +      return finished;
   1.102 +    });
   1.103 +
   1.104 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.105 +      gDebugger.document.getElementById("resume"),
   1.106 +      gDebugger);
   1.107 +
   1.108 +    return finished;
   1.109 +  });
   1.110 +
   1.111 +  // Spin the event loop before causing the debuggee to pause, to allow
   1.112 +  // this function to return first.
   1.113 +  executeSoon(() => {
   1.114 +    EventUtils.sendMouseEvent({ type: "click" },
   1.115 +      gDebuggee.document.querySelector("button"),
   1.116 +      gDebuggee.window);
   1.117 +  });
   1.118 +
   1.119 +  return finished;
   1.120 +}
   1.121 +
   1.122 +function enablePauseOnExceptions() {
   1.123 +  let deferred = promise.defer();
   1.124 +
   1.125 +  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   1.126 +    is(gPrefs.pauseOnExceptions, true,
   1.127 +      "The pause-on-exceptions pref should now be enabled.");
   1.128 +    is(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
   1.129 +      "The pause-on-exceptions menu item should now be checked.");
   1.130 +
   1.131 +    ok(true, "Pausing on exceptions was enabled.");
   1.132 +    deferred.resolve();
   1.133 +  });
   1.134 +
   1.135 +  gOptions._pauseOnExceptionsItem.setAttribute("checked", "true");
   1.136 +  gOptions._togglePauseOnExceptions();
   1.137 +
   1.138 +  return deferred.promise;
   1.139 +}
   1.140 +
   1.141 +function disablePauseOnExceptions() {
   1.142 +  let deferred = promise.defer();
   1.143 +
   1.144 +  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   1.145 +    is(gPrefs.pauseOnExceptions, false,
   1.146 +      "The pause-on-exceptions pref should now be disabled.");
   1.147 +    isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
   1.148 +      "The pause-on-exceptions menu item should now be unchecked.");
   1.149 +
   1.150 +    ok(true, "Pausing on exceptions was disabled.");
   1.151 +    deferred.resolve();
   1.152 +  });
   1.153 +
   1.154 +  gOptions._pauseOnExceptionsItem.setAttribute("checked", "false");
   1.155 +  gOptions._togglePauseOnExceptions();
   1.156 +
   1.157 +  return deferred.promise;
   1.158 +}
   1.159 +
   1.160 +function enableIgnoreCaughtExceptions() {
   1.161 +  let deferred = promise.defer();
   1.162 +
   1.163 +  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   1.164 +    is(gPrefs.ignoreCaughtExceptions, true,
   1.165 +      "The ignore-caught-exceptions pref should now be enabled.");
   1.166 +    is(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true",
   1.167 +      "The ignore-caught-exceptions menu item should now be checked.");
   1.168 +
   1.169 +    ok(true, "Ignore caught exceptions was enabled.");
   1.170 +    deferred.resolve();
   1.171 +  });
   1.172 +
   1.173 +  gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true");
   1.174 +  gOptions._toggleIgnoreCaughtExceptions();
   1.175 +
   1.176 +  return deferred.promise;
   1.177 +}
   1.178 +
   1.179 +function disableIgnoreCaughtExceptions() {
   1.180 +  let deferred = promise.defer();
   1.181 +
   1.182 +  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   1.183 +    is(gPrefs.ignoreCaughtExceptions, false,
   1.184 +      "The ignore-caught-exceptions pref should now be disabled.");
   1.185 +    isnot(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true",
   1.186 +      "The ignore-caught-exceptions menu item should now be unchecked.");
   1.187 +
   1.188 +    ok(true, "Ignore caught exceptions was disabled.");
   1.189 +    deferred.resolve();
   1.190 +  });
   1.191 +
   1.192 +  gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false");
   1.193 +  gOptions._toggleIgnoreCaughtExceptions();
   1.194 +
   1.195 +  return deferred.promise;
   1.196 +}
   1.197 +
   1.198 +registerCleanupFunction(function() {
   1.199 +  gTab = null;
   1.200 +  gDebuggee = null;
   1.201 +  gPanel = null;
   1.202 +  gDebugger = null;
   1.203 +  gFrames = null;
   1.204 +  gVariables = null;
   1.205 +  gPrefs = null;
   1.206 +  gOptions = null;
   1.207 +});

mercurial