diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/cookiebanners/test/browser/browser_bannerClicking_runContext.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/cookiebanners/test/browser/browser_bannerClicking_runContext.js')
-rw-r--r-- | toolkit/components/cookiebanners/test/browser/browser_bannerClicking_runContext.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_runContext.js b/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_runContext.js new file mode 100644 index 0000000000..7acf94997f --- /dev/null +++ b/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_runContext.js @@ -0,0 +1,97 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_setup(clickTestSetup); + +/** + * Insert a test rule with the specified runContext. + * @param {RunContext} - The runContext to set for the rule. See nsIClickRule + * for documentation. + */ +function insertTestRules({ runContext }) { + info("Clearing existing rules"); + Services.cookieBanners.resetRules(false); + + info("Inserting test rules. " + JSON.stringify({ runContext })); + + info("Add opt-out click rule for DOMAIN_A."); + let ruleA = Cc["@mozilla.org/cookie-banner-rule;1"].createInstance( + Ci.nsICookieBannerRule + ); + ruleA.id = genUUID(); + ruleA.domains = [TEST_DOMAIN_A]; + + ruleA.addClickRule( + "div#banner", + false, + runContext, + null, + "button#optOut", + "button#optIn" + ); + Services.cookieBanners.insertRule(ruleA); +} + +/** + * Test that banner clicking only runs if the context matches the runContext + * specified in the click rule. + */ +add_task(async function test_embedded_iframe() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["cookiebanners.service.mode", Ci.nsICookieBannerService.MODE_REJECT], + ], + }); + + insertTestRules({ runContext: Ci.nsIClickRule.RUN_TOP }); + + await openIframeAndVerify({ + win: window, + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE_A, + visible: true, + expected: "NoClick", + }); + await openPageAndVerify({ + win: window, + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE_A, + visible: false, + expected: "OptOut", + }); + + insertTestRules({ runContext: Ci.nsIClickRule.RUN_CHILD }); + + await openIframeAndVerify({ + win: window, + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE_A, + visible: false, + expected: "OptOut", + }); + await openPageAndVerify({ + win: window, + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE_A, + visible: true, + expected: "NoClick", + }); + + insertTestRules({ runContext: Ci.nsIClickRule.RUN_ALL }); + await openIframeAndVerify({ + win: window, + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE_A, + visible: false, + expected: "OptOut", + }); + await openPageAndVerify({ + win: window, + domain: TEST_DOMAIN_A, + testURL: TEST_PAGE_A, + visible: false, + expected: "OptOut", + }); +}); |