|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests more complex functionality of sources filtering (file search). |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_editor-mode.html"; |
|
9 |
|
10 let gTab, gDebuggee, gPanel, gDebugger; |
|
11 let gSources, gSourceUtils, gSearchView, gSearchBox; |
|
12 |
|
13 function test() { |
|
14 // Debug test slaves are a bit slow at this test. |
|
15 requestLongerTimeout(3); |
|
16 |
|
17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
18 gTab = aTab; |
|
19 gDebuggee = aDebuggee; |
|
20 gPanel = aPanel; |
|
21 gDebugger = gPanel.panelWin; |
|
22 gSources = gDebugger.DebuggerView.Sources; |
|
23 gSourceUtils = gDebugger.SourceUtils; |
|
24 gSearchView = gDebugger.DebuggerView.FilteredSources; |
|
25 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; |
|
26 |
|
27 waitForSourceShown(gPanel, "-01.js") |
|
28 .then(firstSearch) |
|
29 .then(secondSearch) |
|
30 .then(thirdSearch) |
|
31 .then(fourthSearch) |
|
32 .then(fifthSearch) |
|
33 .then(goDown) |
|
34 .then(goDownAndWrap) |
|
35 .then(goUpAndWrap) |
|
36 .then(goUp) |
|
37 .then(returnAndSwitch) |
|
38 .then(firstSearch) |
|
39 .then(clickAndSwitch) |
|
40 .then(() => closeDebuggerAndFinish(gPanel)) |
|
41 .then(null, aError => { |
|
42 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
43 }); |
|
44 }); |
|
45 } |
|
46 |
|
47 function firstSearch() { |
|
48 let finished = promise.all([ |
|
49 ensureSourceIs(gPanel, "-01.js"), |
|
50 ensureCaretAt(gPanel, 1), |
|
51 once(gDebugger, "popupshown"), |
|
52 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND) |
|
53 ]); |
|
54 |
|
55 setText(gSearchBox, "."); |
|
56 |
|
57 return finished.then(() => promise.all([ |
|
58 ensureSourceIs(gPanel, "-01.js"), |
|
59 ensureCaretAt(gPanel, 1), |
|
60 verifyContents([ |
|
61 "code_script-switching-01.js?a=b", |
|
62 "code_test-editor-mode?c=d", |
|
63 "doc_editor-mode.html" |
|
64 ]) |
|
65 ])); |
|
66 } |
|
67 |
|
68 function secondSearch() { |
|
69 let finished = promise.all([ |
|
70 ensureSourceIs(gPanel, "-01.js"), |
|
71 ensureCaretAt(gPanel, 1), |
|
72 once(gDebugger, "popupshown"), |
|
73 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND) |
|
74 ]); |
|
75 |
|
76 typeText(gSearchBox, "-0"); |
|
77 |
|
78 return finished.then(() => promise.all([ |
|
79 ensureSourceIs(gPanel, "-01.js"), |
|
80 ensureCaretAt(gPanel, 1), |
|
81 verifyContents(["code_script-switching-01.js?a=b"]) |
|
82 ])); |
|
83 } |
|
84 |
|
85 function thirdSearch() { |
|
86 let finished = promise.all([ |
|
87 ensureSourceIs(gPanel, "-01.js"), |
|
88 ensureCaretAt(gPanel, 1), |
|
89 once(gDebugger, "popupshown"), |
|
90 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND) |
|
91 ]); |
|
92 |
|
93 backspaceText(gSearchBox, 1); |
|
94 |
|
95 return finished.then(() => promise.all([ |
|
96 ensureSourceIs(gPanel, "-01.js"), |
|
97 ensureCaretAt(gPanel, 1), |
|
98 verifyContents([ |
|
99 "code_script-switching-01.js?a=b", |
|
100 "code_test-editor-mode?c=d", |
|
101 "doc_editor-mode.html" |
|
102 ]) |
|
103 ])); |
|
104 } |
|
105 |
|
106 function fourthSearch() { |
|
107 let finished = promise.all([ |
|
108 ensureSourceIs(gPanel, "-01.js"), |
|
109 ensureCaretAt(gPanel, 1), |
|
110 once(gDebugger, "popupshown"), |
|
111 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
112 waitForSourceShown(gPanel, "test-editor-mode") |
|
113 ]); |
|
114 |
|
115 setText(gSearchBox, "code_test"); |
|
116 |
|
117 return finished.then(() => promise.all([ |
|
118 ensureSourceIs(gPanel, "test-editor-mode"), |
|
119 ensureCaretAt(gPanel, 1), |
|
120 verifyContents(["code_test-editor-mode?c=d"]) |
|
121 ])); |
|
122 } |
|
123 |
|
124 function fifthSearch() { |
|
125 let finished = promise.all([ |
|
126 ensureSourceIs(gPanel, "test-editor-mode"), |
|
127 ensureCaretAt(gPanel, 1), |
|
128 once(gDebugger, "popupshown"), |
|
129 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
130 waitForSourceShown(gPanel, "-01.js") |
|
131 ]); |
|
132 |
|
133 backspaceText(gSearchBox, 4); |
|
134 |
|
135 return finished.then(() => promise.all([ |
|
136 ensureSourceIs(gPanel, "-01.js"), |
|
137 ensureCaretAt(gPanel, 1), |
|
138 verifyContents([ |
|
139 "code_script-switching-01.js?a=b", |
|
140 "code_test-editor-mode?c=d" |
|
141 ]) |
|
142 ])); |
|
143 } |
|
144 |
|
145 function goDown() { |
|
146 let finished = promise.all([ |
|
147 ensureSourceIs(gPanel, "-01.js"), |
|
148 ensureCaretAt(gPanel, 1), |
|
149 waitForSourceShown(gPanel, "test-editor-mode"), |
|
150 ]); |
|
151 |
|
152 EventUtils.sendKey("DOWN", gDebugger); |
|
153 |
|
154 return finished.then(() => promise.all([ |
|
155 ensureSourceIs(gPanel,"test-editor-mode"), |
|
156 ensureCaretAt(gPanel, 1), |
|
157 verifyContents([ |
|
158 "code_script-switching-01.js?a=b", |
|
159 "code_test-editor-mode?c=d" |
|
160 ]) |
|
161 ])); |
|
162 } |
|
163 |
|
164 function goDownAndWrap() { |
|
165 let finished = promise.all([ |
|
166 ensureSourceIs(gPanel, "test-editor-mode"), |
|
167 ensureCaretAt(gPanel, 1), |
|
168 waitForSourceShown(gPanel, "-01.js") |
|
169 ]); |
|
170 |
|
171 EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger); |
|
172 |
|
173 return finished.then(() => promise.all([ |
|
174 ensureSourceIs(gPanel,"-01.js"), |
|
175 ensureCaretAt(gPanel, 1), |
|
176 verifyContents([ |
|
177 "code_script-switching-01.js?a=b", |
|
178 "code_test-editor-mode?c=d" |
|
179 ]) |
|
180 ])); |
|
181 } |
|
182 |
|
183 function goUpAndWrap() { |
|
184 let finished = promise.all([ |
|
185 ensureSourceIs(gPanel,"-01.js"), |
|
186 ensureCaretAt(gPanel, 1), |
|
187 waitForSourceShown(gPanel, "test-editor-mode") |
|
188 ]); |
|
189 |
|
190 EventUtils.synthesizeKey("G", { metaKey: true }, gDebugger); |
|
191 |
|
192 return finished.then(() => promise.all([ |
|
193 ensureSourceIs(gPanel,"test-editor-mode"), |
|
194 ensureCaretAt(gPanel, 1), |
|
195 verifyContents([ |
|
196 "code_script-switching-01.js?a=b", |
|
197 "code_test-editor-mode?c=d" |
|
198 ]) |
|
199 ])); |
|
200 } |
|
201 |
|
202 function goUp() { |
|
203 let finished = promise.all([ |
|
204 ensureSourceIs(gPanel,"test-editor-mode"), |
|
205 ensureCaretAt(gPanel, 1), |
|
206 waitForSourceShown(gPanel, "-01.js"), |
|
207 ]); |
|
208 |
|
209 EventUtils.sendKey("UP", gDebugger); |
|
210 |
|
211 return finished.then(() => promise.all([ |
|
212 ensureSourceIs(gPanel,"-01.js"), |
|
213 ensureCaretAt(gPanel, 1), |
|
214 verifyContents([ |
|
215 "code_script-switching-01.js?a=b", |
|
216 "code_test-editor-mode?c=d" |
|
217 ]) |
|
218 ])); |
|
219 } |
|
220 |
|
221 function returnAndSwitch() { |
|
222 let finished = promise.all([ |
|
223 ensureSourceIs(gPanel,"-01.js"), |
|
224 ensureCaretAt(gPanel, 1), |
|
225 once(gDebugger, "popuphidden") |
|
226 ]); |
|
227 |
|
228 EventUtils.sendKey("RETURN", gDebugger); |
|
229 |
|
230 return finished.then(() => promise.all([ |
|
231 ensureSourceIs(gPanel,"-01.js"), |
|
232 ensureCaretAt(gPanel, 1) |
|
233 ])); |
|
234 } |
|
235 |
|
236 function clickAndSwitch() { |
|
237 let finished = promise.all([ |
|
238 ensureSourceIs(gPanel,"-01.js"), |
|
239 ensureCaretAt(gPanel, 1), |
|
240 once(gDebugger, "popuphidden"), |
|
241 waitForSourceShown(gPanel, "test-editor-mode") |
|
242 ]); |
|
243 |
|
244 EventUtils.sendMouseEvent({ type: "click" }, gSearchView.items[1].target, gDebugger); |
|
245 |
|
246 return finished.then(() => promise.all([ |
|
247 ensureSourceIs(gPanel,"test-editor-mode"), |
|
248 ensureCaretAt(gPanel, 1) |
|
249 ])); |
|
250 } |
|
251 |
|
252 function verifyContents(aMatches) { |
|
253 is(gSources.visibleItems.length, 3, |
|
254 "The unmatched sources in the widget should not be hidden."); |
|
255 is(gSearchView.itemCount, aMatches.length, |
|
256 "The filtered sources view should have the right items available."); |
|
257 |
|
258 for (let i = 0; i < gSearchView.itemCount; i++) { |
|
259 let trimmedLabel = gSourceUtils.trimUrlLength(gSourceUtils.trimUrlQuery(aMatches[i])); |
|
260 let trimmedLocation = gSourceUtils.trimUrlLength(EXAMPLE_URL + aMatches[i], 0, "start"); |
|
261 |
|
262 ok(gSearchView.widget._parent.querySelector(".results-panel-item-label[value=\"" + trimmedLabel + "\"]"), |
|
263 "The filtered sources view should have the correct source labels."); |
|
264 ok(gSearchView.widget._parent.querySelector(".results-panel-item-label-below[value=\"" + trimmedLocation + "\"]"), |
|
265 "The filtered sources view should have the correct source locations."); |
|
266 } |
|
267 } |
|
268 |
|
269 registerCleanupFunction(function() { |
|
270 gTab = null; |
|
271 gDebuggee = null; |
|
272 gPanel = null; |
|
273 gDebugger = null; |
|
274 gSources = null; |
|
275 gSourceUtils = null; |
|
276 gSearchView = null; |
|
277 gSearchBox = null; |
|
278 }); |