Bug 1249698 - Dead CPOW testcase. r=billm
authorMike Conley <mconley@mozilla.com>
Mon, 18 Jul 2016 16:32:18 -0400
changeset 333353 893aa91455dec467b7257da0731261cc3fa2cd88
parent 333352 d4130ffb32090902cb050aab0ed302784c39dd2a
child 333354 0901574275090b099b3ae1d704297416689d06fe
push id10033
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:50:26 +0000
treeherdermozilla-aurora@5dddbefdf759 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1249698
milestone50.0a1
Bug 1249698 - Dead CPOW testcase. r=billm MozReview-Commit-ID: IrSChyl6HOx
dom/base/test/chrome/cpows_child.js
dom/base/test/chrome/cpows_parent.xul
--- 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() {