summaryrefslogtreecommitdiffstats
path: root/toolkit/components/antitracking/test/browser/browser_cookieBetweenTabs.js
blob: 635f145d46faa5b77efe7b221aceccdd014b194e (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
add_task(async function () {
  await SpecialPowers.flushPrefEnv();
  await SpecialPowers.pushPrefEnv({
    set: [
      ["dom.storage_access.enabled", true],
      ["network.cookie.cookieBehavior", BEHAVIOR_REJECT],
      ["network.cookie.cookieBehavior.pbmode", BEHAVIOR_REJECT],
      ["privacy.trackingprotection.enabled", false],
      ["privacy.trackingprotection.pbmode.enabled", false],
      ["privacy.trackingprotection.annotate_channels", true],
      ["dom.ipc.processCount", 4],
    ],
  });

  info("First tab opened");
  let tab = BrowserTestUtils.addTab(
    gBrowser,
    TEST_DOMAIN + TEST_PATH + "empty.html"
  );
  gBrowser.selectedTab = tab;

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

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

  await BrowserTestUtils.browserLoaded(browser);

  await SpecialPowers.spawn(browser, [], async _ => {
    is(content.document.cookie, "", "No cookie set");
    content.document.cookie = "a=b";
    is(content.document.cookie, "a=b", "Cookie set");
  });

  info("Second tab opened");
  let tab2 = BrowserTestUtils.addTab(
    gBrowser,
    TEST_DOMAIN + TEST_PATH + "empty.html"
  );
  gBrowser.selectedTab = tab2;

  let browser2 = gBrowser.getBrowserForTab(tab2);
  await BrowserTestUtils.browserLoaded(browser2);

  await SpecialPowers.spawn(browser2, [], async _ => {
    is(content.document.cookie, "a=b", "Cookie set");
  });

  info("Removing tabs");
  BrowserTestUtils.removeTab(tab);
  BrowserTestUtils.removeTab(tab2);

  await new Promise(resolve => {
    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>
      resolve()
    );
  });
});