diff options
Diffstat (limited to 'toolkit/components/forgetaboutsite/test/browser')
-rw-r--r-- | toolkit/components/forgetaboutsite/test/browser/browser.ini | 3 | ||||
-rw-r--r-- | toolkit/components/forgetaboutsite/test/browser/browser_cookieDomain.js | 63 |
2 files changed, 66 insertions, 0 deletions
diff --git a/toolkit/components/forgetaboutsite/test/browser/browser.ini b/toolkit/components/forgetaboutsite/test/browser/browser.ini new file mode 100644 index 0000000000..90ea432d7f --- /dev/null +++ b/toolkit/components/forgetaboutsite/test/browser/browser.ini @@ -0,0 +1,3 @@ +[DEFAULT] + +[browser_cookieDomain.js] 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(); +}); |