tor-browser

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

browser_dbg_target-scoped-actor-01.js (1110B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Check target-scoped actor lifetimes.
      8 */
      9 
     10 const ACTORS_URL = EXAMPLE_URL + "testactors.js";
     11 const TAB_URL = TEST_URI_ROOT + "doc_empty-tab-01.html";
     12 
     13 add_task(async function test() {
     14  const tab = await addTab(TAB_URL);
     15 
     16  await registerActorInContentProcess(ACTORS_URL, {
     17    prefix: "testOne",
     18    constructor: "TestActor1",
     19    type: { target: true },
     20  });
     21 
     22  const target = await createAndAttachTargetForTab(tab);
     23  const { client } = target;
     24  const form = target.targetForm;
     25 
     26  await testTargetScopedActor(client, form);
     27  await removeTab(gBrowser.selectedTab);
     28  await target.destroy();
     29 });
     30 
     31 async function testTargetScopedActor(client, form) {
     32  ok(form.testOneActor, "Found the test target-scoped actor.");
     33  ok(
     34    form.testOneActor.includes("testOne"),
     35    "testOneActor's typeName should be used."
     36  );
     37 
     38  const response = await client.request({
     39    to: form.testOneActor,
     40    type: "ping",
     41  });
     42  is(response.pong, "pong", "Actor should respond to requests.");
     43 }