tor-browser

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

browser_browser_toolbox_watchedByDevTools.js (3726B)


      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 that the "watchedByDevTools" flag is properly handled.
      8 */
      9 
     10 const EXAMPLE_NET_URI =
     11  "https://example.net/document-builder.sjs?html=<div id=net>net";
     12 const EXAMPLE_COM_URI =
     13  "https://example.com/document-builder.sjs?html=<div id=com>com";
     14 const EXAMPLE_ORG_URI =
     15  "https://example.org/document-builder.sjs?headers=Cross-Origin-Opener-Policy:same-origin&html=<div id=org>org</div>";
     16 
     17 add_task(async function () {
     18  await pushPref("devtools.browsertoolbox.scope", "everything");
     19 
     20  const topWindow = Services.wm.getMostRecentBrowserWindow();
     21  is(
     22    topWindow.browsingContext.watchedByDevTools,
     23    false,
     24    "watchedByDevTools isn't set on the parent process browsing context when DevTools aren't opened"
     25  );
     26 
     27  // Open 2 tabs that we can check the flag on
     28  const tabNet = await addTab(EXAMPLE_NET_URI);
     29  const tabCom = await addTab(EXAMPLE_COM_URI);
     30 
     31  is(
     32    tabNet.linkedBrowser.browsingContext.watchedByDevTools,
     33    false,
     34    "watchedByDevTools is not set on the .net tab"
     35  );
     36  is(
     37    tabCom.linkedBrowser.browsingContext.watchedByDevTools,
     38    false,
     39    "watchedByDevTools is not set on the .com tab"
     40  );
     41 
     42  info("Open the BrowserToolbox so the parent process will be watched");
     43  const ToolboxTask = await initBrowserToolboxTask();
     44 
     45  is(
     46    topWindow.browsingContext.watchedByDevTools,
     47    true,
     48    "watchedByDevTools is set when the browser toolbox is opened"
     49  );
     50 
     51  // Open a new tab when the browser toolbox is opened
     52  const newTab = await addTab(EXAMPLE_COM_URI);
     53 
     54  is(
     55    tabNet.linkedBrowser.browsingContext.watchedByDevTools,
     56    true,
     57    "watchedByDevTools is set on the .net tab browsing context after opening the browser toolbox"
     58  );
     59  is(
     60    tabCom.linkedBrowser.browsingContext.watchedByDevTools,
     61    true,
     62    "watchedByDevTools is set on the .com tab browsing context after opening the browser toolbox"
     63  );
     64 
     65  info(
     66    "Check that adding watchedByDevTools is set on a tab that was added when the browser toolbox was opened"
     67  );
     68  is(
     69    newTab.linkedBrowser.browsingContext.watchedByDevTools,
     70    true,
     71    "watchedByDevTools is set on the newly opened tab"
     72  );
     73 
     74  info(
     75    "Check that watchedByDevTools persist when navigating to a page that creates a new browsing context"
     76  );
     77  const previousBrowsingContextId = newTab.linkedBrowser.browsingContext.id;
     78  const onBrowserLoaded = BrowserTestUtils.browserLoaded(
     79    newTab.linkedBrowser,
     80    false,
     81    encodeURI(EXAMPLE_ORG_URI)
     82  );
     83  BrowserTestUtils.startLoadingURIString(newTab.linkedBrowser, EXAMPLE_ORG_URI);
     84  await onBrowserLoaded;
     85 
     86  isnot(
     87    newTab.linkedBrowser.browsingContext.id,
     88    previousBrowsingContextId,
     89    "A new browsing context was created"
     90  );
     91 
     92  is(
     93    newTab.linkedBrowser.browsingContext.watchedByDevTools,
     94    true,
     95    "watchedByDevTools is still set after navigating the tab to a page which forces a new browsing context"
     96  );
     97 
     98  info("Destroying browser toolbox");
     99  await ToolboxTask.destroy();
    100 
    101  is(
    102    topWindow.browsingContext.watchedByDevTools,
    103    false,
    104    "watchedByDevTools was reset when the browser toolbox was closed"
    105  );
    106 
    107  is(
    108    tabNet.linkedBrowser.browsingContext.watchedByDevTools,
    109    false,
    110    "watchedByDevTools was reset on the .net tab after closing the browser toolbox"
    111  );
    112  is(
    113    tabCom.linkedBrowser.browsingContext.watchedByDevTools,
    114    false,
    115    "watchedByDevTools was reset on the .com tab after closing the browser toolbox"
    116  );
    117  is(
    118    newTab.linkedBrowser.browsingContext.watchedByDevTools,
    119    false,
    120    "watchedByDevTools was reset on the tab opened while the browser toolbox was opened"
    121  );
    122 });