1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/iframesandbox/test_sibling_navigation_by_location.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=785310 1.8 +html5 sandboxed iframe should not be able to perform top navigation with scripts allowed 1.9 +--> 1.10 +<head> 1.11 +<meta charset="utf-8"> 1.12 +<title>Test for Bug 785310 - iframe sandbox sibling navigation by location tests</title> 1.13 +<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.14 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.15 + 1.16 +<script> 1.17 + SimpleTest.waitForExplicitFinish(); 1.18 + 1.19 + function runScriptNavigationTest(testCase) { 1.20 + window.onmessage = function(event) { 1.21 + if (event.data != "siblingIframe") { 1.22 + ok(false, "event.data: got '" + event.data + "', expected 'siblingIframe'"); 1.23 + } 1.24 + 1.25 + ok(false, testCase.desc, "sibling navigation was NOT blocked"); 1.26 + runNextTest(); 1.27 + }; 1.28 + 1.29 + try { 1.30 + window["testIframe"].eval(testCase.script); 1.31 + } catch(e) { 1.32 + ok(true, testCase.desc, e.message); 1.33 + runNextTest(); 1.34 + } 1.35 + } 1.36 + 1.37 + var testCaseIndex = -1; 1.38 + testCases = [ 1.39 + { 1.40 + desc: "Test 1: sibling location.replace should be blocked even when sandboxed with allow-same-origin allow-top-navigation", 1.41 + script: "parent['siblingIframe'].location.replace('file_sibling_navigation_by_location.html')" 1.42 + }, 1.43 + { 1.44 + desc: "Test 2: sibling location.assign should be blocked even when sandboxed with allow-same-origin allow-top-navigation", 1.45 + script: "parent['siblingIframe'].location.assign('file_sibling_navigation_by_location.html')" 1.46 + }, 1.47 + { 1.48 + desc: "Test 3: sibling location.href should be blocked even when sandboxed with allow-same-origin allow-top-navigation", 1.49 + script: "parent['siblingIframe'].location.href = 'file_sibling_navigation_by_location.html'" 1.50 + }, 1.51 + { 1.52 + desc: "Test 4: sibling location.hash should be blocked even when sandboxed with allow-same-origin allow-top-navigation", 1.53 + script: "parent['siblingIframe'].location.hash = 'wibble'" 1.54 + } 1.55 + ]; 1.56 + 1.57 + function runNextTest() { 1.58 + ++testCaseIndex; 1.59 + if (testCaseIndex == testCases.length) { 1.60 + SimpleTest.finish(); 1.61 + return; 1.62 + } 1.63 + 1.64 + runScriptNavigationTest(testCases[testCaseIndex]); 1.65 + } 1.66 + 1.67 + window.onmessage = runNextTest; 1.68 +</script> 1.69 +</head> 1.70 +<body> 1.71 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a> 1.72 +<p id="display"></p> 1.73 +<div id="content"> 1.74 +Tests for Bug 785310 1.75 +</div> 1.76 + 1.77 +<iframe name="testIframe" sandbox="allow-scripts allow-same-origin allow-top-navigation"></iframe> 1.78 +<iframe name="siblingIframe" src="file_sibling_navigation_by_location.html"></iframe> 1.79 + 1.80 +</body> 1.81 +</html>