1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/webconsole/test/test_jsterm.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,254 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html lang="en"> 1.6 +<head> 1.7 + <meta charset="utf8"> 1.8 + <title>Test for JavaScript terminal functionality</title> 1.9 + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <script type="text/javascript;version=1.8" src="common.js"></script> 1.11 + <!-- Any copyright is dedicated to the Public Domain. 1.12 + - http://creativecommons.org/publicdomain/zero/1.0/ --> 1.13 +</head> 1.14 +<body> 1.15 +<p>Test for JavaScript terminal functionality</p> 1.16 + 1.17 +<script class="testbody" type="text/javascript;version=1.8"> 1.18 +SimpleTest.waitForExplicitFinish(); 1.19 + 1.20 +let gState; 1.21 + 1.22 +function startTest() 1.23 +{ 1.24 + removeEventListener("load", startTest); 1.25 + 1.26 + attachConsole(["PageError"], onAttach, true); 1.27 +} 1.28 + 1.29 +function onAttach(aState, aResponse) 1.30 +{ 1.31 + top.foobarObject = Object.create(null); 1.32 + top.foobarObject.foo = 1; 1.33 + top.foobarObject.foobar = 2; 1.34 + top.foobarObject.foobaz = 3; 1.35 + top.foobarObject.omg = 4; 1.36 + top.foobarObject.omgfoo = 5; 1.37 + top.foobarObject.strfoo = "foobarz"; 1.38 + top.foobarObject.omgstr = "foobarz" + 1.39 + (new Array(DebuggerServer.LONG_STRING_LENGTH * 2)).join("abb"); 1.40 + 1.41 + gState = aState; 1.42 + 1.43 + let tests = [doAutocomplete1, doAutocomplete2, doAutocomplete3, 1.44 + doAutocomplete4, doSimpleEval, doWindowEval, doEvalWithException, 1.45 + doEvalWithHelper, doEvalString, doEvalLongString]; 1.46 + runTests(tests, testEnd); 1.47 +} 1.48 + 1.49 +function doAutocomplete1() 1.50 +{ 1.51 + info("test autocomplete for 'window.foo'"); 1.52 + gState.client.autocomplete("window.foo", 10, onAutocomplete1); 1.53 +} 1.54 + 1.55 +function onAutocomplete1(aResponse) 1.56 +{ 1.57 + let matches = aResponse.matches; 1.58 + 1.59 + is(aResponse.matchProp, "foo", "matchProp"); 1.60 + is(matches.length, 1, "matches.length"); 1.61 + is(matches[0], "foobarObject", "matches[0]"); 1.62 + 1.63 + nextTest(); 1.64 +} 1.65 + 1.66 +function doAutocomplete2() 1.67 +{ 1.68 + info("test autocomplete for 'window.foobarObject.'"); 1.69 + gState.client.autocomplete("window.foobarObject.", 20, onAutocomplete2); 1.70 +} 1.71 + 1.72 +function onAutocomplete2(aResponse) 1.73 +{ 1.74 + let matches = aResponse.matches; 1.75 + 1.76 + ok(!aResponse.matchProp, "matchProp"); 1.77 + is(matches.length, 7, "matches.length"); 1.78 + checkObject(matches, 1.79 + ["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]); 1.80 + 1.81 + nextTest(); 1.82 +} 1.83 + 1.84 +function doAutocomplete3() 1.85 +{ 1.86 + // Check that completion suggestions are offered inside the string. 1.87 + info("test autocomplete for 'dump(window.foobarObject.)'"); 1.88 + gState.client.autocomplete("dump(window.foobarObject.)", 25, onAutocomplete3); 1.89 +} 1.90 + 1.91 +function onAutocomplete3(aResponse) 1.92 +{ 1.93 + let matches = aResponse.matches; 1.94 + 1.95 + ok(!aResponse.matchProp, "matchProp"); 1.96 + is(matches.length, 7, "matches.length"); 1.97 + checkObject(matches, 1.98 + ["foo", "foobar", "foobaz", "omg", "omgfoo", "omgstr", "strfoo"]); 1.99 + 1.100 + nextTest(); 1.101 +} 1.102 + 1.103 +function doAutocomplete4() 1.104 +{ 1.105 + // Check that completion requests can have no suggestions. 1.106 + info("test autocomplete for 'dump(window.foobarObject.)'"); 1.107 + gState.client.autocomplete("dump(window.foobarObject.)", 26, onAutocomplete4); 1.108 +} 1.109 + 1.110 +function onAutocomplete4(aResponse) 1.111 +{ 1.112 + ok(!aResponse.matchProp, "matchProp"); 1.113 + is(aResponse.matches.length, 0, "matches.length"); 1.114 + 1.115 + nextTest(); 1.116 +} 1.117 + 1.118 +function doSimpleEval() 1.119 +{ 1.120 + info("test eval '2+2'"); 1.121 + gState.client.evaluateJS("2+2", onSimpleEval); 1.122 +} 1.123 + 1.124 +function onSimpleEval(aResponse) 1.125 +{ 1.126 + checkObject(aResponse, { 1.127 + from: gState.actor, 1.128 + input: "2+2", 1.129 + result: 4, 1.130 + }); 1.131 + 1.132 + ok(!aResponse.exception, "no eval exception"); 1.133 + ok(!aResponse.helperResult, "no helper result"); 1.134 + 1.135 + nextTest(); 1.136 +} 1.137 + 1.138 +function doWindowEval() 1.139 +{ 1.140 + info("test eval 'document'"); 1.141 + gState.client.evaluateJS("document", onWindowEval); 1.142 +} 1.143 + 1.144 +function onWindowEval(aResponse) 1.145 +{ 1.146 + checkObject(aResponse, { 1.147 + from: gState.actor, 1.148 + input: "document", 1.149 + result: { 1.150 + type: "object", 1.151 + class: "XULDocument", 1.152 + actor: /[a-z]/, 1.153 + }, 1.154 + }); 1.155 + 1.156 + ok(!aResponse.exception, "no eval exception"); 1.157 + ok(!aResponse.helperResult, "no helper result"); 1.158 + 1.159 + nextTest(); 1.160 +} 1.161 + 1.162 +function doEvalWithException() 1.163 +{ 1.164 + info("test eval with exception"); 1.165 + gState.client.evaluateJS("window.doTheImpossible()", onEvalWithException); 1.166 +} 1.167 + 1.168 +function onEvalWithException(aResponse) 1.169 +{ 1.170 + checkObject(aResponse, { 1.171 + from: gState.actor, 1.172 + input: "window.doTheImpossible()", 1.173 + result: { 1.174 + type: "undefined", 1.175 + }, 1.176 + exceptionMessage: /doTheImpossible/, 1.177 + }); 1.178 + 1.179 + ok(aResponse.exception, "js eval exception"); 1.180 + ok(!aResponse.helperResult, "no helper result"); 1.181 + 1.182 + nextTest(); 1.183 +} 1.184 + 1.185 +function doEvalWithHelper() 1.186 +{ 1.187 + info("test eval with helper"); 1.188 + gState.client.evaluateJS("clear()", onEvalWithHelper); 1.189 +} 1.190 + 1.191 +function onEvalWithHelper(aResponse) 1.192 +{ 1.193 + checkObject(aResponse, { 1.194 + from: gState.actor, 1.195 + input: "clear()", 1.196 + result: { 1.197 + type: "undefined", 1.198 + }, 1.199 + helperResult: { type: "clearOutput" }, 1.200 + }); 1.201 + 1.202 + ok(!aResponse.exception, "no eval exception"); 1.203 + 1.204 + nextTest(); 1.205 +} 1.206 + 1.207 +function doEvalString() 1.208 +{ 1.209 + gState.client.evaluateJS("window.foobarObject.strfoo", onEvalString); 1.210 +} 1.211 + 1.212 +function onEvalString(aResponse) 1.213 +{ 1.214 + checkObject(aResponse, { 1.215 + from: gState.actor, 1.216 + input: "window.foobarObject.strfoo", 1.217 + result: "foobarz", 1.218 + }); 1.219 + 1.220 + nextTest(); 1.221 +} 1.222 + 1.223 +function doEvalLongString() 1.224 +{ 1.225 + gState.client.evaluateJS("window.foobarObject.omgstr", onEvalLongString); 1.226 +} 1.227 + 1.228 +function onEvalLongString(aResponse) 1.229 +{ 1.230 + let str = top.foobarObject.omgstr; 1.231 + let initial = str.substring(0, DebuggerServer.LONG_STRING_INITIAL_LENGTH); 1.232 + 1.233 + checkObject(aResponse, { 1.234 + from: gState.actor, 1.235 + input: "window.foobarObject.omgstr", 1.236 + result: { 1.237 + type: "longString", 1.238 + initial: initial, 1.239 + length: str.length, 1.240 + }, 1.241 + }); 1.242 + 1.243 + nextTest(); 1.244 +} 1.245 + 1.246 +function testEnd() 1.247 +{ 1.248 + closeDebugger(gState, function() { 1.249 + gState = null; 1.250 + SimpleTest.finish(); 1.251 + }); 1.252 +} 1.253 + 1.254 +addEventListener("load", startTest); 1.255 +</script> 1.256 +</body> 1.257 +</html>