1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/iframesandbox/test_parent_navigation_by_location.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 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 parent 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 != "parentIframe") { 1.22 + ok(false, "event.data: got '" + event.data + "', expected 'parentIframe'"); 1.23 + } 1.24 + ok(false, testCase.desc, "parent navigation was NOT blocked"); 1.25 + runNextTest(); 1.26 + }; 1.27 + try { 1.28 + window["parentIframe"]["childIframe"].eval(testCase.script); 1.29 + } catch(e) { 1.30 + ok(true, testCase.desc, e.message); 1.31 + runNextTest(); 1.32 + } 1.33 + } 1.34 + 1.35 + var testCaseIndex = -1; 1.36 + testCases = [ 1.37 + { 1.38 + desc: "Test 1: parent.location.replace should be blocked even when sandboxed with allow-same-origin allow-top-navigation", 1.39 + script: "parent.location.replace('file_parent_navigation_by_location.html')" 1.40 + }, 1.41 + { 1.42 + desc: "Test 2: parent.location.assign should be blocked even when sandboxed with allow-same-origin allow-top-navigation", 1.43 + script: "parent.location.assign('file_parent_navigation_by_location.html')" 1.44 + }, 1.45 + { 1.46 + desc: "Test 3: parent.location.href should be blocked even when sandboxed with allow-same-origin allow-top-navigation", 1.47 + script: "parent.location.href = 'file_parent_navigation_by_location.html'" 1.48 + }, 1.49 + { 1.50 + desc: "Test 4: parent.location.hash should be blocked even when sandboxed with allow-same-origin allow-top-navigation", 1.51 + script: "parent.location.hash = 'wibble'" 1.52 + } 1.53 + ]; 1.54 + 1.55 + function runNextTest() { 1.56 + ++testCaseIndex; 1.57 + if (testCaseIndex == testCases.length) { 1.58 + SimpleTest.finish(); 1.59 + return; 1.60 + } 1.61 + 1.62 + runScriptNavigationTest(testCases[testCaseIndex]); 1.63 + } 1.64 + 1.65 + window.onmessage = runNextTest; 1.66 +</script> 1.67 +</head> 1.68 +<body> 1.69 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a> 1.70 +<p id="display"></p> 1.71 +<div id="content"> 1.72 +Tests for Bug 785310 1.73 +</div> 1.74 + 1.75 +<iframe name="parentIframe" src="file_parent_navigation_by_location.html"></iframe> 1.76 + 1.77 +</body> 1.78 +</html>