browser/devtools/debugger/test/browser_dbg_scripts-switching-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_scripts-switching-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,187 @@
     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 switching the displayed source in the UI works as advertised.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-02.html";
    1.12 +
    1.13 +let gTab, gDebuggee, gPanel, gDebugger;
    1.14 +let gEditor, gSources;
    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 +    gEditor = gDebugger.DebuggerView.editor;
    1.23 +    gSources = gDebugger.DebuggerView.Sources;
    1.24 +
    1.25 +    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    1.26 +      .then(testSourcesDisplay)
    1.27 +      .then(testSwitchPaused1)
    1.28 +      .then(testSwitchPaused2)
    1.29 +      .then(testSwitchRunning)
    1.30 +      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    1.31 +      .then(null, aError => {
    1.32 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.33 +      });
    1.34 +
    1.35 +    gDebuggee.firstCall();
    1.36 +  });
    1.37 +}
    1.38 +
    1.39 +let gLabel1 = "code_script-switching-01.js";
    1.40 +let gLabel2 = "code_script-switching-02.js";
    1.41 +let gParams = "?foo=bar,baz|lol";
    1.42 +
    1.43 +function testSourcesDisplay() {
    1.44 +  let deferred = promise.defer();
    1.45 +
    1.46 +  is(gSources.itemCount, 2,
    1.47 +    "Found the expected number of sources.");
    1.48 +
    1.49 +  ok(gSources.containsValue(EXAMPLE_URL + gLabel1),
    1.50 +    "First source url is incorrect.");
    1.51 +  ok(gSources.containsValue(EXAMPLE_URL + gLabel2 + gParams),
    1.52 +    "Second source url is incorrect.");
    1.53 +
    1.54 +  ok(gSources.getItemForAttachment(e => e.label == gLabel1),
    1.55 +    "First source label is incorrect.");
    1.56 +  ok(gSources.getItemForAttachment(e => e.label == gLabel2),
    1.57 +    "Second source label is incorrect.");
    1.58 +
    1.59 +  ok(gSources.selectedItem,
    1.60 +    "There should be a selected item in the sources pane.");
    1.61 +  is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams,
    1.62 +    "The selected value is the sources pane is incorrect.");
    1.63 +
    1.64 +  is(gEditor.getText().search(/firstCall/), -1,
    1.65 +    "The first source is not displayed.");
    1.66 +  is(gEditor.getText().search(/debugger/), 172,
    1.67 +    "The second source is displayed.");
    1.68 +
    1.69 +  ok(isCaretPos(gPanel, 1),
    1.70 +    "Editor caret location is correct.");
    1.71 +
    1.72 +  // The editor's debug location takes a tick to update.
    1.73 +  executeSoon(() => {
    1.74 +    is(gEditor.getDebugLocation(), 0,
    1.75 +      "Editor debugger location is correct.");
    1.76 +    ok(gEditor.hasLineClass(0, "debug-line"),
    1.77 +      "The debugged line is highlighted appropriately.");
    1.78 +
    1.79 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
    1.80 +    gSources.selectedItem = e => e.attachment.label == gLabel1;
    1.81 +  });
    1.82 +
    1.83 +  return deferred.promise;
    1.84 +}
    1.85 +
    1.86 +function testSwitchPaused1() {
    1.87 +  let deferred = promise.defer();
    1.88 +
    1.89 +  ok(gSources.selectedItem,
    1.90 +    "There should be a selected item in the sources pane.");
    1.91 +  is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
    1.92 +    "The selected value is the sources pane is incorrect.");
    1.93 +
    1.94 +  is(gEditor.getText().search(/firstCall/), 118,
    1.95 +    "The first source is displayed.");
    1.96 +  is(gEditor.getText().search(/debugger/), -1,
    1.97 +    "The second source is not displayed.");
    1.98 +
    1.99 +  // The editor's debug location takes a tick to update.
   1.100 +  executeSoon(() => {
   1.101 +    ok(isCaretPos(gPanel, 1),
   1.102 +      "Editor caret location is correct.");
   1.103 +
   1.104 +    is(gEditor.getDebugLocation(), null,
   1.105 +      "Editor debugger location is correct.");
   1.106 +    ok(!gEditor.hasLineClass(5, "debug-line"),
   1.107 +      "The debugged line highlight was removed.");
   1.108 +
   1.109 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
   1.110 +    gSources.selectedItem = e => e.attachment.label == gLabel2;
   1.111 +  });
   1.112 +
   1.113 +  return deferred.promise;
   1.114 +}
   1.115 +
   1.116 +function testSwitchPaused2() {
   1.117 +  let deferred = promise.defer();
   1.118 +
   1.119 +  ok(gSources.selectedItem,
   1.120 +    "There should be a selected item in the sources pane.");
   1.121 +  is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams,
   1.122 +    "The selected value is the sources pane is incorrect.");
   1.123 +
   1.124 +  is(gEditor.getText().search(/firstCall/), -1,
   1.125 +    "The first source is not displayed.");
   1.126 +  is(gEditor.getText().search(/debugger/), 172,
   1.127 +    "The second source is displayed.");
   1.128 +
   1.129 +  // The editor's debug location takes a tick to update.
   1.130 +  executeSoon(() => {
   1.131 +    ok(isCaretPos(gPanel, 1),
   1.132 +      "Editor caret location is correct.");
   1.133 +    is(gEditor.getDebugLocation(), 0,
   1.134 +      "Editor debugger location is correct.");
   1.135 +    ok(gEditor.hasLineClass(0, "debug-line"),
   1.136 +      "The debugged line is highlighted appropriately.");
   1.137 +
   1.138 +    // Step out three times.
   1.139 +    waitForThreadEvents(gPanel, "paused").then(() => {
   1.140 +      waitForThreadEvents(gPanel, "paused").then(() => {
   1.141 +        waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
   1.142 +        gDebugger.gThreadClient.stepOut();
   1.143 +      });
   1.144 +      gDebugger.gThreadClient.stepOut();
   1.145 +    });
   1.146 +    gDebugger.gThreadClient.stepOut();
   1.147 +  });
   1.148 +
   1.149 +  return deferred.promise;
   1.150 +}
   1.151 +
   1.152 +function testSwitchRunning() {
   1.153 +  let deferred = promise.defer();
   1.154 +
   1.155 +  ok(gSources.selectedItem,
   1.156 +    "There should be a selected item in the sources pane.");
   1.157 +  is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
   1.158 +    "The selected value is the sources pane is incorrect.");
   1.159 +
   1.160 +  is(gEditor.getText().search(/firstCall/), 118,
   1.161 +    "The first source is displayed.");
   1.162 +  is(gEditor.getText().search(/debugger/), -1,
   1.163 +    "The second source is not displayed.");
   1.164 +
   1.165 +  // The editor's debug location takes a tick to update.
   1.166 +  executeSoon(() => {
   1.167 +    ok(isCaretPos(gPanel, 1),
   1.168 +      "Editor caret location is correct.");
   1.169 +    is(gEditor.getDebugLocation(), 0,
   1.170 +      "Editor debugger location is correct.");
   1.171 +    ok(gEditor.hasLineClass(0, "debug-line"),
   1.172 +      "The debugged line is highlighted appropriately.");
   1.173 +
   1.174 +    deferred.resolve();
   1.175 +  });
   1.176 +
   1.177 +  return deferred.promise;
   1.178 +}
   1.179 +
   1.180 +registerCleanupFunction(function() {
   1.181 +  gTab = null;
   1.182 +  gDebuggee = null;
   1.183 +  gPanel = null;
   1.184 +  gDebugger = null;
   1.185 +  gEditor = null;
   1.186 +  gSources = null;
   1.187 +  gLabel1 = null;
   1.188 +  gLabel2 = null;
   1.189 +  gParams = null;
   1.190 +});

mercurial