tor-browser

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

browser_tab_commands_factory.js (1570B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test LocalTabCommandsFactory
      7 
      8 const {
      9  LocalTabCommandsFactory,
     10 } = require("resource://devtools/client/framework/local-tab-commands-factory.js");
     11 
     12 add_task(async function () {
     13  await testTabDescriptorWithURL("data:text/html;charset=utf-8,foo");
     14 
     15  // Bug 1699497: Also test against a page in the parent process
     16  // which can hit some race with frame-connector's frame scripts.
     17  await testTabDescriptorWithURL("about:robots");
     18 });
     19 
     20 async function testTabDescriptorWithURL(url) {
     21  info(`Test TabDescriptor against url ${url}\n`);
     22  const tab = await addTab(url);
     23 
     24  const commands = await LocalTabCommandsFactory.createCommandsForTab(tab);
     25  is(
     26    commands.descriptorFront.localTab,
     27    tab,
     28    "TabDescriptor's localTab is set correctly"
     29  );
     30 
     31  info(
     32    "Calling a second time createCommandsForTab with the same tab, will return the same commands"
     33  );
     34  const secondCommands =
     35    await LocalTabCommandsFactory.createCommandsForTab(tab);
     36  is(commands, secondCommands, "second commands is the same");
     37 
     38  // We have to involve TargetCommand in order to have a function TabDescriptor.getTarget.
     39  await commands.targetCommand.startListening();
     40 
     41  info("Wait for descriptor's target");
     42  const target = await commands.descriptorFront.getTarget();
     43 
     44  info("Call any method to ensure that each target works");
     45  await target.logInPage("foo");
     46 
     47  info("Destroy the command");
     48  await commands.destroy();
     49 
     50  gBrowser.removeCurrentTab();
     51 }