tor-browser

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

browser_toolbox_window_global_debugging.js (1737B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Note: adding Date.now to the function name to generate a unique test URL to
      5 // allow running the test with --repeat / --verify.
      6 const TEST_URL = `data:text/html,<script>window.someInlineSource${Date.now()} = () => {}</script>`;
      7 
      8 add_task(async function () {
      9  // Ensure debugging the content processes
     10  await pushPref("devtools.browsertoolbox.scope", "everything");
     11 
     12  // This is the one test involving enableWindowGlobalThreadActors option.
     13  // It instructs the Watcher Front to allow debugging sources related to Window Global targets.
     14  //
     15  // This codepath isn't used by DevTools, but by VS Code to debug all tabs via their
     16  // Window Global targets, that, without involving the Content Process targets.
     17  const commands = await CommandsFactory.forMainProcess({
     18    enableWindowGlobalThreadActors: true,
     19  });
     20  await commands.targetCommand.startListening();
     21 
     22  await addTab(TEST_URL);
     23 
     24  const sources = [];
     25  await commands.resourceCommand.watchResources(
     26    [commands.resourceCommand.TYPES.SOURCE],
     27    {
     28      onAvailable(resources) {
     29        sources.push(...resources);
     30      },
     31    }
     32  );
     33 
     34  const sourceForTab = sources
     35    .filter(s => s.url == TEST_URL)
     36    .map(s => s.targetFront.targetType);
     37  is(
     38    sourceForTab.length,
     39    2,
     40    "We should get two source matching the tab url. One for the content process target and another copy for the window global target"
     41  );
     42  ok(
     43    sourceForTab.includes("process"),
     44    "We got a source from the content process target"
     45  );
     46  ok(
     47    sourceForTab.includes("frame"),
     48    "We got a source from the window global target"
     49  );
     50 
     51  await commands.destroy();
     52 });