dom/plugins/test/mochitest/test_NPNVdocumentOrigin.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <html>
     2 <head>
     3   <title>Test NPNVdocumentOrigin</title>
     4   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     5   <script type="application/javascript" src="utils.js"></script>
     6 </head>
     7 <body onload="runTest()">
     8   <script class="testbody" type="application/javascript">
     9     SimpleTest.waitForExplicitFinish();
    10     setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    12     function runTest() {
    13       "use strict";
    14       var p1 = document.getElementById("plugin1");
    15       var realOrigin = "http://mochi.test:8888";
    17       // Test with no modifications
    18       is(p1.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin.");
    20       // This used to test that shadowing window.location.toString didn't confuse
    21       // getNPNVdocumentOrigin. But now we explicitly throw when that happens. So
    22       // just verify that we throw. There's no reason why getNPNVdocumentOrigin _would_
    23       // be confused in this case anyway.
    24       try {
    25         window.location.toString = function() { return 'http://victim.rckc.at/'; }
    26         ok(false, "Should throw when shadowing window.location.toString");
    27       }
    28       catch (e) {
    29         ok(true, "Should throw when shadowing window.location.toString");
    30       }
    32       // Create a plugin in a new window with about:blank
    33       var newWindow = window.open("about:blank");
    34       newWindow.onload = function() {
    35         newWindow.document.writeln('<embed id="plugin2" type="application/x-test" width="200" height="200"></embed>');
    36         var p2 = newWindow.document.getElementById("plugin2");
    37         is(p2.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin of plugin in new about:blank window.");
    38         newWindow.close();
    40         SimpleTest.finish();
    41       };
    42     }
    43   </script>
    45   <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
    46 </body>
    47 </html>

mercurial