browser/devtools/debugger/test/browser_dbg_search-global-06.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:41a927b49bee
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Tests if the global search results are hidden when they're supposed to
6 * (after a focus lost, or when ESCAPE is pressed).
7 */
8
9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
10
11 let gTab, gDebuggee, gPanel, gDebugger;
12 let gEditor, gSources, gSearchView, gSearchBox;
13
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;
24
25 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
26 .then(doSearch)
27 .then(testFocusLost)
28 .then(doSearch)
29 .then(testEscape)
30 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
31 .then(null, aError => {
32 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
33 });
34
35 gDebuggee.firstCall();
36 });
37 }
38
39 function doSearch() {
40 let deferred = promise.defer();
41
42 is(gSearchView.itemCount, 0,
43 "The global search pane shouldn't have any entries yet.");
44 is(gSearchView.widget._parent.hidden, true,
45 "The global search pane shouldn't be visible yet.");
46 is(gSearchView._splitter.hidden, true,
47 "The global search pane splitter shouldn't be visible yet.");
48
49 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
50 // Some operations are synchronously dispatched on the main thread,
51 // to avoid blocking UI, thus giving the impression of faster searching.
52 executeSoon(() => {
53 info("Current source url:\n" + gSources.selectedValue);
54 info("Debugger editor text:\n" + gEditor.getText());
55
56 ok(isCaretPos(gPanel, 1),
57 "The editor shouldn't have jumped to a matching line yet.");
58 ok(gSources.selectedValue.contains("-02.js"),
59 "The current source shouldn't have changed after a global search.");
60 is(gSources.visibleItems.length, 2,
61 "Not all the sources are shown after the global search.");
62
63 deferred.resolve();
64 });
65 });
66
67 setText(gSearchBox, "!a");
68
69 return deferred.promise;
70 }
71
72 function testFocusLost() {
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.");
79
80 gDebugger.DebuggerView.editor.focus();
81
82 info("Current source url:\n" + gSources.selectedValue);
83 info("Debugger editor text:\n" + gEditor.getText());
84
85 is(gSearchView.itemCount, 0,
86 "The global search pane shouldn't have any child nodes after clearing.");
87 is(gSearchView.widget._parent.hidden, true,
88 "The global search pane shouldn't be visible after clearing.");
89 is(gSearchView._splitter.hidden, true,
90 "The global search pane splitter shouldn't be visible after clearing.");
91 }
92
93 function testEscape() {
94 is(gSearchView.itemCount, 2,
95 "The global search pane should have some entries from the previous search.");
96 is(gSearchView.widget._parent.hidden, false,
97 "The global search pane should be visible from the previous search.");
98 is(gSearchView._splitter.hidden, false,
99 "The global search pane splitter should be visible from the previous search.");
100
101 gSearchBox.focus();
102 EventUtils.sendKey("ESCAPE", gDebugger);
103
104 is(gSearchView.itemCount, 0,
105 "The global search pane shouldn't have any child nodes after clearing.");
106 is(gSearchView.widget._parent.hidden, true,
107 "The global search pane shouldn't be visible after clearing.");
108 is(gSearchView._splitter.hidden, true,
109 "The global search pane splitter shouldn't be visible after clearing.");
110 }
111
112 registerCleanupFunction(function() {
113 gTab = null;
114 gDebuggee = null;
115 gPanel = null;
116 gDebugger = null;
117 gEditor = null;
118 gSources = null;
119 gSearchView = null;
120 gSearchBox = null;
121 });

mercurial