diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/components/preferences/tests/browser_permissions_checkPermissionsWereAdded.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/preferences/tests/browser_permissions_checkPermissionsWereAdded.js')
-rw-r--r-- | browser/components/preferences/tests/browser_permissions_checkPermissionsWereAdded.js | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/browser/components/preferences/tests/browser_permissions_checkPermissionsWereAdded.js b/browser/components/preferences/tests/browser_permissions_checkPermissionsWereAdded.js new file mode 100644 index 0000000000..829f897b72 --- /dev/null +++ b/browser/components/preferences/tests/browser_permissions_checkPermissionsWereAdded.js @@ -0,0 +1,127 @@ +/* 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 _checkAndOpenCookiesDialog = async doc => { + let cookieExceptionsButton = doc.getElementById("cookieExceptions"); + ok(cookieExceptionsButton, "cookieExceptionsButton found"); + let dialogPromise = promiseLoadSubDialog(PERMISSIONS_URL); + cookieExceptionsButton.click(); + let dialog = await dialogPromise; + return dialog; +}; + +const _checkCookiesDialog = (dialog, buttonIds) => { + ok(dialog, "dialog loaded"); + let urlLabel = dialog.document.getElementById("urlLabel"); + ok(!urlLabel.hidden, "urlLabel should be visible"); + let url = dialog.document.getElementById("url"); + ok(!url.hidden, "url should be visible"); + for (let buttonId of buttonIds) { + let buttonDialog = dialog.document.getElementById(buttonId); + ok(buttonDialog, "blockButtonDialog found"); + is( + buttonDialog.hasAttribute("disabled"), + true, + "If the user hasn't added an url the button shouldn't be clickable" + ); + } + return dialog; +}; + +const _addWebsiteAddressToPermissionBox = ( + websiteAddress, + dialog, + buttonId +) => { + let url = dialog.document.getElementById("url"); + let buttonDialog = dialog.document.getElementById(buttonId); + url.value = websiteAddress; + url.dispatchEvent(new Event("input", { bubbles: true })); + is( + buttonDialog.hasAttribute("disabled"), + false, + "When the user add an url the button should be clickable" + ); + buttonDialog.click(); + let permissionsBox = dialog.document.getElementById("permissionsBox"); + let children = permissionsBox.getElementsByAttribute("origin", "*"); + is(!children.length, false, "Website added in url should be in the list"); +}; + +const _checkIfPermissionsWereAdded = (dialog, expectedResult) => { + let permissionsBox = dialog.document.getElementById("permissionsBox"); + for (let website of expectedResult) { + let elements = permissionsBox.getElementsByAttribute("origin", website); + is(elements.length, 1, "It should find only one coincidence"); + } +}; + +const _removesAllSitesInPermissionBox = dialog => { + let removeAllWebsitesButton = dialog.document.getElementById( + "removeAllPermissions" + ); + ok(removeAllWebsitesButton, "removeAllWebsitesButton found"); + is( + removeAllWebsitesButton.hasAttribute("disabled"), + false, + "There should be websites in the list" + ); + removeAllWebsitesButton.click(); +}; + +add_task(async function checkCookiePermissions() { + await openPreferencesViaOpenPreferencesAPI("panePrivacy", { + leaveOpen: true, + }); + let win = gBrowser.selectedBrowser.contentWindow; + let doc = win.document; + let buttonIds = ["btnBlock", "btnCookieSession", "btnAllow"]; + + let dialog = await _checkAndOpenCookiesDialog(doc); + _checkCookiesDialog(dialog, buttonIds); + + let tests = [ + { + inputWebsite: "google.com", + expectedResult: ["http://google.com", "https://google.com"], + }, + { + inputWebsite: "https://google.com", + expectedResult: ["https://google.com"], + }, + { + inputWebsite: "http://", + expectedResult: ["http://http", "https://http"], + }, + { + inputWebsite: "s3.eu-central-1.amazonaws.com", + expectedResult: [ + "http://s3.eu-central-1.amazonaws.com", + "https://s3.eu-central-1.amazonaws.com", + ], + }, + { + inputWebsite: "file://", + expectedResult: ["file:///"], + }, + { + inputWebsite: "about:config", + expectedResult: ["about:config"], + }, + ]; + + for (let buttonId of buttonIds) { + for (let test of tests) { + _addWebsiteAddressToPermissionBox(test.inputWebsite, dialog, buttonId); + _checkIfPermissionsWereAdded(dialog, test.expectedResult); + _removesAllSitesInPermissionBox(dialog); + } + } + + gBrowser.removeCurrentTab(); +}); |