|
|
|
|
|
|
1 |
<!DOCTYPE HTML> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
https://bugzilla.mozilla.org/show_bug.cgi?id=341604 |
| 5 |
Implement HTML5 sandbox attribute for IFRAMEs - inheritance tests |
| 6 |
--> |
| 7 |
<head> |
| 8 |
<meta charset="utf-8"> |
| 9 |
<title>Test for Bug 341604</title> |
| 10 |
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
| 11 |
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
| 12 |
</head> |
| 13 |
<script type="application/javascript"> |
| 14 |
/** Test for Bug 341604 - Implement HTML5 sandbox attribute for IFRAMEs **/ |
| 15 |
/** Inheritance Tests **/ |
| 16 |
|
| 17 |
// A postMessage handler that is used by sandboxed iframes without |
| 18 |
// 'allow-same-origin' to communicate pass/fail back to this main page. |
| 19 |
// It expects to be called with an object like {ok: true/false, desc: |
| 20 |
// <description of the test> which it then forwards to ok(). |
| 21 |
window.addEventListener("message", receiveMessage, false); |
| 22 |
|
| 23 |
var completedTests = 0; |
| 24 |
var passedTests = 0; |
| 25 |
|
| 26 |
function receiveMessage(event) |
| 27 |
{ |
| 28 |
ok_wrapper(event.data.ok, event.data.desc); |
| 29 |
} |
| 30 |
|
| 31 |
function ok_wrapper(result, desc) { |
| 32 |
ok(result, desc); |
| 33 |
|
| 34 |
completedTests++; |
| 35 |
|
| 36 |
if (result) |
| 37 |
passedTests++; |
| 38 |
|
| 39 |
// REVIEW : if one of these tests fails and the message isn't sent |
| 40 |
// this means this test will hang until the time out happens :( |
| 41 |
// advice on better ways to synchronize things appreciated ! |
| 42 |
if (completedTests == 4) { |
| 43 |
is(passedTests, 4, "there should be 3 passed inheritance tests"); |
| 44 |
SimpleTest.finish(); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
function doTest() { |
| 49 |
SimpleTest.waitForExplicitFinish(); |
| 50 |
|
| 51 |
// fails if bad |
| 52 |
// 1) an iframe with no sandbox attribute inside an iframe that has sandbox = "" |
| 53 |
// should not be able to execute scripts (cannot ever loosen permissions) |
| 54 |
// (done by file_iframe_sandbox_a_if2.html contained within file_iframe_sandbox_a_if1.html) |
| 55 |
|
| 56 |
// fails if bad |
| 57 |
// 2) an iframe with sandbox = "allow-scripts" inside an iframe that has sandbox = "" |
| 58 |
// should not be able to execute scripts (cannot ever loosen permissions) |
| 59 |
// (done by file_iframe_sandbox_a_if2.html contained within file_iframe_sandbox_a_if1.html) |
| 60 |
|
| 61 |
// fails if bad |
| 62 |
// 3) an iframe with no sandbox attribute inside an iframe that has sandbox = "allow-scripts" |
| 63 |
// should not be same origin with the top window |
| 64 |
// (done by file_iframe_sandbox_a_if4.html contained within file_iframe_sandbox_a_if3.html) |
| 65 |
|
| 66 |
// fails if bad |
| 67 |
// 4) an iframe with no sandbox attribute inside an iframe that has sandbox = "allow-scripts" |
| 68 |
// should not be same origin with its parent |
| 69 |
// (done by file_iframe_sandbox_a_if4.html contained within file_iframe_sandbox_a_if3.html) |
| 70 |
|
| 71 |
// passes if good |
| 72 |
// 5) an iframe with 'allow-same-origin' and 'allow-scripts' inside an iframe with 'allow-same-origin' |
| 73 |
// and 'allow-scripts' should be same origin with the top window |
| 74 |
// (done by file_iframe_sandbox_a_if6.html contained within file_iframe_sandbox_a_if5.html) |
| 75 |
|
| 76 |
// passes if good |
| 77 |
// 6) an iframe with 'allow-same-origin' and 'allow-scripts' inside an iframe with 'allow-same-origin' |
| 78 |
// and 'allow-scripts' should be same origin with its parent |
| 79 |
// (done by file_iframe_sandbox_a_if6.html contained within file_iframe_sandbox_a_if5.html) |
| 80 |
|
| 81 |
// passes if good |
| 82 |
// 7) an iframe with no sandbox attribute inside an iframe that has sandbox = "allow-scripts" |
| 83 |
// should be able to execute scripts |
| 84 |
// (done by file_iframe_sandbox_a_if7.html contained within file_iframe_sandbox_a_if3.html) |
| 85 |
|
| 86 |
// fails if bad |
| 87 |
// 8) an iframe with sandbox="" inside an iframe that has allow-scripts should not be able |
| 88 |
// to execute scripts |
| 89 |
// (done by file_iframe_sandbox_a_if2.html contained within file_iframe_sandbox_a_if3.html) |
| 90 |
|
| 91 |
// passes if good |
| 92 |
// 9) make sure that changing the sandbox flags on an iframe (if_8) doesn't affect |
| 93 |
// the sandboxing of subloads of content within that iframe |
| 94 |
var if_8 = document.getElementById('if_8'); |
| 95 |
if_8.sandbox = 'allow-scripts'; |
| 96 |
if_8.contentWindow.doSubload(); |
| 97 |
} |
| 98 |
</script> |
| 99 |
<body onload="doTest()"> |
| 100 |
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=341604">Mozilla Bug 341604</a> - Implement HTML5 sandbox attribute for IFRAMEs |
| 101 |
<p id="display"></p> |
| 102 |
<div id="content"> |
| 103 |
<iframe sandbox="" id="if_1" src="file_iframe_sandbox_a_if1.html" height="10" width="10"></iframe> |
| 104 |
<iframe sandbox="allow-scripts" id="if_3" src="file_iframe_sandbox_a_if3.html" height="10" width="10"></iframe> |
| 105 |
<iframe sandbox="allow-scripts allow-same-origin" id="if_5" src="file_iframe_sandbox_a_if5.html" height="10" width="10"></iframe> |
| 106 |
<iframe sandbox="allow-scripts allow-same-origin" id="if_8" src="file_iframe_sandbox_a_if8.html" height="10" width="10"></iframe> |
| 107 |
</div> |