tor-browser

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

browser_toolbox_watchedByDevTools.js (2354B)


      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 const EXAMPLE_HTTP_URI =
     10  "http://mochi.test:8888/document-builder.sjs?html=<div id=http>http";
     11 const EXAMPLE_COM_URI =
     12  "https://example.com/document-builder.sjs?html=<div id=com>com";
     13 const EXAMPLE_ORG_URI =
     14  "https://example.org/document-builder.sjs?headers=Cross-Origin-Opener-Policy:same-origin&html=<div id=org>org</div>";
     15 
     16 add_task(async function () {
     17  const tab = await addTab(EXAMPLE_HTTP_URI);
     18 
     19  is(
     20    tab.linkedBrowser.browsingContext.watchedByDevTools,
     21    false,
     22    "watchedByDevTools isn't set when DevTools aren't opened"
     23  );
     24 
     25  info(
     26    "Open a toolbox for the opened tab and check that watchedByDevTools is set"
     27  );
     28  await gDevTools.showToolboxForTab(tab, { toolId: "options" });
     29 
     30  is(
     31    tab.linkedBrowser.browsingContext.watchedByDevTools,
     32    true,
     33    "watchedByDevTools is set after opening a toolbox"
     34  );
     35 
     36  info(
     37    "Check that watchedByDevTools persist when the tab navigates to a different origin"
     38  );
     39  await navigateTo(EXAMPLE_COM_URI);
     40 
     41  is(
     42    tab.linkedBrowser.browsingContext.watchedByDevTools,
     43    true,
     44    "watchedByDevTools is still set after navigating to a different origin"
     45  );
     46 
     47  info(
     48    "Check that watchedByDevTools persist when navigating to a page that creates a new browsing context"
     49  );
     50  const previousBrowsingContextId = tab.linkedBrowser.browsingContext.id;
     51  await navigateTo(EXAMPLE_ORG_URI);
     52 
     53  isnot(
     54    tab.linkedBrowser.browsingContext.id,
     55    previousBrowsingContextId,
     56    "A new browsing context was created"
     57  );
     58 
     59  is(
     60    tab.linkedBrowser.browsingContext.watchedByDevTools,
     61    true,
     62    "watchedByDevTools is still set after navigating to a new browsing context"
     63  );
     64 
     65  info("Check that the flag is reset when the toolbox is closed");
     66  await gDevTools.closeToolboxForTab(tab);
     67 
     68  // As the destroy sequence of DevTools server is synchronous and we aren't waiting
     69  // for full completion of server cleanups, we have to wait for its full processing.
     70  await waitFor(() => !tab.linkedBrowser.browsingContext.watchedByDevTools);
     71 
     72  is(
     73    tab.linkedBrowser.browsingContext.watchedByDevTools,
     74    false,
     75    "watchedByDevTools is reset after closing the toolbox"
     76  );
     77 });