tor-browser

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

browser_fullscreen_from_minimize.js (2805B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // This test checks whether fullscreen windows can transition to minimized windows,
      5 // and back again. This is sometimes not directly supported by the OS widgets. For
      6 // example, in macOS, the minimize button is greyed-out in the title bar of
      7 // fullscreen windows, making this transition impossible for users to initiate.
      8 // Still, web APIs do allow arbitrary combinations of window calls, and this test
      9 // exercises some of those combinations.
     10 
     11 const restoreWindowToNormal = async () => {
     12  // Get the window to normal state by calling window.restore(). This may take
     13  // multiple attempts since a call to restore could bring the window to either
     14  // NORMAL or MAXIMIZED state.
     15  while (window.windowState != window.STATE_NORMAL) {
     16    info(
     17      `Calling window.restore(), to try to reach "normal" state ${window.STATE_NORMAL}.`
     18    );
     19    let promiseSizeModeChange = BrowserTestUtils.waitForEvent(
     20      window,
     21      "sizemodechange"
     22    );
     23    window.restore();
     24    await promiseSizeModeChange;
     25    info(`Window reached state ${window.windowState}.`);
     26  }
     27 };
     28 
     29 add_task(async function () {
     30  registerCleanupFunction(function () {
     31    window.restore();
     32  });
     33 
     34  // We reuse these variables to create new promises for each transition.
     35  let promiseSizeModeChange;
     36  let promiseFullscreen;
     37 
     38  await restoreWindowToNormal();
     39  ok(!window.fullScreen, "Window should not be fullscreen at start of test.");
     40 
     41  // Get to fullscreen.
     42  info("Requesting fullscreen.");
     43  promiseFullscreen = document.documentElement.requestFullscreen();
     44  await promiseFullscreen;
     45  ok(window.fullScreen, "Window should be fullscreen before being minimized.");
     46 
     47  // Transition between fullscreen and minimize states.
     48  info("Requesting minimize on a fullscreen window.");
     49  promiseSizeModeChange = BrowserTestUtils.waitForEvent(
     50    window,
     51    "sizemodechange"
     52  );
     53  window.minimize();
     54  await promiseSizeModeChange;
     55  is(
     56    window.windowState,
     57    window.STATE_MINIMIZED,
     58    "Window should be minimized after fullscreen."
     59  );
     60 
     61  // Whether or not the previous transition worked, restore the window
     62  // and then minimize it.
     63  await restoreWindowToNormal();
     64 
     65  info("Requesting minimize on a normal window.");
     66  promiseSizeModeChange = BrowserTestUtils.waitForEvent(
     67    window,
     68    "sizemodechange"
     69  );
     70  window.minimize();
     71  await promiseSizeModeChange;
     72  is(
     73    window.windowState,
     74    window.STATE_MINIMIZED,
     75    "Window should be minimized before fullscreen."
     76  );
     77 
     78  info("Requesting fullscreen on a minimized window.");
     79  promiseFullscreen = document.documentElement.requestFullscreen();
     80  await promiseFullscreen;
     81  ok(window.fullScreen, "Window should be fullscreen after being minimized.");
     82 });