|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests basic search functionality (find token and jump to line). |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; |
|
9 |
|
10 let gTab, gDebuggee, gPanel, gDebugger; |
|
11 let gEditor, gSources, gFiltering, gSearchBox; |
|
12 |
|
13 function test() { |
|
14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
15 gTab = aTab; |
|
16 gDebuggee = aDebuggee; |
|
17 gPanel = aPanel; |
|
18 gDebugger = gPanel.panelWin; |
|
19 gEditor = gDebugger.DebuggerView.editor; |
|
20 gSources = gDebugger.DebuggerView.Sources; |
|
21 gFiltering = gDebugger.DebuggerView.Filtering; |
|
22 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; |
|
23 |
|
24 waitForSourceShown(gPanel, ".html").then(performTest); |
|
25 }); |
|
26 } |
|
27 |
|
28 function performTest() { |
|
29 setText(gSearchBox, "#html"); |
|
30 |
|
31 EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger); |
|
32 is(gFiltering.searchData.toSource(), '["#", ["", "html"]]', |
|
33 "The searchbox data wasn't parsed correctly."); |
|
34 ok(isCaretPos(gPanel, 35, 7), |
|
35 "The editor didn't jump to the correct line."); |
|
36 |
|
37 EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger); |
|
38 is(gFiltering.searchData.toSource(), '["#", ["", "html"]]', |
|
39 "The searchbox data wasn't parsed correctly."); |
|
40 ok(isCaretPos(gPanel, 5, 6), |
|
41 "The editor didn't jump to the correct line."); |
|
42 |
|
43 EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger); |
|
44 is(gFiltering.searchData.toSource(), '["#", ["", "html"]]', |
|
45 "The searchbox data wasn't parsed correctly."); |
|
46 ok(isCaretPos(gPanel, 3, 15), |
|
47 "The editor didn't jump to the correct line."); |
|
48 |
|
49 setText(gSearchBox, ":12"); |
|
50 is(gFiltering.searchData.toSource(), '[":", ["", 12]]', |
|
51 "The searchbox data wasn't parsed correctly."); |
|
52 ok(isCaretPos(gPanel, 12), |
|
53 "The editor didn't jump to the correct line."); |
|
54 |
|
55 EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger); |
|
56 is(gFiltering.searchData.toSource(), '[":", ["", 13]]', |
|
57 "The searchbox data wasn't parsed correctly."); |
|
58 ok(isCaretPos(gPanel, 13), |
|
59 "The editor didn't jump to the correct line after Meta+G."); |
|
60 |
|
61 EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger); |
|
62 is(gFiltering.searchData.toSource(), '[":", ["", 14]]', |
|
63 "The searchbox data wasn't parsed correctly."); |
|
64 ok(isCaretPos(gPanel, 14), |
|
65 "The editor didn't jump to the correct line after Ctrl+N."); |
|
66 |
|
67 EventUtils.synthesizeKey("G", { metaKey: true, shiftKey: true }, gDebugger); |
|
68 is(gFiltering.searchData.toSource(), '[":", ["", 13]]', |
|
69 "The searchbox data wasn't parsed correctly."); |
|
70 ok(isCaretPos(gPanel, 13), |
|
71 "The editor didn't jump to the correct line after Meta+Shift+G."); |
|
72 |
|
73 EventUtils.synthesizeKey("p", { ctrlKey: true }, gDebugger); |
|
74 is(gFiltering.searchData.toSource(), '[":", ["", 12]]', |
|
75 "The searchbox data wasn't parsed correctly."); |
|
76 ok(isCaretPos(gPanel, 12), |
|
77 "The editor didn't jump to the correct line after Ctrl+P."); |
|
78 |
|
79 for (let i = 0; i < 100; i++) { |
|
80 EventUtils.sendKey("DOWN", gDebugger); |
|
81 } |
|
82 is(gFiltering.searchData.toSource(), '[":", ["", 36]]', |
|
83 "The searchbox data wasn't parsed correctly."); |
|
84 ok(isCaretPos(gPanel, 36), |
|
85 "The editor didn't jump to the correct line after multiple DOWN keys."); |
|
86 |
|
87 for (let i = 0; i < 100; i++) { |
|
88 EventUtils.sendKey("UP", gDebugger); |
|
89 } |
|
90 is(gFiltering.searchData.toSource(), '[":", ["", 1]]', |
|
91 "The searchbox data wasn't parsed correctly."); |
|
92 ok(isCaretPos(gPanel, 1), |
|
93 "The editor didn't jump to the correct line after multiple UP keys."); |
|
94 |
|
95 |
|
96 let token = "debugger"; |
|
97 setText(gSearchBox, "#" + token); |
|
98 is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]', |
|
99 "The searchbox data wasn't parsed correctly."); |
|
100 ok(isCaretPos(gPanel, 8, 12 + token.length), |
|
101 "The editor didn't jump to the correct token (1)."); |
|
102 |
|
103 EventUtils.sendKey("DOWN", gDebugger); |
|
104 is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]', |
|
105 "The searchbox data wasn't parsed correctly."); |
|
106 ok(isCaretPos(gPanel, 14, 9 + token.length), |
|
107 "The editor didn't jump to the correct token (2)."); |
|
108 |
|
109 EventUtils.sendKey("DOWN", gDebugger); |
|
110 is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]', |
|
111 "The searchbox data wasn't parsed correctly."); |
|
112 ok(isCaretPos(gPanel, 18, 15 + token.length), |
|
113 "The editor didn't jump to the correct token (3)."); |
|
114 |
|
115 EventUtils.sendKey("RETURN", gDebugger); |
|
116 is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]', |
|
117 "The searchbox data wasn't parsed correctly."); |
|
118 ok(isCaretPos(gPanel, 26, 11 + token.length), |
|
119 "The editor didn't jump to the correct token (4)."); |
|
120 |
|
121 EventUtils.sendKey("RETURN", gDebugger); |
|
122 is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]', |
|
123 "The searchbox data wasn't parsed correctly."); |
|
124 ok(isCaretPos(gPanel, 8, 12 + token.length), |
|
125 "The editor didn't jump to the correct token (5)."); |
|
126 |
|
127 EventUtils.sendKey("UP", gDebugger); |
|
128 is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]', |
|
129 "The searchbox data wasn't parsed correctly."); |
|
130 ok(isCaretPos(gPanel, 26, 11 + token.length), |
|
131 "The editor didn't jump to the correct token (6)."); |
|
132 |
|
133 setText(gSearchBox, ":bogus#" + token + ";"); |
|
134 is(gFiltering.searchData.toSource(), '["#", [":bogus", "debugger;"]]', |
|
135 "The searchbox data wasn't parsed correctly."); |
|
136 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
137 "The editor didn't jump to the correct token (7)."); |
|
138 |
|
139 setText(gSearchBox, ":13#" + token + ";"); |
|
140 is(gFiltering.searchData.toSource(), '["#", [":13", "debugger;"]]', |
|
141 "The searchbox data wasn't parsed correctly."); |
|
142 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
143 "The editor didn't jump to the correct token (8)."); |
|
144 |
|
145 setText(gSearchBox, ":#" + token + ";"); |
|
146 is(gFiltering.searchData.toSource(), '["#", [":", "debugger;"]]', |
|
147 "The searchbox data wasn't parsed correctly."); |
|
148 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
149 "The editor didn't jump to the correct token (9)."); |
|
150 |
|
151 setText(gSearchBox, "::#" + token + ";"); |
|
152 is(gFiltering.searchData.toSource(), '["#", ["::", "debugger;"]]', |
|
153 "The searchbox data wasn't parsed correctly."); |
|
154 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
155 "The editor didn't jump to the correct token (10)."); |
|
156 |
|
157 setText(gSearchBox, ":::#" + token + ";"); |
|
158 is(gFiltering.searchData.toSource(), '["#", [":::", "debugger;"]]', |
|
159 "The searchbox data wasn't parsed correctly."); |
|
160 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
161 "The editor didn't jump to the correct token (11)."); |
|
162 |
|
163 |
|
164 setText(gSearchBox, "#" + token + ";" + ":bogus"); |
|
165 is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:bogus"]]', |
|
166 "The searchbox data wasn't parsed correctly."); |
|
167 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
168 "The editor didn't jump to the correct token (12)."); |
|
169 |
|
170 setText(gSearchBox, "#" + token + ";" + ":13"); |
|
171 is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:13"]]', |
|
172 "The searchbox data wasn't parsed correctly."); |
|
173 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
174 "The editor didn't jump to the correct token (13)."); |
|
175 |
|
176 setText(gSearchBox, "#" + token + ";" + ":"); |
|
177 is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:"]]', |
|
178 "The searchbox data wasn't parsed correctly."); |
|
179 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
180 "The editor didn't jump to the correct token (14)."); |
|
181 |
|
182 setText(gSearchBox, "#" + token + ";" + "::"); |
|
183 is(gFiltering.searchData.toSource(), '["#", ["", "debugger;::"]]', |
|
184 "The searchbox data wasn't parsed correctly."); |
|
185 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
186 "The editor didn't jump to the correct token (15)."); |
|
187 |
|
188 setText(gSearchBox, "#" + token + ";" + ":::"); |
|
189 is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:::"]]', |
|
190 "The searchbox data wasn't parsed correctly."); |
|
191 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
192 "The editor didn't jump to the correct token (16)."); |
|
193 |
|
194 |
|
195 setText(gSearchBox, ":i am not a number"); |
|
196 is(gFiltering.searchData.toSource(), '[":", ["", 0]]', |
|
197 "The searchbox data wasn't parsed correctly."); |
|
198 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
199 "The editor didn't remain at the correct token (17)."); |
|
200 |
|
201 setText(gSearchBox, "#__i do not exist__"); |
|
202 is(gFiltering.searchData.toSource(), '["#", ["", "__i do not exist__"]]', |
|
203 "The searchbox data wasn't parsed correctly."); |
|
204 ok(isCaretPos(gPanel, 14, 9 + token.length + 1), |
|
205 "The editor didn't remain at the correct token (18)."); |
|
206 |
|
207 |
|
208 setText(gSearchBox, "#" + token); |
|
209 is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]', |
|
210 "The searchbox data wasn't parsed correctly."); |
|
211 ok(isCaretPos(gPanel, 8, 12 + token.length), |
|
212 "The editor didn't jump to the correct token (19)."); |
|
213 |
|
214 |
|
215 clearText(gSearchBox); |
|
216 is(gFiltering.searchData.toSource(), '["", [""]]', |
|
217 "The searchbox data wasn't parsed correctly."); |
|
218 |
|
219 EventUtils.sendKey("RETURN", gDebugger); |
|
220 is(gFiltering.searchData.toSource(), '["", [""]]', |
|
221 "The searchbox data wasn't parsed correctly."); |
|
222 ok(isCaretPos(gPanel, 8, 12 + token.length), |
|
223 "The editor shouldn't jump to another token (20)."); |
|
224 |
|
225 EventUtils.sendKey("RETURN", gDebugger); |
|
226 is(gFiltering.searchData.toSource(), '["", [""]]', |
|
227 "The searchbox data wasn't parsed correctly."); |
|
228 ok(isCaretPos(gPanel, 8, 12 + token.length), |
|
229 "The editor shouldn't jump to another token (21)."); |
|
230 |
|
231 |
|
232 setText(gSearchBox, ":1:2:3:a:b:c:::12"); |
|
233 is(gFiltering.searchData.toSource(), '[":", [":1:2:3:a:b:c::", 12]]', |
|
234 "The searchbox data wasn't parsed correctly."); |
|
235 ok(isCaretPos(gPanel, 12), |
|
236 "The editor didn't jump to the correct line (22)."); |
|
237 |
|
238 setText(gSearchBox, "#don't#find#me#instead#find#" + token); |
|
239 is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]', |
|
240 "The searchbox data wasn't parsed correctly."); |
|
241 ok(isCaretPos(gPanel, 8, 12 + token.length), |
|
242 "The editor didn't jump to the correct token (23)."); |
|
243 |
|
244 EventUtils.sendKey("DOWN", gDebugger); |
|
245 is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]', |
|
246 "The searchbox data wasn't parsed correctly."); |
|
247 ok(isCaretPos(gPanel, 14, 9 + token.length), |
|
248 "The editor didn't jump to the correct token (24)."); |
|
249 |
|
250 EventUtils.sendKey("DOWN", gDebugger); |
|
251 is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]', |
|
252 "The searchbox data wasn't parsed correctly."); |
|
253 ok(isCaretPos(gPanel, 18, 15 + token.length), |
|
254 "The editor didn't jump to the correct token (25)."); |
|
255 |
|
256 EventUtils.sendKey("RETURN", gDebugger); |
|
257 is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]', |
|
258 "The searchbox data wasn't parsed correctly."); |
|
259 ok(isCaretPos(gPanel, 26, 11 + token.length), |
|
260 "The editor didn't jump to the correct token (26)."); |
|
261 |
|
262 EventUtils.sendKey("RETURN", gDebugger); |
|
263 is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]', |
|
264 "The searchbox data wasn't parsed correctly."); |
|
265 ok(isCaretPos(gPanel, 8, 12 + token.length), |
|
266 "The editor didn't jump to the correct token (27)."); |
|
267 |
|
268 EventUtils.sendKey("UP", gDebugger); |
|
269 is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]', |
|
270 "The searchbox data wasn't parsed correctly."); |
|
271 ok(isCaretPos(gPanel, 26, 11 + token.length), |
|
272 "The editor didn't jump to the correct token (28)."); |
|
273 |
|
274 |
|
275 clearText(gSearchBox); |
|
276 is(gFiltering.searchData.toSource(), '["", [""]]', |
|
277 "The searchbox data wasn't parsed correctly."); |
|
278 ok(isCaretPos(gPanel, 26, 11 + token.length), |
|
279 "The editor didn't remain at the correct token (29)."); |
|
280 is(gSources.visibleItems.length, 1, |
|
281 "Not all the sources are shown after the search (30)."); |
|
282 |
|
283 |
|
284 gEditor.focus(); |
|
285 gEditor.setSelection.apply(gEditor, gEditor.getPosition(1, 5)); |
|
286 ok(isCaretPos(gPanel, 1, 6), |
|
287 "The editor caret position didn't update after selecting some text."); |
|
288 |
|
289 EventUtils.synthesizeKey("F", { accelKey: true }); |
|
290 is(gFiltering.searchData.toSource(), '["#", ["", "!-- "]]', |
|
291 "The searchbox data wasn't parsed correctly."); |
|
292 is(gSearchBox.value, "#!-- ", |
|
293 "The search field has the right initial value (1)."); |
|
294 |
|
295 gEditor.focus(); |
|
296 gEditor.setSelection.apply(gEditor, gEditor.getPosition(415, 418)); |
|
297 ok(isCaretPos(gPanel, 21, 30), |
|
298 "The editor caret position didn't update after selecting some number."); |
|
299 |
|
300 EventUtils.synthesizeKey("L", { accelKey: true }); |
|
301 is(gFiltering.searchData.toSource(), '[":", ["", 100]]', |
|
302 "The searchbox data wasn't parsed correctly."); |
|
303 is(gSearchBox.value, ":100", |
|
304 "The search field has the right initial value (2)."); |
|
305 |
|
306 |
|
307 closeDebuggerAndFinish(gPanel); |
|
308 } |
|
309 |
|
310 registerCleanupFunction(function() { |
|
311 gTab = null; |
|
312 gDebuggee = null; |
|
313 gPanel = null; |
|
314 gDebugger = null; |
|
315 gEditor = null; |
|
316 gSources = null; |
|
317 gFiltering = null; |
|
318 gSearchBox = null; |
|
319 }); |