browser/devtools/debugger/test/browser_dbg_search-global-04.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-04.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     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 trigger MatchFound and NoMatchFound events
     1.9 + * properly, and triggers the expected UI behavior.
    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(secondSearch)
    1.31 +      .then(() => resumeDebuggerThenCloseAndFinish(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 +  gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
    1.44 +    // Some operations are synchronously dispatched on the main thread,
    1.45 +    // to avoid blocking UI, thus giving the impression of faster searching.
    1.46 +    executeSoon(() => {
    1.47 +      info("Current source url:\n" + gSources.selectedValue);
    1.48 +      info("Debugger editor text:\n" + gEditor.getText());
    1.49 +
    1.50 +      ok(isCaretPos(gPanel, 1),
    1.51 +        "The editor shouldn't have jumped to a matching line yet.");
    1.52 +      ok(gSources.selectedValue.contains("-02.js"),
    1.53 +        "The current source shouldn't have changed after a global search.");
    1.54 +      is(gSources.visibleItems.length, 2,
    1.55 +        "Not all the sources are shown after the global search.");
    1.56 +
    1.57 +      deferred.resolve();
    1.58 +    });
    1.59 +  });
    1.60 +
    1.61 +  setText(gSearchBox, "!eval");
    1.62 +
    1.63 +  return deferred.promise;
    1.64 +}
    1.65 +
    1.66 +function secondSearch() {
    1.67 +  let deferred = promise.defer();
    1.68 +
    1.69 +  gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_NOT_FOUND, () => {
    1.70 +    info("Current source url:\n" + gSources.selectedValue);
    1.71 +    info("Debugger editor text:\n" + gEditor.getText());
    1.72 +
    1.73 +    ok(isCaretPos(gPanel, 1),
    1.74 +      "The editor shouldn't have jumped to a matching line yet.");
    1.75 +    ok(gSources.selectedValue.contains("-02.js"),
    1.76 +      "The current source shouldn't have changed after a global search.");
    1.77 +    is(gSources.visibleItems.length, 2,
    1.78 +      "Not all the sources are shown after the global search.");
    1.79 +
    1.80 +    deferred.resolve();
    1.81 +  });
    1.82 +
    1.83 +  typeText(gSearchBox, "/");
    1.84 +
    1.85 +  return deferred.promise;
    1.86 +}
    1.87 +
    1.88 +registerCleanupFunction(function() {
    1.89 +  gTab = null;
    1.90 +  gDebuggee = null;
    1.91 +  gPanel = null;
    1.92 +  gDebugger = null;
    1.93 +  gEditor = null;
    1.94 +  gSources = null;
    1.95 +  gSearchView = null;
    1.96 +  gSearchBox = null;
    1.97 +});

mercurial