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.

     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.
     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   requestLongerTimeout(2);
    15   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    16     gTab = aTab;
    17     gDebuggee = aDebuggee;
    18     gPanel = aPanel;
    19     gDebugger = gPanel.panelWin;
    20     gFrames = gDebugger.DebuggerView.StackFrames;
    21     gVariables = gDebugger.DebuggerView.Variables;
    22     gPrefs = gDebugger.Prefs;
    23     gOptions = gDebugger.DebuggerView.Options;
    25     is(gPrefs.pauseOnExceptions, false,
    26       "The pause-on-exceptions pref should be disabled by default.");
    27     isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
    28       "The pause-on-exceptions menu item should not be checked.");
    30     testPauseOnExceptionsDisabled()
    31       .then(enablePauseOnExceptions)
    32       .then(disableIgnoreCaughtExceptions)
    33       .then(testPauseOnExceptionsEnabled)
    34       .then(disablePauseOnExceptions)
    35       .then(enableIgnoreCaughtExceptions)
    36       .then(() => closeDebuggerAndFinish(gPanel))
    37       .then(null, aError => {
    38         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    39       });
    40   });
    41 }
    43 function testPauseOnExceptionsDisabled() {
    44   let finished = waitForCaretAndScopes(gPanel, 26).then(() => {
    45     info("Testing disabled pause-on-exceptions.");
    47     is(gDebugger.gThreadClient.state, "paused",
    48       "Should only be getting stack frames while paused (1).");
    49     ok(isCaretPos(gPanel, 26),
    50       "Should be paused on the debugger statement (1).");
    52     let innerScope = gVariables.getScopeAtIndex(0);
    53     let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
    55     is(gFrames.itemCount, 1,
    56       "Should have one frame.");
    57     is(gVariables._store.length, 3,
    58       "Should have three scopes.");
    60     is(innerNodes[0].querySelector(".name").getAttribute("value"), "this",
    61       "Should have the right property name for 'this'.");
    62     is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>",
    63       "Should have the right property value for 'this'.");
    65     let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
    66       isnot(gDebugger.gThreadClient.state, "paused",
    67         "Should not be paused after resuming.");
    68       ok(isCaretPos(gPanel, 26),
    69         "Should be idle on the debugger statement.");
    71       ok(true, "Frames were cleared, debugger didn't pause again.");
    72     });
    74     EventUtils.sendMouseEvent({ type: "mousedown" },
    75       gDebugger.document.getElementById("resume"),
    76       gDebugger);
    78     return finished;
    79   });
    81   EventUtils.sendMouseEvent({ type: "click" },
    82     gDebuggee.document.querySelector("button"),
    83     gDebuggee);
    85   return finished;
    86 }
    88 function testPauseOnExceptionsEnabled() {
    89   let finished = waitForCaretAndScopes(gPanel, 19).then(() => {
    90     info("Testing enabled pause-on-exceptions.");
    92     is(gDebugger.gThreadClient.state, "paused",
    93       "Should only be getting stack frames while paused.");
    94     ok(isCaretPos(gPanel, 19),
    95       "Should be paused on the debugger statement.");
    97     let innerScope = gVariables.getScopeAtIndex(0);
    98     let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
   100     is(gFrames.itemCount, 1,
   101       "Should have one frame.");
   102     is(gVariables._store.length, 3,
   103       "Should have three scopes.");
   105     is(innerNodes[0].querySelector(".name").getAttribute("value"), "<exception>",
   106       "Should have the right property name for <exception>.");
   107     is(innerNodes[0].querySelector(".value").getAttribute("value"), "Error",
   108       "Should have the right property value for <exception>.");
   110     let finished = waitForCaretAndScopes(gPanel, 26).then(() => {
   111       info("Testing enabled pause-on-exceptions and resumed after pause.");
   113       is(gDebugger.gThreadClient.state, "paused",
   114         "Should only be getting stack frames while paused.");
   115       ok(isCaretPos(gPanel, 26),
   116         "Should be paused on the debugger statement.");
   118       let innerScope = gVariables.getScopeAtIndex(0);
   119       let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;
   121       is(gFrames.itemCount, 1,
   122         "Should have one frame.");
   123       is(gVariables._store.length, 3,
   124         "Should have three scopes.");
   126       is(innerNodes[0].querySelector(".name").getAttribute("value"), "this",
   127         "Should have the right property name for 'this'.");
   128       is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>",
   129         "Should have the right property value for 'this'.");
   131       let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
   132         isnot(gDebugger.gThreadClient.state, "paused",
   133           "Should not be paused after resuming.");
   134         ok(isCaretPos(gPanel, 26),
   135           "Should be idle on the debugger statement.");
   137         ok(true, "Frames were cleared, debugger didn't pause again.");
   138       });
   140       EventUtils.sendMouseEvent({ type: "mousedown" },
   141         gDebugger.document.getElementById("resume"),
   142         gDebugger);
   144       return finished;
   145     });
   147     EventUtils.sendMouseEvent({ type: "mousedown" },
   148       gDebugger.document.getElementById("resume"),
   149       gDebugger);
   151     return finished;
   152   });
   154   EventUtils.sendMouseEvent({ type: "click" },
   155     gDebuggee.document.querySelector("button"),
   156     gDebuggee);
   158   return finished;
   159 }
   161 function enablePauseOnExceptions() {
   162   let deferred = promise.defer();
   164   gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   165     is(gPrefs.pauseOnExceptions, true,
   166       "The pause-on-exceptions pref should now be enabled.");
   167     is(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
   168       "The pause-on-exceptions menu item should now be checked.");
   170     ok(true, "Pausing on exceptions was enabled.");
   171     deferred.resolve();
   172   });
   174   gOptions._pauseOnExceptionsItem.setAttribute("checked", "true");
   175   gOptions._togglePauseOnExceptions();
   177   return deferred.promise;
   178 }
   180 function disablePauseOnExceptions() {
   181   let deferred = promise.defer();
   183   gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   184     is(gPrefs.pauseOnExceptions, false,
   185       "The pause-on-exceptions pref should now be disabled.");
   186     isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
   187       "The pause-on-exceptions menu item should now be unchecked.");
   189     ok(true, "Pausing on exceptions was disabled.");
   190     deferred.resolve();
   191   });
   193   gOptions._pauseOnExceptionsItem.setAttribute("checked", "false");
   194   gOptions._togglePauseOnExceptions();
   196   return deferred.promise;
   197 }
   199 function enableIgnoreCaughtExceptions() {
   200   let deferred = promise.defer();
   202   gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   203     is(gPrefs.ignoreCaughtExceptions, true,
   204       "The ignore-caught-exceptions pref should now be enabled.");
   205     is(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true",
   206       "The ignore-caught-exceptions menu item should now be checked.");
   208     ok(true, "Ignore caught exceptions was enabled.");
   209     deferred.resolve();
   210   });
   212   gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true");
   213   gOptions._toggleIgnoreCaughtExceptions();
   215   return deferred.promise;
   216 }
   218 function disableIgnoreCaughtExceptions() {
   219   let deferred = promise.defer();
   221   gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   222     is(gPrefs.ignoreCaughtExceptions, false,
   223       "The ignore-caught-exceptions pref should now be disabled.");
   224     isnot(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true",
   225       "The ignore-caught-exceptions menu item should now be unchecked.");
   227     ok(true, "Ignore caught exceptions was disabled.");
   228     deferred.resolve();
   229   });
   231   gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false");
   232   gOptions._toggleIgnoreCaughtExceptions();
   234   return deferred.promise;
   235 }
   237 registerCleanupFunction(function() {
   238   gTab = null;
   239   gDebuggee = null;
   240   gPanel = null;
   241   gDebugger = null;
   242   gFrames = null;
   243   gVariables = null;
   244   gPrefs = null;
   245   gOptions = null;
   246 });

mercurial