browser/devtools/debugger/test/browser_dbg_stack-05.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_stack-05.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,169 @@
     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 + * Test that switching between stack frames properly sets the current debugger
     1.9 + * location in the source editor.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    1.13 +
    1.14 +let gTab, gDebuggee, gPanel, gDebugger;
    1.15 +let gEditor, gSources, gFrames, gClassicFrames;
    1.16 +
    1.17 +function test() {
    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 +    gEditor = gDebugger.DebuggerView.editor;
    1.24 +    gSources = gDebugger.DebuggerView.Sources;
    1.25 +    gFrames = gDebugger.DebuggerView.StackFrames;
    1.26 +    gClassicFrames = gDebugger.DebuggerView.StackFramesClassicList;
    1.27 +
    1.28 +    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    1.29 +      .then(initialChecks)
    1.30 +      .then(testNewestTwoFrames)
    1.31 +      .then(testOldestTwoFrames)
    1.32 +      .then(testAfterResume)
    1.33 +      .then(() => closeDebuggerAndFinish(gPanel))
    1.34 +      .then(null, aError => {
    1.35 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.36 +      });
    1.37 +
    1.38 +    gDebuggee.firstCall();
    1.39 +  });
    1.40 +}
    1.41 +
    1.42 +function initialChecks() {
    1.43 +  is(gDebugger.gThreadClient.state, "paused",
    1.44 +    "Should only be getting stack frames while paused.");
    1.45 +  is(gFrames.itemCount, 4,
    1.46 +    "Should have four frames.");
    1.47 +  is(gClassicFrames.itemCount, 4,
    1.48 +    "Should also have four frames in the mirrored view.");
    1.49 +}
    1.50 +
    1.51 +function testNewestTwoFrames() {
    1.52 +  let deferred = promise.defer();
    1.53 +
    1.54 +  is(gFrames.selectedIndex, 3,
    1.55 +    "Newest frame should be selected by default.");
    1.56 +  is(gClassicFrames.selectedIndex, 0,
    1.57 +    "Newest frame should be selected in the mirrored view as well.");
    1.58 +  is(gSources.selectedIndex, 1,
    1.59 +    "The second source is selected in the widget.");
    1.60 +  ok(isCaretPos(gPanel, 1),
    1.61 +    "Editor caret location is correct (1).");
    1.62 +
    1.63 +  // The editor's debug location takes a tick to update.
    1.64 +  executeSoon(() => {
    1.65 +    is(gEditor.getDebugLocation(), 0,
    1.66 +      "Editor debug location is correct.");
    1.67 +
    1.68 +    EventUtils.sendMouseEvent({ type: "mousedown" },
    1.69 +      gFrames.getItemAtIndex(2).target,
    1.70 +      gDebugger);
    1.71 +
    1.72 +    is(gFrames.selectedIndex, 2,
    1.73 +      "Third frame should be selected after click.");
    1.74 +    is(gClassicFrames.selectedIndex, 1,
    1.75 +      "Third frame should be selected in the mirrored view as well.");
    1.76 +    is(gSources.selectedIndex, 1,
    1.77 +      "The second source is still selected in the widget.");
    1.78 +    ok(isCaretPos(gPanel, 6),
    1.79 +      "Editor caret location is correct (2).");
    1.80 +
    1.81 +    // The editor's debug location takes a tick to update.
    1.82 +    executeSoon(() => {
    1.83 +      is(gEditor.getDebugLocation(), 5,
    1.84 +        "Editor debug location is correct.");
    1.85 +
    1.86 +      deferred.resolve();
    1.87 +    });
    1.88 +  });
    1.89 +
    1.90 +  return deferred.promise;
    1.91 +}
    1.92 +
    1.93 +function testOldestTwoFrames() {
    1.94 +  let deferred = promise.defer();
    1.95 +
    1.96 +  waitForSourceAndCaret(gPanel, "-01.js", 1).then(waitForTick).then(() => {
    1.97 +    is(gFrames.selectedIndex, 1,
    1.98 +      "Second frame should be selected after click.");
    1.99 +    is(gClassicFrames.selectedIndex, 2,
   1.100 +      "Second frame should be selected in the mirrored view as well.");
   1.101 +    is(gSources.selectedIndex, 0,
   1.102 +      "The first source is now selected in the widget.");
   1.103 +    ok(isCaretPos(gPanel, 1),
   1.104 +      "Editor caret location is correct (3).");
   1.105 +
   1.106 +    // The editor's debug location takes a tick to update.
   1.107 +    executeSoon(() => {
   1.108 +      is(gEditor.getDebugLocation(), 0,
   1.109 +        "Editor debug location is correct.");
   1.110 +
   1.111 +      EventUtils.sendMouseEvent({ type: "mousedown" },
   1.112 +        gFrames.getItemAtIndex(0).target,
   1.113 +        gDebugger);
   1.114 +
   1.115 +      is(gFrames.selectedIndex, 0,
   1.116 +        "Oldest frame should be selected after click.");
   1.117 +      is(gClassicFrames.selectedIndex, 3,
   1.118 +        "Oldest frame should be selected in the mirrored view as well.");
   1.119 +      is(gSources.selectedIndex, 0,
   1.120 +        "The first source is still selected in the widget.");
   1.121 +      ok(isCaretPos(gPanel, 5),
   1.122 +        "Editor caret location is correct (4).");
   1.123 +
   1.124 +      // The editor's debug location takes a tick to update.
   1.125 +      executeSoon(() => {
   1.126 +        is(gEditor.getDebugLocation(), 4,
   1.127 +          "Editor debug location is correct.");
   1.128 +
   1.129 +        deferred.resolve();
   1.130 +      });
   1.131 +    });
   1.132 +  });
   1.133 +
   1.134 +  EventUtils.sendMouseEvent({ type: "mousedown" },
   1.135 +    gDebugger.document.querySelector("#stackframe-2"),
   1.136 +    gDebugger);
   1.137 +
   1.138 +  return deferred.promise;
   1.139 +}
   1.140 +
   1.141 +function testAfterResume() {
   1.142 +  let deferred = promise.defer();
   1.143 +
   1.144 +  gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => {
   1.145 +    is(gFrames.itemCount, 0,
   1.146 +      "Should have no frames after resume.");
   1.147 +    is(gClassicFrames.itemCount, 0,
   1.148 +      "Should have no frames in the mirrored view as well.");
   1.149 +    ok(isCaretPos(gPanel, 5),
   1.150 +      "Editor caret location is correct after resume.");
   1.151 +    is(gEditor.getDebugLocation(), null,
   1.152 +      "Editor debug location is correct after resume.");
   1.153 +
   1.154 +    deferred.resolve();
   1.155 +  }, true);
   1.156 +
   1.157 +  gDebugger.gThreadClient.resume();
   1.158 +
   1.159 +  return deferred.promise;
   1.160 +}
   1.161 +
   1.162 +registerCleanupFunction(function() {
   1.163 +  gTab = null;
   1.164 +  gDebuggee = null;
   1.165 +  gPanel = null;
   1.166 +  gDebugger = null;
   1.167 +  gEditor = null;
   1.168 +  gSources = null;
   1.169 +  gFrames = null;
   1.170 +  gClassicFrames = null;
   1.171 +});
   1.172 +

mercurial