123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
- /* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
- /**
- * Tests basic search functionality (find token and jump to line).
- */
- const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
- var gTab, gPanel, gDebugger;
- var gEditor, gSources, gFiltering, gSearchBox;
- function test() {
- let options = {
- source: TAB_URL,
- line: 1
- };
- initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
- gTab = aTab;
- gPanel = aPanel;
- gDebugger = gPanel.panelWin;
- gEditor = gDebugger.DebuggerView.editor;
- gSources = gDebugger.DebuggerView.Sources;
- gFiltering = gDebugger.DebuggerView.Filtering;
- gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
- performTest();
- });
- }
- function performTest() {
- // Make sure that the search box becomes focused when pressing ctrl+f - Bug 1211038
- gEditor.focus();
- synthesizeKeyFromKeyTag(gDebugger.document.getElementById("tokenSearchKey"));
- let focusedEl = Services.focus.focusedElement;
- focusedEl = focusedEl.ownerDocument.getBindingParent(focusedEl) || focusedEl;
- is(focusedEl, gDebugger.document.getElementById("searchbox"), "Searchbox is focused");
- setText(gSearchBox, "#html");
- EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 35, 7),
- "The editor didn't jump to the correct line.");
- EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 5, 6),
- "The editor didn't jump to the correct line.");
- EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 3, 15),
- "The editor didn't jump to the correct line.");
- setText(gSearchBox, ":12");
- is(gFiltering.searchData.toSource(), '[":", ["", 12]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 12),
- "The editor didn't jump to the correct line.");
- EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
- is(gFiltering.searchData.toSource(), '[":", ["", 13]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 13),
- "The editor didn't jump to the correct line after Meta+G.");
- EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger);
- is(gFiltering.searchData.toSource(), '[":", ["", 14]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14),
- "The editor didn't jump to the correct line after Ctrl+N.");
- EventUtils.synthesizeKey("G", { metaKey: true, shiftKey: true }, gDebugger);
- is(gFiltering.searchData.toSource(), '[":", ["", 13]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 13),
- "The editor didn't jump to the correct line after Meta+Shift+G.");
- EventUtils.synthesizeKey("p", { ctrlKey: true }, gDebugger);
- is(gFiltering.searchData.toSource(), '[":", ["", 12]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 12),
- "The editor didn't jump to the correct line after Ctrl+P.");
- for (let i = 0; i < 100; i++) {
- EventUtils.sendKey("DOWN", gDebugger);
- }
- is(gFiltering.searchData.toSource(), '[":", ["", 36]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 36),
- "The editor didn't jump to the correct line after multiple DOWN keys.");
- for (let i = 0; i < 100; i++) {
- EventUtils.sendKey("UP", gDebugger);
- }
- is(gFiltering.searchData.toSource(), '[":", ["", 1]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 1),
- "The editor didn't jump to the correct line after multiple UP keys.");
- let token = "debugger";
- setText(gSearchBox, "#" + token);
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 8, 12 + token.length),
- "The editor didn't jump to the correct token (1).");
- EventUtils.sendKey("DOWN", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length),
- "The editor didn't jump to the correct token (2).");
- EventUtils.sendKey("DOWN", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 18, 15 + token.length),
- "The editor didn't jump to the correct token (3).");
- EventUtils.sendKey("RETURN", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 26, 11 + token.length),
- "The editor didn't jump to the correct token (4).");
- EventUtils.sendKey("RETURN", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 8, 12 + token.length),
- "The editor didn't jump to the correct token (5).");
- EventUtils.sendKey("UP", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 26, 11 + token.length),
- "The editor didn't jump to the correct token (6).");
- setText(gSearchBox, ":bogus#" + token + ";");
- is(gFiltering.searchData.toSource(), '["#", [":bogus", "debugger;"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (7).");
- setText(gSearchBox, ":13#" + token + ";");
- is(gFiltering.searchData.toSource(), '["#", [":13", "debugger;"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (8).");
- setText(gSearchBox, ":#" + token + ";");
- is(gFiltering.searchData.toSource(), '["#", [":", "debugger;"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (9).");
- setText(gSearchBox, "::#" + token + ";");
- is(gFiltering.searchData.toSource(), '["#", ["::", "debugger;"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (10).");
- setText(gSearchBox, ":::#" + token + ";");
- is(gFiltering.searchData.toSource(), '["#", [":::", "debugger;"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (11).");
- setText(gSearchBox, "#" + token + ";" + ":bogus");
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:bogus"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (12).");
- setText(gSearchBox, "#" + token + ";" + ":13");
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:13"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (13).");
- setText(gSearchBox, "#" + token + ";" + ":");
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (14).");
- setText(gSearchBox, "#" + token + ";" + "::");
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger;::"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (15).");
- setText(gSearchBox, "#" + token + ";" + ":::");
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:::"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't jump to the correct token (16).");
- setText(gSearchBox, ":i am not a number");
- is(gFiltering.searchData.toSource(), '[":", ["", 0]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't remain at the correct token (17).");
- setText(gSearchBox, "#__i do not exist__");
- is(gFiltering.searchData.toSource(), '["#", ["", "__i do not exist__"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
- "The editor didn't remain at the correct token (18).");
- setText(gSearchBox, "#" + token);
- is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 8, 12 + token.length),
- "The editor didn't jump to the correct token (19).");
- clearText(gSearchBox);
- is(gFiltering.searchData.toSource(), '["", [""]]',
- "The searchbox data wasn't parsed correctly.");
- EventUtils.sendKey("RETURN", gDebugger);
- is(gFiltering.searchData.toSource(), '["", [""]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 8, 12 + token.length),
- "The editor shouldn't jump to another token (20).");
- EventUtils.sendKey("RETURN", gDebugger);
- is(gFiltering.searchData.toSource(), '["", [""]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 8, 12 + token.length),
- "The editor shouldn't jump to another token (21).");
- setText(gSearchBox, ":1:2:3:a:b:c:::12");
- is(gFiltering.searchData.toSource(), '[":", [":1:2:3:a:b:c::", 12]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 12),
- "The editor didn't jump to the correct line (22).");
- setText(gSearchBox, "#don't#find#me#instead#find#" + token);
- is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 8, 12 + token.length),
- "The editor didn't jump to the correct token (23).");
- EventUtils.sendKey("DOWN", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 14, 9 + token.length),
- "The editor didn't jump to the correct token (24).");
- EventUtils.sendKey("DOWN", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 18, 15 + token.length),
- "The editor didn't jump to the correct token (25).");
- EventUtils.sendKey("RETURN", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 26, 11 + token.length),
- "The editor didn't jump to the correct token (26).");
- EventUtils.sendKey("RETURN", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 8, 12 + token.length),
- "The editor didn't jump to the correct token (27).");
- EventUtils.sendKey("UP", gDebugger);
- is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 26, 11 + token.length),
- "The editor didn't jump to the correct token (28).");
- clearText(gSearchBox);
- is(gFiltering.searchData.toSource(), '["", [""]]',
- "The searchbox data wasn't parsed correctly.");
- ok(isCaretPos(gPanel, 26, 11 + token.length),
- "The editor didn't remain at the correct token (29).");
- is(gSources.visibleItems.length, 1,
- "Not all the sources are shown after the search (30).");
- gEditor.focus();
- gEditor.setSelection.apply(gEditor, gEditor.getPosition(1, 5));
- ok(isCaretPos(gPanel, 1, 6),
- "The editor caret position didn't update after selecting some text.");
- EventUtils.synthesizeKey("F", { accelKey: true });
- is(gFiltering.searchData.toSource(), '["#", ["", "!-- "]]',
- "The searchbox data wasn't parsed correctly.");
- is(gSearchBox.value, "#!-- ",
- "The search field has the right initial value (1).");
- gEditor.focus();
- gEditor.setSelection.apply(gEditor, gEditor.getPosition(415, 418));
- ok(isCaretPos(gPanel, 21, 30),
- "The editor caret position didn't update after selecting some number.");
- EventUtils.synthesizeKey("L", { accelKey: true });
- is(gFiltering.searchData.toSource(), '[":", ["", 100]]',
- "The searchbox data wasn't parsed correctly.");
- is(gSearchBox.value, ":100",
- "The search field has the right initial value (2).");
- closeDebuggerAndFinish(gPanel);
- }
- registerCleanupFunction(function () {
- gTab = null;
- gPanel = null;
- gDebugger = null;
- gEditor = null;
- gSources = null;
- gFiltering = null;
- gSearchBox = null;
- });
|