summaryrefslogtreecommitdiffstats
path: root/toolkit/components/antitracking/test/browser/browser_firstPartyCookieRejectionHonoursAllowList.js
blob: d3d06d29506868dc2dd553d01988ced08bc3b8a3 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
add_task(async function () {
  info("Starting subResources test");

  await SpecialPowers.flushPrefEnv();
  await SpecialPowers.pushPrefEnv({
    set: [
      ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT],
      [
        "network.cookie.cookieBehavior.pbmode",
        Ci.nsICookieService.BEHAVIOR_REJECT,
      ],
      ["privacy.trackingprotection.enabled", false],
      ["privacy.trackingprotection.pbmode.enabled", false],
      ["privacy.trackingprotection.annotate_channels", true],
    ],
  });

  let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
  gBrowser.selectedTab = tab;

  let browser = gBrowser.getBrowserForTab(tab);
  await BrowserTestUtils.browserLoaded(browser);

  info("Disabling content blocking for this page");
  gProtectionsHandler.disableForCurrentPage();

  // The previous function reloads the browser, so wait for it to load again!
  await BrowserTestUtils.browserLoaded(browser);

  await SpecialPowers.spawn(browser, [], async function (obj) {
    await new content.Promise(async resolve => {
      let document = content.document;
      let window = document.defaultView;

      is(document.cookie, "", "No cookies for me");

      await window
        .fetch("server.sjs")
        .then(r => r.text())
        .then(text => {
          is(text, "cookie-not-present", "We should not have cookies");
        });

      document.cookie = "name=value";
      ok(document.cookie.includes("name=value"), "Some cookies for me");
      ok(document.cookie.includes("foopy=1"), "Some cookies for me");

      await window
        .fetch("server.sjs")
        .then(r => r.text())
        .then(text => {
          is(text, "cookie-present", "We should have cookies");
        });

      ok(document.cookie.length, "Some Cookies for me");

      resolve();
    });
  });

  info("Enabling content blocking for this page");
  gProtectionsHandler.enableForCurrentPage();

  // The previous function reloads the browser, so wait for it to load again!
  await BrowserTestUtils.browserLoaded(browser);

  BrowserTestUtils.removeTab(tab);
});

add_task(async function () {
  info("Cleaning up.");
  await new Promise(resolve => {
    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>
      resolve()
    );
  });
});