tor-browser

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

browser_fullscreen_ui_state.js (6790B)


      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 click_hamburger_fs_toggle() {
      7  // show panel
      8  let menuShown = BrowserTestUtils.waitForEvent(PanelUI.panel, "ViewShown");
      9  PanelUI.show();
     10  await menuShown;
     11 
     12  // click button
     13  let hamburgerMenuButton = window.document.getElementById(
     14    "appMenu-fullscreen-button2"
     15  );
     16 
     17  // clicking the button might hide the menu
     18  let menuHidden = BrowserTestUtils.waitForEvent(PanelUI.panel, "popuphidden");
     19 
     20  hamburgerMenuButton.click();
     21 
     22  // try to hide panel explicitly
     23  PanelUI.hide();
     24  await menuHidden;
     25 }
     26 
     27 async function check_states(fullscreen) {
     28  // These are the menu items in the View menu
     29  const fsEnableMac = document.getElementById("enterFullScreenItem");
     30  const fsDisableMac = document.getElementById("exitFullScreenItem");
     31  const fullScreenItem = document.getElementById("fullScreenItem");
     32 
     33  const toolbarButton = document.getElementById("fullscreen-button");
     34 
     35  if (AppConstants.platform == "macosx") {
     36    ok(
     37      !fsEnableMac.hasAttribute("checked"),
     38      "On MacOS, the Enter Full Screen menu item should never get a checkmark"
     39    );
     40    ok(
     41      !fsDisableMac.hasAttribute("checked"),
     42      "On MacOS, the Exit Full Screen menu item should never get a checkmark"
     43    );
     44    is(
     45      fsEnableMac.hasAttribute("hidden"),
     46      fullscreen,
     47      "Enter Full Screen should be visible iff not in full screen mode"
     48    );
     49    is(
     50      fsDisableMac.hasAttribute("hidden"),
     51      !fullscreen,
     52      "Exit Full Screen should be visible iff in full screen mode"
     53    );
     54  } else {
     55    is(
     56      fullScreenItem.hasAttribute("checked"),
     57      fullscreen,
     58      "On non-mac platforms, the menu item should be checked iff in full screen mode"
     59    );
     60  }
     61  is(
     62    toolbarButton.hasAttribute("checked"),
     63    fullscreen,
     64    "The toolbar button must be checked iff in full screen mode"
     65  );
     66 
     67  // And there is little button in the hamburger menu
     68  let menuShown = BrowserTestUtils.waitForEvent(PanelUI.panel, "ViewShown");
     69  PanelUI.show();
     70  await menuShown;
     71  let hamburgerMenuButton = window.document.getElementById(
     72    "appMenu-fullscreen-button2"
     73  );
     74  is(
     75    hamburgerMenuButton.hasAttribute("checked"),
     76    fullscreen,
     77    "The hambuger menu button should be checked iff in full screen mode"
     78  );
     79  let menuHidden = BrowserTestUtils.waitForEvent(PanelUI.panel, "popuphidden");
     80  PanelUI.hide();
     81  await menuHidden;
     82 }
     83 
     84 async function toggle_fs() {
     85  let oldFSState = window.fullScreen;
     86  const fullScreenEntered = BrowserTestUtils.waitForEvent(window, "fullscreen");
     87  document.getElementById("View:FullScreen").doCommand();
     88  info(
     89    `Now waiting for fullscreen mode to be ${oldFSState ? "exited" : "entered"}`
     90  );
     91  await fullScreenEntered;
     92  return window.fullScreen;
     93 }
     94 
     95 add_task(async function test_fullscreen_ui_state() {
     96  // We add the custom button to the toolbar to make sure it works
     97  CustomizableUI.addWidgetToArea(
     98    "fullscreen-button",
     99    CustomizableUI.AREA_NAVBAR
    100  );
    101  registerCleanupFunction(() => CustomizableUI.reset());
    102 
    103  let inFullScreen = await toggle_fs();
    104  ok(inFullScreen, "Full screen should be ON");
    105  await check_states(inFullScreen);
    106 
    107  inFullScreen = await toggle_fs();
    108  is(inFullScreen, false, "Full screen should be OFF");
    109  await check_states(inFullScreen);
    110 });
    111 
    112 add_task(async function test_f11_fullscreen() {
    113  const fullScreenEntered = BrowserTestUtils.waitForEvent(window, "fullscreen");
    114  info("Pressing F11 to enter fullscreen");
    115  EventUtils.synthesizeKey("KEY_F11", {});
    116  await fullScreenEntered;
    117  ok(window.fullScreen, "Full screen should be ON");
    118 
    119  const fullScreenExited = BrowserTestUtils.waitForEvent(window, "fullscreen");
    120  info("Pressing F11 to exit fullscreen");
    121  EventUtils.synthesizeKey("KEY_F11", {});
    122  await fullScreenExited;
    123  ok(!window.fullScreen, "Full screen should be OFF");
    124 });
    125 
    126 add_task(async function test_mac_fullscreen_shortcut() {
    127  if (AppConstants.platform !== "macosx") {
    128    info("Skipping test for MacOS shortcut on non-Mac");
    129    return;
    130  }
    131 
    132  const fullScreenEntered = BrowserTestUtils.waitForEvent(window, "fullscreen");
    133  info("Pressing Ctrl+Cmd+F to enter fullscreen");
    134  EventUtils.synthesizeKey("f", { ctrlKey: true, metaKey: true }, window);
    135  await fullScreenEntered;
    136  ok(window.fullScreen, "Full screen should be ON");
    137 
    138  const fullScreenExited = BrowserTestUtils.waitForEvent(window, "fullscreen");
    139  info("Pressing Ctrl+Cmd+F to enter fullscreen");
    140  EventUtils.synthesizeKey("f", { ctrlKey: true, metaKey: true }, window);
    141  await fullScreenExited;
    142  ok(!window.fullScreen, "Full screen should be OFF");
    143 });
    144 
    145 add_task(async function test_menubar_click() {
    146  let fsEnable;
    147  let fsDisable;
    148  if (AppConstants.platform === "macosx") {
    149    fsEnable = document.getElementById("enterFullScreenItem");
    150    fsDisable = document.getElementById("exitFullScreenItem");
    151  } else {
    152    fsEnable = document.getElementById("fullScreenItem");
    153    fsDisable = fsEnable;
    154  }
    155 
    156  const fullScreenEntered = BrowserTestUtils.waitForEvent(window, "fullscreen");
    157  info("Pressing Enter Full Screen");
    158  fsEnable.click();
    159  await fullScreenEntered;
    160  ok(window.fullScreen, "Full screen should be ON");
    161 
    162  const fullScreenExited = BrowserTestUtils.waitForEvent(window, "fullscreen");
    163  fsDisable.click();
    164  await fullScreenExited;
    165  ok(!window.fullScreen, "Full screen should be OFF");
    166 });
    167 
    168 add_task(async function test_hamburger_menu_click() {
    169  const fullScreenEntered = BrowserTestUtils.waitForEvent(window, "fullscreen");
    170  info("Pressing little double arrow icon");
    171  await click_hamburger_fs_toggle();
    172  await fullScreenEntered;
    173  ok(window.fullScreen, "Full screen should be ON");
    174 
    175  const fullScreenExited = BrowserTestUtils.waitForEvent(window, "fullscreen");
    176  info("Pressing little double arrow icon");
    177  await click_hamburger_fs_toggle();
    178  await fullScreenExited;
    179  ok(!window.fullScreen, "Full screen should be OFF");
    180 });
    181 
    182 add_task(async function test_custom_menu_icon_click() {
    183  // We add the custom button to the toolbar to make sure it works
    184  CustomizableUI.addWidgetToArea(
    185    "fullscreen-button",
    186    CustomizableUI.AREA_NAVBAR
    187  );
    188 
    189  registerCleanupFunction(() => CustomizableUI.reset());
    190  const toolbarButton = document.getElementById("fullscreen-button");
    191  const fullScreenEntered = BrowserTestUtils.waitForEvent(window, "fullscreen");
    192  info("Pressing custom double arrow icon");
    193  toolbarButton.click();
    194  await fullScreenEntered;
    195  ok(window.fullScreen, "Full screen should be ON");
    196 
    197  const fullScreenExited = BrowserTestUtils.waitForEvent(window, "fullscreen");
    198  info("Pressing custom double arrow icon");
    199  toolbarButton.click();
    200  await fullScreenExited;
    201  ok(!window.fullScreen, "Full screen should be OFF");
    202 });