summaryrefslogtreecommitdiffstats
path: root/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_events.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/cookiebanners/test/browser/browser_bannerClicking_events.js')
-rw-r--r--toolkit/components/cookiebanners/test/browser/browser_bannerClicking_events.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_events.js b/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_events.js
new file mode 100644
index 0000000000..2a21841a68
--- /dev/null
+++ b/toolkit/components/cookiebanners/test/browser/browser_bannerClicking_events.js
@@ -0,0 +1,79 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_setup(clickTestSetup);
+
+/**
+ * Triggers cookie banner clicking and tests the events dispatched.
+ * @param {*} options - Test options.
+ * @param {nsICookieBannerService::Modes} options.mode - The cookie banner service mode to test with.
+ * @param {*} options.openPageOptions - Options to overwrite for the openPageAndVerify call.
+ */
+async function runTest({ mode, openPageOptions = {} }) {
+ let initFn = () => {
+ // Insert rules only if the feature is enabled.
+ if (Services.cookieBanners.isEnabled) {
+ insertTestClickRules();
+ }
+ };
+
+ let shouldHandleBanner = mode == Ci.nsICookieBannerService.MODE_REJECT;
+ let testURL = openPageOptions.testURL || TEST_PAGE_A;
+ let triggerFn = async () => {
+ await openPageAndVerify({
+ win: window,
+ domain: TEST_DOMAIN_A,
+ testURL,
+ visible: !shouldHandleBanner,
+ expected: shouldHandleBanner ? "OptOut" : "NoClick",
+ keepTabOpen: true,
+ ...openPageOptions, // Allow test callers to override any options for this method.
+ });
+ };
+
+ await runEventTest({ mode, initFn, triggerFn, testURL });
+
+ // Clean up the test tab opened by openPageAndVerify.
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+}
+
+/**
+ * Test the banner clicking events with MODE_REJECT.
+ */
+add_task(async function test_events_mode_reject() {
+ await runTest({ mode: Ci.nsICookieBannerService.MODE_REJECT });
+});
+
+/**
+ * Test the banner clicking events with MODE_DETECT_ONLY.
+ */
+add_task(async function test_events_mode_detect_only() {
+ await runTest({ mode: Ci.nsICookieBannerService.MODE_DETECT_ONLY });
+});
+
+/**
+ * Test the banner clicking events with MODE_DETECT_ONLY with a click rule that
+ * only supports opt-in..
+ */
+add_task(async function test_events_mode_detect_only_opt_in_rule() {
+ await runTest({
+ mode: Ci.nsICookieBannerService.MODE_DETECT_ONLY,
+ openPageOptions: {
+ // We only have an opt-in rule for DOMAIN_B. This ensures we still fire
+ // detection events for that case.
+ domain: TEST_DOMAIN_B,
+ testURL: TEST_PAGE_B,
+ shouldHandleBanner: true,
+ expected: "NoClick",
+ },
+ });
+});
+
+/**
+ * Test the banner clicking events with MODE_DETECT_ONLY.
+ */
+add_task(async function test_events_mode_disabled() {
+ await runTest({ mode: Ci.nsICookieBannerService.MODE_DISABLED });
+});