summaryrefslogtreecommitdiffstats
path: root/toolkit/components/cookiebanners/test/browser/browser_cookieinjector_events.js
blob: 0459731a46aa5f60ecbbf4023244457ce2db2c40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const { SiteDataTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/SiteDataTestUtils.sys.mjs"
);

add_setup(cookieInjectorTestSetup);

/**
 * Tests that we dispatch cookiebannerhandled and cookiebannerdetected events
 * for cookie injection.
 */
add_task(async function test_events() {
  let tab;

  let triggerFn = async () => {
    tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_ORIGIN_A);
  };

  await runEventTest({
    mode: Ci.nsICookieBannerService.MODE_REJECT,
    initFn: insertTestCookieRules,
    triggerFn,
    testURL: `${TEST_ORIGIN_A}/`,
  });

  // Clean up the test tab opened by triggerFn.
  BrowserTestUtils.removeTab(tab);

  ok(
    SiteDataTestUtils.hasCookies(TEST_ORIGIN_A, [
      {
        key: `cookieConsent_${TEST_DOMAIN_A}_1`,
        value: "optOut1",
      },
      {
        key: `cookieConsent_${TEST_DOMAIN_A}_2`,
        value: "optOut2",
      },
    ]),
    "Should set opt-out cookies for ORIGIN_A"
  );
  ok(
    !SiteDataTestUtils.hasCookies(TEST_ORIGIN_B),
    "Should not set any cookies for ORIGIN_B"
  );
  ok(
    !SiteDataTestUtils.hasCookies(TEST_ORIGIN_C),
    "Should not set any cookies for ORIGIN_C"
  );

  await SiteDataTestUtils.clear();
});