dom/plugins/test/mochitest/test_NPNVdocumentOrigin.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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