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 are cleared on location changes, and
6 * the expected UI behaviors are triggered.
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(performTest)
28 .then(() => closeDebuggerAndFinish(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 is(gSearchView.itemCount, 0,
41 "The global search pane shouldn't have any entries yet.");
42 is(gSearchView.widget._parent.hidden, true,
43 "The global search pane shouldn't be visible yet.");
44 is(gSearchView._splitter.hidden, true,
45 "The global search pane splitter shouldn't be visible yet.");
47 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
48 // Some operations are synchronously dispatched on the main thread,
49 // to avoid blocking UI, thus giving the impression of faster searching.
50 executeSoon(() => {
51 info("Current source url:\n" + gSources.selectedValue);
52 info("Debugger editor text:\n" + gEditor.getText());
54 ok(isCaretPos(gPanel, 1),
55 "The editor shouldn't have jumped to a matching line yet.");
56 ok(gSources.selectedValue.contains("-02.js"),
57 "The current source shouldn't have changed after a global search.");
58 is(gSources.visibleItems.length, 2,
59 "Not all the sources are shown after the global search.");
61 deferred.resolve();
62 });
63 });
65 setText(gSearchBox, "!eval");
67 return deferred.promise;
68 }
70 function performTest() {
71 let deferred = promise.defer();
73 is(gSearchView.itemCount, 2,
74 "The global search pane should have some entries from the previous search.");
75 is(gSearchView.widget._parent.hidden, false,
76 "The global search pane should be visible from the previous search.");
77 is(gSearchView._splitter.hidden, false,
78 "The global search pane splitter should be visible from the previous search.");
80 reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(() => {
81 info("Current source url:\n" + gSources.selectedValue);
82 info("Debugger editor text:\n" + gEditor.getText());
84 is(gSearchView.itemCount, 0,
85 "The global search pane shouldn't have any entries after a page navigation.");
86 is(gSearchView.widget._parent.hidden, true,
87 "The global search pane shouldn't be visible after a page navigation.");
88 is(gSearchView._splitter.hidden, true,
89 "The global search pane splitter shouldn't be visible after a page navigation.");
91 deferred.resolve();
92 });
94 return deferred.promise;
95 }
97 registerCleanupFunction(function() {
98 gTab = null;
99 gDebuggee = null;
100 gPanel = null;
101 gDebugger = null;
102 gEditor = null;
103 gSources = null;
104 gSearchView = null;
105 gSearchBox = null;
106 });