tor-browser

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

browser_fullscreen-navigation-race.js (4576B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 requestLongerTimeout(2);
      7 
      8 // Import helpers
      9 Services.scriptloader.loadSubScript(
     10  "chrome://mochitests/content/browser/dom/base/test/fullscreen/fullscreen_helpers.js",
     11  this
     12 );
     13 
     14 add_setup(async function () {
     15  await pushPrefs(
     16    ["test.wait300msAfterTabSwitch", true],
     17    ["full-screen-api.transition-duration.enter", "0 0"],
     18    ["full-screen-api.transition-duration.leave", "0 0"],
     19    ["full-screen-api.allow-trusted-requests-only", false]
     20  );
     21 });
     22 
     23 add_task(async function navigation() {
     24  await BrowserTestUtils.withNewTab(
     25    {
     26      gBrowser,
     27      url: `data:text/html,
     28      <button id="button">Click here</button>
     29      <script>
     30        let button = document.getElementById("button");
     31        button.addEventListener("click", function() {
     32          button.requestFullscreen();
     33          location.href = "about:blank";
     34        });
     35      </script>`,
     36    },
     37    async function (browser) {
     38      BrowserTestUtils.synthesizeMouseAtCenter("#button", {}, browser);
     39 
     40      // Give some time for fullscreen transition.
     41      await new Promise(aResolve => {
     42        SimpleTest.executeSoon(() => {
     43          SimpleTest.executeSoon(aResolve);
     44        });
     45      });
     46 
     47      // Wait fullscreen exit event if browser is still in fullscreen mode.
     48      if (
     49        window.fullScreen ||
     50        document.documentElement.hasAttribute("inFullscreen")
     51      ) {
     52        info("The widget is still in fullscreen, wait again");
     53        await waitWidgetFullscreenEvent(window, false, true);
     54      }
     55      if (document.documentElement.hasAttribute("inDOMFullscreen")) {
     56        info("The chrome document is still in fullscreen, wait again");
     57        await waitForFullScreenObserver(window, false, true);
     58      }
     59 
     60      // Ensure the browser exits fullscreen state.
     61      ok(!window.fullScreen, "The widget should not be in fullscreen");
     62      ok(
     63        !document.documentElement.hasAttribute("inFullscreen"),
     64        "The chrome window should not be in fullscreen"
     65      );
     66      ok(
     67        !document.documentElement.hasAttribute("inDOMFullscreen"),
     68        "The chrome document should not be in fullscreen"
     69      );
     70    }
     71  );
     72 });
     73 
     74 async function startTests(setupFun, name) {
     75  TEST_URLS.forEach(url => {
     76    add_task(async () => {
     77      info(`Test ${name}, url: ${url}`);
     78      await BrowserTestUtils.withNewTab(
     79        {
     80          gBrowser,
     81          url,
     82        },
     83        async function (browser) {
     84          let promiseFsState = Promise.all([
     85            setupFun(browser),
     86            waitForFullscreenState(document, false, true),
     87          ]);
     88          // Trigger click event in inner most iframe
     89          SpecialPowers.spawn(
     90            browser.browsingContext.children[0].children[0],
     91            [],
     92            function () {
     93              content.setTimeout(() => {
     94                content.document.getElementById("div").click();
     95              }, 0);
     96            }
     97          );
     98          await promiseFsState;
     99 
    100          // Ensure the browser exits fullscreen state.
    101          ok(
    102            !window.fullScreen,
    103            "The chrome window should not be in fullscreen"
    104          );
    105          ok(
    106            !document.documentElement.hasAttribute("inDOMFullscreen"),
    107            "The chrome document should not be in fullscreen"
    108          );
    109        }
    110      );
    111    });
    112  });
    113 }
    114 
    115 function NavigateRemoteDocument(aBrowsingContext, aURL) {
    116  return SpecialPowers.spawn(aBrowsingContext, [aURL], async function (url) {
    117    content.document.addEventListener(
    118      "fullscreenchange",
    119      function () {
    120        content.location.href = url;
    121      },
    122      { once: true }
    123    );
    124  });
    125 }
    126 
    127 startTests(async browser => {
    128  // toplevel
    129  await NavigateRemoteDocument(browser.browsingContext, "about:blank");
    130 }, "navigation_toplevel");
    131 
    132 startTests(async browser => {
    133  // middle iframe
    134  let promise = waitRemoteFullscreenExitEvents([
    135    // browsingContext, name
    136    [browser.browsingContext, "toplevel"],
    137  ]);
    138  await NavigateRemoteDocument(
    139    browser.browsingContext.children[0],
    140    "about:blank"
    141  );
    142  return promise;
    143 }, "navigation_middle_frame");
    144 
    145 startTests(async browser => {
    146  // innermost iframe
    147  let promise = waitRemoteFullscreenExitEvents([
    148    // browsingContext, name
    149    [browser.browsingContext, "toplevel"],
    150    [browser.browsingContext.children[0], "middle"],
    151  ]);
    152  await NavigateRemoteDocument(
    153    browser.browsingContext.children[0].children[0],
    154    "about:blank"
    155  );
    156  return promise;
    157 }, "navigation_inner_frame");