summaryrefslogtreecommitdiffstats
path: root/toolkit/components/url-classifier/tests/mochitest/test_classify_top_sandboxed.html
blob: 7e3ae97751175ba462fb25f2d14adb59a88fdf95 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Bug 1647681</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
  <script>

async function runTests() {
  await SpecialPowers.pushPrefEnv({set: [
    ["privacy.trackingprotection.annotate_channels", true],
  ]});

  var chromeScript;
  chromeScript = SpecialPowers.loadChromeScript(_ => {
    /* eslint-env mozilla/chrome-script */
    function onExamResp(subject, topic, data) {
      let channel = subject.QueryInterface(Ci.nsIHttpChannel);
      let classifiedChannel = subject.QueryInterface(Ci.nsIClassifiedChannel);
      if (
        !channel ||
        !classifiedChannel ||
        !channel.URI.spec.startsWith(
          "https://itisatracker.org/tests/toolkit/components/url-classifier/tests/mochitest/evil.js"
        )
      ) {
        return;
      }

      sendAsyncMessage("last-channel-flags", {
        classified: Ci.nsIClassifiedChannel.CLASSIFIED_TRACKING == classifiedChannel.classificationFlags,
      });
    }

    addMessageListener("done", __ => {
      Services.obs.removeObserver(onExamResp, "http-on-examine-response");
    });

    Services.obs.addObserver(onExamResp, "http-on-examine-response");

    sendAsyncMessage("start-test");
  });

  chromeScript.addMessageListener(
    "start-test",
    async _ => {
      window.open("https://example.org/tests/toolkit/components/url-classifier/tests/mochitest/sandboxed.html")
    },
    { once: true }
  );

  chromeScript.addMessageListener(
    "last-channel-flags",
    data => {
      ok(data.classified, "tracker script should be classified when the top-level is sandboxed");
      chromeScript.sendAsyncMessage("done");
      SimpleTest.finish();
    },
    { once: true }
  );
}

SimpleTest.waitForExplicitFinish();
runTests();

  </script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>