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