Bug 1521688 - Show titlebar buttons when drawInTitlebar=true, window.open with features="toolbar", View => Toolbars => Menu Bar=checked r=dao
authorYUKI "Piro" Hiroshi <yuki@clear-code.com>
Thu, 07 Feb 2019 12:46:25 +0000
changeset 457644 7d8248d9408488e792559a6fde04987f5e7ea2f9
parent 457643 cc26e0ca64e8c8f29b0f10775c8f729220fd343e
child 457645 7f66045a90f2d433aa71064f8ee06d24467dd5ad
push id35516
push userrmaries@mozilla.com
push dateFri, 08 Feb 2019 04:23:26 +0000
treeherdermozilla-central@d599d1a73a3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1521688
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1521688 - Show titlebar buttons when drawInTitlebar=true, window.open with features="toolbar", View => Toolbars => Menu Bar=checked r=dao Differential Revision: https://phabricator.services.mozilla.com/D17331
browser/base/content/browser.css
browser/base/content/test/popups/browser_popupUI.js
--- a/browser/base/content/browser.css
+++ b/browser/base/content/browser.css
@@ -296,18 +296,18 @@ window:not([chromehidden~="toolbar"]) #n
  */
 #widget-overflow-list:empty + #widget-overflow-fixed-separator,
 #widget-overflow:not([hasfixeditems]) #widget-overflow-fixed-separator {
   display: none;
 }
 
 
 %ifdef MENUBAR_CAN_AUTOHIDE
-#toolbar-menubar:not([autohide=true]) + #TabsToolbar > .titlebar-buttonbox-container,
-#toolbar-menubar:not([autohide=true]) + #TabsToolbar .titlebar-spacer,
+:root:not([chromehidden~="menubar"]) #toolbar-menubar:not([autohide=true]) + #TabsToolbar > .titlebar-buttonbox-container,
+:root:not([chromehidden~="menubar"]) #toolbar-menubar:not([autohide=true]) + #TabsToolbar .titlebar-spacer,
 %endif
 %ifndef MOZ_WIDGET_COCOA
 %ifndef MOZ_WIDGET_GTK
 :root:not([sizemode=normal]) .titlebar-spacer[type="pre-tabs"],
 %endif
 %endif
 :root:not([chromemargin]) .titlebar-buttonbox-container,
 :root[inFullscreen] .titlebar-buttonbox-container,
--- a/browser/base/content/test/popups/browser_popupUI.js
+++ b/browser/base/content/test/popups/browser_popupUI.js
@@ -1,21 +1,23 @@
-function test() {
-  waitForExplicitFinish();
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+add_task(async function toolbar_ui_visibility() {
   SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_open_during_load", false ]] });
 
   let popupOpened = BrowserTestUtils.waitForNewWindow({url: "about:blank"});
   BrowserTestUtils.openNewForegroundTab(gBrowser,
     "data:text/html,<html><script>popup=open('about:blank','','width=300,height=200')</script>"
   );
-  popupOpened.then((win) => testPopupUI(win));
-}
-
-function testPopupUI(win) {
-  var doc = win.document;
+  const win = await popupOpened;
+  const doc = win.document;
 
   ok(win.gURLBar, "location bar exists in the popup");
   isnot(win.gURLBar.clientWidth, 0, "location bar is visible in the popup");
   ok(win.gURLBar.readOnly, "location bar is read-only in the popup");
   isnot(doc.getElementById("Browser:OpenLocation").getAttribute("disabled"), "true",
      "'open location' command is not disabled in the popup");
 
   let historyButton = doc.getAnonymousElementByAttribute(win.gURLBar, "anonid",
@@ -28,10 +30,75 @@ function testPopupUI(win) {
   gBrowser.removeCurrentTab();
 
   EventUtils.synthesizeKey("w", { accelKey: true }, win);
   ok(win.closed, "Accel+W closes the popup");
 
   if (!win.closed)
     win.close();
   gBrowser.removeCurrentTab();
-  finish();
-}
+});
+
+add_task(async function titlebar_buttons_visibility() {
+  if (!navigator.platform.startsWith("Win")) {
+    ok(true, "Testing only on Windows");
+    return;
+  }
+
+  const BUTTONS_MAY_VISIBLE = true;
+  const BUTTONS_NEVER_VISIBLE = false;
+
+  const drawInTitlebarValues = {
+    "true": BUTTONS_MAY_VISIBLE,
+    "false": BUTTONS_NEVER_VISIBLE,
+  };
+  const windowFeaturesValues = {
+    "width=300,height=100": BUTTONS_NEVER_VISIBLE,
+    "toolbar": BUTTONS_MAY_VISIBLE,
+    "menubar": BUTTONS_NEVER_VISIBLE,
+    "menubar,toolbar": BUTTONS_MAY_VISIBLE,
+  };
+  const menuBarShownValues = [true, false];
+
+  for (const drawInTitlebar of Object.keys(drawInTitlebarValues)) {
+    Services.prefs.setBoolPref("browser.tabs.drawInTitlebar", drawInTitlebar == "true");
+
+    for (const windowFeatures of Object.keys(windowFeaturesValues)) {
+      for (const menuBarShown of menuBarShownValues) {
+        CustomizableUI.setToolbarVisibility("toolbar-menubar", menuBarShown);
+
+        const popupPromise = BrowserTestUtils.waitForNewWindow("about:blank");
+        BrowserTestUtils.openNewForegroundTab(gBrowser,
+          `data:text/html;charset=UTF-8,<html><script>window.open("about:blank","","${windowFeatures}")</script>`
+        );
+        const popupWin = await popupPromise;
+
+        const menubar = popupWin.document.querySelector("#toolbar-menubar");
+        const menubarIsShown = menubar.getAttribute("autohide") != "true" || menubar.getAttribute("inactive") != "true";
+        const buttonsInMenubar = menubar.querySelector(".titlebar-buttonbox-container");
+        const buttonsInMenubarShown = menubarIsShown && popupWin.getComputedStyle(buttonsInMenubar).display != "none";
+
+        const buttonsInTabbar = popupWin.document.querySelector("#TabsToolbar .titlebar-buttonbox-container");
+        const buttonsInTabbarShown = popupWin.getComputedStyle(buttonsInTabbar).display != "none";
+
+        const params = `drawInTitlebar=${drawInTitlebar}, windowFeatures=${windowFeatures}, menuBarShown=${menuBarShown}`;
+        if (drawInTitlebarValues[drawInTitlebar] == BUTTONS_MAY_VISIBLE &&
+            windowFeaturesValues[windowFeatures] == BUTTONS_MAY_VISIBLE) {
+          ok(buttonsInMenubarShown || buttonsInTabbarShown,
+             `Titlebar buttons should be visible: ${params}`);
+        } else {
+          ok(!buttonsInMenubarShown,
+             `Titlebar buttons should not be visible: ${params}`);
+          ok(!buttonsInTabbarShown,
+             `Titlebar buttons should not be visible: ${params}`);
+        }
+
+        const closedPopupPromise = BrowserTestUtils.windowClosed(popupWin);
+        popupWin.close();
+        await closedPopupPromise;
+        gBrowser.removeCurrentTab();
+      }
+    }
+  }
+
+  CustomizableUI.setToolbarVisibility("toolbar-menubar", false);
+  Services.prefs.clearUserPref("browser.tabs.drawInTitlebar");
+});