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 if the global search results trigger MatchFound and NoMatchFound events
6 * properly, and triggers the expected UI behavior.
7 */
9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
11 let gTab, gDebuggee, gPanel, gDebugger;
12 let gEditor, gSources, gSearchView, 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 gEditor = gDebugger.DebuggerView.editor;
21 gSources = gDebugger.DebuggerView.Sources;
22 gSearchView = gDebugger.DebuggerView.GlobalSearch;
23 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
25 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
26 .then(firstSearch)
27 .then(secondSearch)
28 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
29 .then(null, aError => {
30 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
31 });
33 gDebuggee.firstCall();
34 });
35 }
37 function firstSearch() {
38 let deferred = promise.defer();
40 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
41 // Some operations are synchronously dispatched on the main thread,
42 // to avoid blocking UI, thus giving the impression of faster searching.
43 executeSoon(() => {
44 info("Current source url:\n" + gSources.selectedValue);
45 info("Debugger editor text:\n" + gEditor.getText());
47 ok(isCaretPos(gPanel, 1),
48 "The editor shouldn't have jumped to a matching line yet.");
49 ok(gSources.selectedValue.contains("-02.js"),
50 "The current source shouldn't have changed after a global search.");
51 is(gSources.visibleItems.length, 2,
52 "Not all the sources are shown after the global search.");
54 deferred.resolve();
55 });
56 });
58 setText(gSearchBox, "!eval");
60 return deferred.promise;
61 }
63 function secondSearch() {
64 let deferred = promise.defer();
66 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_NOT_FOUND, () => {
67 info("Current source url:\n" + gSources.selectedValue);
68 info("Debugger editor text:\n" + gEditor.getText());
70 ok(isCaretPos(gPanel, 1),
71 "The editor shouldn't have jumped to a matching line yet.");
72 ok(gSources.selectedValue.contains("-02.js"),
73 "The current source shouldn't have changed after a global search.");
74 is(gSources.visibleItems.length, 2,
75 "Not all the sources are shown after the global search.");
77 deferred.resolve();
78 });
80 typeText(gSearchBox, "/");
82 return deferred.promise;
83 }
85 registerCleanupFunction(function() {
86 gTab = null;
87 gDebuggee = null;
88 gPanel = null;
89 gDebugger = null;
90 gEditor = null;
91 gSources = null;
92 gSearchView = null;
93 gSearchBox = null;
94 });