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
|
/* -*- 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 file search functionality.
*/
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
var gTab, gPanel, gDebugger;
var gSources, gSearchBox;
function test() {
let options = {
source: EXAMPLE_URL + "code_script-switching-01.js",
line: 1,
};
initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
gTab = aTab;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gSources = gDebugger.DebuggerView.Sources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
// Calling `firstCall` is going to break into the other script
waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
.then(performSimpleSearch)
.then(() => verifySourceAndCaret("-01.js", 1, 1, [1, 1]))
.then(combineWithLineSearch)
.then(() => verifySourceAndCaret("-01.js", 2, 1, [53, 53]))
.then(combineWithTokenSearch)
.then(() => verifySourceAndCaret("-01.js", 2, 48, [96, 100]))
.then(combineWithTokenColonSearch)
.then(() => verifySourceAndCaret("-01.js", 2, 11, [56, 63]))
.then(() => resumeDebuggerThenCloseAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
callInTab(gTab, "firstCall");
});
}
function performSimpleSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 6),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js")
]);
setText(gSearchBox, "1");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1)
]));
}
function combineWithLineSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 2)
]);
typeText(gSearchBox, ":2");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 2)
]));
}
function combineWithTokenSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 2),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 2, 48)
]);
backspaceText(gSearchBox, 2);
typeText(gSearchBox, "#zero");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 2, 48)
]));
}
function combineWithTokenColonSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 2, 48),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 2, 11)
]);
backspaceText(gSearchBox, 4);
typeText(gSearchBox, "http://");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 2, 11)
]));
}
function verifySourceAndCaret(aUrl, aLine, aColumn, aSelection) {
ok(gSources.selectedItem.attachment.label.includes(aUrl),
"The selected item's label appears to be correct.");
ok(gSources.selectedItem.attachment.source.url.includes(aUrl),
"The selected item's value appears to be correct.");
ok(isCaretPos(gPanel, aLine, aColumn),
"The current caret position appears to be correct.");
ok(isEditorSel(gPanel, aSelection),
"The current editor selection appears to be correct.");
}
registerCleanupFunction(function () {
gTab = null;
gPanel = null;
gDebugger = null;
gSources = null;
gSearchBox = null;
});
|