Bug 1249698 - Dead CPOW testcase. r=billm
MozReview-Commit-ID: IrSChyl6HOx
--- a/dom/base/test/chrome/cpows_child.js
+++ b/dom/base/test/chrome/cpows_child.js
@@ -1,11 +1,12 @@
dump('loaded child cpow test\n');
var Cu = Components.utils;
+var Ci = Components.interfaces;
(function start() {
[is_remote] = sendRpcMessage("cpows:is_remote");
var tests = [
parent_test,
error_reporting_test,
dom_test,
@@ -15,16 +16,17 @@ var Cu = Components.utils;
regexp_test,
postmessage_test,
sync_test,
async_test,
rpc_test,
lifetime_test,
cancel_test,
cancel_test2,
+ dead_test,
unsafe_test,
];
function go() {
if (tests.length == 0) {
sendRpcMessage("cpows:done", {});
return;
}
@@ -350,8 +352,28 @@ function unsafe_test(finish)
function f() {}
sendAsyncMessage("cpows:unsafe", null, {f});
addMessageListener("cpows:unsafe_done", msg => {
sendRpcMessage("cpows:safe", null, {f});
addMessageListener("cpows:safe_done", finish);
});
}
+
+function dead_test(finish)
+{
+ if (!is_remote) {
+ // Only run this test when running out-of-process.
+ finish();
+ return;
+ }
+
+ {
+ let thing = { value: "Gonna croak" };
+ sendAsyncMessage("cpows:dead", null, { thing });
+ }
+ // Force the GC to dead-ify the thing.
+ content.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils)
+ .garbageCollect();
+
+ addMessageListener("cpows:dead_done", finish);
+}
--- a/dom/base/test/chrome/cpows_parent.xul
+++ b/dom/base/test/chrome/cpows_parent.xul
@@ -412,16 +412,27 @@
msg.objects.f();
} catch (e if /unsafe CPOW usage forbidden/.test(String(e))) {
ok(false, "cpow failed");
}
opener.wrappedJSObject.SpecialPowers.clearUserPref(PREF_UNSAFE_FORBIDDEN);
msg.target.messageManager.sendAsyncMessage("cpows:safe_done");
}
+ function recvDead(msg) {
+ try {
+ msg.objects.thing.value;
+ ok(false, "Should have been a dead CPOW");
+ } catch(e if /dead CPOW/.test(String(e))) {
+ ok(true, "Got the expected dead CPOW");
+ ok(e.stack, "The exception has a stack");
+ }
+ msg.target.messageManager.sendAsyncMessage("cpows:dead_done");
+ }
+
function run_tests(type) {
info("Running tests: " + type);
var node = document.getElementById('cpowbrowser_' + type);
test_state = type;
test_node = node;
function recvIsRemote(message) {
@@ -453,16 +464,17 @@
mm.addMessageListener("cpows:postmessage_test", recvPostMessageTest);
mm.addMessageListener("cpows:lifetime_test_1", recvLifetimeTest1);
mm.addMessageListener("cpows:lifetime_test_2", recvLifetimeTest2);
mm.addMessageListener("cpows:cancel_test", recvCancelTest);
mm.addMessageListener("cpows:cancel_sync_message", recvCancelSyncMessage);
mm.addMessageListener("cpows:cancel_test2", recvCancelTest2);
mm.addMessageListener("cpows:unsafe", recvUnsafe);
mm.addMessageListener("cpows:safe", recvSafe);
+ mm.addMessageListener("cpows:dead", recvDead);
mm.loadFrameScript("chrome://mochitests/content/chrome/dom/base/test/chrome/cpows_child.js", true);
}
function start() {
run_tests('remote');
}
function finish() {