summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/protectionsUI/browser_protectionsUI_shield_visibility.js
blob: 539ac077ac3aac99a47fe12717d8e6522c94b2ca (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/* This test checks pages of different URL variants (mostly differing in scheme)
 * and verifies that the shield is only shown when content blocking can deal
 * with the specific variant. */

const TEST_CASES = [
  {
    type: "http",
    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    testURL: "http://example.com",
    hidden: false,
  },
  {
    type: "https",
    testURL: "https://example.com",
    hidden: false,
  },
  {
    type: "chrome page",
    testURL: "chrome://global/skin/in-content/info-pages.css",
    hidden: true,
  },
  {
    type: "content-privileged about page",
    testURL: "about:robots",
    hidden: true,
  },
  {
    type: "non-chrome about page",
    testURL: "about:about",
    hidden: true,
  },
  {
    type: "chrome about page",
    testURL: "about:preferences",
    hidden: true,
  },
  {
    type: "file",
    testURL: "benignPage.html",
    hidden: true,
  },
  {
    type: "certificateError",
    testURL: "https://self-signed.example.com",
    hidden: true,
  },
  {
    type: "localhost",
    testURL: "http://127.0.0.1",
    hidden: false,
  },
  {
    type: "data URI",
    testURL: "data:text/html,<div>",
    hidden: true,
  },
  {
    type: "view-source HTTP",
    testURL: "view-source:http://example.com/",
    hidden: true,
  },
  {
    type: "view-source HTTPS",
    testURL: "view-source:https://example.com/",
    hidden: true,
  },
  {
    type: "top level sandbox",
    testURL:
      "https://example.com/browser/browser/base/content/test/protectionsUI/sandboxed.html",
    hidden: false,
  },
];

add_task(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      // By default, proxies don't apply to 127.0.0.1. We need them to for this test, though:
      ["network.proxy.allow_hijacking_localhost", true],
    ],
  });

  for (let testData of TEST_CASES) {
    info(`Testing for ${testData.type}`);
    let testURL = testData.testURL;

    // Overwrite the url if it is testing the file url.
    if (testData.type === "file") {
      let dir = getChromeDir(getResolvedURI(gTestPath));
      dir.append(testURL);
      dir.normalize();
      testURL = Services.io.newFileURI(dir).spec;
    }

    let pageLoaded;
    let tab = await BrowserTestUtils.openNewForegroundTab(
      gBrowser,
      () => {
        gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, testURL);
        let browser = gBrowser.selectedBrowser;
        if (testData.type === "certificateError") {
          pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
        } else {
          pageLoaded = BrowserTestUtils.browserLoaded(browser, true);
        }
      },
      false
    );
    await pageLoaded;

    is(
      BrowserTestUtils.is_hidden(
        gProtectionsHandler._trackingProtectionIconContainer
      ),
      testData.hidden,
      "tracking protection icon container is correctly displayed"
    );

    BrowserTestUtils.removeTab(tab);
  }
});