Skip to content

Commit eae8573

Browse files
committed
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
1 parent cf7800e commit eae8573

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎browser/components/enterprisepolicies/Policies.sys.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,6 +3177,8 @@ export function runOnce(actionName, callback) {
31773177
* A promise that will resolve once the callback finishes running.
31783178
*/
31793179
async function runOncePerModification(actionName, policyValue, callback) {
3180+
// Stringify the value so that it matches what we'd get from getStringPref.
3181+
policyValue = policyValue + "";
31803182
let prefName = `browser.policies.runOncePerModification.${actionName}`;
31813183
let oldPolicyValue = Services.prefs.getStringPref(prefName, undefined);
31823184
if (policyValue === oldPolicyValue) {

‎browser/components/enterprisepolicies/tests/browser/browser_policy_display_menu.js‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ add_task(async function test_menu_shown_boolean() {
2020
});
2121

2222
add_task(async function test_menu_shown_string() {
23+
if (Services.appinfo.nativeMenubar) {
24+
// On macOS we can't really control menubar visibility.
25+
ok(true, "Native menubar is not controlled by this policy");
26+
return;
27+
}
28+
2329
await setupPolicyEngineWithJson({
2430
policies: {
2531
DisplayMenuBar: "default-on",
@@ -28,11 +34,22 @@ add_task(async function test_menu_shown_string() {
2834

2935
// Since testing will apply the policy after the browser has already started,
3036
// we will need to open a new window to actually see the menu bar
31-
let newWin = await BrowserTestUtils.openNewBrowserWindow();
32-
let menubar = newWin.document.getElementById("toolbar-menubar");
33-
ok(!menubar.hasAttribute("autohide"), "The menu bar should not be hidden");
37+
{
38+
let newWin = await BrowserTestUtils.openNewBrowserWindow();
39+
let menubar = newWin.document.getElementById("toolbar-menubar");
40+
ok(!menubar.hasAttribute("autohide"), "The menu bar should not be hidden");
41+
setToolbarVisibility(menubar, false);
42+
ok(menubar.hasAttribute("autohide"), "The menu bar should be hidden");
43+
await BrowserTestUtils.closeWindow(newWin);
44+
}
3445

35-
await BrowserTestUtils.closeWindow(newWin);
46+
{
47+
// Make sure the menubar autohide persists even tho it's default-on.
48+
let newWin = await BrowserTestUtils.openNewBrowserWindow();
49+
let menubar = newWin.document.getElementById("toolbar-menubar");
50+
ok(menubar.hasAttribute("autohide"), "The menu bar should be hidden");
51+
await BrowserTestUtils.closeWindow(newWin);
52+
}
3653
});
3754

3855
add_task(async function test_menubar_on() {

0 commit comments

Comments
 (0)