From afd4cf321d44f3e0a8191474ca8a1e61eedec1dd Mon Sep 17 00:00:00 2001 From: Michael Kaply Date: Tue, 12 May 2020 13:48:38 +0000 Subject: [PATCH] Bug 1630884 - Handle locked prefs in page info dialog. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D74477 --- browser/base/content/pageinfo/permissions.js | 27 +++++++ .../tests/browser/browser.ini | 1 + .../browser_policy_pageinfo_permissions.js | 71 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js diff --git a/browser/base/content/pageinfo/permissions.js b/browser/base/content/pageinfo/permissions.js index b8eadb0184a4..6a24ffa00699 100644 --- a/browser/base/content/pageinfo/permissions.js +++ b/browser/base/content/pageinfo/permissions.js @@ -87,6 +87,11 @@ function initRow(aPartId) { } setRadioState(aPartId, state); + + checkbox.disabled = Services.prefs.prefIsLocked( + "network.cookie.cookieBehavior" + ); + return; } @@ -106,6 +111,28 @@ function initRow(aPartId) { } setRadioState(aPartId, state); + + switch (aPartId) { + case "install": + checkbox.disabled = !Services.policies.isAllowed("xpinstall"); + break; + case "popup": + checkbox.disabled = Services.prefs.prefIsLocked( + "dom.disable_open_during_load" + ); + break; + case "autoplay-media": + checkbox.disabled = Services.prefs.prefIsLocked("media.autoplay.default"); + break; + case "geo": + case "desktop-notification": + case "camera": + case "microphone": + checkbox.disabled = Services.prefs.prefIsLocked( + "permissions.default." + aPartId + ); + break; + } } function createRow(aPartId) { diff --git a/browser/components/enterprisepolicies/tests/browser/browser.ini b/browser/components/enterprisepolicies/tests/browser/browser.ini index 410a2aca6aa5..9ae6ce0a7639 100644 --- a/browser/components/enterprisepolicies/tests/browser/browser.ini +++ b/browser/components/enterprisepolicies/tests/browser/browser.ini @@ -44,6 +44,7 @@ skip-if = (verify && debug && (os == 'mac')) [browser_policy_extensionsettings.js] [browser_policy_firefoxhome.js] [browser_policy_override_postupdatepage.js] +[browser_policy_pageinfo_permissions.js] [browser_policy_passwordmanager.js] [browser_policy_search_engine.js] [browser_policy_searchbar.js] diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js new file mode 100644 index 000000000000..203c0149f34c --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js @@ -0,0 +1,71 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const TEST_ORIGIN = "https://example.com"; + +/* Verifies that items on the page info page are properly disabled + when the corresponding policies are locked */ +add_task(async function test_pageinfo_permissions() { + await setupPolicyEngineWithJson({ + policies: { + Permissions: { + Camera: { + BlockNewRequests: true, + Locked: true, + }, + Microphone: { + BlockNewRequests: true, + Locked: true, + }, + Location: { + BlockNewRequests: true, + Locked: true, + }, + Notifications: { + BlockNewRequests: true, + Locked: true, + }, + Autoplay: { + Default: "block-audio", + Locked: true, + }, + }, + InstallAddonsPermission: { + Default: false, + }, + PopupBlocking: { + Locked: true, + }, + Cookies: { + Locked: true, + }, + }, + }); + + let permissions = [ + "geo", + "autoplay-media", + "install", + "popup", + "desktop-notification", + "cookie", + "camera", + "microphone", + ]; + + await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function(browser) { + let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab"); + await BrowserTestUtils.waitForEvent(pageInfo, "load"); + + for (let i = 0; i < permissions.length; i++) { + let permission = permissions[i]; + let checkbox = await TestUtils.waitForCondition(() => + pageInfo.document.getElementById(`${permission}Def`) + ); + + ok(checkbox.disabled, `${permission} checkbox should be disabled`); + } + + pageInfo.close(); + }); +});