docshell/test/iframesandbox/test_sibling_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 sibling 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 != "siblingIframe") {
michael@0 19 ok(false, "event.data: got '" + event.data + "', expected 'siblingIframe'");
michael@0 20 }
michael@0 21
michael@0 22 ok(false, testCase.desc, "sibling navigation was NOT blocked");
michael@0 23 runNextTest();
michael@0 24 };
michael@0 25
michael@0 26 try {
michael@0 27 window["testIframe"].eval(testCase.script);
michael@0 28 } catch(e) {
michael@0 29 ok(true, testCase.desc, e.message);
michael@0 30 runNextTest();
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 var testCaseIndex = -1;
michael@0 35 testCases = [
michael@0 36 {
michael@0 37 desc: "Test 1: sibling location.replace should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
michael@0 38 script: "parent['siblingIframe'].location.replace('file_sibling_navigation_by_location.html')"
michael@0 39 },
michael@0 40 {
michael@0 41 desc: "Test 2: sibling location.assign should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
michael@0 42 script: "parent['siblingIframe'].location.assign('file_sibling_navigation_by_location.html')"
michael@0 43 },
michael@0 44 {
michael@0 45 desc: "Test 3: sibling location.href should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
michael@0 46 script: "parent['siblingIframe'].location.href = 'file_sibling_navigation_by_location.html'"
michael@0 47 },
michael@0 48 {
michael@0 49 desc: "Test 4: sibling location.hash should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
michael@0 50 script: "parent['siblingIframe'].location.hash = 'wibble'"
michael@0 51 }
michael@0 52 ];
michael@0 53
michael@0 54 function runNextTest() {
michael@0 55 ++testCaseIndex;
michael@0 56 if (testCaseIndex == testCases.length) {
michael@0 57 SimpleTest.finish();
michael@0 58 return;
michael@0 59 }
michael@0 60
michael@0 61 runScriptNavigationTest(testCases[testCaseIndex]);
michael@0 62 }
michael@0 63
michael@0 64 window.onmessage = runNextTest;
michael@0 65 </script>
michael@0 66 </head>
michael@0 67 <body>
michael@0 68 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a>
michael@0 69 <p id="display"></p>
michael@0 70 <div id="content">
michael@0 71 Tests for Bug 785310
michael@0 72 </div>
michael@0 73
michael@0 74 <iframe name="testIframe" sandbox="allow-scripts allow-same-origin allow-top-navigation"></iframe>
michael@0 75 <iframe name="siblingIframe" src="file_sibling_navigation_by_location.html"></iframe>
michael@0 76
michael@0 77 </body>
michael@0 78 </html>

mercurial