|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests basic functionality of sources filtering (file search). |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
|
9 |
|
10 let gTab, gDebuggee, gPanel, gDebugger; |
|
11 let gSources, 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 gSearchView = gDebugger.DebuggerView.FilteredSources; |
|
24 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; |
|
25 |
|
26 waitForSourceShown(gPanel, "-01.js") |
|
27 .then(bogusSearch) |
|
28 .then(firstSearch) |
|
29 .then(secondSearch) |
|
30 .then(thirdSearch) |
|
31 .then(fourthSearch) |
|
32 .then(fifthSearch) |
|
33 .then(sixthSearch) |
|
34 .then(seventhSearch) |
|
35 .then(() => closeDebuggerAndFinish(gPanel)) |
|
36 .then(null, aError => { |
|
37 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
38 }); |
|
39 }); |
|
40 } |
|
41 |
|
42 function bogusSearch() { |
|
43 let finished = promise.all([ |
|
44 ensureSourceIs(gPanel, "-01.js"), |
|
45 ensureCaretAt(gPanel, 1), |
|
46 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND) |
|
47 ]); |
|
48 |
|
49 setText(gSearchBox, "BOGUS"); |
|
50 |
|
51 return finished.then(() => promise.all([ |
|
52 ensureSourceIs(gPanel, "-01.js"), |
|
53 ensureCaretAt(gPanel, 1), |
|
54 verifyContents({ itemCount: 0, hidden: true }) |
|
55 ])); |
|
56 } |
|
57 |
|
58 function firstSearch() { |
|
59 let finished = promise.all([ |
|
60 ensureSourceIs(gPanel, "-01.js"), |
|
61 ensureCaretAt(gPanel, 1), |
|
62 once(gDebugger, "popupshown"), |
|
63 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
64 waitForSourceShown(gPanel, "-02.js") |
|
65 ]); |
|
66 |
|
67 setText(gSearchBox, "-02.js"); |
|
68 |
|
69 return finished.then(() => promise.all([ |
|
70 ensureSourceIs(gPanel, "-02.js"), |
|
71 ensureCaretAt(gPanel, 1), |
|
72 verifyContents({ itemCount: 1, hidden: false }) |
|
73 ])); |
|
74 } |
|
75 |
|
76 function secondSearch() { |
|
77 let finished = promise.all([ |
|
78 once(gDebugger, "popupshown"), |
|
79 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
80 waitForSourceShown(gPanel, "-01.js") |
|
81 ]) |
|
82 .then(() => { |
|
83 let finished = promise.all([ |
|
84 once(gDebugger, "popupshown"), |
|
85 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
86 waitForCaretUpdated(gPanel, 5) |
|
87 ]) |
|
88 .then(() => promise.all([ |
|
89 ensureSourceIs(gPanel, "-01.js"), |
|
90 ensureCaretAt(gPanel, 5), |
|
91 verifyContents({ itemCount: 1, hidden: false }) |
|
92 ])); |
|
93 |
|
94 typeText(gSearchBox, ":5"); |
|
95 return finished; |
|
96 }); |
|
97 |
|
98 setText(gSearchBox, ".*-01\.js"); |
|
99 return finished; |
|
100 } |
|
101 |
|
102 function thirdSearch() { |
|
103 let finished = promise.all([ |
|
104 once(gDebugger, "popupshown"), |
|
105 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
106 waitForSourceShown(gPanel, "-02.js") |
|
107 ]) |
|
108 .then(() => { |
|
109 let finished = promise.all([ |
|
110 once(gDebugger, "popupshown"), |
|
111 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
112 waitForCaretUpdated(gPanel, 6, 12) |
|
113 ]) |
|
114 .then(() => promise.all([ |
|
115 ensureSourceIs(gPanel, "-02.js"), |
|
116 ensureCaretAt(gPanel, 6, 12), |
|
117 verifyContents({ itemCount: 1, hidden: false }) |
|
118 ])); |
|
119 |
|
120 typeText(gSearchBox, "#deb"); |
|
121 return finished; |
|
122 }); |
|
123 |
|
124 setText(gSearchBox, ".*-02\.js"); |
|
125 return finished; |
|
126 } |
|
127 |
|
128 function fourthSearch() { |
|
129 let finished = promise.all([ |
|
130 once(gDebugger, "popupshown"), |
|
131 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
132 waitForSourceShown(gPanel, "-01.js") |
|
133 ]) |
|
134 .then(() => { |
|
135 let finished = promise.all([ |
|
136 once(gDebugger, "popupshown"), |
|
137 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
138 waitForCaretUpdated(gPanel, 2, 9), |
|
139 ]) |
|
140 .then(() => promise.all([ |
|
141 ensureSourceIs(gPanel, "-01.js"), |
|
142 ensureCaretAt(gPanel, 2, 9), |
|
143 verifyContents({ itemCount: 1, hidden: false }) |
|
144 // ...because we simply searched for ":" in the current file. |
|
145 ])); |
|
146 |
|
147 typeText(gSearchBox, "#:"); // # has precedence. |
|
148 return finished; |
|
149 }); |
|
150 |
|
151 setText(gSearchBox, ".*-01\.js"); |
|
152 return finished; |
|
153 } |
|
154 |
|
155 function fifthSearch() { |
|
156 let finished = promise.all([ |
|
157 once(gDebugger, "popupshown"), |
|
158 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
159 waitForSourceShown(gPanel, "-02.js") |
|
160 ]) |
|
161 .then(() => { |
|
162 let finished = promise.all([ |
|
163 once(gDebugger, "popuphidden"), |
|
164 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND), |
|
165 waitForCaretUpdated(gPanel, 1, 3) |
|
166 ]) |
|
167 .then(() => promise.all([ |
|
168 ensureSourceIs(gPanel, "-02.js"), |
|
169 ensureCaretAt(gPanel, 1, 3), |
|
170 verifyContents({ itemCount: 0, hidden: true }) |
|
171 // ...because the searched label includes ":5", so nothing is found. |
|
172 ])); |
|
173 |
|
174 typeText(gSearchBox, ":5#*"); // # has precedence. |
|
175 return finished; |
|
176 }); |
|
177 |
|
178 setText(gSearchBox, ".*-02\.js"); |
|
179 return finished; |
|
180 } |
|
181 |
|
182 function sixthSearch() { |
|
183 let finished = promise.all([ |
|
184 ensureSourceIs(gPanel, "-02.js"), |
|
185 ensureCaretAt(gPanel, 1, 3), |
|
186 once(gDebugger, "popupshown"), |
|
187 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
188 waitForCaretUpdated(gPanel, 5) |
|
189 ]); |
|
190 |
|
191 backspaceText(gSearchBox, 2); |
|
192 |
|
193 return finished.then(() => promise.all([ |
|
194 ensureSourceIs(gPanel, "-02.js"), |
|
195 ensureCaretAt(gPanel, 5), |
|
196 verifyContents({ itemCount: 1, hidden: false }) |
|
197 ])); |
|
198 } |
|
199 |
|
200 function seventhSearch() { |
|
201 let finished = promise.all([ |
|
202 ensureSourceIs(gPanel, "-02.js"), |
|
203 ensureCaretAt(gPanel, 5), |
|
204 once(gDebugger, "popupshown"), |
|
205 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
|
206 waitForSourceShown(gPanel, "-01.js"), |
|
207 ]); |
|
208 |
|
209 backspaceText(gSearchBox, 6); |
|
210 |
|
211 return finished.then(() => promise.all([ |
|
212 ensureSourceIs(gPanel, "-01.js"), |
|
213 ensureCaretAt(gPanel, 1), |
|
214 verifyContents({ itemCount: 2, hidden: false }) |
|
215 ])); |
|
216 } |
|
217 |
|
218 function verifyContents(aArgs) { |
|
219 is(gSources.visibleItems.length, 2, |
|
220 "The unmatched sources in the widget should not be hidden."); |
|
221 is(gSearchView.itemCount, aArgs.itemCount, |
|
222 "No sources should be displayed in the sources container after a bogus search."); |
|
223 is(gSearchView.hidden, aArgs.hidden, |
|
224 "No sources should be displayed in the sources container after a bogus search."); |
|
225 } |
|
226 |
|
227 registerCleanupFunction(function() { |
|
228 gTab = null; |
|
229 gDebuggee = null; |
|
230 gPanel = null; |
|
231 gDebugger = null; |
|
232 gSources = null; |
|
233 gSearchView = null; |
|
234 gSearchBox = null; |
|
235 }); |