tor-browser

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

browser_frame_context_utils.js (4198B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { isBrowsingContextCompatible } = ChromeUtils.importESModule(
      7  "chrome://remote/content/shared/messagehandler/transports/BrowsingContextUtils.sys.mjs"
      8 );
      9 const TEST_COM_PAGE = "https://example.com/document-builder.sjs?html=com";
     10 const TEST_NET_PAGE = "https://example.net/document-builder.sjs?html=net";
     11 
     12 // Test helpers from BrowsingContextUtils in various processes.
     13 add_task(async function () {
     14  const tab1 = BrowserTestUtils.addTab(gBrowser, TEST_COM_PAGE);
     15  const contentBrowser1 = tab1.linkedBrowser;
     16  await BrowserTestUtils.browserLoaded(contentBrowser1);
     17  const browserId1 = contentBrowser1.browsingContext.browserId;
     18 
     19  const tab2 = BrowserTestUtils.addTab(gBrowser, TEST_NET_PAGE);
     20  const contentBrowser2 = tab2.linkedBrowser;
     21  await BrowserTestUtils.browserLoaded(contentBrowser2);
     22  const browserId2 = contentBrowser2.browsingContext.browserId;
     23 
     24  const { extension, sidebarBrowser } = await installSidebarExtension();
     25 
     26  const tab3 = BrowserTestUtils.addTab(
     27    gBrowser,
     28    `moz-extension://${extension.uuid}/tab.html`
     29  );
     30  const { bcId } = await extension.awaitMessage("tab-loaded");
     31  const tabExtensionBrowser = BrowsingContext.get(bcId).top.embedderElement;
     32 
     33  const parentBrowser1 = createParentBrowserElement(tab1, "content");
     34  const parentBrowser2 = createParentBrowserElement(tab1, "chrome");
     35 
     36  info("Check browsing context compatibility for content browser 1");
     37  await checkBrowsingContextCompatible(contentBrowser1, undefined, true);
     38  await checkBrowsingContextCompatible(contentBrowser1, browserId1, true);
     39  await checkBrowsingContextCompatible(contentBrowser1, browserId2, false);
     40 
     41  info("Check browsing context compatibility for content browser 2");
     42  await checkBrowsingContextCompatible(contentBrowser2, undefined, true);
     43  await checkBrowsingContextCompatible(contentBrowser2, browserId1, false);
     44  await checkBrowsingContextCompatible(contentBrowser2, browserId2, true);
     45 
     46  info("Check browsing context compatibility for parent browser 1");
     47  await checkBrowsingContextCompatible(parentBrowser1, undefined, false);
     48  await checkBrowsingContextCompatible(parentBrowser1, browserId1, false);
     49  await checkBrowsingContextCompatible(parentBrowser1, browserId2, false);
     50 
     51  info("Check browsing context compatibility for parent browser 2");
     52  await checkBrowsingContextCompatible(parentBrowser2, undefined, false);
     53  await checkBrowsingContextCompatible(parentBrowser2, browserId1, false);
     54  await checkBrowsingContextCompatible(parentBrowser2, browserId2, false);
     55 
     56  info("Check browsing context compatibility for extension");
     57  await checkBrowsingContextCompatible(sidebarBrowser, undefined, false);
     58  await checkBrowsingContextCompatible(sidebarBrowser, browserId1, false);
     59  await checkBrowsingContextCompatible(sidebarBrowser, browserId2, false);
     60 
     61  info("Check browsing context compatibility for extension viewed in a tab");
     62  await checkBrowsingContextCompatible(tabExtensionBrowser, undefined, false);
     63  await checkBrowsingContextCompatible(tabExtensionBrowser, browserId1, false);
     64  await checkBrowsingContextCompatible(tabExtensionBrowser, browserId2, false);
     65 
     66  gBrowser.removeTab(tab1);
     67  gBrowser.removeTab(tab2);
     68  gBrowser.removeTab(tab3);
     69  await extension.unload();
     70 });
     71 
     72 async function checkBrowsingContextCompatible(browser, browserId, expected) {
     73  const options = { browserId };
     74  info("Check browsing context compatibility from the parent process");
     75  is(isBrowsingContextCompatible(browser.browsingContext, options), expected);
     76 
     77  info(
     78    "Check browsing context compatibility from the browsing context's process"
     79  );
     80  await SpecialPowers.spawn(
     81    browser,
     82    [browserId, expected],
     83    (_browserId, _expected) => {
     84      const BrowsingContextUtils = ChromeUtils.importESModule(
     85        "chrome://remote/content/shared/messagehandler/transports/BrowsingContextUtils.sys.mjs"
     86      );
     87      is(
     88        BrowsingContextUtils.isBrowsingContextCompatible(
     89          content.browsingContext,
     90          {
     91            browserId: _browserId,
     92          }
     93        ),
     94        _expected
     95      );
     96    }
     97  );
     98 }