docshell/test/iframesandbox/test_our_auxiliary_navigation_by_location.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.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=785310
michael@0 5 html5 sandboxed iframe should not be able to perform top navigation with scripts allowed
michael@0 6 -->
michael@0 7 <head>
michael@0 8 <meta charset="utf-8">
michael@0 9 <title>Test for Bug 785310 - iframe sandbox our auxiliary navigation by location tests</title>
michael@0 10 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 12
michael@0 13 <script>
michael@0 14 SimpleTest.waitForExplicitFinish();
michael@0 15
michael@0 16 function runScriptNavigationTest(testCase) {
michael@0 17 window.onmessage = function(event) {
michael@0 18 if (event.data != "ourWindow") {
michael@0 19 ok(false, "event.data: got '" + event.data + "', expected 'ourWindow'");
michael@0 20 }
michael@0 21 ok(!testCase.shouldBeBlocked, testCase.desc, "auxiliary navigation was NOT blocked");
michael@0 22 runNextTest();
michael@0 23 };
michael@0 24 try {
michael@0 25 SpecialPowers.wrap(window["testIframe"]).eval(testCase.script);
michael@0 26 } catch(e) {
michael@0 27 ok(testCase.shouldBeBlocked, testCase.desc, SpecialPowers.wrap(e).message);
michael@0 28 runNextTest();
michael@0 29 }
michael@0 30 }
michael@0 31
michael@0 32 var testCaseIndex = -1;
michael@0 33 testCases = [
michael@0 34 {
michael@0 35 desc: "Test 1: location.replace on auxiliary opened by us should NOT be blocked",
michael@0 36 script: "openedWindow.location.replace('file_our_auxiliary_navigation_by_location.html')",
michael@0 37 shouldBeBlocked: false
michael@0 38 },
michael@0 39 {
michael@0 40 desc: "Test 2: location.assign on auxiliary opened by us should be blocked without allow-same-origin",
michael@0 41 script: "openedWindow.location.assign('file_our_auxiliary_navigation_by_location.html')",
michael@0 42 shouldBeBlocked: true
michael@0 43 },
michael@0 44 {
michael@0 45 desc: "Test 3: location.href on auxiliary opened by us should NOT be blocked",
michael@0 46 script: "openedWindow.location.href = 'file_our_auxiliary_navigation_by_location.html'",
michael@0 47 shouldBeBlocked: false
michael@0 48 },
michael@0 49 {
michael@0 50 desc: "Test 4: location.hash on auxiliary opened by us should be blocked without allow-same-origin",
michael@0 51 script: "openedWindow.location.hash = 'wibble'",
michael@0 52 shouldBeBlocked: true
michael@0 53 }
michael@0 54 ];
michael@0 55
michael@0 56 function runNextTest() {
michael@0 57 ++testCaseIndex;
michael@0 58 if (testCaseIndex == testCases.length) {
michael@0 59 SpecialPowers.wrap(window["testIframe"]).eval("openedWindow.close()");
michael@0 60 SimpleTest.finish();
michael@0 61 return;
michael@0 62 }
michael@0 63
michael@0 64 runScriptNavigationTest(testCases[testCaseIndex]);
michael@0 65 }
michael@0 66
michael@0 67 window.onmessage = runNextTest;
michael@0 68
michael@0 69 window.onload = function() {
michael@0 70 SpecialPowers.wrap(window["testIframe"]).eval("var openedWindow = window.open('file_our_auxiliary_navigation_by_location.html', 'ourWindow')");
michael@0 71 }
michael@0 72 </script>
michael@0 73
michael@0 74 </head>
michael@0 75 <body>
michael@0 76 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a>
michael@0 77 <p id="display"></p>
michael@0 78 <div id="content">
michael@0 79 Tests for Bug 785310
michael@0 80 </div>
michael@0 81
michael@0 82 <iframe name="testIframe" sandbox="allow-scripts allow-popups"></iframe>
michael@0 83 </body>
michael@0 84 </html>

mercurial