tor-browser

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

browser_browsingContext-getAllBrowsingContextsInSubtree.js (1741B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 async function addFrame(url) {
      7  let iframe = content.document.createElement("iframe");
      8  await new Promise(resolve => {
      9    iframe.addEventListener("load", resolve, { once: true });
     10    iframe.src = url;
     11    content.document.body.appendChild(iframe);
     12  });
     13  return iframe.browsingContext;
     14 }
     15 
     16 add_task(async function () {
     17  await BrowserTestUtils.withNewTab(
     18    { gBrowser, url: "about:blank" },
     19    async browser => {
     20      // Add 15 example.com frames to the toplevel document.
     21      let frames = await Promise.all(
     22        Array.from({ length: 15 }).map(_ =>
     23          // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     24          SpecialPowers.spawn(browser, ["http://example.com/"], addFrame)
     25        )
     26      );
     27 
     28      // Add an example.org subframe to each example.com frame.
     29      let subframes = await Promise.all(
     30        Array.from({ length: 15 }).map((_, i) =>
     31          // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     32          SpecialPowers.spawn(frames[i], ["http://example.org/"], addFrame)
     33        )
     34      );
     35 
     36      Assert.deepEqual(
     37        subframes[0].getAllBrowsingContextsInSubtree(),
     38        [subframes[0]],
     39        "Childless context only has self in subtree"
     40      );
     41      Assert.deepEqual(
     42        frames[0].getAllBrowsingContextsInSubtree(),
     43        [frames[0], subframes[0]],
     44        "Single-child context has 2 contexts in subtree"
     45      );
     46      Assert.deepEqual(
     47        browser.browsingContext.getAllBrowsingContextsInSubtree(),
     48        [browser.browsingContext, ...frames, ...subframes],
     49        "Toplevel context has all subtree contexts"
     50      );
     51    }
     52  );
     53 });