1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/webconsole/test/test_object_actor.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,178 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html lang="en"> 1.6 +<head> 1.7 + <meta charset="utf8"> 1.8 + <title>Test for the object actor</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 the object actor</p> 1.16 + 1.17 +<script class="testbody" type="text/javascript;version=1.8"> 1.18 +SimpleTest.waitForExplicitFinish(); 1.19 + 1.20 +let expectedProps = []; 1.21 + 1.22 +function startTest() 1.23 +{ 1.24 + removeEventListener("load", startTest); 1.25 + 1.26 + attachConsole(["ConsoleAPI"], onAttach, true); 1.27 +} 1.28 + 1.29 +function onAttach(aState, aResponse) 1.30 +{ 1.31 + onConsoleCall = onConsoleCall.bind(null, aState); 1.32 + aState.dbgClient.addListener("consoleAPICall", onConsoleCall); 1.33 + 1.34 + let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 3)).join("\u0629"); 1.35 + 1.36 + // Here we put the objects in the correct window, to avoid having them all 1.37 + // wrapped by proxies for cross-compartment access. 1.38 + 1.39 + let foobarObject = top.Object.create(null); 1.40 + foobarObject.tamarbuta = longString; 1.41 + foobarObject.foo = 1; 1.42 + foobarObject.foobar = "hello"; 1.43 + foobarObject.omg = null; 1.44 + foobarObject.testfoo = false; 1.45 + foobarObject.notInspectable = top.Object.create(null); 1.46 + foobarObject.omgfn = new top.Function("return 'myResult'"); 1.47 + foobarObject.abArray = new top.Array("a", "b"); 1.48 + foobarObject.foobaz = top.document; 1.49 + 1.50 + top.Object.defineProperty(foobarObject, "getterAndSetter", { 1.51 + enumerable: true, 1.52 + get: new top.Function("return 'foo';"), 1.53 + set: new top.Function("1+2"), 1.54 + }); 1.55 + 1.56 + foobarObject.longStringObj = top.Object.create(null); 1.57 + foobarObject.longStringObj.toSource = new top.Function("'" + longString + "'"); 1.58 + foobarObject.longStringObj.toString = new top.Function("'" + longString + "'"); 1.59 + foobarObject.longStringObj.boom = "explode"; 1.60 + 1.61 + top.wrappedJSObject.foobarObject = foobarObject; 1.62 + top.console.log("hello", top.wrappedJSObject.foobarObject); 1.63 + 1.64 + expectedProps = { 1.65 + "abArray": { 1.66 + value: { 1.67 + type: "object", 1.68 + class: "Array", 1.69 + actor: /[a-z]/, 1.70 + }, 1.71 + }, 1.72 + "foo": { 1.73 + configurable: true, 1.74 + enumerable: true, 1.75 + writable: true, 1.76 + value: 1, 1.77 + }, 1.78 + "foobar": { 1.79 + value: "hello", 1.80 + }, 1.81 + "foobaz": { 1.82 + value: { 1.83 + type: "object", 1.84 + class: "XULDocument", 1.85 + actor: /[a-z]/, 1.86 + }, 1.87 + }, 1.88 + "getterAndSetter": { 1.89 + get: { 1.90 + type: "object", 1.91 + class: "Function", 1.92 + actor: /[a-z]/, 1.93 + }, 1.94 + set: { 1.95 + type: "object", 1.96 + class: "Function", 1.97 + actor: /[a-z]/, 1.98 + }, 1.99 + }, 1.100 + "longStringObj": { 1.101 + value: { 1.102 + type: "object", 1.103 + class: "Object", 1.104 + actor: /[a-z]/, 1.105 + }, 1.106 + }, 1.107 + "notInspectable": { 1.108 + value: { 1.109 + type: "object", 1.110 + class: "Object", 1.111 + actor: /[a-z]/, 1.112 + }, 1.113 + }, 1.114 + "omg": { 1.115 + value: { type: "null" }, 1.116 + }, 1.117 + "omgfn": { 1.118 + value: { 1.119 + type: "object", 1.120 + class: "Function", 1.121 + actor: /[a-z]/, 1.122 + }, 1.123 + }, 1.124 + "tamarbuta": { 1.125 + value: { 1.126 + type: "longString", 1.127 + initial: longString.substring(0, 1.128 + DebuggerServer.LONG_STRING_INITIAL_LENGTH), 1.129 + length: longString.length, 1.130 + }, 1.131 + }, 1.132 + "testfoo": { 1.133 + value: false, 1.134 + }, 1.135 + }; 1.136 +} 1.137 + 1.138 +function onConsoleCall(aState, aType, aPacket) 1.139 +{ 1.140 + is(aPacket.from, aState.actor, "console API call actor"); 1.141 + 1.142 + info("checking the console API call packet"); 1.143 + 1.144 + checkConsoleAPICall(aPacket.message, { 1.145 + level: "log", 1.146 + filename: /test_object_actor/, 1.147 + functionName: "onAttach", 1.148 + arguments: ["hello", { 1.149 + type: "object", 1.150 + actor: /[a-z]/, 1.151 + }], 1.152 + }); 1.153 + 1.154 + aState.dbgClient.removeListener("consoleAPICall", onConsoleCall); 1.155 + 1.156 + info("inspecting object properties"); 1.157 + let args = aPacket.message.arguments; 1.158 + onProperties = onProperties.bind(null, aState); 1.159 + 1.160 + let client = new ObjectClient(aState.dbgClient, args[1]); 1.161 + client.getPrototypeAndProperties(onProperties); 1.162 +} 1.163 + 1.164 +function onProperties(aState, aResponse) 1.165 +{ 1.166 + let props = aResponse.ownProperties; 1.167 + is(Object.keys(props).length, Object.keys(expectedProps).length, 1.168 + "number of enumerable properties"); 1.169 + checkObject(props, expectedProps); 1.170 + 1.171 + expectedProps = []; 1.172 + 1.173 + closeDebugger(aState, function() { 1.174 + SimpleTest.finish(); 1.175 + }); 1.176 +} 1.177 + 1.178 +addEventListener("load", startTest); 1.179 +</script> 1.180 +</body> 1.181 +</html>