browser/devtools/debugger/test/browser_dbg_search-basic-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-basic-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,319 @@
     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 search functionality (find token and jump to line).
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
    1.12 +
    1.13 +let gTab, gDebuggee, gPanel, gDebugger;
    1.14 +let gEditor, gSources, gFiltering, 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 +    gEditor = gDebugger.DebuggerView.editor;
    1.23 +    gSources = gDebugger.DebuggerView.Sources;
    1.24 +    gFiltering = gDebugger.DebuggerView.Filtering;
    1.25 +    gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
    1.26 +
    1.27 +    waitForSourceShown(gPanel, ".html").then(performTest);
    1.28 +  });
    1.29 +}
    1.30 +
    1.31 +function performTest() {
    1.32 +  setText(gSearchBox, "#html");
    1.33 +  
    1.34 +  EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
    1.35 +  is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
    1.36 +    "The searchbox data wasn't parsed correctly.");
    1.37 +  ok(isCaretPos(gPanel, 35, 7),
    1.38 +    "The editor didn't jump to the correct line.");
    1.39 +
    1.40 +  EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
    1.41 +  is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
    1.42 +    "The searchbox data wasn't parsed correctly.");
    1.43 +  ok(isCaretPos(gPanel, 5, 6),
    1.44 +    "The editor didn't jump to the correct line.");
    1.45 +
    1.46 +  EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
    1.47 +  is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
    1.48 +    "The searchbox data wasn't parsed correctly.");
    1.49 +  ok(isCaretPos(gPanel, 3, 15),
    1.50 +    "The editor didn't jump to the correct line.");
    1.51 +  
    1.52 +  setText(gSearchBox, ":12");
    1.53 +  is(gFiltering.searchData.toSource(), '[":", ["", 12]]',
    1.54 +    "The searchbox data wasn't parsed correctly.");
    1.55 +  ok(isCaretPos(gPanel, 12),
    1.56 +    "The editor didn't jump to the correct line.");
    1.57 +
    1.58 +  EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
    1.59 +  is(gFiltering.searchData.toSource(), '[":", ["", 13]]',
    1.60 +    "The searchbox data wasn't parsed correctly.");
    1.61 +  ok(isCaretPos(gPanel, 13),
    1.62 +    "The editor didn't jump to the correct line after Meta+G.");
    1.63 +
    1.64 +  EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger);
    1.65 +  is(gFiltering.searchData.toSource(), '[":", ["", 14]]',
    1.66 +    "The searchbox data wasn't parsed correctly.");
    1.67 +  ok(isCaretPos(gPanel, 14),
    1.68 +    "The editor didn't jump to the correct line after Ctrl+N.");
    1.69 +
    1.70 +  EventUtils.synthesizeKey("G", { metaKey: true, shiftKey: true }, gDebugger);
    1.71 +  is(gFiltering.searchData.toSource(), '[":", ["", 13]]',
    1.72 +    "The searchbox data wasn't parsed correctly.");
    1.73 +  ok(isCaretPos(gPanel, 13),
    1.74 +    "The editor didn't jump to the correct line after Meta+Shift+G.");
    1.75 +
    1.76 +  EventUtils.synthesizeKey("p", { ctrlKey: true }, gDebugger);
    1.77 +  is(gFiltering.searchData.toSource(), '[":", ["", 12]]',
    1.78 +    "The searchbox data wasn't parsed correctly.");
    1.79 +  ok(isCaretPos(gPanel, 12),
    1.80 +    "The editor didn't jump to the correct line after Ctrl+P.");
    1.81 +
    1.82 +  for (let i = 0; i < 100; i++) {
    1.83 +    EventUtils.sendKey("DOWN", gDebugger);
    1.84 +  }
    1.85 +  is(gFiltering.searchData.toSource(), '[":", ["", 36]]',
    1.86 +    "The searchbox data wasn't parsed correctly.");
    1.87 +  ok(isCaretPos(gPanel, 36),
    1.88 +    "The editor didn't jump to the correct line after multiple DOWN keys.");
    1.89 +
    1.90 +  for (let i = 0; i < 100; i++) {
    1.91 +    EventUtils.sendKey("UP", gDebugger);
    1.92 +  }
    1.93 +  is(gFiltering.searchData.toSource(), '[":", ["", 1]]',
    1.94 +    "The searchbox data wasn't parsed correctly.");
    1.95 +  ok(isCaretPos(gPanel, 1),
    1.96 +    "The editor didn't jump to the correct line after multiple UP keys.");
    1.97 +
    1.98 +
    1.99 +  let token = "debugger";
   1.100 +  setText(gSearchBox, "#" + token);
   1.101 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
   1.102 +    "The searchbox data wasn't parsed correctly.");
   1.103 +  ok(isCaretPos(gPanel, 8, 12 + token.length),
   1.104 +    "The editor didn't jump to the correct token (1).");
   1.105 +
   1.106 +  EventUtils.sendKey("DOWN", gDebugger);
   1.107 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
   1.108 +    "The searchbox data wasn't parsed correctly.");
   1.109 +  ok(isCaretPos(gPanel, 14, 9 + token.length),
   1.110 +    "The editor didn't jump to the correct token (2).");
   1.111 +
   1.112 +  EventUtils.sendKey("DOWN", gDebugger);
   1.113 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
   1.114 +    "The searchbox data wasn't parsed correctly.");
   1.115 +  ok(isCaretPos(gPanel, 18, 15 + token.length),
   1.116 +    "The editor didn't jump to the correct token (3).");
   1.117 +
   1.118 +  EventUtils.sendKey("RETURN", gDebugger);
   1.119 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
   1.120 +    "The searchbox data wasn't parsed correctly.");
   1.121 +  ok(isCaretPos(gPanel, 26, 11 + token.length),
   1.122 +    "The editor didn't jump to the correct token (4).");
   1.123 +
   1.124 +  EventUtils.sendKey("RETURN", gDebugger);
   1.125 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
   1.126 +    "The searchbox data wasn't parsed correctly.");
   1.127 +  ok(isCaretPos(gPanel, 8, 12 + token.length),
   1.128 +    "The editor didn't jump to the correct token (5).");
   1.129 +
   1.130 +  EventUtils.sendKey("UP", gDebugger);
   1.131 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
   1.132 +    "The searchbox data wasn't parsed correctly.");
   1.133 +  ok(isCaretPos(gPanel, 26, 11 + token.length),
   1.134 +    "The editor didn't jump to the correct token (6).");
   1.135 +
   1.136 +  setText(gSearchBox, ":bogus#" + token + ";");
   1.137 +  is(gFiltering.searchData.toSource(), '["#", [":bogus", "debugger;"]]',
   1.138 +    "The searchbox data wasn't parsed correctly.");
   1.139 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.140 +    "The editor didn't jump to the correct token (7).");
   1.141 +
   1.142 +  setText(gSearchBox, ":13#" + token + ";");
   1.143 +  is(gFiltering.searchData.toSource(), '["#", [":13", "debugger;"]]',
   1.144 +    "The searchbox data wasn't parsed correctly.");
   1.145 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.146 +    "The editor didn't jump to the correct token (8).");
   1.147 +
   1.148 +  setText(gSearchBox, ":#" + token + ";");
   1.149 +  is(gFiltering.searchData.toSource(), '["#", [":", "debugger;"]]',
   1.150 +    "The searchbox data wasn't parsed correctly.");
   1.151 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.152 +    "The editor didn't jump to the correct token (9).");
   1.153 +
   1.154 +  setText(gSearchBox, "::#" + token + ";");
   1.155 +  is(gFiltering.searchData.toSource(), '["#", ["::", "debugger;"]]',
   1.156 +    "The searchbox data wasn't parsed correctly.");
   1.157 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.158 +    "The editor didn't jump to the correct token (10).");
   1.159 +
   1.160 +  setText(gSearchBox, ":::#" + token + ";");
   1.161 +  is(gFiltering.searchData.toSource(), '["#", [":::", "debugger;"]]',
   1.162 +    "The searchbox data wasn't parsed correctly.");
   1.163 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.164 +    "The editor didn't jump to the correct token (11).");
   1.165 +
   1.166 +
   1.167 +  setText(gSearchBox, "#" + token + ";" + ":bogus");
   1.168 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:bogus"]]',
   1.169 +    "The searchbox data wasn't parsed correctly.");
   1.170 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.171 +    "The editor didn't jump to the correct token (12).");
   1.172 +
   1.173 +  setText(gSearchBox, "#" + token + ";" + ":13");
   1.174 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:13"]]',
   1.175 +    "The searchbox data wasn't parsed correctly.");
   1.176 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.177 +    "The editor didn't jump to the correct token (13).");
   1.178 +
   1.179 +  setText(gSearchBox, "#" + token + ";" + ":");
   1.180 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:"]]',
   1.181 +    "The searchbox data wasn't parsed correctly.");
   1.182 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.183 +    "The editor didn't jump to the correct token (14).");
   1.184 +
   1.185 +  setText(gSearchBox, "#" + token + ";" + "::");
   1.186 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger;::"]]',
   1.187 +    "The searchbox data wasn't parsed correctly.");
   1.188 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.189 +    "The editor didn't jump to the correct token (15).");
   1.190 +
   1.191 +  setText(gSearchBox, "#" + token + ";" + ":::");
   1.192 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:::"]]',
   1.193 +    "The searchbox data wasn't parsed correctly.");
   1.194 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.195 +    "The editor didn't jump to the correct token (16).");
   1.196 +
   1.197 +
   1.198 +  setText(gSearchBox, ":i am not a number");
   1.199 +  is(gFiltering.searchData.toSource(), '[":", ["", 0]]',
   1.200 +    "The searchbox data wasn't parsed correctly.");
   1.201 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.202 +    "The editor didn't remain at the correct token (17).");
   1.203 +
   1.204 +  setText(gSearchBox, "#__i do not exist__");
   1.205 +  is(gFiltering.searchData.toSource(), '["#", ["", "__i do not exist__"]]',
   1.206 +    "The searchbox data wasn't parsed correctly.");
   1.207 +  ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
   1.208 +    "The editor didn't remain at the correct token (18).");
   1.209 +
   1.210 +
   1.211 +  setText(gSearchBox, "#" + token);
   1.212 +  is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
   1.213 +    "The searchbox data wasn't parsed correctly.");
   1.214 +  ok(isCaretPos(gPanel, 8, 12 + token.length),
   1.215 +    "The editor didn't jump to the correct token (19).");
   1.216 +
   1.217 +
   1.218 +  clearText(gSearchBox);
   1.219 +  is(gFiltering.searchData.toSource(), '["", [""]]',
   1.220 +    "The searchbox data wasn't parsed correctly.");
   1.221 +
   1.222 +  EventUtils.sendKey("RETURN", gDebugger);
   1.223 +  is(gFiltering.searchData.toSource(), '["", [""]]',
   1.224 +    "The searchbox data wasn't parsed correctly.");
   1.225 +  ok(isCaretPos(gPanel, 8, 12 + token.length),
   1.226 +    "The editor shouldn't jump to another token (20).");
   1.227 +
   1.228 +  EventUtils.sendKey("RETURN", gDebugger);
   1.229 +  is(gFiltering.searchData.toSource(), '["", [""]]',
   1.230 +    "The searchbox data wasn't parsed correctly.");
   1.231 +  ok(isCaretPos(gPanel, 8, 12 + token.length),
   1.232 +    "The editor shouldn't jump to another token (21).");
   1.233 +
   1.234 +
   1.235 +  setText(gSearchBox, ":1:2:3:a:b:c:::12");
   1.236 +  is(gFiltering.searchData.toSource(), '[":", [":1:2:3:a:b:c::", 12]]',
   1.237 +    "The searchbox data wasn't parsed correctly.");
   1.238 +  ok(isCaretPos(gPanel, 12),
   1.239 +    "The editor didn't jump to the correct line (22).");
   1.240 +
   1.241 +  setText(gSearchBox, "#don't#find#me#instead#find#" + token);
   1.242 +  is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
   1.243 +    "The searchbox data wasn't parsed correctly.");
   1.244 +  ok(isCaretPos(gPanel, 8, 12 + token.length),
   1.245 +    "The editor didn't jump to the correct token (23).");
   1.246 +
   1.247 +  EventUtils.sendKey("DOWN", gDebugger);
   1.248 +  is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
   1.249 +    "The searchbox data wasn't parsed correctly.");
   1.250 +  ok(isCaretPos(gPanel, 14, 9 + token.length),
   1.251 +    "The editor didn't jump to the correct token (24).");
   1.252 +
   1.253 +  EventUtils.sendKey("DOWN", gDebugger);
   1.254 +  is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
   1.255 +    "The searchbox data wasn't parsed correctly.");
   1.256 +  ok(isCaretPos(gPanel, 18, 15 + token.length),
   1.257 +    "The editor didn't jump to the correct token (25).");
   1.258 +
   1.259 +  EventUtils.sendKey("RETURN", gDebugger);
   1.260 +  is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
   1.261 +    "The searchbox data wasn't parsed correctly.");
   1.262 +  ok(isCaretPos(gPanel, 26, 11 + token.length),
   1.263 +    "The editor didn't jump to the correct token (26).");
   1.264 +
   1.265 +  EventUtils.sendKey("RETURN", gDebugger);
   1.266 +  is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
   1.267 +    "The searchbox data wasn't parsed correctly.");
   1.268 +  ok(isCaretPos(gPanel, 8, 12 + token.length),
   1.269 +    "The editor didn't jump to the correct token (27).");
   1.270 +
   1.271 +  EventUtils.sendKey("UP", gDebugger);
   1.272 +  is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
   1.273 +    "The searchbox data wasn't parsed correctly.");
   1.274 +  ok(isCaretPos(gPanel, 26, 11 + token.length),
   1.275 +    "The editor didn't jump to the correct token (28).");
   1.276 +
   1.277 +
   1.278 +  clearText(gSearchBox);
   1.279 +  is(gFiltering.searchData.toSource(), '["", [""]]',
   1.280 +    "The searchbox data wasn't parsed correctly.");
   1.281 +  ok(isCaretPos(gPanel, 26, 11 + token.length),
   1.282 +    "The editor didn't remain at the correct token (29).");
   1.283 +  is(gSources.visibleItems.length, 1,
   1.284 +    "Not all the sources are shown after the search (30).");
   1.285 +
   1.286 +
   1.287 +  gEditor.focus();
   1.288 +  gEditor.setSelection.apply(gEditor, gEditor.getPosition(1, 5));
   1.289 +  ok(isCaretPos(gPanel, 1, 6),
   1.290 +    "The editor caret position didn't update after selecting some text.");
   1.291 +
   1.292 +  EventUtils.synthesizeKey("F", { accelKey: true });
   1.293 +  is(gFiltering.searchData.toSource(), '["#", ["", "!-- "]]',
   1.294 +    "The searchbox data wasn't parsed correctly.");
   1.295 +  is(gSearchBox.value, "#!-- ",
   1.296 +    "The search field has the right initial value (1).");
   1.297 +
   1.298 +  gEditor.focus();
   1.299 +  gEditor.setSelection.apply(gEditor, gEditor.getPosition(415, 418));
   1.300 +  ok(isCaretPos(gPanel, 21, 30),
   1.301 +    "The editor caret position didn't update after selecting some number.");
   1.302 +
   1.303 +  EventUtils.synthesizeKey("L", { accelKey: true });
   1.304 +  is(gFiltering.searchData.toSource(), '[":", ["", 100]]',
   1.305 +    "The searchbox data wasn't parsed correctly.");
   1.306 +  is(gSearchBox.value, ":100",
   1.307 +    "The search field has the right initial value (2).");
   1.308 +
   1.309 +
   1.310 +  closeDebuggerAndFinish(gPanel);
   1.311 +}
   1.312 +
   1.313 +registerCleanupFunction(function() {
   1.314 +  gTab = null;
   1.315 +  gDebuggee = null;
   1.316 +  gPanel = null;
   1.317 +  gDebugger = null;
   1.318 +  gEditor = null;
   1.319 +  gSources = null;
   1.320 +  gFiltering = null;
   1.321 +  gSearchBox = null;
   1.322 +});

mercurial