dom/plugins/test/mochitest/test_NPNVdocumentOrigin.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/test_NPNVdocumentOrigin.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +  <title>Test NPNVdocumentOrigin</title>
     1.7 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.8 +  <script type="application/javascript" src="utils.js"></script>
     1.9 +</head>
    1.10 +<body onload="runTest()">
    1.11 +  <script class="testbody" type="application/javascript">
    1.12 +    SimpleTest.waitForExplicitFinish();
    1.13 +    setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    1.14 +
    1.15 +    function runTest() {
    1.16 +      "use strict";
    1.17 +      var p1 = document.getElementById("plugin1");
    1.18 +      var realOrigin = "http://mochi.test:8888";
    1.19 +
    1.20 +      // Test with no modifications
    1.21 +      is(p1.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin.");
    1.22 +
    1.23 +      // This used to test that shadowing window.location.toString didn't confuse
    1.24 +      // getNPNVdocumentOrigin. But now we explicitly throw when that happens. So
    1.25 +      // just verify that we throw. There's no reason why getNPNVdocumentOrigin _would_
    1.26 +      // be confused in this case anyway.
    1.27 +      try {
    1.28 +        window.location.toString = function() { return 'http://victim.rckc.at/'; }
    1.29 +        ok(false, "Should throw when shadowing window.location.toString");
    1.30 +      }
    1.31 +      catch (e) {
    1.32 +        ok(true, "Should throw when shadowing window.location.toString");
    1.33 +      }
    1.34 +
    1.35 +      // Create a plugin in a new window with about:blank
    1.36 +      var newWindow = window.open("about:blank");
    1.37 +      newWindow.onload = function() {
    1.38 +        newWindow.document.writeln('<embed id="plugin2" type="application/x-test" width="200" height="200"></embed>');
    1.39 +        var p2 = newWindow.document.getElementById("plugin2");
    1.40 +        is(p2.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin of plugin in new about:blank window.");
    1.41 +        newWindow.close();
    1.42 +
    1.43 +        SimpleTest.finish();
    1.44 +      };
    1.45 +    }
    1.46 +  </script>
    1.47 +
    1.48 +  <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
    1.49 +</body>
    1.50 +</html>

mercurial