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 /toolkit/components/forgetaboutsite/test/browser/browser_cookieDomain.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 'toolkit/components/forgetaboutsite/test/browser/browser_cookieDomain.js')
-rw-r--r-- | toolkit/components/forgetaboutsite/test/browser/browser_cookieDomain.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/toolkit/components/forgetaboutsite/test/browser/browser_cookieDomain.js b/toolkit/components/forgetaboutsite/test/browser/browser_cookieDomain.js new file mode 100644 index 0000000000..21dff6ada0 --- /dev/null +++ b/toolkit/components/forgetaboutsite/test/browser/browser_cookieDomain.js @@ -0,0 +1,63 @@ +const { ForgetAboutSite } = ChromeUtils.importESModule( + "resource://gre/modules/ForgetAboutSite.sys.mjs" +); +const { SiteDataTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/SiteDataTestUtils.sys.mjs" +); + +function checkCookie(host, originAttributes) { + for (let cookie of Services.cookies.cookies) { + if ( + ChromeUtils.isOriginAttributesEqual( + originAttributes, + cookie.originAttributes + ) && + cookie.host.includes(host) + ) { + return true; + } + } + return false; +} + +add_task(async function test_singleDomain() { + info("Test single cookie domain"); + + // Let's clean up all the data. + await SiteDataTestUtils.clear(); + + SiteDataTestUtils.addToCookies({ origin: "https://example.com" }); + + // Cleaning up. + await ForgetAboutSite.removeDataFromDomain("example.com"); + + // All good. + ok(!checkCookie("example.com", {}), "No cookies"); + + // Clean up. + await SiteDataTestUtils.clear(); +}); + +add_task(async function test_subDomain() { + info("Test cookies for sub domains"); + + // Let's clean up all the data. + await SiteDataTestUtils.clear(); + + SiteDataTestUtils.addToCookies({ origin: "https://example.com" }); + SiteDataTestUtils.addToCookies({ origin: "https://sub.example.com" }); + SiteDataTestUtils.addToCookies({ origin: "https://sub2.example.com" }); + SiteDataTestUtils.addToCookies({ origin: "https://sub2.example.com" }); + + SiteDataTestUtils.addToCookies({ origin: "https://example.org" }); + + // Cleaning up. + await ForgetAboutSite.removeDataFromDomain("sub.example.com"); + + // All good. + ok(!checkCookie("example.com", {}), "No cookies for example.com"); + ok(checkCookie("example.org", {}), "Has cookies for example.org"); + + // Clean up. + await SiteDataTestUtils.clear(); +}); |