browser/devtools/debugger/test/browser_dbg_search-global-03.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-03.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     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 are cleared on location changes, and
     1.9 + * the expected UI behaviors are triggered.
    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(performTest)
    1.31 +      .then(() => closeDebuggerAndFinish(gPanel))
    1.32 +      .then(null, aError => {
    1.33 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.34 +      });
    1.35 +
    1.36 +    gDebuggee.firstCall();
    1.37 +  });
    1.38 +}
    1.39 +
    1.40 +function firstSearch() {
    1.41 +  let deferred = promise.defer();
    1.42 +
    1.43 +  is(gSearchView.itemCount, 0,
    1.44 +    "The global search pane shouldn't have any entries yet.");
    1.45 +  is(gSearchView.widget._parent.hidden, true,
    1.46 +    "The global search pane shouldn't be visible yet.");
    1.47 +  is(gSearchView._splitter.hidden, true,
    1.48 +    "The global search pane splitter shouldn't be visible yet.");
    1.49 +
    1.50 +  gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
    1.51 +    // Some operations are synchronously dispatched on the main thread,
    1.52 +    // to avoid blocking UI, thus giving the impression of faster searching.
    1.53 +    executeSoon(() => {
    1.54 +      info("Current source url:\n" + gSources.selectedValue);
    1.55 +      info("Debugger editor text:\n" + gEditor.getText());
    1.56 +
    1.57 +      ok(isCaretPos(gPanel, 1),
    1.58 +        "The editor shouldn't have jumped to a matching line yet.");
    1.59 +      ok(gSources.selectedValue.contains("-02.js"),
    1.60 +        "The current source shouldn't have changed after a global search.");
    1.61 +      is(gSources.visibleItems.length, 2,
    1.62 +        "Not all the sources are shown after the global search.");
    1.63 +
    1.64 +      deferred.resolve();
    1.65 +    });
    1.66 +  });
    1.67 +
    1.68 +  setText(gSearchBox, "!eval");
    1.69 +
    1.70 +  return deferred.promise;
    1.71 +}
    1.72 +
    1.73 +function performTest() {
    1.74 +  let deferred = promise.defer();
    1.75 +
    1.76 +  is(gSearchView.itemCount, 2,
    1.77 +    "The global search pane should have some entries from the previous search.");
    1.78 +  is(gSearchView.widget._parent.hidden, false,
    1.79 +    "The global search pane should be visible from the previous search.");
    1.80 +  is(gSearchView._splitter.hidden, false,
    1.81 +    "The global search pane splitter should be visible from the previous search.");
    1.82 +
    1.83 +  reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(() => {
    1.84 +    info("Current source url:\n" + gSources.selectedValue);
    1.85 +    info("Debugger editor text:\n" + gEditor.getText());
    1.86 +
    1.87 +    is(gSearchView.itemCount, 0,
    1.88 +      "The global search pane shouldn't have any entries after a page navigation.");
    1.89 +    is(gSearchView.widget._parent.hidden, true,
    1.90 +      "The global search pane shouldn't be visible after a page navigation.");
    1.91 +    is(gSearchView._splitter.hidden, true,
    1.92 +      "The global search pane splitter shouldn't be visible after a page navigation.");
    1.93 +
    1.94 +    deferred.resolve();
    1.95 +  });
    1.96 +
    1.97 +  return deferred.promise;
    1.98 +}
    1.99 +
   1.100 +registerCleanupFunction(function() {
   1.101 +  gTab = null;
   1.102 +  gDebuggee = null;
   1.103 +  gPanel = null;
   1.104 +  gDebugger = null;
   1.105 +  gEditor = null;
   1.106 +  gSources = null;
   1.107 +  gSearchView = null;
   1.108 +  gSearchBox = null;
   1.109 +});

mercurial