browser/devtools/debugger/test/browser_dbg_search-global-01.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-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,274 @@
     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 functionality of global search (lowercase + upper case, expected
     1.9 + * UI behavior, number of results found etc.)
    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(clearSearch)
    1.32 +      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    1.33 +      .then(null, aError => {
    1.34 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.35 +      });
    1.36 +
    1.37 +    gDebuggee.firstCall();
    1.38 +  });
    1.39 +}
    1.40 +
    1.41 +function firstSearch() {
    1.42 +  let deferred = promise.defer();
    1.43 +
    1.44 +  is(gSearchView.itemCount, 0,
    1.45 +    "The global search pane shouldn't have any entries yet.");
    1.46 +  is(gSearchView.widget._parent.hidden, true,
    1.47 +    "The global search pane shouldn't be visible yet.");
    1.48 +  is(gSearchView._splitter.hidden, true,
    1.49 +    "The global search pane splitter shouldn't be visible yet.");
    1.50 +
    1.51 +  gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
    1.52 +    // Some operations are synchronously dispatched on the main thread,
    1.53 +    // to avoid blocking UI, thus giving the impression of faster searching.
    1.54 +    executeSoon(() => {
    1.55 +      info("Current source url:\n" + gSources.selectedValue);
    1.56 +      info("Debugger editor text:\n" + gEditor.getText());
    1.57 +
    1.58 +      ok(isCaretPos(gPanel, 1),
    1.59 +        "The editor shouldn't have jumped to a matching line yet.");
    1.60 +      ok(gSources.selectedValue.contains("-02.js"),
    1.61 +        "The current source shouldn't have changed after a global search.");
    1.62 +      is(gSources.visibleItems.length, 2,
    1.63 +        "Not all the sources are shown after the global search.");
    1.64 +
    1.65 +      let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
    1.66 +      is(sourceResults.length, 2,
    1.67 +        "There should be matches found in two sources.");
    1.68 +
    1.69 +      let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]);
    1.70 +      let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]);
    1.71 +      is(item0.instance.expanded, true,
    1.72 +        "The first source results should automatically be expanded.")
    1.73 +      is(item1.instance.expanded, true,
    1.74 +        "The second source results should automatically be expanded.")
    1.75 +
    1.76 +      let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result");
    1.77 +      let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result");
    1.78 +      is(searchResult0.length, 1,
    1.79 +        "There should be one line result for the first url.");
    1.80 +      is(searchResult1.length, 2,
    1.81 +        "There should be two line results for the second url.");
    1.82 +
    1.83 +      let firstLine0 = searchResult0[0];
    1.84 +      is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
    1.85 +        "The first result for the first source doesn't have the correct line attached.");
    1.86 +
    1.87 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1,
    1.88 +        "The first result for the first source doesn't have the correct number of nodes for a line.");
    1.89 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 3,
    1.90 +        "The first result for the first source doesn't have the correct number of strings in a line.");
    1.91 +
    1.92 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
    1.93 +        "The first result for the first source doesn't have the correct number of matches in a line.");
    1.94 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
    1.95 +        "The first result for the first source doesn't have the correct match in a line.");
    1.96 +
    1.97 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
    1.98 +        "The first result for the first source doesn't have the correct number of non-matches in a line.");
    1.99 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ",
   1.100 +        "The first result for the first source doesn't have the correct non-matches in a line.");
   1.101 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.",
   1.102 +        "The first result for the first source doesn't have the correct non-matches in a line.");
   1.103 +
   1.104 +      let firstLine1 = searchResult1[0];
   1.105 +      is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
   1.106 +        "The first result for the second source doesn't have the correct line attached.");
   1.107 +
   1.108 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
   1.109 +        "The first result for the second source doesn't have the correct number of nodes for a line.");
   1.110 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3,
   1.111 +        "The first result for the second source doesn't have the correct number of strings in a line.");
   1.112 +
   1.113 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
   1.114 +        "The first result for the second source doesn't have the correct number of matches in a line.");
   1.115 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
   1.116 +        "The first result for the second source doesn't have the correct match in a line.");
   1.117 +
   1.118 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
   1.119 +        "The first result for the second source doesn't have the correct number of non-matches in a line.");
   1.120 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ",
   1.121 +        "The first result for the second source doesn't have the correct non-matches in a line.");
   1.122 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.",
   1.123 +        "The first result for the second source doesn't have the correct non-matches in a line.");
   1.124 +
   1.125 +      let secondLine1 = searchResult1[1];
   1.126 +      is(secondLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "6",
   1.127 +        "The second result for the second source doesn't have the correct line attached.");
   1.128 +
   1.129 +      is(secondLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
   1.130 +        "The second result for the second source doesn't have the correct number of nodes for a line.");
   1.131 +      is(secondLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3,
   1.132 +        "The second result for the second source doesn't have the correct number of strings in a line.");
   1.133 +
   1.134 +      is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
   1.135 +        "The second result for the second source doesn't have the correct number of matches in a line.");
   1.136 +      is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
   1.137 +        "The second result for the second source doesn't have the correct match in a line.");
   1.138 +
   1.139 +      is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
   1.140 +        "The second result for the second source doesn't have the correct number of non-matches in a line.");
   1.141 +      is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), '  eval("',
   1.142 +        "The second result for the second source doesn't have the correct non-matches in a line.");
   1.143 +      is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), 'bugger;");',
   1.144 +        "The second result for the second source doesn't have the correct non-matches in a line.");
   1.145 +
   1.146 +      deferred.resolve();
   1.147 +    });
   1.148 +  });
   1.149 +
   1.150 +  setText(gSearchBox, "!de");
   1.151 +
   1.152 +  return deferred.promise;
   1.153 +}
   1.154 +
   1.155 +function secondSearch() {
   1.156 +  let deferred = promise.defer();
   1.157 +
   1.158 +  is(gSearchView.itemCount, 2,
   1.159 +    "The global search pane should have some child nodes from the previous search.");
   1.160 +  is(gSearchView.widget._parent.hidden, false,
   1.161 +    "The global search pane should be visible from the previous search.");
   1.162 +  is(gSearchView._splitter.hidden, false,
   1.163 +    "The global search pane splitter should be visible from the previous search.");
   1.164 +
   1.165 +  gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
   1.166 +    // Some operations are synchronously dispatched on the main thread,
   1.167 +    // to avoid blocking UI, thus giving the impression of faster searching.
   1.168 +    executeSoon(() => {
   1.169 +      info("Current source url:\n" + gSources.selectedValue);
   1.170 +      info("Debugger editor text:\n" + gEditor.getText());
   1.171 +
   1.172 +      ok(isCaretPos(gPanel, 1),
   1.173 +        "The editor shouldn't have jumped to a matching line yet.");
   1.174 +      ok(gSources.selectedValue.contains("-02.js"),
   1.175 +        "The current source shouldn't have changed after a global search.");
   1.176 +      is(gSources.visibleItems.length, 2,
   1.177 +        "Not all the sources are shown after the global search.");
   1.178 +
   1.179 +      let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
   1.180 +      is(sourceResults.length, 2,
   1.181 +        "There should be matches found in two sources.");
   1.182 +
   1.183 +      let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]);
   1.184 +      let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]);
   1.185 +      is(item0.instance.expanded, true,
   1.186 +        "The first source results should automatically be expanded.")
   1.187 +      is(item1.instance.expanded, true,
   1.188 +        "The second source results should automatically be expanded.")
   1.189 +
   1.190 +      let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result");
   1.191 +      let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result");
   1.192 +      is(searchResult0.length, 1,
   1.193 +        "There should be one line result for the first url.");
   1.194 +      is(searchResult1.length, 1,
   1.195 +        "There should be one line result for the second url.");
   1.196 +
   1.197 +      let firstLine0 = searchResult0[0];
   1.198 +      is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
   1.199 +        "The first result for the first source doesn't have the correct line attached.");
   1.200 +
   1.201 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1,
   1.202 +        "The first result for the first source doesn't have the correct number of nodes for a line.");
   1.203 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 5,
   1.204 +        "The first result for the first source doesn't have the correct number of strings in a line.");
   1.205 +
   1.206 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2,
   1.207 +        "The first result for the first source doesn't have the correct number of matches in a line.");
   1.208 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed",
   1.209 +        "The first result for the first source doesn't have the correct matches in a line.");
   1.210 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed",
   1.211 +        "The first result for the first source doesn't have the correct matches in a line.");
   1.212 +
   1.213 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3,
   1.214 +        "The first result for the first source doesn't have the correct number of non-matches in a line.");
   1.215 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d",
   1.216 +        "The first result for the first source doesn't have the correct non-matches in a line.");
   1.217 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat",
   1.218 +        "The first result for the first source doesn't have the correct non-matches in a line.");
   1.219 +      is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.",
   1.220 +        "The first result for the first source doesn't have the correct non-matches in a line.");
   1.221 +
   1.222 +      let firstLine1 = searchResult1[0];
   1.223 +      is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
   1.224 +        "The first result for the second source doesn't have the correct line attached.");
   1.225 +
   1.226 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
   1.227 +        "The first result for the second source doesn't have the correct number of nodes for a line.");
   1.228 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 5,
   1.229 +        "The first result for the second source doesn't have the correct number of strings in a line.");
   1.230 +
   1.231 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2,
   1.232 +        "The first result for the second source doesn't have the correct number of matches in a line.");
   1.233 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed",
   1.234 +        "The first result for the second source doesn't have the correct matches in a line.");
   1.235 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed",
   1.236 +        "The first result for the second source doesn't have the correct matches in a line.");
   1.237 +
   1.238 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3,
   1.239 +        "The first result for the second source doesn't have the correct number of non-matches in a line.");
   1.240 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d",
   1.241 +        "The first result for the second source doesn't have the correct non-matches in a line.");
   1.242 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat",
   1.243 +        "The first result for the second source doesn't have the correct non-matches in a line.");
   1.244 +      is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.",
   1.245 +        "The first result for the second source doesn't have the correct non-matches in a line.");
   1.246 +
   1.247 +      deferred.resolve();
   1.248 +    });
   1.249 +  });
   1.250 +
   1.251 +  backspaceText(gSearchBox, 2);
   1.252 +  typeText(gSearchBox, "ED");
   1.253 +
   1.254 +  return deferred.promise;
   1.255 +}
   1.256 +
   1.257 +function clearSearch() {
   1.258 +  gSearchView.clearView();
   1.259 +
   1.260 +  is(gSearchView.itemCount, 0,
   1.261 +    "The global search pane shouldn't have any child nodes after clearing.");
   1.262 +  is(gSearchView.widget._parent.hidden, true,
   1.263 +    "The global search pane shouldn't be visible after clearing.");
   1.264 +  is(gSearchView._splitter.hidden, true,
   1.265 +    "The global search pane splitter shouldn't be visible after clearing.");
   1.266 +}
   1.267 +
   1.268 +registerCleanupFunction(function() {
   1.269 +  gTab = null;
   1.270 +  gDebuggee = null;
   1.271 +  gPanel = null;
   1.272 +  gDebugger = null;
   1.273 +  gEditor = null;
   1.274 +  gSources = null;
   1.275 +  gSearchView = null;
   1.276 +  gSearchBox = null;
   1.277 +});

mercurial