Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 /**
5 * Tests basic file search functionality.
6 */
8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
10 let gTab, gDebuggee, gPanel, gDebugger;
11 let gSources, gSearchBox;
13 function test() {
14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
15 gTab = aTab;
16 gDebuggee = aDebuggee;
17 gPanel = aPanel;
18 gDebugger = gPanel.panelWin;
19 gSources = gDebugger.DebuggerView.Sources;
20 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
22 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
23 .then(performSimpleSearch)
24 .then(() => verifySourceAndCaret("-01.js", 1, 1, [1, 1]))
25 .then(combineWithLineSearch)
26 .then(() => verifySourceAndCaret("-01.js", 2, 1, [53, 53]))
27 .then(combineWithTokenSearch)
28 .then(() => verifySourceAndCaret("-01.js", 2, 48, [96, 100]))
29 .then(combineWithTokenColonSearch)
30 .then(() => verifySourceAndCaret("-01.js", 2, 11, [56, 63]))
31 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
32 .then(null, aError => {
33 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
34 });
36 gDebuggee.firstCall();
37 });
38 }
40 function performSimpleSearch() {
41 let finished = promise.all([
42 ensureSourceIs(gPanel, "-02.js"),
43 ensureCaretAt(gPanel, 1),
44 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
45 waitForSourceShown(gPanel, "-01.js")
46 ]);
48 setText(gSearchBox, "1");
50 return finished.then(() => promise.all([
51 ensureSourceIs(gPanel, "-01.js"),
52 ensureCaretAt(gPanel, 1)
53 ]));
54 }
56 function combineWithLineSearch() {
57 let finished = promise.all([
58 ensureSourceIs(gPanel, "-01.js"),
59 ensureCaretAt(gPanel, 1),
60 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
61 waitForCaretUpdated(gPanel, 2)
62 ]);
64 typeText(gSearchBox, ":2");
66 return finished.then(() => promise.all([
67 ensureSourceIs(gPanel, "-01.js"),
68 ensureCaretAt(gPanel, 2)
69 ]));
70 }
72 function combineWithTokenSearch() {
73 let finished = promise.all([
74 ensureSourceIs(gPanel, "-01.js"),
75 ensureCaretAt(gPanel, 2),
76 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
77 waitForCaretUpdated(gPanel, 2, 48)
78 ]);
80 backspaceText(gSearchBox, 2);
81 typeText(gSearchBox, "#zero");
83 return finished.then(() => promise.all([
84 ensureSourceIs(gPanel, "-01.js"),
85 ensureCaretAt(gPanel, 2, 48)
86 ]));
87 }
89 function combineWithTokenColonSearch() {
90 let finished = promise.all([
91 ensureSourceIs(gPanel, "-01.js"),
92 ensureCaretAt(gPanel, 2, 48),
93 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
94 waitForCaretUpdated(gPanel, 2, 11)
95 ]);
97 backspaceText(gSearchBox, 4);
98 typeText(gSearchBox, "http://");
100 return finished.then(() => promise.all([
101 ensureSourceIs(gPanel, "-01.js"),
102 ensureCaretAt(gPanel, 2, 11)
103 ]));
104 }
106 function verifySourceAndCaret(aUrl, aLine, aColumn, aSelection) {
107 ok(gSources.selectedItem.attachment.label.contains(aUrl),
108 "The selected item's label appears to be correct.");
109 ok(gSources.selectedItem.value.contains(aUrl),
110 "The selected item's value appears to be correct.");
111 ok(isCaretPos(gPanel, aLine, aColumn),
112 "The current caret position appears to be correct.");
113 ok(isEditorSel(gPanel, aSelection),
114 "The current editor selection appears to be correct.");
115 }
117 registerCleanupFunction(function() {
118 gTab = null;
119 gDebuggee = null;
120 gPanel = null;
121 gDebugger = null;
122 gSources = null;
123 gSearchBox = null;
124 });