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/cookiebanners/test/browser/browser_bannerClicking_globalRules.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/cookiebanners/test/browser/browser_bannerClicking_globalRules.js')
-rw-r--r-- | toolkit/components/cookiebanners/test/browser/browser_bannerClicking_globalRules.js | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_globalRules.js b/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_globalRules.js new file mode 100644 index 0000000000..c097d31529 --- /dev/null +++ b/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_globalRules.js @@ -0,0 +1,216 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_setup(clickTestSetup); + +/** + * Test the banner clicking with global rules and MODE_REJECT. + */ +add_task(async function test_clicking_global_rules() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT], + ["cookiebanners.service.enableGlobalRules", true], + ], + }); + + info("Clearing existing rules"); + Services.cookieBanners.resetRules(false); + + info("Inserting global test rules."); + + info( + "Add global ruleA which targets an existing banner (presence) with existing buttons. This rule should handle the banner." + ); + let ruleA = Cc["@mozilla.org/cookie-banner-rule;1"].createInstance( + Ci.nsICookieBannerRule + ); + ruleA.id = genUUID(); + ruleA.domains = []; + ruleA.addClickRule( + "div#banner", + false, + Ci.nsIClickRule.RUN_TOP, + null, + "button#optOut", + "button#optIn" + ); + Services.cookieBanners.insertRule(ruleA); + + info( + "Add global ruleC which targets an existing banner (presence) but non-existing buttons." + ); + let ruleC = Cc["@mozilla.org/cookie-banner-rule;1"].createInstance( + Ci.nsICookieBannerRule + ); + ruleC.id = genUUID(); + ruleC.domains = []; + ruleC.addClickRule( + "div#banner", + false, + Ci.nsIClickRule.RUN_TOP, + null, + "button#nonExistingOptOut", + "button#nonExistingOptIn" + ); + Services.cookieBanners.insertRule(ruleC); + + info("Add global ruleD which targets a non-existing banner (presence)."); + let ruleD = Cc["@mozilla.org/cookie-banner-rule;1"].createInstance( + Ci.nsICookieBannerRule + ); + ruleD.id = genUUID(); + ruleD.domains = []; + ruleD.addClickRule( + "div#nonExistingBanner", + false, + Ci.nsIClickRule.RUN_TOP, + null, + null, + "button#optIn" + ); + Services.cookieBanners.insertRule(ruleD); + + await testClickResultTelemetry({}); + + info("The global rule ruleA should handle both test pages with div#banner."); + await openPageAndVerify({ + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE_A, + visible: false, + expected: "OptOut", + }); + + await testClickResultTelemetry( + { + success: 1, + success_dom_content_loaded: 1, + }, + false + ); + + await openPageAndVerify({ + domain: TEST_DOMAIN_B, + testURL: TEST_PAGE_B, + visible: false, + expected: "OptOut", + }); + + await testClickResultTelemetry( + { + success: 2, + success_dom_content_loaded: 2, + }, + false + ); + + info("No global rule should handle TEST_PAGE_C with div#bannerB."); + await openPageAndVerify({ + domain: TEST_DOMAIN_C, + testURL: TEST_PAGE_C, + visible: true, + expected: "NoClick", + bannerId: "bannerB", + }); + + await testClickResultTelemetry( + { + success: 2, + success_dom_content_loaded: 2, + fail: 1, + fail_banner_not_found: 1, + }, + false + ); + + info("Test delayed banner handling with global rules."); + let TEST_PAGE = + TEST_ORIGIN_A + TEST_PATH + "file_delayed_banner.html?delay=100"; + await openPageAndVerify({ + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE, + visible: false, + expected: "OptOut", + }); + + await testClickResultTelemetry({ + success: 3, + success_dom_content_loaded: 2, + fail: 1, + fail_banner_not_found: 1, + success_mutation_pre_load: 1, + }); +}); + +/** + * Test that domain-specific rules take precedence over global rules. + */ +add_task(async function test_clicking_global_rules_precedence() { + await SpecialPowers.pushPrefEnv({ + set: [ + [ + "cookiebanners.service.mode", + Ci.nsICookieBannerService.MODE_REJECT_OR_ACCEPT, + ], + ["cookiebanners.service.enableGlobalRules", true], + ], + }); + + info("Clearing existing rules"); + Services.cookieBanners.resetRules(false); + + info("Inserting global test rules."); + + info( + "Add global ruleA which targets an existing banner (presence) with existing buttons." + ); + let ruleGlobal = Cc["@mozilla.org/cookie-banner-rule;1"].createInstance( + Ci.nsICookieBannerRule + ); + ruleGlobal.id = genUUID(); + ruleGlobal.domains = []; + ruleGlobal.addClickRule( + "div#banner", + false, + Ci.nsIClickRule.RUN_TOP, + null, + "button#optOut", + null + ); + Services.cookieBanners.insertRule(ruleGlobal); + + info("Add domain specific rule which also targets the existing banner."); + let ruleDomain = Cc["@mozilla.org/cookie-banner-rule;1"].createInstance( + Ci.nsICookieBannerRule + ); + ruleDomain.id = genUUID(); + ruleDomain.domains = [TEST_DOMAIN_A]; + ruleDomain.addClickRule( + "div#banner", + false, + Ci.nsIClickRule.RUN_TOP, + null, + null, + "button#optIn" + ); + Services.cookieBanners.insertRule(ruleDomain); + + await testClickResultTelemetry({}); + + info("Test that the domain-specific rule applies, not the global one."); + await openPageAndVerify({ + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE_A, + visible: false, + // Because of the way the rules are setup OptOut would mean the global rule + // applies, opt-in means the domain specific rule applies. + expected: "OptIn", + }); + + await testClickResultTelemetry({ + success: 1, + success_dom_content_loaded: 1, + }); +}); |