From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser_policy_disable_popup_blocker.js | 149 +++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js (limited to 'browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js') diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js new file mode 100644 index 0000000000..b9573c7614 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js @@ -0,0 +1,149 @@ +/* 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_setup(async function () { + // 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#privacy" + ); + await SpecialPowers.spawn( + tab.linkedBrowser, + [{ disabled, locked }], + // eslint-disable-next-line no-shadow + 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(); +}); -- cgit v1.2.3