summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_NPNVdocumentOrigin.html
blob: 75ec66e1389ae71017bb50c7e9a02244542a467f (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
<html>
<head>
  <title>Test NPNVdocumentOrigin</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="plugin-utils.js"></script>
</head>
<body onload="runTest()">
  <script class="testbody" type="application/javascript">
    SimpleTest.waitForExplicitFinish();
    setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);

    function runTest() {
      "use strict";
      var p1 = document.getElementById("plugin1");
      var realOrigin = "http://mochi.test:8888";

      // Test with no modifications
      is(p1.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin.");

      // This used to test that shadowing window.location.toString didn't confuse
      // getNPNVdocumentOrigin. But now we explicitly throw when that happens. So
      // just verify that we throw. There's no reason why getNPNVdocumentOrigin _would_
      // be confused in this case anyway.
      try {
        window.location.toString = function() { return 'http://victim.rckc.at/'; }
        ok(false, "Should throw when shadowing window.location.toString");
      }
      catch (e) {
        ok(true, "Should throw when shadowing window.location.toString");
      }

      // Create a plugin in a new window with about:blank
      var newWindow = window.open("about:blank");
      newWindow.onload = function() {
        newWindow.document.writeln('<embed id="plugin2" type="application/x-test" width="200" height="200"></embed>');
        var p2 = newWindow.document.getElementById("plugin2");
        is(p2.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin of plugin in new about:blank window.");
        newWindow.close();

        SimpleTest.finish();
      };
    }
  </script>

  <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
</body>
</html>