Bug 1637212 - Simplify actorCreated test;r=nika
authorDavid Teller <dteller@mozilla.com>
Wed, 13 May 2020 18:09:09 +0000
changeset 529707 173a02b7c33d11be5b32c4d41a2d7bb51ee8da4f
parent 529706 1813cb675a68f10ca82536fad034766bdd585f83
child 529708 785db9bee7137571578eb6f33c04e8330b7ebe4d
push id37414
push usernbeleuzu@mozilla.com
push dateThu, 14 May 2020 02:40:10 +0000
treeherdermozilla-central@045d696faa87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1637212
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1637212 - Simplify actorCreated test;r=nika Differential Revision: https://phabricator.services.mozilla.com/D75076
dom/ipc/tests/JSProcessActor/browser_getActor.js
dom/ipc/tests/JSProcessActor/browser_sendQuery.js
dom/ipc/tests/JSWindowActor/browser_getActor.js
dom/ipc/tests/JSWindowActor/browser_sendQuery.js
toolkit/actors/TestProcessActorChild.jsm
toolkit/actors/TestProcessActorParent.jsm
toolkit/actors/TestWindowChild.jsm
toolkit/actors/TestWindowParent.jsm
--- a/dom/ipc/tests/JSProcessActor/browser_getActor.js
+++ b/dom/ipc/tests/JSProcessActor/browser_getActor.js
@@ -1,71 +1,47 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
-const ACTOR_PARENT_CREATED_NOTIFICATION = "test-process-actor-parent-created";
-
-function promiseNotification(aNotification) {
-  const { Services } = ChromeUtils.import(
-    "resource://gre/modules/Services.jsm"
-  );
-  let notificationResolve;
-  let notificationObserver = function observer() {
-    notificationResolve();
-    Services.obs.removeObserver(notificationObserver, aNotification);
-  };
-  return new Promise(resolve => {
-    notificationResolve = resolve;
-    Services.obs.addObserver(notificationObserver, aNotification);
-  });
-}
-
 declTest("getActor on both sides", {
   async test(browser) {
-    let parentCreationObserved = promiseNotification(
-      ACTOR_PARENT_CREATED_NOTIFICATION
-    );
     let parent = browser.browsingContext.currentWindowGlobal.contentParent;
     ok(parent, "WindowGlobalParent should have value.");
     let actorParent = parent.getActor("TestProcessActor");
     is(
       actorParent.show(),
       "TestProcessActorParent",
-      "actor show should have value."
+      "actor `show` should have value."
     );
     is(
       actorParent.manager,
       parent,
       "manager should match WindowGlobalParent.contentParent"
     );
 
-    await parentCreationObserved;
-    ok(true, "Parent creation was observed");
+    ok(
+      actorParent.sawActorCreated,
+      "Checking that we can observe parent creation"
+    );
 
-    await SpecialPowers.spawn(
-      browser,
-      [promiseNotification.toString()],
-      async function(promiseNotificationSource) {
-        const ACTOR_CHILD_CREATED_NOTIFICATION =
-          "test-process-actor-child-created";
-        let childCreationObserved = new Function(promiseNotificationSource)(
-          ACTOR_CHILD_CREATED_NOTIFICATION
-        );
-        let child = ChromeUtils.contentChild;
-        ok(child, "WindowGlobalChild should have value.");
-        let actorChild = child.getActor("TestProcessActor");
-        is(
-          actorChild.show(),
-          "TestProcessActorChild",
-          "actor show should have vaule."
-        );
-        is(
-          actorChild.manager,
-          child,
-          "manager should match ChromeUtils.contentChild."
-        );
-        await childCreationObserved;
-        ok(true, "Child creation was observed");
-      }
-    );
+    await SpecialPowers.spawn(browser, [], async function() {
+      let child = ChromeUtils.contentChild;
+      ok(child, "WindowGlobalChild should have value.");
+      let actorChild = child.getActor("TestProcessActor");
+      is(
+        actorChild.show(),
+        "TestProcessActorChild",
+        "actor show should have vaule."
+      );
+      is(
+        actorChild.manager,
+        child,
+        "manager should match ChromeUtils.contentChild."
+      );
+
+      ok(
+        actorChild.sawActorCreated,
+        "Checking that we can observe child creation"
+      );
+    });
   },
 });
--- a/dom/ipc/tests/JSProcessActor/browser_sendQuery.js
+++ b/dom/ipc/tests/JSProcessActor/browser_sendQuery.js
@@ -26,17 +26,17 @@ declTest("sendQuery Error", {
     let error = await actorParent
       .sendQuery("error", { message: "foo" })
       .catch(e => e);
 
     is(error.message, "foo", "Error should have the correct message");
     is(error.name, "SyntaxError", "Error should have the correct name");
     is(
       error.stack,
-      "receiveMessage@resource://testing-common/TestProcessActorChild.jsm:35:31\n" +
+      "receiveMessage@resource://testing-common/TestProcessActorChild.jsm:33:31\n" +
         asyncStack,
       "Error should have the correct stack"
     );
   },
 });
 
 declTest("sendQuery Exception", {
   async test(browser) {
@@ -54,17 +54,17 @@ declTest("sendQuery Exception", {
     is(error.message, "foo", "Error should have the correct message");
     is(
       error.result,
       Cr.NS_ERROR_INVALID_ARG,
       "Error should have the correct result code"
     );
     is(
       error.stack,
-      "receiveMessage@resource://testing-common/TestProcessActorChild.jsm:38:22\n" +
+      "receiveMessage@resource://testing-common/TestProcessActorChild.jsm:36:22\n" +
         asyncStack,
       "Error should have the correct stack"
     );
   },
 });
 
 declTest("sendQuery testing", {
   async test(browser) {
--- a/dom/ipc/tests/JSWindowActor/browser_getActor.js
+++ b/dom/ipc/tests/JSWindowActor/browser_getActor.js
@@ -1,72 +1,36 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
-const ACTOR_PARENT_CREATED_NOTIFICATION = "test-window-actor-parent-created";
-
-function promiseNotification(aNotification) {
-  const { Services } = ChromeUtils.import(
-    "resource://gre/modules/Services.jsm"
-  );
-  let notificationResolve;
-  let notificationObserver = function observer() {
-    notificationResolve();
-    Services.obs.removeObserver(notificationObserver, aNotification);
-  };
-  return new Promise(resolve => {
-    notificationResolve = resolve;
-    Services.obs.addObserver(notificationObserver, aNotification);
-  });
-}
-
 declTest("getActor on both sides", {
   async test(browser) {
-    let parentCreationObserved = promiseNotification(
-      ACTOR_PARENT_CREATED_NOTIFICATION
-    );
     let parent = browser.browsingContext.currentWindowGlobal;
     ok(parent, "WindowGlobalParent should have value.");
     let actorParent = parent.getActor("TestWindow");
     is(actorParent.show(), "TestWindowParent", "actor show should have vaule.");
     is(actorParent.manager, parent, "manager should match WindowGlobalParent.");
 
-    ok(true, "Checking that we can observe parent creation");
-    await parentCreationObserved;
-    ok(true, "Parent creation was observed");
-
-    await SpecialPowers.spawn(
-      browser,
-      [promiseNotification.toString()],
-      async function(promiseNotificationSource) {
-        const ACTOR_CHILD_CREATED_NOTIFICATION =
-          "test-window-actor-child-created";
-        let childCreationObserved = new Function(promiseNotificationSource)(
-          ACTOR_CHILD_CREATED_NOTIFICATION
-        );
+    ok(
+      actorParent.sawActorCreated,
+      "Checking that we can observe parent creation"
+    );
 
-        let child = content.windowGlobalChild;
-        ok(child, "WindowGlobalChild should have value.");
-        is(
-          child.isInProcess,
-          false,
-          "Actor should be loaded in the content process."
-        );
-        let actorChild = child.getActor("TestWindow");
-        is(
-          actorChild.show(),
-          "TestWindowChild",
-          "actor show should have vaule."
-        );
-        is(
-          actorChild.manager,
-          child,
-          "manager should match WindowGlobalChild."
-        );
+    await SpecialPowers.spawn(browser, [], async function() {
+      let child = content.windowGlobalChild;
+      ok(child, "WindowGlobalChild should have value.");
+      is(
+        child.isInProcess,
+        false,
+        "Actor should be loaded in the content process."
+      );
+      let actorChild = child.getActor("TestWindow");
+      is(actorChild.show(), "TestWindowChild", "actor show should have vaule.");
+      is(actorChild.manager, child, "manager should match WindowGlobalChild.");
 
-        ok(true, "Checking that we can observe child creation");
-        await childCreationObserved;
-        ok(true, "Child creation was observed");
-      }
-    );
+      ok(
+        actorChild.sawActorCreated,
+        "Checking that we can observe child creation"
+      );
+    });
   },
 });
--- a/dom/ipc/tests/JSWindowActor/browser_sendQuery.js
+++ b/dom/ipc/tests/JSWindowActor/browser_sendQuery.js
@@ -26,17 +26,17 @@ declTest("sendQuery Error", {
     let error = await actorParent
       .sendQuery("error", { message: "foo" })
       .catch(e => e);
 
     is(error.message, "foo", "Error should have the correct message");
     is(error.name, "SyntaxError", "Error should have the correct name");
     is(
       error.stack,
-      "receiveMessage@resource://testing-common/TestWindowChild.jsm:35:31\n" +
+      "receiveMessage@resource://testing-common/TestWindowChild.jsm:33:31\n" +
         asyncStack,
       "Error should have the correct stack"
     );
   },
 });
 
 declTest("sendQuery Exception", {
   async test(browser) {
@@ -54,17 +54,17 @@ declTest("sendQuery Exception", {
     is(error.message, "foo", "Error should have the correct message");
     is(
       error.result,
       Cr.NS_ERROR_INVALID_ARG,
       "Error should have the correct result code"
     );
     is(
       error.stack,
-      "receiveMessage@resource://testing-common/TestWindowChild.jsm:38:22\n" +
+      "receiveMessage@resource://testing-common/TestWindowChild.jsm:36:22\n" +
         asyncStack,
       "Error should have the correct stack"
     );
   },
 });
 
 declTest("sendQuery testing", {
   async test(browser) {
--- a/toolkit/actors/TestProcessActorChild.jsm
+++ b/toolkit/actors/TestProcessActorChild.jsm
@@ -6,23 +6,21 @@
 
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var EXPORTED_SYMBOLS = ["TestProcessActorChild"];
 
 class TestProcessActorChild extends JSProcessActorChild {
   constructor() {
     super();
+    this.sawActorCreated = false;
   }
 
   actorCreated() {
-    const { Services } = ChromeUtils.import(
-      "resource://gre/modules/Services.jsm"
-    );
-    Services.obs.notifyObservers(null, "test-process-actor-child-created");
+    this.sawActorCreated = true;
   }
 
   receiveMessage(aMessage) {
     switch (aMessage.name) {
       case "toChild":
         aMessage.data.toChild = true;
         this.sendAsyncMessage("toParent", aMessage.data);
         break;
--- a/toolkit/actors/TestProcessActorParent.jsm
+++ b/toolkit/actors/TestProcessActorParent.jsm
@@ -5,23 +5,23 @@
 "use strict";
 
 var EXPORTED_SYMBOLS = ["TestProcessActorParent"];
 
 class TestProcessActorParent extends JSProcessActorParent {
   constructor() {
     super();
     this.wrappedJSObject = this;
+    this.sawActorCreated = false;
   }
+
   actorCreated() {
-    const { Services } = ChromeUtils.import(
-      "resource://gre/modules/Services.jsm"
-    );
-    Services.obs.notifyObservers(null, "test-process-actor-parent-created");
+    this.sawActorCreated = true;
   }
+
   receiveMessage(aMessage) {
     switch (aMessage.name) {
       case "init":
         aMessage.data.initial = true;
         this.sendAsyncMessage("toChild", aMessage.data);
         break;
       case "toParent":
         aMessage.data.toParent = true;
--- a/toolkit/actors/TestWindowChild.jsm
+++ b/toolkit/actors/TestWindowChild.jsm
@@ -6,23 +6,21 @@
 
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var EXPORTED_SYMBOLS = ["TestWindowChild"];
 
 class TestWindowChild extends JSWindowActorChild {
   constructor() {
     super();
+    this.sawActorCreated = false;
   }
 
   actorCreated() {
-    const { Services } = ChromeUtils.import(
-      "resource://gre/modules/Services.jsm"
-    );
-    Services.obs.notifyObservers(null, "test-window-actor-child-created");
+    this.sawActorCreated = true;
   }
 
   receiveMessage(aMessage) {
     switch (aMessage.name) {
       case "toChild":
         aMessage.data.toChild = true;
         this.sendAsyncMessage("toParent", aMessage.data);
         break;
--- a/toolkit/actors/TestWindowParent.jsm
+++ b/toolkit/actors/TestWindowParent.jsm
@@ -7,23 +7,21 @@
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var EXPORTED_SYMBOLS = ["TestWindowParent"];
 
 class TestWindowParent extends JSWindowActorParent {
   constructor() {
     super();
     this.wrappedJSObject = this;
+    this.sawActorCreated = false;
   }
 
   actorCreated() {
-    const { Services } = ChromeUtils.import(
-      "resource://gre/modules/Services.jsm"
-    );
-    Services.obs.notifyObservers(null, "test-window-actor-parent-created");
+    this.sawActorCreated = true;
   }
 
   receiveMessage(aMessage) {
     switch (aMessage.name) {
       case "init":
         aMessage.data.initial = true;
         this.sendAsyncMessage("toChild", aMessage.data);
         break;