test_object_actor.html (4095B)
1 <!DOCTYPE HTML> 2 <html lang="en"> 3 <head> 4 <meta charset="utf8"> 5 <title>Test for the object actor</title> 6 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 7 <script type="text/javascript" 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 the object actor</p> 13 14 <script class="testbody" type="text/javascript"> 15 "use strict"; 16 17 SimpleTest.waitForExplicitFinish(); 18 19 SpecialPowers.pushPrefEnv({ 20 "set": [["security.allow_eval_with_system_principal", true]] 21 }); 22 23 async function startTest() { 24 removeEventListener("load", startTest); 25 26 const longString = (new Array(DevToolsServer.LONG_STRING_LENGTH + 3)).join("\u0629"); 27 createTestGlobalVariable(longString); 28 29 const {state} = await attachConsoleToTab(["ConsoleAPI"]); 30 const onConsoleApiCall = state.webConsoleFront.once("consoleAPICall"); 31 top.console.log("hello", top.wrappedJSObject.foobarObject); 32 const {message} = await onConsoleApiCall; 33 34 info("checking the console API call packet"); 35 checkConsoleAPICall(message, { 36 level: "log", 37 filename: /test_object_actor/, 38 arguments: ["hello", { 39 type: "object", 40 actor: /[a-z]/, 41 }], 42 }); 43 44 info("inspecting object properties"); 45 const {ownProperties} = await message.arguments[1].getPrototypeAndProperties(); 46 47 const expectedProps = { 48 "abArray": { 49 value: { 50 type: "object", 51 class: "Array", 52 actor: /[a-z]/, 53 }, 54 }, 55 "foo": { 56 configurable: true, 57 enumerable: true, 58 writable: true, 59 value: 1, 60 }, 61 "foobar": { 62 value: "hello", 63 }, 64 "foobaz": { 65 value: { 66 type: "object", 67 class: "HTMLDocument", 68 actor: /[a-z]/, 69 }, 70 }, 71 "getterAndSetter": { 72 get: { 73 type: "object", 74 class: "Function", 75 actor: /[a-z]/, 76 }, 77 set: { 78 type: "object", 79 class: "Function", 80 actor: /[a-z]/, 81 }, 82 }, 83 "longStringObj": { 84 value: { 85 type: "object", 86 class: "Object", 87 actor: /[a-z]/, 88 }, 89 }, 90 "notInspectable": { 91 value: { 92 type: "object", 93 class: "Object", 94 actor: /[a-z]/, 95 }, 96 }, 97 "omg": { 98 value: { type: "null" }, 99 }, 100 "omgfn": { 101 value: { 102 type: "object", 103 class: "Function", 104 actor: /[a-z]/, 105 }, 106 }, 107 "tamarbuta": { 108 value: { 109 type: "longString", 110 initial: longString.substring(0, 111 DevToolsServer.LONG_STRING_INITIAL_LENGTH), 112 length: longString.length, 113 }, 114 }, 115 "testfoo": { 116 value: false, 117 }, 118 }; 119 is(Object.keys(ownProperties).length, Object.keys(expectedProps).length, 120 "number of enumerable properties"); 121 checkObject(ownProperties, expectedProps); 122 123 await closeDebugger(state); 124 SimpleTest.finish(); 125 } 126 127 128 function createTestGlobalVariable(longString) { 129 // Here we put the objects in the correct window, to avoid having them all 130 // wrapped by proxies for cross-compartment access. 131 const foobarObject = top.Object.create(null); 132 foobarObject.tamarbuta = longString; 133 foobarObject.foo = 1; 134 foobarObject.foobar = "hello"; 135 foobarObject.omg = null; 136 foobarObject.testfoo = false; 137 foobarObject.notInspectable = top.Object.create(null); 138 foobarObject.omgfn = new top.Function("return 'myResult'"); 139 foobarObject.abArray = new top.Array("a", "b"); 140 foobarObject.foobaz = top.document; 141 142 top.Object.defineProperty(foobarObject, "getterAndSetter", { 143 enumerable: true, 144 get: new top.Function("return 'foo';"), 145 set: new top.Function("1+2"), 146 }); 147 148 foobarObject.longStringObj = top.Object.create(null); 149 foobarObject.longStringObj.toSource = new top.Function("'" + longString + "'"); 150 foobarObject.longStringObj.toString = new top.Function("'" + longString + "'"); 151 foobarObject.longStringObj.boom = "explode"; 152 top.wrappedJSObject.foobarObject = foobarObject; 153 } 154 155 addEventListener("load", startTest); 156 </script> 157 </body> 158 </html>