browser/devtools/debugger/test/browser_dbg_search-basic-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-basic-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     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 basic file search functionality.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    1.12 +
    1.13 +let gTab, gDebuggee, gPanel, gDebugger;
    1.14 +let gSources, gSearchBox;
    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 +    gSources = gDebugger.DebuggerView.Sources;
    1.23 +    gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
    1.24 +
    1.25 +    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    1.26 +      .then(performSimpleSearch)
    1.27 +      .then(() => verifySourceAndCaret("-01.js", 1, 1, [1, 1]))
    1.28 +      .then(combineWithLineSearch)
    1.29 +      .then(() => verifySourceAndCaret("-01.js", 2, 1, [53, 53]))
    1.30 +      .then(combineWithTokenSearch)
    1.31 +      .then(() => verifySourceAndCaret("-01.js", 2, 48, [96, 100]))
    1.32 +      .then(combineWithTokenColonSearch)
    1.33 +      .then(() => verifySourceAndCaret("-01.js", 2, 11, [56, 63]))
    1.34 +      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    1.35 +      .then(null, aError => {
    1.36 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.37 +      });
    1.38 +
    1.39 +    gDebuggee.firstCall();
    1.40 +  });
    1.41 +}
    1.42 +
    1.43 +function performSimpleSearch() {
    1.44 +  let finished = promise.all([
    1.45 +    ensureSourceIs(gPanel, "-02.js"),
    1.46 +    ensureCaretAt(gPanel, 1),
    1.47 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
    1.48 +    waitForSourceShown(gPanel, "-01.js")
    1.49 +  ]);
    1.50 +
    1.51 +  setText(gSearchBox, "1");
    1.52 +
    1.53 +  return finished.then(() => promise.all([
    1.54 +    ensureSourceIs(gPanel, "-01.js"),
    1.55 +    ensureCaretAt(gPanel, 1)
    1.56 +  ]));
    1.57 +}
    1.58 +
    1.59 +function combineWithLineSearch() {
    1.60 +  let finished = promise.all([
    1.61 +    ensureSourceIs(gPanel, "-01.js"),
    1.62 +    ensureCaretAt(gPanel, 1),
    1.63 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
    1.64 +    waitForCaretUpdated(gPanel, 2)
    1.65 +  ]);
    1.66 +
    1.67 +  typeText(gSearchBox, ":2");
    1.68 +
    1.69 +  return finished.then(() => promise.all([
    1.70 +    ensureSourceIs(gPanel, "-01.js"),
    1.71 +    ensureCaretAt(gPanel, 2)
    1.72 +  ]));
    1.73 +}
    1.74 +
    1.75 +function combineWithTokenSearch() {
    1.76 +  let finished = promise.all([
    1.77 +    ensureSourceIs(gPanel, "-01.js"),
    1.78 +    ensureCaretAt(gPanel, 2),
    1.79 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
    1.80 +    waitForCaretUpdated(gPanel, 2, 48)
    1.81 +  ]);
    1.82 +
    1.83 +  backspaceText(gSearchBox, 2);
    1.84 +  typeText(gSearchBox, "#zero");
    1.85 +
    1.86 +  return finished.then(() => promise.all([
    1.87 +    ensureSourceIs(gPanel, "-01.js"),
    1.88 +    ensureCaretAt(gPanel, 2, 48)
    1.89 +  ]));
    1.90 +}
    1.91 +
    1.92 +function combineWithTokenColonSearch() {
    1.93 +  let finished = promise.all([
    1.94 +    ensureSourceIs(gPanel, "-01.js"),
    1.95 +    ensureCaretAt(gPanel, 2, 48),
    1.96 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
    1.97 +    waitForCaretUpdated(gPanel, 2, 11)
    1.98 +  ]);
    1.99 +
   1.100 +  backspaceText(gSearchBox, 4);
   1.101 +  typeText(gSearchBox, "http://");
   1.102 +
   1.103 +  return finished.then(() => promise.all([
   1.104 +    ensureSourceIs(gPanel, "-01.js"),
   1.105 +    ensureCaretAt(gPanel, 2, 11)
   1.106 +  ]));
   1.107 +}
   1.108 +
   1.109 +function verifySourceAndCaret(aUrl, aLine, aColumn, aSelection) {
   1.110 +  ok(gSources.selectedItem.attachment.label.contains(aUrl),
   1.111 +    "The selected item's label appears to be correct.");
   1.112 +  ok(gSources.selectedItem.value.contains(aUrl),
   1.113 +    "The selected item's value appears to be correct.");
   1.114 +  ok(isCaretPos(gPanel, aLine, aColumn),
   1.115 +    "The current caret position appears to be correct.");
   1.116 +  ok(isEditorSel(gPanel, aSelection),
   1.117 +    "The current editor selection appears to be correct.");
   1.118 +}
   1.119 +
   1.120 +registerCleanupFunction(function() {
   1.121 +  gTab = null;
   1.122 +  gDebuggee = null;
   1.123 +  gPanel = null;
   1.124 +  gDebugger = null;
   1.125 +  gSources = null;
   1.126 +  gSearchBox = null;
   1.127 +});

mercurial