tor-browser

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

browser_popupUI.js (6111B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 add_task(async function toolbar_ui_visibility() {
      8  SpecialPowers.pushPrefEnv({ set: [["dom.disable_open_during_load", false]] });
      9 
     10  let popupOpened = BrowserTestUtils.waitForNewWindow({ url: "about:blank" });
     11  BrowserTestUtils.openNewForegroundTab(
     12    gBrowser,
     13    "data:text/html,<html><script>popup=open('about:blank','','width=300,height=200')</script>"
     14  );
     15  const win = await popupOpened;
     16  const doc = win.document;
     17 
     18  ok(win.gURLBar, "location bar exists in the popup");
     19  isnot(win.gURLBar.clientWidth, 0, "location bar is visible in the popup");
     20  ok(win.gURLBar.readOnly, "location bar is read-only in the popup");
     21  isnot(
     22    doc.getElementById("Browser:OpenLocation").getAttribute("disabled"),
     23    "true",
     24    "'open location' command is not disabled in the popup"
     25  );
     26 
     27  EventUtils.synthesizeKey("t", { accelKey: true }, win);
     28  is(
     29    win.gBrowser.browsers.length,
     30    1,
     31    "Accel+T doesn't open a new tab in the popup"
     32  );
     33  is(
     34    gBrowser.browsers.length,
     35    3,
     36    "Accel+T opened a new tab in the parent window"
     37  );
     38  gBrowser.removeCurrentTab();
     39 
     40  EventUtils.synthesizeKey("w", { accelKey: true }, win);
     41  ok(win.closed, "Accel+W closes the popup");
     42 
     43  if (!win.closed) {
     44    win.close();
     45  }
     46  gBrowser.removeCurrentTab();
     47 });
     48 
     49 add_task(async function titlebar_buttons_visibility() {
     50  if (!navigator.platform.startsWith("Win")) {
     51    ok(true, "Testing only on Windows");
     52    return;
     53  }
     54 
     55  const BUTTONS_MAY_VISIBLE = true;
     56  const BUTTONS_NEVER_VISIBLE = false;
     57 
     58  // Always open a new window.
     59  // With default behavior, it opens a new tab, that doesn't affect button
     60  // visibility at all.
     61  Services.prefs.setIntPref("browser.link.open_newwindow", 2);
     62 
     63  const drawInTitlebarValues = [
     64    [1, BUTTONS_MAY_VISIBLE],
     65    [0, BUTTONS_NEVER_VISIBLE],
     66  ];
     67  const windowFeaturesValues = [
     68    // Opens a popup
     69    ["width=300,height=100", BUTTONS_NEVER_VISIBLE],
     70    ["toolbar", BUTTONS_NEVER_VISIBLE],
     71    ["menubar", BUTTONS_NEVER_VISIBLE],
     72    ["menubar,toolbar", BUTTONS_NEVER_VISIBLE],
     73 
     74    // Opens a new window
     75    ["", BUTTONS_MAY_VISIBLE],
     76  ];
     77  const menuBarShownValues = [true, false];
     78 
     79  for (const [drawInTitlebar, drawInTitlebarButtons] of drawInTitlebarValues) {
     80    Services.prefs.setIntPref("browser.tabs.inTitlebar", drawInTitlebar);
     81 
     82    for (const [
     83      windowFeatures,
     84      windowFeaturesButtons,
     85    ] of windowFeaturesValues) {
     86      for (const menuBarShown of menuBarShownValues) {
     87        CustomizableUI.setToolbarVisibility("toolbar-menubar", menuBarShown);
     88 
     89        const popupPromise = BrowserTestUtils.waitForNewWindow("about:blank");
     90        BrowserTestUtils.openNewForegroundTab(
     91          gBrowser,
     92          `data:text/html;charset=UTF-8,<html><script>window.open("about:blank","","${windowFeatures}")</script>`
     93        );
     94        const popupWin = await popupPromise;
     95 
     96        const menubar = popupWin.document.querySelector("#toolbar-menubar");
     97        const menubarIsShown =
     98          menubar.getAttribute("autohide") != "true" ||
     99          menubar.getAttribute("inactive") != "true";
    100        const buttonsInMenubar = menubar.querySelector(
    101          ".titlebar-buttonbox-container"
    102        );
    103        const buttonsInMenubarShown =
    104          menubarIsShown &&
    105          popupWin.getComputedStyle(buttonsInMenubar).display != "none";
    106 
    107        const buttonsInTabbar = popupWin.document.querySelector(
    108          "#TabsToolbar .titlebar-buttonbox-container"
    109        );
    110        const buttonsInTabbarShown =
    111          popupWin.getComputedStyle(buttonsInTabbar).display != "none";
    112 
    113        const params = `drawInTitlebar=${drawInTitlebar}, windowFeatures=${windowFeatures}, menuBarShown=${menuBarShown}`;
    114        if (
    115          drawInTitlebarButtons == BUTTONS_MAY_VISIBLE &&
    116          windowFeaturesButtons == BUTTONS_MAY_VISIBLE
    117        ) {
    118          ok(
    119            buttonsInMenubarShown || buttonsInTabbarShown,
    120            `Titlebar buttons should be visible: ${params}`
    121          );
    122        } else {
    123          ok(
    124            !buttonsInMenubarShown,
    125            `Titlebar buttons should not be visible: ${params}`
    126          );
    127          ok(
    128            !buttonsInTabbarShown,
    129            `Titlebar buttons should not be visible: ${params}`
    130          );
    131        }
    132 
    133        const closedPopupPromise = BrowserTestUtils.windowClosed(popupWin);
    134        popupWin.close();
    135        await closedPopupPromise;
    136        gBrowser.removeCurrentTab();
    137      }
    138    }
    139  }
    140 
    141  CustomizableUI.setToolbarVisibility("toolbar-menubar", false);
    142  Services.prefs.clearUserPref("browser.tabs.inTitlebar");
    143  Services.prefs.clearUserPref("browser.link.open_newwindow");
    144 });
    145 
    146 // Test only `visibility` rule here, to verify bug 1636229 fix.
    147 // Other styles and ancestors can be different for each OS.
    148 function isVisible(element) {
    149  const style = element.ownerGlobal.getComputedStyle(element);
    150  return style.visibility == "visible";
    151 }
    152 
    153 async function testTabBarVisibility() {
    154  SpecialPowers.pushPrefEnv({ set: [["dom.disable_open_during_load", false]] });
    155 
    156  const popupOpened = BrowserTestUtils.waitForNewWindow({ url: "about:blank" });
    157  BrowserTestUtils.openNewForegroundTab(
    158    gBrowser,
    159    "data:text/html,<html><script>popup=open('about:blank','','width=300,height=200')</script>"
    160  );
    161  const win = await popupOpened;
    162  const doc = win.document;
    163 
    164  ok(
    165    !isVisible(doc.getElementById("TabsToolbar")),
    166    "tabbar should be hidden for popup"
    167  );
    168 
    169  const closedPopupPromise = BrowserTestUtils.windowClosed(win);
    170  win.close();
    171  await closedPopupPromise;
    172 
    173  gBrowser.removeCurrentTab();
    174 }
    175 
    176 add_task(async function tabbar_visibility() {
    177  await testTabBarVisibility();
    178 });
    179 
    180 add_task(async function tabbar_visibility_with_theme() {
    181  const extension = ExtensionTestUtils.loadExtension({
    182    manifest: {
    183      theme: {},
    184    },
    185  });
    186 
    187  await extension.startup();
    188 
    189  await testTabBarVisibility();
    190 
    191  await extension.unload();
    192 });