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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e9d7f61c4b2f
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 switch back and forth, and wrap around
6 * when switching between them.
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(firstSearch)
27 .then(doFirstJump)
28 .then(doSecondJump)
29 .then(doWrapAroundJump)
30 .then(doBackwardsWrapAroundJump)
31 .then(testSearchTokenEmpty)
32 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
33 .then(null, aError => {
34 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
35 });
36
37 gDebuggee.firstCall();
38 });
39 }
40
41 function firstSearch() {
42 let deferred = promise.defer();
43
44 is(gSearchView.itemCount, 0,
45 "The global search pane shouldn't have any entries yet.");
46 is(gSearchView.widget._parent.hidden, true,
47 "The global search pane shouldn't be visible yet.");
48 is(gSearchView._splitter.hidden, true,
49 "The global search pane splitter shouldn't be visible yet.");
50
51 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
52 // Some operations are synchronously dispatched on the main thread,
53 // to avoid blocking UI, thus giving the impression of faster searching.
54 executeSoon(() => {
55 info("Current source url:\n" + gSources.selectedValue);
56 info("Debugger editor text:\n" + gEditor.getText());
57
58 ok(isCaretPos(gPanel, 1),
59 "The editor shouldn't have jumped to a matching line yet.");
60 ok(gSources.selectedValue.contains("-02.js"),
61 "The current source shouldn't have changed after a global search.");
62 is(gSources.visibleItems.length, 2,
63 "Not all the sources are shown after the global search.");
64
65 deferred.resolve();
66 });
67 });
68
69 setText(gSearchBox, "!eval");
70
71 return deferred.promise;
72 }
73
74 function doFirstJump() {
75 let deferred = promise.defer();
76
77 waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => {
78 info("Current source url:\n" + gSources.selectedValue);
79 info("Debugger editor text:\n" + gEditor.getText());
80
81 ok(gSources.selectedValue.contains("-01.js"),
82 "The currently shown source is incorrect (1).");
83 is(gSources.visibleItems.length, 2,
84 "Not all the sources are shown after the global search (1).");
85
86 // The editor's selected text takes a tick to update.
87 executeSoon(() => {
88 ok(isCaretPos(gPanel, 5, 7),
89 "The editor didn't jump to the correct line (1).");
90 is(gEditor.getSelection(), "eval",
91 "The editor didn't select the correct text (1).");
92
93 deferred.resolve();
94 });
95 });
96
97 EventUtils.sendKey("DOWN", gDebugger);
98
99 return deferred.promise;
100 }
101
102 function doSecondJump() {
103 let deferred = promise.defer();
104
105 waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => {
106 info("Current source url:\n" + gSources.selectedValue);
107 info("Debugger editor text:\n" + gEditor.getText());
108
109 ok(gSources.selectedValue.contains("-02.js"),
110 "The currently shown source is incorrect (2).");
111 is(gSources.visibleItems.length, 2,
112 "Not all the sources are shown after the global search (2).");
113
114 // The editor's selected text takes a tick to update.
115 executeSoon(() => {
116 ok(isCaretPos(gPanel, 6, 7),
117 "The editor didn't jump to the correct line (2).");
118 is(gEditor.getSelection(), "eval",
119 "The editor didn't select the correct text (2).");
120
121 deferred.resolve();
122 });
123 });
124
125 EventUtils.sendKey("DOWN", gDebugger);
126
127 return deferred.promise;
128 }
129
130 function doWrapAroundJump() {
131 let deferred = promise.defer();
132
133 waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => {
134 info("Current source url:\n" + gSources.selectedValue);
135 info("Debugger editor text:\n" + gEditor.getText());
136
137 ok(gSources.selectedValue.contains("-01.js"),
138 "The currently shown source is incorrect (3).");
139 is(gSources.visibleItems.length, 2,
140 "Not all the sources are shown after the global search (3).");
141
142 // The editor's selected text takes a tick to update.
143 executeSoon(() => {
144 ok(isCaretPos(gPanel, 5, 7),
145 "The editor didn't jump to the correct line (3).");
146 is(gEditor.getSelection(), "eval",
147 "The editor didn't select the correct text (3).");
148
149 deferred.resolve();
150 });
151 });
152
153 EventUtils.sendKey("DOWN", gDebugger);
154
155 return deferred.promise;
156 }
157
158 function doBackwardsWrapAroundJump() {
159 let deferred = promise.defer();
160
161 waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => {
162 info("Current source url:\n" + gSources.selectedValue);
163 info("Debugger editor text:\n" + gEditor.getText());
164
165 ok(gSources.selectedValue.contains("-02.js"),
166 "The currently shown source is incorrect (4).");
167 is(gSources.visibleItems.length, 2,
168 "Not all the sources are shown after the global search (4).");
169
170 // The editor's selected text takes a tick to update.
171 executeSoon(() => {
172 ok(isCaretPos(gPanel, 6, 7),
173 "The editor didn't jump to the correct line (4).");
174 is(gEditor.getSelection(), "eval",
175 "The editor didn't select the correct text (4).");
176
177 deferred.resolve();
178 });
179 });
180
181 EventUtils.sendKey("UP", gDebugger);
182
183 return deferred.promise;
184 }
185
186 function testSearchTokenEmpty() {
187 backspaceText(gSearchBox, 4);
188
189 info("Current source url:\n" + gSources.selectedValue);
190 info("Debugger editor text:\n" + gEditor.getText());
191
192 ok(gSources.selectedValue.contains("-02.js"),
193 "The currently shown source is incorrect (4).");
194 is(gSources.visibleItems.length, 2,
195 "Not all the sources are shown after the global search (4).");
196 ok(isCaretPos(gPanel, 6, 7),
197 "The editor didn't remain at the correct line (4).");
198 is(gEditor.getSelection(), "",
199 "The editor shouldn't keep the previous text selected (4).");
200
201 is(gSearchView.itemCount, 0,
202 "The global search pane shouldn't have any child nodes after clearing.");
203 is(gSearchView.widget._parent.hidden, true,
204 "The global search pane shouldn't be visible after clearing.");
205 is(gSearchView._splitter.hidden, true,
206 "The global search pane splitter shouldn't be visible after clearing.");
207 }
208
209 registerCleanupFunction(function() {
210 gTab = null;
211 gDebuggee = null;
212 gPanel = null;
213 gDebugger = null;
214 gEditor = null;
215 gSources = null;
216 gSearchView = null;
217 gSearchBox = null;
218 });

mercurial