Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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>
14 <script class="testbody" type="text/javascript;version=1.8">
15 SimpleTest.waitForExplicitFinish();
17 let gState;
19 function startTest()
20 {
21 removeEventListener("load", startTest);
23 attachConsole(["PageError"], onAttach, true);
24 }
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");
38 gState = aState;
40 let tests = [doAutocomplete1, doAutocomplete2, doAutocomplete3,
41 doAutocomplete4, doSimpleEval, doWindowEval, doEvalWithException,
42 doEvalWithHelper, doEvalString, doEvalLongString];
43 runTests(tests, testEnd);
44 }
46 function doAutocomplete1()
47 {
48 info("test autocomplete for 'window.foo'");
49 gState.client.autocomplete("window.foo", 10, onAutocomplete1);
50 }
52 function onAutocomplete1(aResponse)
53 {
54 let matches = aResponse.matches;
56 is(aResponse.matchProp, "foo", "matchProp");
57 is(matches.length, 1, "matches.length");
58 is(matches[0], "foobarObject", "matches[0]");
60 nextTest();
61 }
63 function doAutocomplete2()
64 {
65 info("test autocomplete for 'window.foobarObject.'");
66 gState.client.autocomplete("window.foobarObject.", 20, onAutocomplete2);
67 }
69 function onAutocomplete2(aResponse)
70 {
71 let matches = aResponse.matches;
73 ok(!aResponse.matchProp, "matchProp");
74 is(matches.length, 7, "matches.length");
75 checkObject(matches,
76 ["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]);
78 nextTest();
79 }
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 }
88 function onAutocomplete3(aResponse)
89 {
90 let matches = aResponse.matches;
92 ok(!aResponse.matchProp, "matchProp");
93 is(matches.length, 7, "matches.length");
94 checkObject(matches,
95 ["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]);
97 nextTest();
98 }
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 }
107 function onAutocomplete4(aResponse)
108 {
109 ok(!aResponse.matchProp, "matchProp");
110 is(aResponse.matches.length, 0, "matches.length");
112 nextTest();
113 }
115 function doSimpleEval()
116 {
117 info("test eval '2+2'");
118 gState.client.evaluateJS("2+2", onSimpleEval);
119 }
121 function onSimpleEval(aResponse)
122 {
123 checkObject(aResponse, {
124 from: gState.actor,
125 input: "2+2",
126 result: 4,
127 });
129 ok(!aResponse.exception, "no eval exception");
130 ok(!aResponse.helperResult, "no helper result");
132 nextTest();
133 }
135 function doWindowEval()
136 {
137 info("test eval 'document'");
138 gState.client.evaluateJS("document", onWindowEval);
139 }
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 });
153 ok(!aResponse.exception, "no eval exception");
154 ok(!aResponse.helperResult, "no helper result");
156 nextTest();
157 }
159 function doEvalWithException()
160 {
161 info("test eval with exception");
162 gState.client.evaluateJS("window.doTheImpossible()", onEvalWithException);
163 }
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 });
176 ok(aResponse.exception, "js eval exception");
177 ok(!aResponse.helperResult, "no helper result");
179 nextTest();
180 }
182 function doEvalWithHelper()
183 {
184 info("test eval with helper");
185 gState.client.evaluateJS("clear()", onEvalWithHelper);
186 }
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 });
199 ok(!aResponse.exception, "no eval exception");
201 nextTest();
202 }
204 function doEvalString()
205 {
206 gState.client.evaluateJS("window.foobarObject.strfoo", onEvalString);
207 }
209 function onEvalString(aResponse)
210 {
211 checkObject(aResponse, {
212 from: gState.actor,
213 input: "window.foobarObject.strfoo",
214 result: "foobarz",
215 });
217 nextTest();
218 }
220 function doEvalLongString()
221 {
222 gState.client.evaluateJS("window.foobarObject.omgstr", onEvalLongString);
223 }
225 function onEvalLongString(aResponse)
226 {
227 let str = top.foobarObject.omgstr;
228 let initial = str.substring(0, DebuggerServer.LONG_STRING_INITIAL_LENGTH);
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 });
240 nextTest();
241 }
243 function testEnd()
244 {
245 closeDebugger(gState, function() {
246 gState = null;
247 SimpleTest.finish();
248 });
249 }
251 addEventListener("load", startTest);
252 </script>
253 </body>
254 </html>