browser/devtools/debugger/test/browser_dbg_search-global-02.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  * Tests if the global search results switch back and forth, and wrap around
     6  * when switching between them.
     7  */
     9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    11 let gTab, gDebuggee, gPanel, gDebugger;
    12 let gEditor, gSources, gSearchView, gSearchBox;
    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     gSearchView = gDebugger.DebuggerView.GlobalSearch;
    23     gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
    25     waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    26       .then(firstSearch)
    27       .then(doFirstJump)
    28       .then(doSecondJump)
    29       .then(doWrapAroundJump)
    30       .then(doBackwardsWrapAroundJump)
    31       .then(testSearchTokenEmpty)
    32       .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    33       .then(null, aError => {
    34         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    35       });
    37     gDebuggee.firstCall();
    38   });
    39 }
    41 function firstSearch() {
    42   let deferred = promise.defer();
    44   is(gSearchView.itemCount, 0,
    45     "The global search pane shouldn't have any entries yet.");
    46   is(gSearchView.widget._parent.hidden, true,
    47     "The global search pane shouldn't be visible yet.");
    48   is(gSearchView._splitter.hidden, true,
    49     "The global search pane splitter shouldn't be visible yet.");
    51   gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
    52     // Some operations are synchronously dispatched on the main thread,
    53     // to avoid blocking UI, thus giving the impression of faster searching.
    54     executeSoon(() => {
    55       info("Current source url:\n" + gSources.selectedValue);
    56       info("Debugger editor text:\n" + gEditor.getText());
    58       ok(isCaretPos(gPanel, 1),
    59         "The editor shouldn't have jumped to a matching line yet.");
    60       ok(gSources.selectedValue.contains("-02.js"),
    61         "The current source shouldn't have changed after a global search.");
    62       is(gSources.visibleItems.length, 2,
    63         "Not all the sources are shown after the global search.");
    65       deferred.resolve();
    66     });
    67   });
    69   setText(gSearchBox, "!eval");
    71   return deferred.promise;
    72 }
    74 function doFirstJump() {
    75   let deferred = promise.defer();
    77   waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => {
    78     info("Current source url:\n" + gSources.selectedValue);
    79     info("Debugger editor text:\n" + gEditor.getText());
    81     ok(gSources.selectedValue.contains("-01.js"),
    82       "The currently shown source is incorrect (1).");
    83     is(gSources.visibleItems.length, 2,
    84       "Not all the sources are shown after the global search (1).");
    86     // The editor's selected text takes a tick to update.
    87     executeSoon(() => {
    88       ok(isCaretPos(gPanel, 5, 7),
    89         "The editor didn't jump to the correct line (1).");
    90       is(gEditor.getSelection(), "eval",
    91         "The editor didn't select the correct text (1).");
    93       deferred.resolve();
    94     });
    95   });
    97   EventUtils.sendKey("DOWN", gDebugger);
    99   return deferred.promise;
   100 }
   102 function doSecondJump() {
   103   let deferred = promise.defer();
   105   waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => {
   106     info("Current source url:\n" + gSources.selectedValue);
   107     info("Debugger editor text:\n" + gEditor.getText());
   109     ok(gSources.selectedValue.contains("-02.js"),
   110       "The currently shown source is incorrect (2).");
   111     is(gSources.visibleItems.length, 2,
   112       "Not all the sources are shown after the global search (2).");
   114     // The editor's selected text takes a tick to update.
   115     executeSoon(() => {
   116       ok(isCaretPos(gPanel, 6, 7),
   117         "The editor didn't jump to the correct line (2).");
   118       is(gEditor.getSelection(), "eval",
   119         "The editor didn't select the correct text (2).");
   121       deferred.resolve();
   122     });
   123   });
   125   EventUtils.sendKey("DOWN", gDebugger);
   127   return deferred.promise;
   128 }
   130 function doWrapAroundJump() {
   131   let deferred = promise.defer();
   133   waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => {
   134     info("Current source url:\n" + gSources.selectedValue);
   135     info("Debugger editor text:\n" + gEditor.getText());
   137     ok(gSources.selectedValue.contains("-01.js"),
   138       "The currently shown source is incorrect (3).");
   139     is(gSources.visibleItems.length, 2,
   140       "Not all the sources are shown after the global search (3).");
   142     // The editor's selected text takes a tick to update.
   143     executeSoon(() => {
   144       ok(isCaretPos(gPanel, 5, 7),
   145         "The editor didn't jump to the correct line (3).");
   146       is(gEditor.getSelection(), "eval",
   147         "The editor didn't select the correct text (3).");
   149       deferred.resolve();
   150     });
   151   });
   153   EventUtils.sendKey("DOWN", gDebugger);
   155   return deferred.promise;
   156 }
   158 function doBackwardsWrapAroundJump() {
   159   let deferred = promise.defer();
   161   waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => {
   162     info("Current source url:\n" + gSources.selectedValue);
   163     info("Debugger editor text:\n" + gEditor.getText());
   165     ok(gSources.selectedValue.contains("-02.js"),
   166       "The currently shown source is incorrect (4).");
   167     is(gSources.visibleItems.length, 2,
   168       "Not all the sources are shown after the global search (4).");
   170     // The editor's selected text takes a tick to update.
   171     executeSoon(() => {
   172       ok(isCaretPos(gPanel, 6, 7),
   173         "The editor didn't jump to the correct line (4).");
   174       is(gEditor.getSelection(), "eval",
   175         "The editor didn't select the correct text (4).");
   177       deferred.resolve();
   178     });
   179   });
   181   EventUtils.sendKey("UP", gDebugger);
   183   return deferred.promise;
   184 }
   186 function testSearchTokenEmpty() {
   187   backspaceText(gSearchBox, 4);
   189   info("Current source url:\n" + gSources.selectedValue);
   190   info("Debugger editor text:\n" + gEditor.getText());
   192   ok(gSources.selectedValue.contains("-02.js"),
   193     "The currently shown source is incorrect (4).");
   194   is(gSources.visibleItems.length, 2,
   195     "Not all the sources are shown after the global search (4).");
   196   ok(isCaretPos(gPanel, 6, 7),
   197     "The editor didn't remain at the correct line (4).");
   198   is(gEditor.getSelection(), "",
   199     "The editor shouldn't keep the previous text selected (4).");
   201   is(gSearchView.itemCount, 0,
   202     "The global search pane shouldn't have any child nodes after clearing.");
   203   is(gSearchView.widget._parent.hidden, true,
   204     "The global search pane shouldn't be visible after clearing.");
   205   is(gSearchView._splitter.hidden, true,
   206     "The global search pane splitter shouldn't be visible after clearing.");
   207 }
   209 registerCleanupFunction(function() {
   210   gTab = null;
   211   gDebuggee = null;
   212   gPanel = null;
   213   gDebugger = null;
   214   gEditor = null;
   215   gSources = null;
   216   gSearchView = null;
   217   gSearchBox = null;
   218 });

mercurial