browser/devtools/debugger/test/browser_dbg_stack-05.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  * Test that switching between stack frames properly sets the current debugger
     6  * location in the source editor.
     7  */
     9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    11 let gTab, gDebuggee, gPanel, gDebugger;
    12 let gEditor, gSources, gFrames, gClassicFrames;
    14 function test() {
    15   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    16     gTab = aTab;
    17     gDebuggee = aDebuggee;
    18     gPanel = aPanel;
    19     gDebugger = gPanel.panelWin;
    20     gEditor = gDebugger.DebuggerView.editor;
    21     gSources = gDebugger.DebuggerView.Sources;
    22     gFrames = gDebugger.DebuggerView.StackFrames;
    23     gClassicFrames = gDebugger.DebuggerView.StackFramesClassicList;
    25     waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    26       .then(initialChecks)
    27       .then(testNewestTwoFrames)
    28       .then(testOldestTwoFrames)
    29       .then(testAfterResume)
    30       .then(() => closeDebuggerAndFinish(gPanel))
    31       .then(null, aError => {
    32         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    33       });
    35     gDebuggee.firstCall();
    36   });
    37 }
    39 function initialChecks() {
    40   is(gDebugger.gThreadClient.state, "paused",
    41     "Should only be getting stack frames while paused.");
    42   is(gFrames.itemCount, 4,
    43     "Should have four frames.");
    44   is(gClassicFrames.itemCount, 4,
    45     "Should also have four frames in the mirrored view.");
    46 }
    48 function testNewestTwoFrames() {
    49   let deferred = promise.defer();
    51   is(gFrames.selectedIndex, 3,
    52     "Newest frame should be selected by default.");
    53   is(gClassicFrames.selectedIndex, 0,
    54     "Newest frame should be selected in the mirrored view as well.");
    55   is(gSources.selectedIndex, 1,
    56     "The second source is selected in the widget.");
    57   ok(isCaretPos(gPanel, 1),
    58     "Editor caret location is correct (1).");
    60   // The editor's debug location takes a tick to update.
    61   executeSoon(() => {
    62     is(gEditor.getDebugLocation(), 0,
    63       "Editor debug location is correct.");
    65     EventUtils.sendMouseEvent({ type: "mousedown" },
    66       gFrames.getItemAtIndex(2).target,
    67       gDebugger);
    69     is(gFrames.selectedIndex, 2,
    70       "Third frame should be selected after click.");
    71     is(gClassicFrames.selectedIndex, 1,
    72       "Third frame should be selected in the mirrored view as well.");
    73     is(gSources.selectedIndex, 1,
    74       "The second source is still selected in the widget.");
    75     ok(isCaretPos(gPanel, 6),
    76       "Editor caret location is correct (2).");
    78     // The editor's debug location takes a tick to update.
    79     executeSoon(() => {
    80       is(gEditor.getDebugLocation(), 5,
    81         "Editor debug location is correct.");
    83       deferred.resolve();
    84     });
    85   });
    87   return deferred.promise;
    88 }
    90 function testOldestTwoFrames() {
    91   let deferred = promise.defer();
    93   waitForSourceAndCaret(gPanel, "-01.js", 1).then(waitForTick).then(() => {
    94     is(gFrames.selectedIndex, 1,
    95       "Second frame should be selected after click.");
    96     is(gClassicFrames.selectedIndex, 2,
    97       "Second frame should be selected in the mirrored view as well.");
    98     is(gSources.selectedIndex, 0,
    99       "The first source is now selected in the widget.");
   100     ok(isCaretPos(gPanel, 1),
   101       "Editor caret location is correct (3).");
   103     // The editor's debug location takes a tick to update.
   104     executeSoon(() => {
   105       is(gEditor.getDebugLocation(), 0,
   106         "Editor debug location is correct.");
   108       EventUtils.sendMouseEvent({ type: "mousedown" },
   109         gFrames.getItemAtIndex(0).target,
   110         gDebugger);
   112       is(gFrames.selectedIndex, 0,
   113         "Oldest frame should be selected after click.");
   114       is(gClassicFrames.selectedIndex, 3,
   115         "Oldest frame should be selected in the mirrored view as well.");
   116       is(gSources.selectedIndex, 0,
   117         "The first source is still selected in the widget.");
   118       ok(isCaretPos(gPanel, 5),
   119         "Editor caret location is correct (4).");
   121       // The editor's debug location takes a tick to update.
   122       executeSoon(() => {
   123         is(gEditor.getDebugLocation(), 4,
   124           "Editor debug location is correct.");
   126         deferred.resolve();
   127       });
   128     });
   129   });
   131   EventUtils.sendMouseEvent({ type: "mousedown" },
   132     gDebugger.document.querySelector("#stackframe-2"),
   133     gDebugger);
   135   return deferred.promise;
   136 }
   138 function testAfterResume() {
   139   let deferred = promise.defer();
   141   gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => {
   142     is(gFrames.itemCount, 0,
   143       "Should have no frames after resume.");
   144     is(gClassicFrames.itemCount, 0,
   145       "Should have no frames in the mirrored view as well.");
   146     ok(isCaretPos(gPanel, 5),
   147       "Editor caret location is correct after resume.");
   148     is(gEditor.getDebugLocation(), null,
   149       "Editor debug location is correct after resume.");
   151     deferred.resolve();
   152   }, true);
   154   gDebugger.gThreadClient.resume();
   156   return deferred.promise;
   157 }
   159 registerCleanupFunction(function() {
   160   gTab = null;
   161   gDebuggee = null;
   162   gPanel = null;
   163   gDebugger = null;
   164   gEditor = null;
   165   gSources = null;
   166   gFrames = null;
   167   gClassicFrames = null;
   168 });

mercurial