Bug 1177013 - Modernize test_cpows.xul (r=dvander)

This commit is contained in:
Bill McCloskey 2015-06-19 17:33:57 -07:00
parent bf88274458
commit 06d53a5cde
2 changed files with 69 additions and 75 deletions

View File

@ -1,38 +1,40 @@
dump('loaded child cpow test\n');
content.document.title = "Hello, Kitty";
const Cu = Components.utils;
var done_count = 0;
var is_remote;
(function start() {
[is_remote] = sendSyncMessage("cpows:is_remote");
parent_test();
error_reporting_test();
dom_test();
xray_test();
if (typeof Symbol === "function") {
symbol_test();
[is_remote] = sendRpcMessage("cpows:is_remote");
var tests = [
parent_test,
error_reporting_test,
dom_test,
xray_test,
symbol_test,
compartment_test,
regexp_test,
postmessage_test,
sync_test,
async_test,
rpc_test,
lifetime_test
];
function go() {
if (tests.length == 0) {
sendRpcMessage("cpows:done", {});
return;
}
compartment_test();
regexp_test();
postmessage_test();
sync_test();
async_test();
rpc_test();
nested_sync_test();
// The sync-ness of this call is important, because otherwise
// we tear down the child's document while we are
// still in the async test in the parent.
// This test races with itself to be the final test.
lifetime_test(function() {
done_count++;
if (done_count == 2)
sendSyncMessage("cpows:done", {});
var test = tests[0];
tests.shift();
test(function() {
go();
});
}
)();
go();
})();
function ok(condition, message) {
dump('condition: ' + condition + ', ' + message + '\n');
@ -69,6 +71,7 @@ function make_object()
let with_null_proto = Object.create(null);
content.document.title = "Hello, Kitty";
return { "data": o,
"throwing": throwing,
"document": content.document,
@ -84,7 +87,7 @@ function make_json()
return { check: "ok" };
}
function parent_test()
function parent_test(finish)
{
function f(check_func) {
let result = check_func(10);
@ -104,38 +107,39 @@ function parent_test()
sb.func = func;
ok(sb.eval('func()') == 101, "can call parent's function in child");
done_count++;
if (done_count == 2)
sendSyncMessage("cpows:done", {});
finish();
});
sendSyncMessage("cpows:parent_test", {}, {func: f});
sendRpcMessage("cpows:parent_test", {}, {func: f});
}
function error_reporting_test() {
sendSyncMessage("cpows:error_reporting_test", {}, {});
function error_reporting_test(finish) {
sendRpcMessage("cpows:error_reporting_test", {}, {});
finish();
}
function dom_test()
function dom_test(finish)
{
let element = content.document.createElement("div");
element.id = "it_works";
content.document.body.appendChild(element);
sendAsyncMessage("cpows:dom_test", {}, {element: element});
sendRpcMessage("cpows:dom_test", {}, {element: element});
Components.utils.schedulePreciseGC(function() {
sendSyncMessage("cpows:dom_test_after_gc");
sendRpcMessage("cpows:dom_test_after_gc");
finish();
});
}
function xray_test()
function xray_test(finish)
{
let element = content.document.createElement("div");
element.wrappedJSObject.foo = "hello";
sendSyncMessage("cpows:xray_test", {}, {element: element});
sendRpcMessage("cpows:xray_test", {}, {element: element});
finish();
}
function symbol_test()
function symbol_test(finish)
{
let iterator = Symbol.iterator;
let named = Symbol.for("cpow-test");
@ -145,16 +149,18 @@ function symbol_test()
[named]: named,
};
let test = ['a'];
sendSyncMessage("cpows:symbol_test", {}, {object: object, test: test});
sendRpcMessage("cpows:symbol_test", {}, {object: object, test: test});
finish();
}
// Parent->Child references should go X->parent.privilegedJunkScope->child.privilegedJunkScope->Y
// Child->Parent references should go X->child.privilegedJunkScope->parent.unprivilegedJunkScope->Y
function compartment_test()
function compartment_test(finish)
{
// This test primarily checks various compartment invariants for CPOWs, and
// doesn't make sense to run in-process.
if (!is_remote) {
finish();
return;
}
@ -178,41 +184,47 @@ function compartment_test()
return results;
}
sendSyncMessage("cpows:compartment_test", {}, { getUnprivilegedObject: sb.getUnprivilegedObject,
sendRpcMessage("cpows:compartment_test", {}, { getUnprivilegedObject: sb.getUnprivilegedObject,
testParentObject: testParentObject });
finish();
}
function regexp_test()
function regexp_test(finish)
{
sendSyncMessage("cpows:regexp_test", {}, { regexp: /myRegExp/g });
sendRpcMessage("cpows:regexp_test", {}, { regexp: /myRegExp/g });
finish();
}
function postmessage_test()
function postmessage_test(finish)
{
sendSyncMessage("cpows:postmessage_test", {}, { win: content.window });
sendRpcMessage("cpows:postmessage_test", {}, { win: content.window });
finish();
}
function sync_test()
function sync_test(finish)
{
dump('beginning cpow sync test\n');
sync_obj = make_object();
sendSyncMessage("cpows:sync",
sendRpcMessage("cpows:sync",
make_json(),
make_object());
finish();
}
function async_test()
function async_test(finish)
{
dump('beginning cpow async test\n');
async_obj = make_object();
sendAsyncMessage("cpows:async",
make_json(),
async_obj);
addMessageListener("cpows:async_done", finish);
}
var rpc_obj;
function rpc_test()
function rpc_test(finish)
{
dump('beginning cpow rpc test\n');
rpc_obj = make_object();
@ -223,26 +235,7 @@ function rpc_test()
sendRpcMessage("cpows:rpc",
make_json(),
rpc_obj);
}
function nested_sync_test()
{
dump('beginning cpow nested sync test\n');
sync_obj = make_object();
sync_obj.data.reenter = function () {
let caught = false;
try {
sendSyncMessage("cpows:reenter_sync", { }, { });
} catch (e) {
caught = true;
}
if (!ok(caught, "should not allow nested sync"))
return "fail";
return "ok";
}
sendSyncMessage("cpows:nested_sync",
make_json(),
rpc_obj);
finish();
}
function lifetime_test(finish)
@ -257,7 +250,7 @@ function lifetime_test(finish)
dump("beginning lifetime test\n");
var obj = {"will_die": {"f": 1}};
let [result] = sendSyncMessage("cpows:lifetime_test_1", {}, {obj: obj});
let [result] = sendRpcMessage("cpows:lifetime_test_1", {}, {obj: obj});
ok(result == 10, "got sync result");
ok(obj.wont_die.f == 2, "got reverse CPOW");
obj.will_die = null;
@ -266,6 +259,6 @@ function lifetime_test(finish)
ok(obj.wont_die.f == 2, "reverse CPOW still works");
finish();
});
sendSyncMessage("cpows:lifetime_test_2");
sendRpcMessage("cpows:lifetime_test_2");
});
}

View File

@ -64,7 +64,7 @@
"getOwnPropertyDescriptor.value works");
let obj = new data.ctor();
ok(obj.a === 3, "constructor call");
ok(document.title === "Hello, Kitty", "document node");
is(document.title, "Hello, Kitty", "document node");
is(typeof document.cookie, "string", "can get document.cookie");
is(typeof document.defaultView.navigator.userAgent, "string", "can get navigator.userAgent");
@ -141,6 +141,7 @@
function recvAsyncMessage(message) {
testCpowMessage(message);
savedMM.sendAsyncMessage("cpows:async_done");
}
function recvSyncMessage(message) {