Commit 10015268 authored by Michael Kaply's avatar Michael Kaply
Browse files

Bug 1587492 - Add a new policy to always show the menubar. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D48724

--HG--
extra : moz-landing-system : lando
parent 2a35015f
......@@ -2107,6 +2107,10 @@ var gBrowserInit = {
window.fullScreen = true;
}
}
if (!Services.policies.isAllowed("hideShowMenuBar")) {
document.getElementById("toolbar-menubar").removeAttribute("toolbarname");
}
},
_setInitialFocus() {
......
......@@ -584,18 +584,53 @@ var Policies = {
DisplayMenuBar: {
onBeforeUIStartup(manager, param) {
let value = (!param).toString();
// This policy is meant to change the default behavior, not to force it.
// If this policy was alreay applied and the user chose to re-hide the
// menu bar, do not show it again.
runOncePerModification("displayMenuBar", value, () => {
let value;
if (
typeof param === "boolean" ||
param == "default-on" ||
param == "default-off"
) {
switch (param) {
case "default-on":
value = "false";
break;
case "default-off":
value = "true";
break;
default:
value = (!param).toString();
break;
}
// This policy is meant to change the default behavior, not to force it.
// If this policy was already applied and the user chose to re-hide the
// menu bar, do not show it again.
runOncePerModification("displayMenuBar", value, () => {
gXulStore.setValue(
BROWSER_DOCUMENT_URL,
"toolbar-menubar",
"autohide",
value
);
});
} else {
switch (param) {
case "always":
value = "false";
break;
case "never":
// Make sure Alt key doesn't show the menubar
setAndLockPref("ui.key.menuAccessKeyFocuses", false);
value = "true";
break;
}
gXulStore.setValue(
BROWSER_DOCUMENT_URL,
"toolbar-menubar",
"autohide",
value
);
});
manager.disallowFeature("hideShowMenuBar");
}
},
},
......
......@@ -277,7 +277,8 @@
},
"DisplayMenuBar": {
"type": "boolean"
"type": ["boolean", "string"],
"enum": ["always", "never", "default-on", "default-off"]
},
"DNSOverHTTPS": {
......
......@@ -3,24 +3,82 @@
"use strict";
add_task(async function setup() {
add_task(async function test_menu_shown_boolean() {
await setupPolicyEngineWithJson({
policies: {
DisplayMenuBar: true,
},
});
// Since testing will apply the policy after the browser has already started,
// we will need to open a new window to actually see the menu bar
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menubar = newWin.document.getElementById("toolbar-menubar");
is(
menubar.getAttribute("autohide"),
"false",
"The menu bar should not be hidden"
);
await BrowserTestUtils.closeWindow(newWin);
});
add_task(async function test_menu_shown() {
add_task(async function test_menu_shown_string() {
await setupPolicyEngineWithJson({
policies: {
DisplayMenuBar: "default-on",
},
});
// Since testing will apply the policy after the browser has already started,
// we will need to open a new window to actually see the menu bar
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menuBar = newWin.document.getElementById("toolbar-menubar");
let menubar = newWin.document.getElementById("toolbar-menubar");
is(
menuBar.getAttribute("autohide"),
menubar.getAttribute("autohide"),
"false",
"The menu bar should not be hidden"
);
await BrowserTestUtils.closeWindow(newWin);
});
add_task(async function test_menubar_on() {
await setupPolicyEngineWithJson({
policies: {
DisplayMenuBar: "always",
},
});
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menubar = newWin.document.getElementById("toolbar-menubar");
is(
menubar.hasAttribute("inactive"),
false,
"Menu bar should not have inactive"
);
is(
menubar.hasAttribute("toolbarname"),
false,
"Menu bar should not have a toolbarname"
);
await BrowserTestUtils.closeWindow(newWin);
});
add_task(async function test_menubar_off() {
await setupPolicyEngineWithJson({
policies: {
DisplayMenuBar: "never",
},
});
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menubar = newWin.document.getElementById("toolbar-menubar");
is(menubar.hasAttribute("inactive"), true, "Menu bar should have inactive");
is(
menubar.hasAttribute("toolbarname"),
false,
"Menu bar should not have a toolbarname"
);
await BrowserTestUtils.closeWindow(newWin);
});
......@@ -39,7 +39,10 @@ var JsonSchemaValidator = {
};
function validateAndParseParamRecursive(param, properties) {
if (properties.enum) {
// If the param is a boolean, don't check the enum values.
// This allows for values that are both a string with enums
// and a boolean.
if (properties.enum && typeof param !== "boolean") {
if (properties.enum.includes(param)) {
return [true, param];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment