commit 0df9ebba38e667abd4fb76adf2861d7e85c74b33
parent 8c5cb13f12e8f0854fe570f2f0e10fbcb6f94f19
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Sat, 8 Nov 2025 10:42:39 +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, 17 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
@@ -28,11 +28,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() {