Skip to content

Commit d148785

Browse files
committed
Bug 1963764 - make sure Report Broken Site is still hidden appropriately when enterprise DisableFeedbackCommands policy is active (regressed by bug 1952334); r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D258785
1 parent 9323344 commit d148785

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

browser/components/reportbrokensite/ReportBrokenSite.sys.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ export var ReportBrokenSite = new (class ReportBrokenSite {
446446

447447
enableOrDisableMenuitems(selectedbrowser) {
448448
// Ensures that the various Report Broken Site menu items and
449-
// toolbar buttons are disabled when appropriate.
449+
// toolbar buttons are enabled/hidden when appropriate.
450450

451451
const canReportUrl = this.canReportURI(selectedbrowser.currentURI);
452452

@@ -455,6 +455,14 @@ export var ReportBrokenSite = new (class ReportBrokenSite {
455455
// Altering the disabled attribute on the command does not propagate
456456
// the change to the related menuitems (see bug 805653), so we change them all.
457457
const cmd = document.getElementById("cmd_reportBrokenSite");
458+
const allowedByPolicy = Services.policies.isAllowed(
459+
"DisableFeedbackCommands"
460+
);
461+
if (allowedByPolicy) {
462+
cmd.setAttribute("hidden", "false"); // see bug 805653
463+
} else {
464+
cmd.setAttribute("hidden", "true");
465+
}
458466
const app = document.ownerGlobal.PanelMultiView.getViewNode(
459467
document,
460468
"appMenu-report-broken-site-button"
@@ -473,11 +481,12 @@ export var ReportBrokenSite = new (class ReportBrokenSite {
473481
prot?.setAttribute("disabled", "true");
474482
}
475483

476-
// Changes to the "disabled" state of the command aren't reliably
484+
// Changes to the "hidden" and "disabled" state of the command aren't reliably
477485
// reflected on the main menu unless we open it twice, or do it manually.
478486
// (See bug 1864953).
479487
const mainmenuItem = document.getElementById("help_reportBrokenSite");
480488
if (mainmenuItem) {
489+
mainmenuItem.hidden = !allowedByPolicy;
481490
mainmenuItem.disabled = !canReportUrl;
482491
}
483492
}

browser/components/reportbrokensite/test/browser/browser_parent_menuitems.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,17 @@ add_task(async function testMenus() {
8080
);
8181
}
8282
});
83+
84+
ensureReportBrokenSitePreffedOn();
85+
ensureReportBrokenSiteDisabledByPolicy();
86+
87+
await BrowserTestUtils.withNewTab(REPORTABLE_PAGE_URL, async function () {
88+
await forceMenuItemStateUpdate();
89+
for (const { menuDescription, reportBrokenSite } of menus) {
90+
isMenuItemHidden(
91+
reportBrokenSite,
92+
`${menuDescription} option hidden when disabled by DisableFeedbackCommands enterprise policy`
93+
);
94+
}
95+
});
8396
});

browser/components/reportbrokensite/test/browser/head.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const { CustomizableUITestUtils } = ChromeUtils.importESModule(
55
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
66
);
77

8+
const { EnterprisePolicyTesting, PoliciesPrefTracker } =
9+
ChromeUtils.importESModule(
10+
"resource://testing-common/EnterprisePolicyTesting.sys.mjs"
11+
);
12+
813
const { UrlClassifierTestUtils } = ChromeUtils.importESModule(
914
"resource://testing-common/UrlClassifierTestUtils.sys.mjs"
1015
);
@@ -146,6 +151,35 @@ function isSelectedTab(win, tab) {
146151
is(selectedTab, tab);
147152
}
148153

154+
async function setupPolicyEngineWithJson(json, customSchema) {
155+
PoliciesPrefTracker.restoreDefaultValues();
156+
if (typeof json != "object") {
157+
let filePath = getTestFilePath(json ? json : "non-existing-file.json");
158+
return EnterprisePolicyTesting.setupPolicyEngineWithJson(
159+
filePath,
160+
customSchema
161+
);
162+
}
163+
return EnterprisePolicyTesting.setupPolicyEngineWithJson(json, customSchema);
164+
}
165+
166+
async function ensureReportBrokenSiteDisabledByPolicy() {
167+
await setupPolicyEngineWithJson({
168+
policies: {
169+
DisableFeedbackCommands: true,
170+
},
171+
});
172+
}
173+
174+
registerCleanupFunction(async function resetPolicies() {
175+
if (Services.policies.status != Ci.nsIEnterprisePolicies.INACTIVE) {
176+
await setupPolicyEngineWithJson("");
177+
}
178+
EnterprisePolicyTesting.resetRunOnceState();
179+
PoliciesPrefTracker.restoreDefaultValues();
180+
PoliciesPrefTracker.stop();
181+
});
182+
149183
function ensureReportBrokenSitePreffedOn() {
150184
Services.prefs.setBoolPref(PREFS.DATAREPORTING_ENABLED, true);
151185
Services.prefs.setBoolPref(PREFS.REPORTER_ENABLED, true);

0 commit comments

Comments
 (0)