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