diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/components/preferences/tests/browser_etp_exceptions_dialog.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/preferences/tests/browser_etp_exceptions_dialog.js')
-rw-r--r-- | browser/components/preferences/tests/browser_etp_exceptions_dialog.js | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/browser/components/preferences/tests/browser_etp_exceptions_dialog.js b/browser/components/preferences/tests/browser_etp_exceptions_dialog.js new file mode 100644 index 0000000000..349223995c --- /dev/null +++ b/browser/components/preferences/tests/browser_etp_exceptions_dialog.js @@ -0,0 +1,96 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const PERMISSIONS_URL = + "chrome://browser/content/preferences/dialogs/permissions.xhtml"; + +const TRACKING_URL = "https://example.com"; + +async function openETPExceptionsDialog(doc) { + let exceptionsButton = doc.getElementById("trackingProtectionExceptions"); + ok(exceptionsButton, "trackingProtectionExceptions button found"); + let dialogPromise = promiseLoadSubDialog(PERMISSIONS_URL); + exceptionsButton.click(); + let dialog = await dialogPromise; + return dialog; +} + +async function addETPPermission(doc) { + let dialog = await openETPExceptionsDialog(doc); + let url = dialog.document.getElementById("url"); + let buttonDisableETP = dialog.document.getElementById("btnDisableETP"); + let permissionsBox = dialog.document.getElementById("permissionsBox"); + let currentPermissions = permissionsBox.itemCount; + + url.value = TRACKING_URL; + url.dispatchEvent(new Event("input", { bubbles: true })); + is( + buttonDisableETP.hasAttribute("disabled"), + false, + "Disable ETP button is selectable after url is entered" + ); + buttonDisableETP.click(); + + // Website is listed + is( + permissionsBox.itemCount, + currentPermissions + 1, + "Website added in url should be in the list" + ); + let saveButton = dialog.document.querySelector("dialog").getButton("accept"); + saveButton.click(); + BrowserTestUtils.waitForEvent(dialog, "unload"); +} + +async function removeETPPermission(doc) { + let dialog = await openETPExceptionsDialog(doc); + let permissionsBox = dialog.document.getElementById("permissionsBox"); + let elements = permissionsBox.getElementsByAttribute("origin", TRACKING_URL); + // Website is listed + ok(permissionsBox.itemCount, "List is not empty"); + permissionsBox.selectItem(elements[0]); + let removePermissionButton = + dialog.document.getElementById("removePermission"); + is( + removePermissionButton.hasAttribute("disabled"), + false, + "The button should be clickable to remove selected item" + ); + removePermissionButton.click(); + + let saveButton = dialog.document.querySelector("dialog").getButton("accept"); + saveButton.click(); + BrowserTestUtils.waitForEvent(dialog, "unload"); +} + +async function checkShieldIcon(shieldIcon) { + // Open the website and check that the tracking protection icon is enabled/disabled + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TRACKING_URL); + let icon = document.getElementById("tracking-protection-icon"); + is( + gBrowser.ownerGlobal + .getComputedStyle(icon) + .getPropertyValue("list-style-image"), + shieldIcon, + `The tracking protection icon shows the icon ${shieldIcon}` + ); + BrowserTestUtils.removeTab(tab); +} + +// test adds and removes an ETP permission via the about:preferences#privacy and checks if the ProtectionsUI shield icon resembles the state +add_task(async function ETPPermissionSyncedFromPrivacyPane() { + await openPreferencesViaOpenPreferencesAPI("panePrivacy", { + leaveOpen: true, + }); + let win = gBrowser.selectedBrowser.contentWindow; + let doc = win.document; + await addETPPermission(doc); + await checkShieldIcon( + `url("chrome://browser/skin/tracking-protection-disabled.svg")` + ); + await removeETPPermission(doc); + await checkShieldIcon(`url("chrome://browser/skin/tracking-protection.svg")`); + BrowserTestUtils.removeTab(gBrowser.selectedTab); +}); |