2013-07-10 15:05:39 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
|
|
|
type="text/css"?>
|
|
|
|
<window title="MessageManager CPOW tests"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
onload="start()">
|
|
|
|
|
|
|
|
<!-- test results are displayed in the html:body -->
|
|
|
|
<label value="CPOWs"/>
|
|
|
|
|
|
|
|
<script type="application/javascript"><![CDATA[
|
|
|
|
var test_state = "remote";
|
|
|
|
var test_node = null;
|
2013-10-01 09:15:06 -07:00
|
|
|
var reentered = false;
|
2013-07-10 15:05:39 -07:00
|
|
|
|
|
|
|
function ok(condition, message) {
|
|
|
|
return opener.wrappedJSObject.ok(condition, message);
|
|
|
|
}
|
|
|
|
|
2013-08-23 16:04:20 -07:00
|
|
|
// Make sure that an error in this file actually causes the test to fail.
|
|
|
|
window.onerror = function (msg, url, line) {
|
|
|
|
ok(false, "Error while executing: \n" + msg + "\n" + url + ":" + line);
|
|
|
|
};
|
|
|
|
|
2013-07-10 15:05:39 -07:00
|
|
|
function testCpowMessage(message) {
|
|
|
|
ok(message.json.check == "ok", "correct json");
|
|
|
|
|
|
|
|
let data = message.objects.data;
|
|
|
|
let document = message.objects.document;
|
|
|
|
ok(data.i === 5, "integer property");
|
|
|
|
ok(data.b === true, "boolean property");
|
|
|
|
ok(data.s === "hello", "string property");
|
|
|
|
ok(data.x.i === 10, "nested property");
|
|
|
|
ok(data.f() === 99, "function call");
|
|
|
|
ok(document.title === "Hello, Kitty", "document node");
|
|
|
|
|
|
|
|
data.i = 6;
|
|
|
|
data.b = false;
|
|
|
|
data.s = "bye";
|
|
|
|
data.x = null;
|
|
|
|
ok(data.i === 6, "integer property");
|
|
|
|
ok(data.b === false, "boolean property");
|
|
|
|
ok(data.s === "bye", "string property");
|
|
|
|
ok(data.x === null, "nested property");
|
2013-07-17 06:27:49 -07:00
|
|
|
|
|
|
|
let throwing = message.objects.throwing;
|
|
|
|
// Based on the table on:
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
|
|
|
|
let tests = [
|
|
|
|
() => Object.getOwnPropertyDescriptor(throwing, 'test'),
|
|
|
|
() => Object.getOwnPropertyNames(throwing),
|
|
|
|
() => Object.defineProperty(throwing, 'test', {value: 1}),
|
|
|
|
() => delete throwing.test,
|
|
|
|
() => "test" in throwing,
|
|
|
|
() => Object.prototype.hasOwnProperty.call(throwing, 'test'),
|
|
|
|
() => throwing.test,
|
|
|
|
() => { throwing.test = 1 },
|
|
|
|
// () => { for (let prop in throwing) {} }, Bug 783829
|
|
|
|
() => { for (let prop of throwing) {} },
|
|
|
|
() => Object.keys(throwing),
|
|
|
|
() => Function.prototype.call.call(throwing),
|
|
|
|
() => new throwing,
|
|
|
|
() => Object.preventExtensions(throwing),
|
|
|
|
() => Object.freeze(throwing),
|
|
|
|
() => Object.seal(throwing),
|
|
|
|
]
|
|
|
|
|
|
|
|
for (let test of tests) {
|
|
|
|
let threw = false;
|
|
|
|
try {
|
|
|
|
test()
|
|
|
|
} catch (e) {
|
|
|
|
threw = true;
|
|
|
|
}
|
|
|
|
ok(threw, "proxy operation threw exception");
|
|
|
|
}
|
|
|
|
|
2013-09-30 12:20:51 -07:00
|
|
|
let array = message.objects.array;
|
|
|
|
let i = 1;
|
|
|
|
for (let elt of array) {
|
|
|
|
ok(elt === i, "correct element found");
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
ok(i === 4, "array has correct length");
|
|
|
|
|
|
|
|
let j = message.objects.for_json;
|
|
|
|
let str = JSON.stringify(j);
|
|
|
|
let j2 = JSON.parse(str);
|
|
|
|
ok(j2.n === 3, "JSON integer property");
|
|
|
|
ok(j2.a[0] === 1, "JSON array index");
|
|
|
|
ok(j2.a[1] === 2, "JSON array index");
|
|
|
|
ok(j2.a[2] === 3, "JSON array index");
|
|
|
|
ok(j2.s === "hello", "JSON string property");
|
|
|
|
ok(j2.o.x === 10, "JSON object property");
|
2013-07-10 15:05:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function recvAsyncMessage(message) {
|
|
|
|
testCpowMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function recvSyncMessage(message) {
|
|
|
|
testCpowMessage(message);
|
|
|
|
}
|
|
|
|
|
2013-10-01 09:15:06 -07:00
|
|
|
function recvRpcMessage(message) {
|
|
|
|
ok(message.json.check == "ok", "correct json");
|
|
|
|
|
|
|
|
let data = message.objects.data;
|
|
|
|
|
|
|
|
// Sanity check.
|
|
|
|
ok(data.i === 5, "integer property");
|
|
|
|
|
|
|
|
// Check that we re-enter.
|
|
|
|
reentered = false;
|
|
|
|
let result = data.reenter();
|
|
|
|
ok(reentered, "re-entered rpc");
|
|
|
|
ok(result == "ok", "got correct result");
|
|
|
|
}
|
|
|
|
|
|
|
|
function recvReenterMessage(message) {
|
|
|
|
ok(message.objects.data.valid === true, "cpows work");
|
|
|
|
reentered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function recvNestedSyncMessage(message) {
|
|
|
|
message.objects.data.reenter();
|
|
|
|
}
|
|
|
|
|
|
|
|
function recvReenterSyncMessage(message) {
|
|
|
|
ok(false, "should not have received re-entered sync message");
|
|
|
|
}
|
|
|
|
|
2013-07-10 15:05:39 -07:00
|
|
|
function recvFailMessage(message) {
|
|
|
|
ok(false, message.json.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function recvDoneMessage(message) {
|
|
|
|
if (test_state == "remote") {
|
|
|
|
test_node.parentNode.removeChild(test_node);
|
|
|
|
run_tests("inprocess");
|
|
|
|
return;
|
|
|
|
}
|
2013-07-17 06:27:49 -07:00
|
|
|
|
2013-07-10 15:05:39 -07:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_tests(type) {
|
|
|
|
var node = document.getElementById('cpowbrowser_' + type);
|
|
|
|
|
|
|
|
test_state = type;
|
|
|
|
test_node = node;
|
|
|
|
|
|
|
|
var mm = node.messageManager;
|
|
|
|
mm.addMessageListener("cpows:async", recvAsyncMessage);
|
|
|
|
mm.addMessageListener("cpows:sync", recvSyncMessage);
|
2013-10-01 09:15:06 -07:00
|
|
|
mm.addMessageListener("cpows:rpc", recvRpcMessage);
|
|
|
|
mm.addMessageListener("cpows:reenter", recvReenterMessage);
|
|
|
|
mm.addMessageListener("cpows:reenter", recvReenterMessage);
|
|
|
|
mm.addMessageListener("cpows:nested_sync", recvNestedSyncMessage);
|
|
|
|
mm.addMessageListener("cpows:reenter_sync", recvReenterSyncMessage);
|
2013-07-10 15:05:39 -07:00
|
|
|
mm.addMessageListener("cpows:done", recvDoneMessage);
|
|
|
|
mm.addMessageListener("cpows:fail", recvFailMessage);
|
|
|
|
mm.loadFrameScript("chrome://mochitests/content/chrome/content/base/test/chrome/cpows_child.js", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function start() {
|
|
|
|
run_tests('remote');
|
|
|
|
}
|
|
|
|
|
|
|
|
function finish() {
|
|
|
|
opener.setTimeout("done()", 0);
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
]]></script>
|
|
|
|
|
|
|
|
<browser type="content" src="about:blank" id="cpowbrowser_remote" remote="true"/>
|
|
|
|
<browser type="content" src="about:blank" id="cpowbrowser_inprocess"/>
|
|
|
|
</window>
|