toolkit/devtools/webconsole/test/test_jsterm.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial