summaryrefslogtreecommitdiffstats
path: root/dom/security/test/general/browser_test_gpc_privateBrowsingMode.js
blob: 5c056395a8fea7dc2f3da4e6035101d4de388509 (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
"use strict";

const kTestPath = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "https://example.com"
);
const kTestURI = kTestPath + "file_empty.html";

add_task(async function test_privateModeGPCEnabled() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["privacy.globalprivacycontrol.enabled", false],
      ["privacy.globalprivacycontrol.pbmode.enabled", true],
      ["privacy.globalprivacycontrol.functionality.enabled", true],
    ],
  });
  let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
  let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, kTestURI);
  let browser = win.gBrowser.getBrowserForTab(tab);
  let result = await SpecialPowers.spawn(browser, [], async function () {
    return content.window
      .fetch("file_gpc_server.sjs")
      .then(response => response.text())
      .then(response => {
        is(response, "true", "GPC header provided");
        is(
          content.window.navigator.globalPrivacyControl,
          true,
          "GPC on navigator"
        );
        // Bug 1320796: Service workers are not enabled in PB Mode
        return true;
      });
  });
  ok(result, "Promise chain resolves in content process");
  win.close();
});

add_task(async function test_privateModeGPCDisabled() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["privacy.globalprivacycontrol.enabled", false],
      ["privacy.globalprivacycontrol.pbmode.enabled", false],
      ["privacy.globalprivacycontrol.functionality.enabled", true],
    ],
  });
  let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
  let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, kTestURI);
  let browser = win.gBrowser.getBrowserForTab(tab);
  let result = await SpecialPowers.spawn(browser, [], async function () {
    return content.window
      .fetch("file_gpc_server.sjs")
      .then(response => response.text())
      .then(response => {
        isnot(response, "true", "GPC header provided");
        isnot(
          content.window.navigator.globalPrivacyControl,
          true,
          "GPC on navigator"
        );
        // Bug 1320796: Service workers are not enabled in PB Mode
        return true;
      });
  });
  ok(result, "Promise chain resolves in content process");
  win.close();
});