|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests basic functionality of global search (lowercase + upper case, expected |
|
6 * UI behavior, number of results found etc.) |
|
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(secondSearch) |
|
28 .then(clearSearch) |
|
29 .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
|
30 .then(null, aError => { |
|
31 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
32 }); |
|
33 |
|
34 gDebuggee.firstCall(); |
|
35 }); |
|
36 } |
|
37 |
|
38 function firstSearch() { |
|
39 let deferred = promise.defer(); |
|
40 |
|
41 is(gSearchView.itemCount, 0, |
|
42 "The global search pane shouldn't have any entries yet."); |
|
43 is(gSearchView.widget._parent.hidden, true, |
|
44 "The global search pane shouldn't be visible yet."); |
|
45 is(gSearchView._splitter.hidden, true, |
|
46 "The global search pane splitter shouldn't be visible yet."); |
|
47 |
|
48 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { |
|
49 // Some operations are synchronously dispatched on the main thread, |
|
50 // to avoid blocking UI, thus giving the impression of faster searching. |
|
51 executeSoon(() => { |
|
52 info("Current source url:\n" + gSources.selectedValue); |
|
53 info("Debugger editor text:\n" + gEditor.getText()); |
|
54 |
|
55 ok(isCaretPos(gPanel, 1), |
|
56 "The editor shouldn't have jumped to a matching line yet."); |
|
57 ok(gSources.selectedValue.contains("-02.js"), |
|
58 "The current source shouldn't have changed after a global search."); |
|
59 is(gSources.visibleItems.length, 2, |
|
60 "Not all the sources are shown after the global search."); |
|
61 |
|
62 let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
|
63 is(sourceResults.length, 2, |
|
64 "There should be matches found in two sources."); |
|
65 |
|
66 let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); |
|
67 let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); |
|
68 is(item0.instance.expanded, true, |
|
69 "The first source results should automatically be expanded.") |
|
70 is(item1.instance.expanded, true, |
|
71 "The second source results should automatically be expanded.") |
|
72 |
|
73 let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result"); |
|
74 let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result"); |
|
75 is(searchResult0.length, 1, |
|
76 "There should be one line result for the first url."); |
|
77 is(searchResult1.length, 2, |
|
78 "There should be two line results for the second url."); |
|
79 |
|
80 let firstLine0 = searchResult0[0]; |
|
81 is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1", |
|
82 "The first result for the first source doesn't have the correct line attached."); |
|
83 |
|
84 is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1, |
|
85 "The first result for the first source doesn't have the correct number of nodes for a line."); |
|
86 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 3, |
|
87 "The first result for the first source doesn't have the correct number of strings in a line."); |
|
88 |
|
89 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, |
|
90 "The first result for the first source doesn't have the correct number of matches in a line."); |
|
91 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", |
|
92 "The first result for the first source doesn't have the correct match in a line."); |
|
93 |
|
94 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, |
|
95 "The first result for the first source doesn't have the correct number of non-matches in a line."); |
|
96 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ", |
|
97 "The first result for the first source doesn't have the correct non-matches in a line."); |
|
98 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.", |
|
99 "The first result for the first source doesn't have the correct non-matches in a line."); |
|
100 |
|
101 let firstLine1 = searchResult1[0]; |
|
102 is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1", |
|
103 "The first result for the second source doesn't have the correct line attached."); |
|
104 |
|
105 is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1, |
|
106 "The first result for the second source doesn't have the correct number of nodes for a line."); |
|
107 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3, |
|
108 "The first result for the second source doesn't have the correct number of strings in a line."); |
|
109 |
|
110 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, |
|
111 "The first result for the second source doesn't have the correct number of matches in a line."); |
|
112 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", |
|
113 "The first result for the second source doesn't have the correct match in a line."); |
|
114 |
|
115 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, |
|
116 "The first result for the second source doesn't have the correct number of non-matches in a line."); |
|
117 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ", |
|
118 "The first result for the second source doesn't have the correct non-matches in a line."); |
|
119 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.", |
|
120 "The first result for the second source doesn't have the correct non-matches in a line."); |
|
121 |
|
122 let secondLine1 = searchResult1[1]; |
|
123 is(secondLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "6", |
|
124 "The second result for the second source doesn't have the correct line attached."); |
|
125 |
|
126 is(secondLine1.querySelectorAll(".dbg-results-line-contents").length, 1, |
|
127 "The second result for the second source doesn't have the correct number of nodes for a line."); |
|
128 is(secondLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3, |
|
129 "The second result for the second source doesn't have the correct number of strings in a line."); |
|
130 |
|
131 is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, |
|
132 "The second result for the second source doesn't have the correct number of matches in a line."); |
|
133 is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", |
|
134 "The second result for the second source doesn't have the correct match in a line."); |
|
135 |
|
136 is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, |
|
137 "The second result for the second source doesn't have the correct number of non-matches in a line."); |
|
138 is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), ' eval("', |
|
139 "The second result for the second source doesn't have the correct non-matches in a line."); |
|
140 is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), 'bugger;");', |
|
141 "The second result for the second source doesn't have the correct non-matches in a line."); |
|
142 |
|
143 deferred.resolve(); |
|
144 }); |
|
145 }); |
|
146 |
|
147 setText(gSearchBox, "!de"); |
|
148 |
|
149 return deferred.promise; |
|
150 } |
|
151 |
|
152 function secondSearch() { |
|
153 let deferred = promise.defer(); |
|
154 |
|
155 is(gSearchView.itemCount, 2, |
|
156 "The global search pane should have some child nodes from the previous search."); |
|
157 is(gSearchView.widget._parent.hidden, false, |
|
158 "The global search pane should be visible from the previous search."); |
|
159 is(gSearchView._splitter.hidden, false, |
|
160 "The global search pane splitter should be visible from the previous search."); |
|
161 |
|
162 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { |
|
163 // Some operations are synchronously dispatched on the main thread, |
|
164 // to avoid blocking UI, thus giving the impression of faster searching. |
|
165 executeSoon(() => { |
|
166 info("Current source url:\n" + gSources.selectedValue); |
|
167 info("Debugger editor text:\n" + gEditor.getText()); |
|
168 |
|
169 ok(isCaretPos(gPanel, 1), |
|
170 "The editor shouldn't have jumped to a matching line yet."); |
|
171 ok(gSources.selectedValue.contains("-02.js"), |
|
172 "The current source shouldn't have changed after a global search."); |
|
173 is(gSources.visibleItems.length, 2, |
|
174 "Not all the sources are shown after the global search."); |
|
175 |
|
176 let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
|
177 is(sourceResults.length, 2, |
|
178 "There should be matches found in two sources."); |
|
179 |
|
180 let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); |
|
181 let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); |
|
182 is(item0.instance.expanded, true, |
|
183 "The first source results should automatically be expanded.") |
|
184 is(item1.instance.expanded, true, |
|
185 "The second source results should automatically be expanded.") |
|
186 |
|
187 let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result"); |
|
188 let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result"); |
|
189 is(searchResult0.length, 1, |
|
190 "There should be one line result for the first url."); |
|
191 is(searchResult1.length, 1, |
|
192 "There should be one line result for the second url."); |
|
193 |
|
194 let firstLine0 = searchResult0[0]; |
|
195 is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1", |
|
196 "The first result for the first source doesn't have the correct line attached."); |
|
197 |
|
198 is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1, |
|
199 "The first result for the first source doesn't have the correct number of nodes for a line."); |
|
200 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 5, |
|
201 "The first result for the first source doesn't have the correct number of strings in a line."); |
|
202 |
|
203 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2, |
|
204 "The first result for the first source doesn't have the correct number of matches in a line."); |
|
205 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed", |
|
206 "The first result for the first source doesn't have the correct matches in a line."); |
|
207 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed", |
|
208 "The first result for the first source doesn't have the correct matches in a line."); |
|
209 |
|
210 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3, |
|
211 "The first result for the first source doesn't have the correct number of non-matches in a line."); |
|
212 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d", |
|
213 "The first result for the first source doesn't have the correct non-matches in a line."); |
|
214 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat", |
|
215 "The first result for the first source doesn't have the correct non-matches in a line."); |
|
216 is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.", |
|
217 "The first result for the first source doesn't have the correct non-matches in a line."); |
|
218 |
|
219 let firstLine1 = searchResult1[0]; |
|
220 is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1", |
|
221 "The first result for the second source doesn't have the correct line attached."); |
|
222 |
|
223 is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1, |
|
224 "The first result for the second source doesn't have the correct number of nodes for a line."); |
|
225 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 5, |
|
226 "The first result for the second source doesn't have the correct number of strings in a line."); |
|
227 |
|
228 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2, |
|
229 "The first result for the second source doesn't have the correct number of matches in a line."); |
|
230 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed", |
|
231 "The first result for the second source doesn't have the correct matches in a line."); |
|
232 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed", |
|
233 "The first result for the second source doesn't have the correct matches in a line."); |
|
234 |
|
235 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3, |
|
236 "The first result for the second source doesn't have the correct number of non-matches in a line."); |
|
237 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d", |
|
238 "The first result for the second source doesn't have the correct non-matches in a line."); |
|
239 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat", |
|
240 "The first result for the second source doesn't have the correct non-matches in a line."); |
|
241 is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.", |
|
242 "The first result for the second source doesn't have the correct non-matches in a line."); |
|
243 |
|
244 deferred.resolve(); |
|
245 }); |
|
246 }); |
|
247 |
|
248 backspaceText(gSearchBox, 2); |
|
249 typeText(gSearchBox, "ED"); |
|
250 |
|
251 return deferred.promise; |
|
252 } |
|
253 |
|
254 function clearSearch() { |
|
255 gSearchView.clearView(); |
|
256 |
|
257 is(gSearchView.itemCount, 0, |
|
258 "The global search pane shouldn't have any child nodes after clearing."); |
|
259 is(gSearchView.widget._parent.hidden, true, |
|
260 "The global search pane shouldn't be visible after clearing."); |
|
261 is(gSearchView._splitter.hidden, true, |
|
262 "The global search pane splitter shouldn't be visible after clearing."); |
|
263 } |
|
264 |
|
265 registerCleanupFunction(function() { |
|
266 gTab = null; |
|
267 gDebuggee = null; |
|
268 gPanel = null; |
|
269 gDebugger = null; |
|
270 gEditor = null; |
|
271 gSources = null; |
|
272 gSearchView = null; |
|
273 gSearchBox = null; |
|
274 }); |