browser/devtools/debugger/test/browser_dbg_search-global-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_search-global-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,218 @@
     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 + * Tests if the global search results switch back and forth, and wrap around
     1.9 + * when switching between them.
    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, gSearchView, gSearchBox;
    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 +    gSearchView = gDebugger.DebuggerView.GlobalSearch;
    1.26 +    gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
    1.27 +
    1.28 +    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    1.29 +      .then(firstSearch)
    1.30 +      .then(doFirstJump)
    1.31 +      .then(doSecondJump)
    1.32 +      .then(doWrapAroundJump)
    1.33 +      .then(doBackwardsWrapAroundJump)
    1.34 +      .then(testSearchTokenEmpty)
    1.35 +      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    1.36 +      .then(null, aError => {
    1.37 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.38 +      });
    1.39 +
    1.40 +    gDebuggee.firstCall();
    1.41 +  });
    1.42 +}
    1.43 +
    1.44 +function firstSearch() {
    1.45 +  let deferred = promise.defer();
    1.46 +
    1.47 +  is(gSearchView.itemCount, 0,
    1.48 +    "The global search pane shouldn't have any entries yet.");
    1.49 +  is(gSearchView.widget._parent.hidden, true,
    1.50 +    "The global search pane shouldn't be visible yet.");
    1.51 +  is(gSearchView._splitter.hidden, true,
    1.52 +    "The global search pane splitter shouldn't be visible yet.");
    1.53 +
    1.54 +  gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
    1.55 +    // Some operations are synchronously dispatched on the main thread,
    1.56 +    // to avoid blocking UI, thus giving the impression of faster searching.
    1.57 +    executeSoon(() => {
    1.58 +      info("Current source url:\n" + gSources.selectedValue);
    1.59 +      info("Debugger editor text:\n" + gEditor.getText());
    1.60 +
    1.61 +      ok(isCaretPos(gPanel, 1),
    1.62 +        "The editor shouldn't have jumped to a matching line yet.");
    1.63 +      ok(gSources.selectedValue.contains("-02.js"),
    1.64 +        "The current source shouldn't have changed after a global search.");
    1.65 +      is(gSources.visibleItems.length, 2,
    1.66 +        "Not all the sources are shown after the global search.");
    1.67 +
    1.68 +      deferred.resolve();
    1.69 +    });
    1.70 +  });
    1.71 +
    1.72 +  setText(gSearchBox, "!eval");
    1.73 +
    1.74 +  return deferred.promise;
    1.75 +}
    1.76 +
    1.77 +function doFirstJump() {
    1.78 +  let deferred = promise.defer();
    1.79 +
    1.80 +  waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => {
    1.81 +    info("Current source url:\n" + gSources.selectedValue);
    1.82 +    info("Debugger editor text:\n" + gEditor.getText());
    1.83 +
    1.84 +    ok(gSources.selectedValue.contains("-01.js"),
    1.85 +      "The currently shown source is incorrect (1).");
    1.86 +    is(gSources.visibleItems.length, 2,
    1.87 +      "Not all the sources are shown after the global search (1).");
    1.88 +
    1.89 +    // The editor's selected text takes a tick to update.
    1.90 +    executeSoon(() => {
    1.91 +      ok(isCaretPos(gPanel, 5, 7),
    1.92 +        "The editor didn't jump to the correct line (1).");
    1.93 +      is(gEditor.getSelection(), "eval",
    1.94 +        "The editor didn't select the correct text (1).");
    1.95 +
    1.96 +      deferred.resolve();
    1.97 +    });
    1.98 +  });
    1.99 +
   1.100 +  EventUtils.sendKey("DOWN", gDebugger);
   1.101 +
   1.102 +  return deferred.promise;
   1.103 +}
   1.104 +
   1.105 +function doSecondJump() {
   1.106 +  let deferred = promise.defer();
   1.107 +
   1.108 +  waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => {
   1.109 +    info("Current source url:\n" + gSources.selectedValue);
   1.110 +    info("Debugger editor text:\n" + gEditor.getText());
   1.111 +
   1.112 +    ok(gSources.selectedValue.contains("-02.js"),
   1.113 +      "The currently shown source is incorrect (2).");
   1.114 +    is(gSources.visibleItems.length, 2,
   1.115 +      "Not all the sources are shown after the global search (2).");
   1.116 +
   1.117 +    // The editor's selected text takes a tick to update.
   1.118 +    executeSoon(() => {
   1.119 +      ok(isCaretPos(gPanel, 6, 7),
   1.120 +        "The editor didn't jump to the correct line (2).");
   1.121 +      is(gEditor.getSelection(), "eval",
   1.122 +        "The editor didn't select the correct text (2).");
   1.123 +
   1.124 +      deferred.resolve();
   1.125 +    });
   1.126 +  });
   1.127 +
   1.128 +  EventUtils.sendKey("DOWN", gDebugger);
   1.129 +
   1.130 +  return deferred.promise;
   1.131 +}
   1.132 +
   1.133 +function doWrapAroundJump() {
   1.134 +  let deferred = promise.defer();
   1.135 +
   1.136 +  waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => {
   1.137 +    info("Current source url:\n" + gSources.selectedValue);
   1.138 +    info("Debugger editor text:\n" + gEditor.getText());
   1.139 +
   1.140 +    ok(gSources.selectedValue.contains("-01.js"),
   1.141 +      "The currently shown source is incorrect (3).");
   1.142 +    is(gSources.visibleItems.length, 2,
   1.143 +      "Not all the sources are shown after the global search (3).");
   1.144 +
   1.145 +    // The editor's selected text takes a tick to update.
   1.146 +    executeSoon(() => {
   1.147 +      ok(isCaretPos(gPanel, 5, 7),
   1.148 +        "The editor didn't jump to the correct line (3).");
   1.149 +      is(gEditor.getSelection(), "eval",
   1.150 +        "The editor didn't select the correct text (3).");
   1.151 +
   1.152 +      deferred.resolve();
   1.153 +    });
   1.154 +  });
   1.155 +
   1.156 +  EventUtils.sendKey("DOWN", gDebugger);
   1.157 +
   1.158 +  return deferred.promise;
   1.159 +}
   1.160 +
   1.161 +function doBackwardsWrapAroundJump() {
   1.162 +  let deferred = promise.defer();
   1.163 +
   1.164 +  waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => {
   1.165 +    info("Current source url:\n" + gSources.selectedValue);
   1.166 +    info("Debugger editor text:\n" + gEditor.getText());
   1.167 +
   1.168 +    ok(gSources.selectedValue.contains("-02.js"),
   1.169 +      "The currently shown source is incorrect (4).");
   1.170 +    is(gSources.visibleItems.length, 2,
   1.171 +      "Not all the sources are shown after the global search (4).");
   1.172 +
   1.173 +    // The editor's selected text takes a tick to update.
   1.174 +    executeSoon(() => {
   1.175 +      ok(isCaretPos(gPanel, 6, 7),
   1.176 +        "The editor didn't jump to the correct line (4).");
   1.177 +      is(gEditor.getSelection(), "eval",
   1.178 +        "The editor didn't select the correct text (4).");
   1.179 +
   1.180 +      deferred.resolve();
   1.181 +    });
   1.182 +  });
   1.183 +
   1.184 +  EventUtils.sendKey("UP", gDebugger);
   1.185 +
   1.186 +  return deferred.promise;
   1.187 +}
   1.188 +
   1.189 +function testSearchTokenEmpty() {
   1.190 +  backspaceText(gSearchBox, 4);
   1.191 +
   1.192 +  info("Current source url:\n" + gSources.selectedValue);
   1.193 +  info("Debugger editor text:\n" + gEditor.getText());
   1.194 +
   1.195 +  ok(gSources.selectedValue.contains("-02.js"),
   1.196 +    "The currently shown source is incorrect (4).");
   1.197 +  is(gSources.visibleItems.length, 2,
   1.198 +    "Not all the sources are shown after the global search (4).");
   1.199 +  ok(isCaretPos(gPanel, 6, 7),
   1.200 +    "The editor didn't remain at the correct line (4).");
   1.201 +  is(gEditor.getSelection(), "",
   1.202 +    "The editor shouldn't keep the previous text selected (4).");
   1.203 +
   1.204 +  is(gSearchView.itemCount, 0,
   1.205 +    "The global search pane shouldn't have any child nodes after clearing.");
   1.206 +  is(gSearchView.widget._parent.hidden, true,
   1.207 +    "The global search pane shouldn't be visible after clearing.");
   1.208 +  is(gSearchView._splitter.hidden, true,
   1.209 +    "The global search pane splitter shouldn't be visible after clearing.");
   1.210 +}
   1.211 +
   1.212 +registerCleanupFunction(function() {
   1.213 +  gTab = null;
   1.214 +  gDebuggee = null;
   1.215 +  gPanel = null;
   1.216 +  gDebugger = null;
   1.217 +  gEditor = null;
   1.218 +  gSources = null;
   1.219 +  gSearchView = null;
   1.220 +  gSearchBox = null;
   1.221 +});

mercurial