diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/cookiebanners/test/browser/browser_cookiebannerservice_getRules.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/cookiebanners/test/browser/browser_cookiebannerservice_getRules.js')
-rw-r--r-- | toolkit/components/cookiebanners/test/browser/browser_cookiebannerservice_getRules.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/toolkit/components/cookiebanners/test/browser/browser_cookiebannerservice_getRules.js b/toolkit/components/cookiebanners/test/browser/browser_cookiebannerservice_getRules.js new file mode 100644 index 0000000000..fcc6078e28 --- /dev/null +++ b/toolkit/components/cookiebanners/test/browser/browser_cookiebannerservice_getRules.js @@ -0,0 +1,88 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let testRules = [ + // Cookie rule with multiple domains. + { + id: "0e4cdbb8-b688-47e0-9c8b-4db620398dbd", + click: {}, + cookies: { + optIn: [ + { + name: "foo", + value: "bar", + }, + ], + }, + domains: [TEST_DOMAIN_A, TEST_DOMAIN_B], + }, + // Click rule with single domain. + { + id: "0560e02c-a50f-4e7b-86e0-d6b7d258eb5f", + click: { + optOut: "#optOutBtn", + presence: "#cookieBanner", + }, + cookies: {}, + domains: [TEST_DOMAIN_C], + }, +]; + +add_setup(async function () { + // Enable the service and insert the test rules. + await SpecialPowers.pushPrefEnv({ + set: [ + [ + "cookiebanners.service.mode", + Ci.nsICookieBannerService.MODE_REJECT_OR_ACCEPT, + ], + ["cookiebanners.listService.testSkipRemoteSettings", true], + ["cookiebanners.listService.testRules", JSON.stringify(testRules)], + ["cookiebanners.listService.logLevel", "Debug"], + ], + }); + + Services.cookieBanners.resetRules(true); +}); + +function ruleCountForDomain(domain) { + return Services.cookieBanners.rules.filter(rule => + rule.domains.includes(domain) + ).length; +} + +/** + * Tests that the rules getter does not return duplicate rules for rules with + * multiple domains. + */ +add_task(async function test_rules_getter_no_duplicates() { + // The rule import is async because it needs to fetch rules from + // RemoteSettings. Wait for the test rules to be applied. + // See CookieBannerListService#importAllRules. + await BrowserTestUtils.waitForCondition( + () => Services.cookieBanners.rules.length, + "Waiting for test rules to be imported." + ); + is( + Services.cookieBanners.rules.length, + 2, + "Rules getter should only return the two test rules." + ); + is( + ruleCountForDomain(TEST_DOMAIN_A), + 1, + "There should only be one rule with TEST_DOMAIN_A." + ); + is( + ruleCountForDomain(TEST_DOMAIN_B), + 1, + "There should only be one rule with TEST_DOMAIN_B." + ); + is( + ruleCountForDomain(TEST_DOMAIN_C), + 1, + "There should only be one rule with TEST_DOMAIN_C." + ); +}); |