summaryrefslogtreecommitdiffstats
path: root/toolkit/identity/tests/chrome/sandbox_content_perms.html
blob: d24c683f8f16a3d098bc0d8fc488f6475e6e2c7d (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
<!DOCTYPE html>
<html>
  <!-- Any copyright is dedicated to the Public Domain.
     - http://creativecommons.org/publicdomain/zero/1.0/ -->
  <head>
    <meta charset="utf-8">
    <title>Page testing content in the Sandbox can't escape</title>
    <script type="application/javascript;version=1.8">
      const TEST_BASE = "http://mochi.test:8888/chrome/toolkit/identity/tests/chrome/"
      const Ci = SpecialPowers.Ci;

      function expectException(aFunc) {
        try {
          aFunc();
        } catch (ex) {
          return true;
        }
        return false;
      }

      function CcNotPresent() {
        if (typeof Components === 'undefined')
          return true;
        // Components shim doesn't define Components.classes.
        try {
          return typeof Components.classes === 'undefined';
        } catch (e) {
          return false;
        }
      }

      // Build an object with test results (true = pass)
      let results = {
        windowTop: window.top == window,

        qiWindow: expectException(function() {
          let isForced = window.QueryInterface(Ci.nsIInterfaceRequestor)
                               .getInterface(Ci.nsIDOMWindowUtils)
                               .docCharsetIsForced;
        }),

        ccAccess: !!CcNotPresent(),
      };

      let resultsJSON = JSON.stringify(results);

      // Send the results to the mochitest server so the test file can retrieve them.
      let stateURL = TEST_BASE + "sandbox_content.sjs"
      let xhr = new XMLHttpRequest();
      xhr.open("GET", stateURL + "?" + encodeURIComponent(resultsJSON), true);
      xhr.onload = function() {
        if (xhr.status != 200) {
          dump("Failed sending results\n");
        }
      };
      xhr.send();

    </script>
  </head>

  <body>

  </body>
</html>