Files
firefox/devtools/shared/webconsole/test/test_object_actor.html
T
jaril d0be8e4c8f Bug 1588997 - Convert ObjectClient to protocol.js front. r=nchevobbe.
- Converted the ObjectClient into an protocoljs Front
- Converted the SymbolIteratorClient into a protocoljs Front and moved it to devtools/shared/fronts
- Converted the PropertyIteratorClient into a protocoljs Front and moved it to devtools/shared/fronts
- Converted the EnvironmentClient into a protocoljs Front and moved it to devtools/shared/fronts
- Modified calls to `DebuggerClient.release()` so that it tries to call the ObjectFront's release method first, and falls back on `DebuggerClient.release()` if there's no object front
- Changed reps so that it instantiates only one ObjectClient per grip
- Changed tests so that they expect what the Front's request method resolves to where applicable (i.e. ObjectFront.allocationStack resolves to allocationStack, not a packet object with an allocationStack property)
- Changed callbacks provided to ObjectClient methods to be chained to the ObjectFront methods (e.g. ObjectClient.getScope(callback) changed to ObjectFront.getScope().callback())
- Changed tests to use async/await (test_framebindings-x.js, test_functiongrips-x.js, test_objectgrips-x.js)
- Changed tests to expect protocoljs to throw an error string instead of an error object (test_objectgrips-fn-apply-03.js, test_threadlifetime-02.js, test_pauselifetime-03.js)

Differential Revision: https://phabricator.services.mozilla.com/D48182
2019-10-17 16:06:25 +00:00

176 lines
4.3 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for the object actor</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for the object actor</p>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["security.allow_eval_with_system_principal",
true]]});
let expectedProps = [];
function startTest() {
removeEventListener("load", startTest);
attachConsoleToTab(["ConsoleAPI"], onAttach);
}
function onAttach(state, response) {
onConsoleCall = onConsoleCall.bind(null, state);
state.webConsoleFront.on("consoleAPICall", onConsoleCall);
let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 3)).join("\u0629");
// Here we put the objects in the correct window, to avoid having them all
// wrapped by proxies for cross-compartment access.
let foobarObject = top.Object.create(null);
foobarObject.tamarbuta = longString;
foobarObject.foo = 1;
foobarObject.foobar = "hello";
foobarObject.omg = null;
foobarObject.testfoo = false;
foobarObject.notInspectable = top.Object.create(null);
foobarObject.omgfn = new top.Function("return 'myResult'");
foobarObject.abArray = new top.Array("a", "b");
foobarObject.foobaz = top.document;
top.Object.defineProperty(foobarObject, "getterAndSetter", {
enumerable: true,
get: new top.Function("return 'foo';"),
set: new top.Function("1+2"),
});
foobarObject.longStringObj = top.Object.create(null);
foobarObject.longStringObj.toSource = new top.Function("'" + longString + "'");
foobarObject.longStringObj.toString = new top.Function("'" + longString + "'");
foobarObject.longStringObj.boom = "explode";
top.wrappedJSObject.foobarObject = foobarObject;
top.console.log("hello", top.wrappedJSObject.foobarObject);
expectedProps = {
"abArray": {
value: {
type: "object",
class: "Array",
actor: /[a-z]/,
},
},
"foo": {
configurable: true,
enumerable: true,
writable: true,
value: 1,
},
"foobar": {
value: "hello",
},
"foobaz": {
value: {
type: "object",
class: "HTMLDocument",
actor: /[a-z]/,
},
},
"getterAndSetter": {
get: {
type: "object",
class: "Function",
actor: /[a-z]/,
},
set: {
type: "object",
class: "Function",
actor: /[a-z]/,
},
},
"longStringObj": {
value: {
type: "object",
class: "Object",
actor: /[a-z]/,
},
},
"notInspectable": {
value: {
type: "object",
class: "Object",
actor: /[a-z]/,
},
},
"omg": {
value: { type: "null" },
},
"omgfn": {
value: {
type: "object",
class: "Function",
actor: /[a-z]/,
},
},
"tamarbuta": {
value: {
type: "longString",
initial: longString.substring(0,
DebuggerServer.LONG_STRING_INITIAL_LENGTH),
length: longString.length,
},
},
"testfoo": {
value: false,
},
};
}
function onConsoleCall(state, aPacket) {
info("checking the console API call packet");
checkConsoleAPICall(aPacket.message, {
level: "log",
filename: /test_object_actor/,
functionName: "onAttach",
arguments: ["hello", {
type: "object",
actor: /[a-z]/,
}],
});
state.webConsoleFront.off("consoleAPICall", onConsoleCall);
info("inspecting object properties");
let args = aPacket.message.arguments;
onProperties = onProperties.bind(null, state);
let client = new ObjectClient(state.dbgClient, args[1]);
client.getPrototypeAndProperties().then(onProperties);
}
function onProperties(state, response) {
let props = response.ownProperties;
is(Object.keys(props).length, Object.keys(expectedProps).length,
"number of enumerable properties");
checkObject(props, expectedProps);
expectedProps = [];
closeDebugger(state, function() {
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>