Skip to content

Commit

Permalink
Bug 1544936 - Part 2: Add a test for the new sendQuery method, r=jdai
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D27810

--HG--
extra : moz-landing-system : lando
  • Loading branch information
mystor committed Apr 17, 2019
1 parent f17e789 commit 1f9c0e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dom/ipc/tests/browser_JSWindowActor.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ add_task(async function test_asyncMessage() {
});
});

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) {
Expand Down
7 changes: 7 additions & 0 deletions toolkit/actors/TestChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ class TestChild extends JSWindowActorChild {
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) {
Expand Down

0 comments on commit 1f9c0e0

Please sign in to comment.