tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_sendAsyncMessage.js (1785B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 declTest("asyncMessage testing", {
      6  async test(browser) {
      7    let parent = browser.browsingContext.currentWindowGlobal.domProcess;
      8    let actorParent = parent.getActor("TestProcessActor");
      9    ok(actorParent, "JSProcessActorParent should have value.");
     10 
     11    await ContentTask.spawn(browser, {}, async function () {
     12      let child = ChromeUtils.domProcessChild;
     13      let actorChild = child.getActor("TestProcessActor");
     14      ok(actorChild, "JSProcessActorChild should have value.");
     15 
     16      let promise = new Promise(resolve => {
     17        actorChild.sendAsyncMessage("init", {});
     18        actorChild.done = data => resolve(data);
     19      }).then(data => {
     20        ok(data.initial, "Initial should be true.");
     21        ok(data.toParent, "ToParent should be true.");
     22        ok(data.toChild, "ToChild should be true.");
     23      });
     24 
     25      await promise;
     26    });
     27  },
     28 });
     29 
     30 declTest("asyncMessage without both sides", {
     31  async test(browser) {
     32    // If we don't create a parent actor, make sure the parent actor
     33    // gets created by having sent the message.
     34    await ContentTask.spawn(browser, {}, async function () {
     35      let child = ChromeUtils.domProcessChild;
     36      let actorChild = child.getActor("TestProcessActor");
     37      ok(actorChild, "JSProcessActorChild should have value.");
     38 
     39      let promise = new Promise(resolve => {
     40        actorChild.sendAsyncMessage("init", {});
     41        actorChild.done = data => resolve(data);
     42      }).then(data => {
     43        ok(data.initial, "Initial should be true.");
     44        ok(data.toParent, "ToParent should be true.");
     45        ok(data.toChild, "ToChild should be true.");
     46      });
     47 
     48      await promise;
     49    });
     50  },
     51 });