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 = { ...@@ -2107,6 +2107,10 @@ var gBrowserInit = {
window.fullScreen = true; window.fullScreen = true;
} }
} }
if (!Services.policies.isAllowed("hideShowMenuBar")) {
document.getElementById("toolbar-menubar").removeAttribute("toolbarname");
}
}, },
_setInitialFocus() { _setInitialFocus() {
......
...@@ -584,18 +584,53 @@ var Policies = { ...@@ -584,18 +584,53 @@ var Policies = {
DisplayMenuBar: { DisplayMenuBar: {
onBeforeUIStartup(manager, param) { onBeforeUIStartup(manager, param) {
let value = (!param).toString(); let value;
// This policy is meant to change the default behavior, not to force it. if (
// If this policy was alreay applied and the user chose to re-hide the typeof param === "boolean" ||
// menu bar, do not show it again. param == "default-on" ||
runOncePerModification("displayMenuBar", value, () => { 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( gXulStore.setValue(
BROWSER_DOCUMENT_URL, BROWSER_DOCUMENT_URL,
"toolbar-menubar", "toolbar-menubar",
"autohide", "autohide",
value value
); );
}); manager.disallowFeature("hideShowMenuBar");
}
}, },
}, },
......
...@@ -277,7 +277,8 @@ ...@@ -277,7 +277,8 @@
}, },
"DisplayMenuBar": { "DisplayMenuBar": {
"type": "boolean" "type": ["boolean", "string"],
"enum": ["always", "never", "default-on", "default-off"]
}, },
"DNSOverHTTPS": { "DNSOverHTTPS": {
......
...@@ -3,24 +3,82 @@ ...@@ -3,24 +3,82 @@
"use strict"; "use strict";
add_task(async function setup() { add_task(async function test_menu_shown_boolean() {
await setupPolicyEngineWithJson({ await setupPolicyEngineWithJson({
policies: { policies: {
DisplayMenuBar: true, 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, // 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 // we will need to open a new window to actually see the menu bar
let newWin = await BrowserTestUtils.openNewBrowserWindow(); let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menuBar = newWin.document.getElementById("toolbar-menubar"); let menubar = newWin.document.getElementById("toolbar-menubar");
is( is(
menuBar.getAttribute("autohide"), menubar.getAttribute("autohide"),
"false", "false",
"The menu bar should not be hidden" "The menu bar should not be hidden"
); );
await BrowserTestUtils.closeWindow(newWin); 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 = { ...@@ -39,7 +39,10 @@ var JsonSchemaValidator = {
}; };
function validateAndParseParamRecursive(param, properties) { 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)) { if (properties.enum.includes(param)) {
return [true, param]; return [true, param];
} }
......
Supports Markdown
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