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

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

mercurial