Bug 1429169 - Add enterprise policy to disable the popup blocker
MozReview-Commit-ID: 8UG9m3mMLA7
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -451,19 +451,29 @@ var Policies = {
"NoDefaultBookmarks": {
onProfileAfterChange(manager, param) {
if (param) {
manager.disallowFeature("defaultBookmarks");
}
}
},
- "Popups": {
+ "PopupBlocking": {
onBeforeUIStartup(manager, param) {
addAllowDenyPermissions("popup", param.Allow, null);
+
+ if (param.Locked) {
+ let blockValue = true;
+ if (param.Default !== undefined && !param.Default) {
+ blockValue = false;
+ }
+ setAndLockPref("dom.disable_open_during_load", blockValue);
+ } else if (param.Default !== undefined) {
+ setDefaultPref("dom.disable_open_during_load", !!param.Default);
+ }
}
},
"Proxy": {
onBeforeAddons(manager, param) {
if (param.Locked) {
manager.disallowFeature("changeProxySettings");
ProxyPolicies.configureProxySettings(param, setAndLockPref);
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -345,27 +345,35 @@
"NoDefaultBookmarks": {
"description": "Don't create the default bookmarks bundled with Firefox, nor the Smart Bookmarks (Most Visited, Recent Tags). Note: this policy is only effective if used before the first run of the profile.",
"first_available": "60.0",
"type": "boolean"
},
- "Popups": {
+ "PopupBlocking": {
"description": "Allow or deny popup usage.",
"first_available": "60.0",
"type": "object",
"properties": {
"Allow": {
"type": "array",
"items": {
"type": "origin"
}
+ },
+
+ "Default": {
+ "type": "boolean"
+ },
+
+ "Locked": {
+ "type": "boolean"
}
}
},
"Proxy": {
"description": "Configure Proxy settings.",
"first_available": "60.0",
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -28,16 +28,17 @@ support-files =
[browser_policy_cookie_settings.js]
[browser_policy_default_browser_check.js]
[browser_policy_disable_feedback_commands.js]
[browser_policy_disable_flash_plugin.js]
[browser_policy_disable_fxaccounts.js]
[browser_policy_disable_masterpassword.js]
[browser_policy_disable_pdfjs.js]
[browser_policy_disable_pocket.js]
+[browser_policy_disable_popup_blocker.js]
[browser_policy_disable_privatebrowsing.js]
[browser_policy_disable_safemode.js]
[browser_policy_disable_shield.js]
[browser_policy_disable_telemetry.js]
[browser_policy_display_bookmarks.js]
[browser_policy_display_menu.js]
[browser_policy_extensions.js]
[browser_policy_proxy.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js
@@ -0,0 +1,129 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+function restore_prefs() {
+ Services.prefs.clearUserPref("dom.disable_open_during_load");
+}
+
+let ORIGINAL_PREF_VALUE = undefined;
+add_task(async function setup() {
+ // It seems that this pref is given a special testing value for some reason.
+ // Unset that value for this test, but save the old value
+ if (Services.prefs.prefHasUserValue("dom.disable_open_during_load")) {
+ ORIGINAL_PREF_VALUE = Services.prefs.getBoolPref("dom.disable_open_during_load");
+ Services.prefs.clearUserPref("dom.disable_open_during_load");
+ }
+});
+registerCleanupFunction(async function cleanup_prefs() {
+ if (ORIGINAL_PREF_VALUE === undefined) {
+ Services.prefs.clearUserPref("dom.disable_open_during_load");
+ } else {
+ Services.prefs.setBoolPref("dom.disable_open_during_load", ORIGINAL_PREF_VALUE);
+ }
+});
+
+async function test_popup_blocker_disabled({disabled, locked}) {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences");
+ // eslint-disable-next-line no-shadow
+ await ContentTask.spawn(tab.linkedBrowser, {disabled, locked}, async function({disabled, locked}) {
+ let checkbox = content.document.getElementById("popupPolicy");
+ is(checkbox.checked, !disabled,
+ "Checkbox checked state should match policy's Block status");
+ is(checkbox.disabled, locked,
+ "Checkbox disabled state should match policy's Locked status");
+ });
+ BrowserTestUtils.removeTab(tab);
+
+ is(Services.prefs.prefIsLocked("dom.disable_open_during_load"), locked,
+ "Flash pref lock state should match policy lock state");
+}
+
+add_task(async function test_initial_state() {
+ await test_popup_blocker_disabled({disabled: false, locked: false});
+});
+
+add_task(async function test_empty_policy() {
+ await setupPolicyEngineWithJson({
+ "policies": {
+ "PopupBlocking": {
+ }
+ }
+ });
+
+ await test_popup_blocker_disabled({disabled: false, locked: false});
+
+ restore_prefs();
+});
+
+add_task(async function test_block() {
+ await setupPolicyEngineWithJson({
+ "policies": {
+ "PopupBlocking": {
+ "Default": true
+ }
+ }
+ });
+
+ await test_popup_blocker_disabled({disabled: false, locked: false});
+
+ restore_prefs();
+});
+
+add_task(async function test_block_locked() {
+ await setupPolicyEngineWithJson({
+ "policies": {
+ "PopupBlocking": {
+ "Default": true,
+ "Locked": true
+ }
+ }
+ });
+
+ await test_popup_blocker_disabled({disabled: false, locked: true});
+
+ restore_prefs();
+});
+
+add_task(async function test_locked() {
+ await setupPolicyEngineWithJson({
+ "policies": {
+ "PopupBlocking": {
+ "Locked": true
+ }
+ }
+ });
+
+ await test_popup_blocker_disabled({disabled: false, locked: true});
+
+ restore_prefs();
+});
+
+add_task(async function test_disabled() {
+ await setupPolicyEngineWithJson({
+ "policies": {
+ "PopupBlocking": {
+ "Default": false
+ }
+ }
+ });
+
+ await test_popup_blocker_disabled({disabled: true, locked: false});
+
+ restore_prefs();
+});
+
+add_task(async function test_disabled_locked() {
+ await setupPolicyEngineWithJson({
+ "policies": {
+ "PopupBlocking": {
+ "Default": false,
+ "Locked": true
+ }
+ }
+ });
+
+ await test_popup_blocker_disabled({disabled: true, locked: true});
+
+ restore_prefs();
+});
--- a/browser/components/enterprisepolicies/tests/browser/config_popups_cookies_addons_flash.json
+++ b/browser/components/enterprisepolicies/tests/browser/config_popups_cookies_addons_flash.json
@@ -1,11 +1,11 @@
{
"policies": {
- "Popups": {
+ "PopupBlocking": {
"Allow": [
"https://www.allow.com",
"https://www.pre-existing-deny.com"
]
},
"Cookies": {
"Allow": [