browser/devtools/debugger/test/browser_dbg_search-basic-03.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests that searches which cause a popup to be shown properly handle the
michael@0 6 * ESCAPE key.
michael@0 7 */
michael@0 8
michael@0 9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
michael@0 10
michael@0 11 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 12 let gSources, gSearchBox;
michael@0 13
michael@0 14 function test() {
michael@0 15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 16 gTab = aTab;
michael@0 17 gDebuggee = aDebuggee;
michael@0 18 gPanel = aPanel;
michael@0 19 gDebugger = gPanel.panelWin;
michael@0 20 gSources = gDebugger.DebuggerView.Sources;
michael@0 21 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
michael@0 22
michael@0 23 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
michael@0 24 .then(performFileSearch)
michael@0 25 .then(escapeAndHide)
michael@0 26 .then(escapeAndClear)
michael@0 27 .then(() => verifySourceAndCaret("-01.js", 1, 1))
michael@0 28 .then(performFunctionSearch)
michael@0 29 .then(escapeAndHide)
michael@0 30 .then(escapeAndClear)
michael@0 31 .then(() => verifySourceAndCaret("-01.js", 4, 10))
michael@0 32 .then(performGlobalSearch)
michael@0 33 .then(escapeAndClear)
michael@0 34 .then(() => verifySourceAndCaret("-01.js", 4, 10))
michael@0 35 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
michael@0 36 .then(null, aError => {
michael@0 37 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 38 });
michael@0 39
michael@0 40 gDebuggee.firstCall();
michael@0 41 });
michael@0 42 }
michael@0 43
michael@0 44 function performFileSearch() {
michael@0 45 let finished = promise.all([
michael@0 46 ensureSourceIs(gPanel, "-02.js"),
michael@0 47 ensureCaretAt(gPanel, 1),
michael@0 48 once(gDebugger, "popupshown"),
michael@0 49 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
michael@0 50 waitForSourceShown(gPanel, "-01.js")
michael@0 51 ]);
michael@0 52
michael@0 53 setText(gSearchBox, ".");
michael@0 54
michael@0 55 return finished.then(() => promise.all([
michael@0 56 ensureSourceIs(gPanel, "-01.js"),
michael@0 57 ensureCaretAt(gPanel, 1)
michael@0 58 ]));
michael@0 59 }
michael@0 60
michael@0 61 function performFunctionSearch() {
michael@0 62 let finished = promise.all([
michael@0 63 ensureSourceIs(gPanel, "-01.js"),
michael@0 64 ensureCaretAt(gPanel, 1),
michael@0 65 once(gDebugger, "popupshown"),
michael@0 66 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FUNCTION_SEARCH_MATCH_FOUND)
michael@0 67 ]);
michael@0 68
michael@0 69 setText(gSearchBox, "@");
michael@0 70
michael@0 71 return finished.then(() => promise.all([
michael@0 72 ensureSourceIs(gPanel, "-01.js"),
michael@0 73 ensureCaretAt(gPanel, 4, 10)
michael@0 74 ]));
michael@0 75 }
michael@0 76
michael@0 77 function performGlobalSearch() {
michael@0 78 let finished = promise.all([
michael@0 79 ensureSourceIs(gPanel, "-01.js"),
michael@0 80 ensureCaretAt(gPanel, 4, 10),
michael@0 81 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND)
michael@0 82 ]);
michael@0 83
michael@0 84 setText(gSearchBox, "!first");
michael@0 85
michael@0 86 return finished.then(() => promise.all([
michael@0 87 ensureSourceIs(gPanel, "-01.js"),
michael@0 88 ensureCaretAt(gPanel, 4, 10)
michael@0 89 ]));
michael@0 90 }
michael@0 91
michael@0 92 function escapeAndHide() {
michael@0 93 let finished = once(gDebugger, "popuphidden", true);
michael@0 94 EventUtils.sendKey("ESCAPE", gDebugger);
michael@0 95 return finished;
michael@0 96 }
michael@0 97
michael@0 98 function escapeAndClear() {
michael@0 99 EventUtils.sendKey("ESCAPE", gDebugger);
michael@0 100 is(gSearchBox.getAttribute("value"), "",
michael@0 101 "The searchbox has properly emptied after pressing escape.");
michael@0 102 }
michael@0 103
michael@0 104 function verifySourceAndCaret(aUrl, aLine, aColumn) {
michael@0 105 ok(gSources.selectedItem.attachment.label.contains(aUrl),
michael@0 106 "The selected item's label appears to be correct.");
michael@0 107 ok(gSources.selectedItem.value.contains(aUrl),
michael@0 108 "The selected item's value appears to be correct.");
michael@0 109 ok(isCaretPos(gPanel, aLine, aColumn),
michael@0 110 "The current caret position appears to be correct.");
michael@0 111 }
michael@0 112
michael@0 113 registerCleanupFunction(function() {
michael@0 114 gTab = null;
michael@0 115 gDebuggee = null;
michael@0 116 gPanel = null;
michael@0 117 gDebugger = null;
michael@0 118 gSources = null;
michael@0 119 gSearchBox = null;
michael@0 120 });

mercurial