commit eae85737b7952990c79155bfaf20e3090ab890e0
parent cf7800eb6fe47b670772f8d75ece8c1fedced8c6
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Sat, 8 Nov 2025 21:17:04 +0000
Bug 1996449 - Ensure runOncePerModification("displayMenuBar", ..) works as expected. r=mkaply,mossop
runOncePerModification works on strings. If you pass a boolean down it
will always call its callback (because "true" != true etc).
Differential Revision: https://phabricator.services.mozilla.com/D271452
Diffstat:
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/browser/components/enterprisepolicies/Policies.sys.mjs b/browser/components/enterprisepolicies/Policies.sys.mjs
@@ -3177,6 +3177,8 @@ export function runOnce(actionName, callback) {
* A promise that will resolve once the callback finishes running.
*/
async function runOncePerModification(actionName, policyValue, callback) {
+ // Stringify the value so that it matches what we'd get from getStringPref.
+ policyValue = policyValue + "";
let prefName = `browser.policies.runOncePerModification.${actionName}`;
let oldPolicyValue = Services.prefs.getStringPref(prefName, undefined);
if (policyValue === oldPolicyValue) {
diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_display_menu.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_display_menu.js
@@ -20,6 +20,12 @@ add_task(async function test_menu_shown_boolean() {
});
add_task(async function test_menu_shown_string() {
+ if (Services.appinfo.nativeMenubar) {
+ // On macOS we can't really control menubar visibility.
+ ok(true, "Native menubar is not controlled by this policy");
+ return;
+ }
+
await setupPolicyEngineWithJson({
policies: {
DisplayMenuBar: "default-on",
@@ -28,11 +34,22 @@ add_task(async function test_menu_shown_string() {
// 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");
- ok(!menubar.hasAttribute("autohide"), "The menu bar should not be hidden");
+ {
+ let newWin = await BrowserTestUtils.openNewBrowserWindow();
+ let menubar = newWin.document.getElementById("toolbar-menubar");
+ ok(!menubar.hasAttribute("autohide"), "The menu bar should not be hidden");
+ setToolbarVisibility(menubar, false);
+ ok(menubar.hasAttribute("autohide"), "The menu bar should be hidden");
+ await BrowserTestUtils.closeWindow(newWin);
+ }
- await BrowserTestUtils.closeWindow(newWin);
+ {
+ // Make sure the menubar autohide persists even tho it's default-on.
+ let newWin = await BrowserTestUtils.openNewBrowserWindow();
+ let menubar = newWin.document.getElementById("toolbar-menubar");
+ ok(menubar.hasAttribute("autohide"), "The menu bar should be hidden");
+ await BrowserTestUtils.closeWindow(newWin);
+ }
});
add_task(async function test_menubar_on() {