|
|
|
|
|
|
1 |
<!DOCTYPE HTML> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
https://bugzilla.mozilla.org/show_bug.cgi?id=341604 |
| 5 |
Implement HTML5 sandbox attribute for IFRAMEs - general 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 - general tests **/ |
| 15 |
|
| 16 |
// a postMessage handler that is used by sandboxed iframes without |
| 17 |
// 'allow-same-origin' to communicate pass/fail back to this main page. |
| 18 |
// it expects to be called with an object like {ok: true/false, desc: |
| 19 |
// <description of the test> which it then forwards to ok() |
| 20 |
window.addEventListener("message", receiveMessage, false); |
| 21 |
|
| 22 |
function receiveMessage(event) |
| 23 |
{ |
| 24 |
ok_wrapper(event.data.ok, event.data.desc); |
| 25 |
} |
| 26 |
|
| 27 |
var completedTests = 0; |
| 28 |
var passedTests = 0; |
| 29 |
|
| 30 |
function ok_wrapper(result, desc) { |
| 31 |
ok(result, desc); |
| 32 |
|
| 33 |
completedTests++; |
| 34 |
|
| 35 |
if (result) { |
| 36 |
passedTests++; |
| 37 |
} |
| 38 |
|
| 39 |
// REVIEW : if one of these tests fails and this isn't called |
| 40 |
// this means this test will hang until the time out happens :( |
| 41 |
// advice on better ways to synchronize things appreciated ! |
| 42 |
if (completedTests == 6) { |
| 43 |
ok(passedTests == 6, "There are 6 general tests that should pass"); |
| 44 |
SimpleTest.finish(); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
function doTest() { |
| 49 |
SimpleTest.waitForExplicitFinish(); |
| 50 |
|
| 51 |
// passes if good |
| 52 |
// 1) test that scripts can run in an iframe sandboxed with "allow-scripts" |
| 53 |
// (done in file_iframe_sandbox_c_if1.html which has 'allow-scripts') |
| 54 |
|
| 55 |
// fails if bad |
| 56 |
// 2) test that allow scripts cannot run in an iframe sandboxed without "allow-scripts" |
| 57 |
// (done in file_iframe_sandbox_c_if2.html which has sandbox='') |
| 58 |
|
| 59 |
// passes if good |
| 60 |
// 3) test that a new iframe has sandbox attribute |
| 61 |
var ifr = document.createElement("iframe"); |
| 62 |
ok_wrapper("sandbox" in ifr, "a new iframe should have a sandbox attribute"); |
| 63 |
|
| 64 |
// passes if good |
| 65 |
// 4) test that the sandbox attribute is a DOMSettableTokenList |
| 66 |
ok_wrapper(ifr.sandbox instanceof DOMSettableTokenList, "sandbox attribute should be a DOMSettable Token List"); |
| 67 |
|
| 68 |
// passes if good |
| 69 |
// 5) test that a sandboxed iframe with 'allow-forms' can submit forms |
| 70 |
// (done in file_iframe_sandbox_c_if3.html which has 'allow-forms' and 'allow-scripts') |
| 71 |
|
| 72 |
// fails if bad |
| 73 |
// 6) test that a sandboxed iframe without 'allow-forms' can NOT submit forms |
| 74 |
// (done in file_iframe_sandbox_c_if1.html which only has 'allow-scripts') |
| 75 |
|
| 76 |
// REVIEW : are there other ways of opening new windows that the 3 below that are mentioned in the HTML5 |
| 77 |
// spec ? |
| 78 |
|
| 79 |
// fails if bad |
| 80 |
// 7) test that a sandboxed iframe can't open a new window using the target.attribute |
| 81 |
// this is done via file_iframe_c_if4.html which is sandboxed with "allow-scripts" and "allow-same-origin" |
| 82 |
// the window it attempts to open calls window.opener.ok(false, ...) and file_iframe_c_if4.html has an ok() |
| 83 |
// function that calls window.parent.ok_wrapper |
| 84 |
|
| 85 |
// passes if good |
| 86 |
// 8) test that a sandboxed iframe can't open a new window using window.open |
| 87 |
// this is done via file_iframe_c_if4.html which is sandboxed with "allow-scripts" and "allow-same-origin" |
| 88 |
// the window it attempts to open calls window.opener.ok(false, ...) and file_iframe_c_if4.html has an ok() |
| 89 |
// function that calls window.parent.ok_wrapper |
| 90 |
|
| 91 |
// passes if good |
| 92 |
// 9) test that a sandboxed iframe can't open a new window using window.ShowModalDialog |
| 93 |
// this is done via file_iframe_c_if4.html which is sandboxed with "allow-scripts" and "allow-same-origin" |
| 94 |
// the window it attempts to open calls window.opener.ok(false, ...) and file_iframe_c_if4.html has an ok() |
| 95 |
// function that calls window.parent.ok_wrapper |
| 96 |
} |
| 97 |
</script> |
| 98 |
<body onload="doTest()"> |
| 99 |
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=341604">Mozilla Bug 341604</a> - Implement HTML5 sandbox attribute for IFRAMEs |
| 100 |
<p id="display"></p> |
| 101 |
<div id="content"> |
| 102 |
<iframe sandbox="allow-scripts" id="if_1" src="file_iframe_sandbox_c_if1.html" height="10" width="10"></iframe> |
| 103 |
<iframe sandbox="" id="if_2" src="file_iframe_sandbox_c_if2.html" height="10" width="10"></iframe> |
| 104 |
<iframe sandbox="allow-forms allow-scripts" id="if_3" src="file_iframe_sandbox_c_if3.html" height="10" width="10"></iframe> |
| 105 |
<iframe sandbox="allow-same-origin allow-scripts" id="if_4" src="file_iframe_sandbox_c_if4.html" height="10" width="10"></iframe> |
| 106 |
</div> |
| 107 |
</body> |
| 108 |
</html> |