tor-browser

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

browser_aboutdebugging_thisfirefox_worker_inspection.js (1936B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function () {
      7  const thisFirefoxClient = createThisFirefoxClientMock();
      8  // Prepare a worker mock.
      9  const testWorker = {
     10    id: "test-worker-id",
     11    name: "Test Worker",
     12  };
     13  // Add a worker mock as other worker.
     14  thisFirefoxClient.listWorkers = () => ({
     15    otherWorkers: [testWorker],
     16    serviceWorkers: [],
     17    sharedWorkers: [],
     18  });
     19  thisFirefoxClient.client.mainRoot = {
     20    getWorker: id => {
     21      return id === testWorker.id ? testWorker : null;
     22    },
     23  };
     24 
     25  const runtimeClientFactoryMock = createRuntimeClientFactoryMock();
     26  runtimeClientFactoryMock.createClientForRuntime = runtime => {
     27    const {
     28      RUNTIMES,
     29    } = require("resource://devtools/client/aboutdebugging/src/constants.js");
     30    if (runtime.id === RUNTIMES.THIS_FIREFOX) {
     31      return thisFirefoxClient;
     32    }
     33    throw new Error("Unexpected runtime id " + runtime.id);
     34  };
     35 
     36  info("Enable mocks");
     37  enableRuntimeClientFactoryMock(runtimeClientFactoryMock);
     38  registerCleanupFunction(() => {
     39    disableRuntimeClientFactoryMock();
     40  });
     41 
     42  const { document, tab, window } = await openAboutDebugging();
     43  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     44 
     45  info("Open a toolbox to debug the worker");
     46  const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
     47    document,
     48    tab,
     49    window,
     50    testWorker.name,
     51    false
     52  );
     53 
     54  info(
     55    "Check whether the correct actor front will be opened in worker toolbox"
     56  );
     57  const url = new window.URL(devtoolsWindow.location.href);
     58  const workerID = url.searchParams.get("id");
     59  is(
     60    workerID,
     61    testWorker.id,
     62    "Correct actor front will be opened in worker toolbox"
     63  );
     64 
     65  await removeTab(devtoolsTab);
     66  await waitUntil(() => !findDebugTargetByText("Toolbox - ", document));
     67  await removeTab(tab);
     68 });