tor-browser

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

browser_panelUINotifications_fullscreen_noAutoHideToolbar.js (4089B)


      1 "use strict";
      2 
      3 const { AppMenuNotifications } = ChromeUtils.importESModule(
      4  "resource://gre/modules/AppMenuNotifications.sys.mjs"
      5 );
      6 
      7 function waitForDocshellActivated() {
      8  return SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
      9    // Setting docshell activated/deactivated will trigger visibility state
     10    // changes to relevant state ("visible" or "hidden"). AFAIK, there is no
     11    // such event notifying docshell is being activated, so I use
     12    // "visibilitychange" event rather than polling the isActive flag.
     13    await ContentTaskUtils.waitForEvent(
     14      content.document,
     15      "visibilitychange",
     16      true /* capture */,
     17      () => {
     18        return content.browsingContext.isActive;
     19      }
     20    );
     21  });
     22 }
     23 
     24 function waitForFullscreen() {
     25  return Promise.all([
     26    BrowserTestUtils.waitForEvent(window, "fullscreen"),
     27    // In the platforms that support reporting occlusion state (e.g. Mac),
     28    // enter/exit fullscreen mode will trigger docshell being set to non-activate
     29    // and then set to activate back again. For those platforms, we should wait
     30    // until the docshell has been activated again before starting next test,
     31    // otherwise, the fullscreen request might be denied.
     32    Services.appinfo.OS === "Darwin"
     33      ? waitForDocshellActivated()
     34      : Promise.resolve(),
     35  ]);
     36 }
     37 
     38 add_task(async function testFullscreen() {
     39  if (Services.appinfo.OS !== "Darwin") {
     40    await SpecialPowers.pushPrefEnv({
     41      set: [["browser.fullscreen.autohide", false]],
     42    });
     43  }
     44 
     45  is(
     46    PanelUI.notificationPanel.state,
     47    "closed",
     48    "update-manual doorhanger is closed."
     49  );
     50  let mainActionCalled = false;
     51  let mainAction = {
     52    callback: () => {
     53      mainActionCalled = true;
     54    },
     55  };
     56  AppMenuNotifications.showNotification("update-manual", mainAction);
     57  await BrowserTestUtils.waitForEvent(PanelUI.notificationPanel, "popupshown");
     58 
     59  isnot(
     60    PanelUI.notificationPanel.state,
     61    "closed",
     62    "update-manual doorhanger is showing."
     63  );
     64  let notifications = [...PanelUI.notificationPanel.children].filter(
     65    n => !n.hidden
     66  );
     67  is(
     68    notifications.length,
     69    1,
     70    "PanelUI doorhanger is only displaying one notification."
     71  );
     72  let doorhanger = notifications[0];
     73  is(
     74    doorhanger.id,
     75    "appMenu-update-manual-notification",
     76    "PanelUI is displaying the update-manual notification."
     77  );
     78 
     79  let fullscreenPromise = waitForFullscreen();
     80  EventUtils.synthesizeKey("KEY_F11");
     81  await fullscreenPromise;
     82  isnot(
     83    PanelUI.notificationPanel.state,
     84    "closed",
     85    "update-manual doorhanger is still showing after entering fullscreen."
     86  );
     87 
     88  let popuphiddenPromise = BrowserTestUtils.waitForEvent(
     89    PanelUI.notificationPanel,
     90    "popuphidden"
     91  );
     92  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => {
     93    content.document.documentElement.requestFullscreen();
     94  });
     95  await popuphiddenPromise;
     96  await new Promise(executeSoon);
     97  is(
     98    PanelUI.notificationPanel.state,
     99    "closed",
    100    "update-manual doorhanger is hidden after entering DOM fullscreen."
    101  );
    102 
    103  let popupshownPromise = BrowserTestUtils.waitForEvent(
    104    PanelUI.notificationPanel,
    105    "popupshown"
    106  );
    107  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => {
    108    content.document.exitFullscreen();
    109  });
    110  await popupshownPromise;
    111  await new Promise(executeSoon);
    112  isnot(
    113    PanelUI.notificationPanel.state,
    114    "closed",
    115    "update-manual doorhanger is shown after exiting DOM fullscreen."
    116  );
    117  isnot(
    118    PanelUI.menuButton.getAttribute("badge-status"),
    119    "update-manual",
    120    "Badge is not displaying on PanelUI button."
    121  );
    122 
    123  doorhanger.button.click();
    124  ok(mainActionCalled, "Main action callback was called");
    125  is(
    126    PanelUI.notificationPanel.state,
    127    "closed",
    128    "update-manual doorhanger is closed."
    129  );
    130  is(
    131    PanelUI.menuButton.hasAttribute("badge-status"),
    132    false,
    133    "Should not have a badge status"
    134  );
    135 
    136  fullscreenPromise = BrowserTestUtils.waitForEvent(window, "fullscreen");
    137  EventUtils.synthesizeKey("KEY_F11");
    138  await fullscreenPromise;
    139 });