Bug 1544936 - Part 2: Add a test for the new sendQuery method, r=jdai
authorNika Layzell <nika@thelayzells.com>
Wed, 17 Apr 2019 18:18:28 +0000
changeset 470498 1d5a3139806514bfd7c0c5b5d2983f55639a6bf4
parent 470497 176055665c32ad9693c66078192064f476edcf95
child 470499 f811995954013dae14ed21659a24a33ce1dbe174
push id35906
push useraciure@mozilla.com
push dateTue, 23 Apr 2019 22:14:56 +0000
treeherdermozilla-central@0ce3633f8b80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdai
bugs1544936
milestone68.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 1544936 - Part 2: Add a test for the new sendQuery method, r=jdai Differential Revision: https://phabricator.services.mozilla.com/D27810
dom/ipc/tests/browser_JSWindowActor.js
toolkit/actors/TestChild.jsm
--- a/dom/ipc/tests/browser_JSWindowActor.js
+++ b/dom/ipc/tests/browser_JSWindowActor.js
@@ -84,16 +84,31 @@ add_task(async function test_asyncMessag
           });
 
           await promise;
         });
         ChromeUtils.unregisterWindowActor("Test");
     });
 });
 
+add_task(async function test_query() {
+  await BrowserTestUtils.withNewTab({gBrowser, url: URL},
+    async function(browser) {
+      ChromeUtils.registerWindowActor("Test", windowActorOptions);
+      let parent = browser.browsingContext.currentWindowGlobal;
+      let actorParent = parent.getActor("Test");
+      ok(actorParent, "JSWindowActorParent should have value.");
+
+      let {result} = await actorParent.sendQuery("asyncAdd", {a: 10, b: 20});
+      is(result, 30);
+
+      ChromeUtils.unregisterWindowActor("Test");
+    });
+});
+
 add_task(async function test_asyncMessage_without_both_side_actor() {
   await BrowserTestUtils.withNewTab({gBrowser, url: URL},
     async function(browser) {
       ChromeUtils.registerWindowActor("Test", windowActorOptions);
       // If we don't create a parent actor, make sure the parent actor
       // gets created by having sent the message.
       await ContentTask.spawn(
         browser, {}, async function() {
--- a/toolkit/actors/TestChild.jsm
+++ b/toolkit/actors/TestChild.jsm
@@ -12,20 +12,27 @@ class TestChild extends JSWindowActorChi
   }
 
   receiveMessage(aMessage) {
     switch (aMessage.name) {
       case "toChild":
         aMessage.data.toChild = true;
         this.sendAsyncMessage("toParent", aMessage.data);
         break;
+      case "asyncAdd":
+        let {a, b} = aMessage.data;
+        return new Promise(resolve => {
+          resolve({ result: a + b });
+        });
       case "done":
         this.done(aMessage.data);
         break;
     }
+
+    return undefined;
   }
 
   handleEvent(aEvent) {
     this.sendAsyncMessage("event", { type: aEvent.type });
   }
 
   observe(subject, topic, data) {
     this.lastObserved = {subject, topic, data};