|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 // Test that makes sure web console autocomplete happens in the user-selected stackframe |
|
7 // from the js debugger. |
|
8 |
|
9 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-autocomplete-in-stackframe.html"; |
|
10 |
|
11 let testDriver, gStackframes; |
|
12 |
|
13 function test() |
|
14 { |
|
15 requestLongerTimeout(2); |
|
16 addTab(TEST_URI); |
|
17 browser.addEventListener("load", function onLoad() { |
|
18 browser.removeEventListener("load", onLoad, true); |
|
19 openConsole(null, function(hud) { |
|
20 testDriver = testCompletion(hud); |
|
21 testDriver.next(); |
|
22 }); |
|
23 }, true); |
|
24 } |
|
25 |
|
26 function testNext() { |
|
27 executeSoon(function() { |
|
28 testDriver.next(); |
|
29 }); |
|
30 } |
|
31 |
|
32 function testCompletion(hud) { |
|
33 let jsterm = hud.jsterm; |
|
34 let input = jsterm.inputNode; |
|
35 let popup = jsterm.autocompletePopup; |
|
36 |
|
37 // Test that document.title gives string methods. Native getters must execute. |
|
38 input.value = "document.title."; |
|
39 input.setSelectionRange(input.value.length, input.value.length); |
|
40 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
41 yield undefined; |
|
42 |
|
43 let newItems = popup.getItems(); |
|
44 ok(newItems.length > 0, "'document.title.' gave a list of suggestions"); |
|
45 ok(newItems.some(function(item) { |
|
46 return item.label == "substr"; |
|
47 }), "autocomplete results do contain substr"); |
|
48 ok(newItems.some(function(item) { |
|
49 return item.label == "toLowerCase"; |
|
50 }), "autocomplete results do contain toLowerCase"); |
|
51 ok(newItems.some(function(item) { |
|
52 return item.label == "strike"; |
|
53 }), "autocomplete results do contain strike"); |
|
54 |
|
55 // Test if 'f' gives 'foo1' but not 'foo2' or 'foo3' |
|
56 input.value = "f"; |
|
57 input.setSelectionRange(1, 1); |
|
58 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
59 yield undefined; |
|
60 |
|
61 newItems = popup.getItems(); |
|
62 ok(newItems.length > 0, "'f' gave a list of suggestions"); |
|
63 ok(!newItems.every(function(item) { |
|
64 return item.label != "foo1"; |
|
65 }), "autocomplete results do contain foo1"); |
|
66 ok(!newItems.every(function(item) { |
|
67 return item.label != "foo1Obj"; |
|
68 }), "autocomplete results do contain foo1Obj"); |
|
69 ok(newItems.every(function(item) { |
|
70 return item.label != "foo2"; |
|
71 }), "autocomplete results do not contain foo2"); |
|
72 ok(newItems.every(function(item) { |
|
73 return item.label != "foo2Obj"; |
|
74 }), "autocomplete results do not contain foo2Obj"); |
|
75 ok(newItems.every(function(item) { |
|
76 return item.label != "foo3"; |
|
77 }), "autocomplete results do not contain foo3"); |
|
78 ok(newItems.every(function(item) { |
|
79 return item.label != "foo3Obj"; |
|
80 }), "autocomplete results do not contain foo3Obj"); |
|
81 |
|
82 // Test if 'foo1Obj.' gives 'prop1' and 'prop2' |
|
83 input.value = "foo1Obj."; |
|
84 input.setSelectionRange(8, 8); |
|
85 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
86 yield undefined; |
|
87 |
|
88 newItems = popup.getItems(); |
|
89 ok(!newItems.every(function(item) { |
|
90 return item.label != "prop1"; |
|
91 }), "autocomplete results do contain prop1"); |
|
92 ok(!newItems.every(function(item) { |
|
93 return item.label != "prop2"; |
|
94 }), "autocomplete results do contain prop2"); |
|
95 |
|
96 // Test if 'foo1Obj.prop2.' gives 'prop21' |
|
97 input.value = "foo1Obj.prop2."; |
|
98 input.setSelectionRange(14, 14); |
|
99 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
100 yield undefined; |
|
101 |
|
102 newItems = popup.getItems(); |
|
103 ok(!newItems.every(function(item) { |
|
104 return item.label != "prop21"; |
|
105 }), "autocomplete results do contain prop21"); |
|
106 |
|
107 info("openDebugger"); |
|
108 executeSoon(() => openDebugger().then(debuggerOpened)); |
|
109 yield undefined; |
|
110 |
|
111 // From this point on the |
|
112 // Test if 'f' gives 'foo3' and 'foo1' but not 'foo2' |
|
113 input.value = "f"; |
|
114 input.setSelectionRange(1, 1); |
|
115 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
116 yield undefined; |
|
117 |
|
118 newItems = popup.getItems(); |
|
119 ok(newItems.length > 0, "'f' gave a list of suggestions"); |
|
120 ok(!newItems.every(function(item) { |
|
121 return item.label != "foo3"; |
|
122 }), "autocomplete results do contain foo3"); |
|
123 ok(!newItems.every(function(item) { |
|
124 return item.label != "foo3Obj"; |
|
125 }), "autocomplete results do contain foo3Obj"); |
|
126 ok(!newItems.every(function(item) { |
|
127 return item.label != "foo1"; |
|
128 }), "autocomplete results do contain foo1"); |
|
129 ok(!newItems.every(function(item) { |
|
130 return item.label != "foo1Obj"; |
|
131 }), "autocomplete results do contain foo1Obj"); |
|
132 ok(newItems.every(function(item) { |
|
133 return item.label != "foo2"; |
|
134 }), "autocomplete results do not contain foo2"); |
|
135 ok(newItems.every(function(item) { |
|
136 return item.label != "foo2Obj"; |
|
137 }), "autocomplete results do not contain foo2Obj"); |
|
138 |
|
139 openDebugger().then(() => { |
|
140 gStackframes.selectFrame(1); |
|
141 |
|
142 info("openConsole"); |
|
143 executeSoon(() => openConsole(null, () => testDriver.next())); |
|
144 }); |
|
145 yield undefined; |
|
146 |
|
147 // Test if 'f' gives 'foo2' and 'foo1' but not 'foo3' |
|
148 input.value = "f"; |
|
149 input.setSelectionRange(1, 1); |
|
150 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
151 yield undefined; |
|
152 |
|
153 newItems = popup.getItems(); |
|
154 ok(newItems.length > 0, "'f' gave a list of suggestions"); |
|
155 ok(!newItems.every(function(item) { |
|
156 return item.label != "foo2"; |
|
157 }), "autocomplete results do contain foo2"); |
|
158 ok(!newItems.every(function(item) { |
|
159 return item.label != "foo2Obj"; |
|
160 }), "autocomplete results do contain foo2Obj"); |
|
161 ok(!newItems.every(function(item) { |
|
162 return item.label != "foo1"; |
|
163 }), "autocomplete results do contain foo1"); |
|
164 ok(!newItems.every(function(item) { |
|
165 return item.label != "foo1Obj"; |
|
166 }), "autocomplete results do contain foo1Obj"); |
|
167 ok(newItems.every(function(item) { |
|
168 return item.label != "foo3"; |
|
169 }), "autocomplete results do not contain foo3"); |
|
170 ok(newItems.every(function(item) { |
|
171 return item.label != "foo3Obj"; |
|
172 }), "autocomplete results do not contain foo3Obj"); |
|
173 |
|
174 // Test if 'foo2Obj.' gives 'prop1' |
|
175 input.value = "foo2Obj."; |
|
176 input.setSelectionRange(8, 8); |
|
177 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
178 yield undefined; |
|
179 |
|
180 newItems = popup.getItems(); |
|
181 ok(!newItems.every(function(item) { |
|
182 return item.label != "prop1"; |
|
183 }), "autocomplete results do contain prop1"); |
|
184 |
|
185 // Test if 'foo2Obj.prop1.' gives 'prop11' |
|
186 input.value = "foo2Obj.prop1."; |
|
187 input.setSelectionRange(14, 14); |
|
188 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
189 yield undefined; |
|
190 |
|
191 newItems = popup.getItems(); |
|
192 ok(!newItems.every(function(item) { |
|
193 return item.label != "prop11"; |
|
194 }), "autocomplete results do contain prop11"); |
|
195 |
|
196 // Test if 'foo2Obj.prop1.prop11.' gives suggestions for a string i.e. 'length' |
|
197 input.value = "foo2Obj.prop1.prop11."; |
|
198 input.setSelectionRange(21, 21); |
|
199 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
200 yield undefined; |
|
201 |
|
202 newItems = popup.getItems(); |
|
203 ok(!newItems.every(function(item) { |
|
204 return item.label != "length"; |
|
205 }), "autocomplete results do contain length"); |
|
206 |
|
207 // Test if 'foo1Obj[0].' throws no errors. |
|
208 input.value = "foo2Obj[0]."; |
|
209 input.setSelectionRange(11, 11); |
|
210 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
|
211 yield undefined; |
|
212 |
|
213 newItems = popup.getItems(); |
|
214 is(newItems.length, 0, "no items for foo2Obj[0]"); |
|
215 |
|
216 testDriver = null; |
|
217 executeSoon(finishUp); |
|
218 yield undefined; |
|
219 } |
|
220 |
|
221 function debuggerOpened(aResult) |
|
222 { |
|
223 let debuggerWin = aResult.panelWin; |
|
224 let debuggerController = debuggerWin.DebuggerController; |
|
225 let thread = debuggerController.activeThread; |
|
226 gStackframes = debuggerController.StackFrames; |
|
227 |
|
228 executeSoon(() => { |
|
229 thread.addOneTimeListener("framesadded", onFramesAdded); |
|
230 info("firstCall()"); |
|
231 content.wrappedJSObject.firstCall(); |
|
232 }); |
|
233 } |
|
234 |
|
235 function onFramesAdded() |
|
236 { |
|
237 info("onFramesAdded, openConsole() now"); |
|
238 executeSoon(() => openConsole(null, testNext)); |
|
239 } |
|
240 |
|
241 function finishUp() { |
|
242 testDriver = gStackframes = null; |
|
243 finishTest(); |
|
244 } |