|
1 <!DOCTYPE HTML> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta charset="utf8"> |
|
5 <title>Test for JavaScript terminal functionality</title> |
|
6 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <script type="text/javascript;version=1.8" src="common.js"></script> |
|
8 <!-- Any copyright is dedicated to the Public Domain. |
|
9 - http://creativecommons.org/publicdomain/zero/1.0/ --> |
|
10 </head> |
|
11 <body> |
|
12 <p>Test for JavaScript terminal functionality</p> |
|
13 |
|
14 <script class="testbody" type="text/javascript;version=1.8"> |
|
15 SimpleTest.waitForExplicitFinish(); |
|
16 |
|
17 let gState; |
|
18 |
|
19 function startTest() |
|
20 { |
|
21 removeEventListener("load", startTest); |
|
22 |
|
23 attachConsole(["PageError"], onAttach, true); |
|
24 } |
|
25 |
|
26 function onAttach(aState, aResponse) |
|
27 { |
|
28 top.foobarObject = Object.create(null); |
|
29 top.foobarObject.foo = 1; |
|
30 top.foobarObject.foobar = 2; |
|
31 top.foobarObject.foobaz = 3; |
|
32 top.foobarObject.omg = 4; |
|
33 top.foobarObject.omgfoo = 5; |
|
34 top.foobarObject.strfoo = "foobarz"; |
|
35 top.foobarObject.omgstr = "foobarz" + |
|
36 (new Array(DebuggerServer.LONG_STRING_LENGTH * 2)).join("abb"); |
|
37 |
|
38 gState = aState; |
|
39 |
|
40 let tests = [doAutocomplete1, doAutocomplete2, doAutocomplete3, |
|
41 doAutocomplete4, doSimpleEval, doWindowEval, doEvalWithException, |
|
42 doEvalWithHelper, doEvalString, doEvalLongString]; |
|
43 runTests(tests, testEnd); |
|
44 } |
|
45 |
|
46 function doAutocomplete1() |
|
47 { |
|
48 info("test autocomplete for 'window.foo'"); |
|
49 gState.client.autocomplete("window.foo", 10, onAutocomplete1); |
|
50 } |
|
51 |
|
52 function onAutocomplete1(aResponse) |
|
53 { |
|
54 let matches = aResponse.matches; |
|
55 |
|
56 is(aResponse.matchProp, "foo", "matchProp"); |
|
57 is(matches.length, 1, "matches.length"); |
|
58 is(matches[0], "foobarObject", "matches[0]"); |
|
59 |
|
60 nextTest(); |
|
61 } |
|
62 |
|
63 function doAutocomplete2() |
|
64 { |
|
65 info("test autocomplete for 'window.foobarObject.'"); |
|
66 gState.client.autocomplete("window.foobarObject.", 20, onAutocomplete2); |
|
67 } |
|
68 |
|
69 function onAutocomplete2(aResponse) |
|
70 { |
|
71 let matches = aResponse.matches; |
|
72 |
|
73 ok(!aResponse.matchProp, "matchProp"); |
|
74 is(matches.length, 7, "matches.length"); |
|
75 checkObject(matches, |
|
76 ["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]); |
|
77 |
|
78 nextTest(); |
|
79 } |
|
80 |
|
81 function doAutocomplete3() |
|
82 { |
|
83 // Check that completion suggestions are offered inside the string. |
|
84 info("test autocomplete for 'dump(window.foobarObject.)'"); |
|
85 gState.client.autocomplete("dump(window.foobarObject.)", 25, onAutocomplete3); |
|
86 } |
|
87 |
|
88 function onAutocomplete3(aResponse) |
|
89 { |
|
90 let matches = aResponse.matches; |
|
91 |
|
92 ok(!aResponse.matchProp, "matchProp"); |
|
93 is(matches.length, 7, "matches.length"); |
|
94 checkObject(matches, |
|
95 ["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]); |
|
96 |
|
97 nextTest(); |
|
98 } |
|
99 |
|
100 function doAutocomplete4() |
|
101 { |
|
102 // Check that completion requests can have no suggestions. |
|
103 info("test autocomplete for 'dump(window.foobarObject.)'"); |
|
104 gState.client.autocomplete("dump(window.foobarObject.)", 26, onAutocomplete4); |
|
105 } |
|
106 |
|
107 function onAutocomplete4(aResponse) |
|
108 { |
|
109 ok(!aResponse.matchProp, "matchProp"); |
|
110 is(aResponse.matches.length, 0, "matches.length"); |
|
111 |
|
112 nextTest(); |
|
113 } |
|
114 |
|
115 function doSimpleEval() |
|
116 { |
|
117 info("test eval '2+2'"); |
|
118 gState.client.evaluateJS("2+2", onSimpleEval); |
|
119 } |
|
120 |
|
121 function onSimpleEval(aResponse) |
|
122 { |
|
123 checkObject(aResponse, { |
|
124 from: gState.actor, |
|
125 input: "2+2", |
|
126 result: 4, |
|
127 }); |
|
128 |
|
129 ok(!aResponse.exception, "no eval exception"); |
|
130 ok(!aResponse.helperResult, "no helper result"); |
|
131 |
|
132 nextTest(); |
|
133 } |
|
134 |
|
135 function doWindowEval() |
|
136 { |
|
137 info("test eval 'document'"); |
|
138 gState.client.evaluateJS("document", onWindowEval); |
|
139 } |
|
140 |
|
141 function onWindowEval(aResponse) |
|
142 { |
|
143 checkObject(aResponse, { |
|
144 from: gState.actor, |
|
145 input: "document", |
|
146 result: { |
|
147 type: "object", |
|
148 class: "XULDocument", |
|
149 actor: /[a-z]/, |
|
150 }, |
|
151 }); |
|
152 |
|
153 ok(!aResponse.exception, "no eval exception"); |
|
154 ok(!aResponse.helperResult, "no helper result"); |
|
155 |
|
156 nextTest(); |
|
157 } |
|
158 |
|
159 function doEvalWithException() |
|
160 { |
|
161 info("test eval with exception"); |
|
162 gState.client.evaluateJS("window.doTheImpossible()", onEvalWithException); |
|
163 } |
|
164 |
|
165 function onEvalWithException(aResponse) |
|
166 { |
|
167 checkObject(aResponse, { |
|
168 from: gState.actor, |
|
169 input: "window.doTheImpossible()", |
|
170 result: { |
|
171 type: "undefined", |
|
172 }, |
|
173 exceptionMessage: /doTheImpossible/, |
|
174 }); |
|
175 |
|
176 ok(aResponse.exception, "js eval exception"); |
|
177 ok(!aResponse.helperResult, "no helper result"); |
|
178 |
|
179 nextTest(); |
|
180 } |
|
181 |
|
182 function doEvalWithHelper() |
|
183 { |
|
184 info("test eval with helper"); |
|
185 gState.client.evaluateJS("clear()", onEvalWithHelper); |
|
186 } |
|
187 |
|
188 function onEvalWithHelper(aResponse) |
|
189 { |
|
190 checkObject(aResponse, { |
|
191 from: gState.actor, |
|
192 input: "clear()", |
|
193 result: { |
|
194 type: "undefined", |
|
195 }, |
|
196 helperResult: { type: "clearOutput" }, |
|
197 }); |
|
198 |
|
199 ok(!aResponse.exception, "no eval exception"); |
|
200 |
|
201 nextTest(); |
|
202 } |
|
203 |
|
204 function doEvalString() |
|
205 { |
|
206 gState.client.evaluateJS("window.foobarObject.strfoo", onEvalString); |
|
207 } |
|
208 |
|
209 function onEvalString(aResponse) |
|
210 { |
|
211 checkObject(aResponse, { |
|
212 from: gState.actor, |
|
213 input: "window.foobarObject.strfoo", |
|
214 result: "foobarz", |
|
215 }); |
|
216 |
|
217 nextTest(); |
|
218 } |
|
219 |
|
220 function doEvalLongString() |
|
221 { |
|
222 gState.client.evaluateJS("window.foobarObject.omgstr", onEvalLongString); |
|
223 } |
|
224 |
|
225 function onEvalLongString(aResponse) |
|
226 { |
|
227 let str = top.foobarObject.omgstr; |
|
228 let initial = str.substring(0, DebuggerServer.LONG_STRING_INITIAL_LENGTH); |
|
229 |
|
230 checkObject(aResponse, { |
|
231 from: gState.actor, |
|
232 input: "window.foobarObject.omgstr", |
|
233 result: { |
|
234 type: "longString", |
|
235 initial: initial, |
|
236 length: str.length, |
|
237 }, |
|
238 }); |
|
239 |
|
240 nextTest(); |
|
241 } |
|
242 |
|
243 function testEnd() |
|
244 { |
|
245 closeDebugger(gState, function() { |
|
246 gState = null; |
|
247 SimpleTest.finish(); |
|
248 }); |
|
249 } |
|
250 |
|
251 addEventListener("load", startTest); |
|
252 </script> |
|
253 </body> |
|
254 </html> |