|
|
|
|
|
|
1 |
<!DOCTYPE HTML> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
https://bugzilla.mozilla.org/show_bug.cgi?id=341604 |
| 5 |
Implement HTML5 sandbox attribute for IFRAMEs - same origin 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 |
/** Same Origin Tests **/ |
| 16 |
|
| 17 |
var completedTests = 0; |
| 18 |
var passedTests = 0; |
| 19 |
|
| 20 |
function ok_wrapper(result, desc) { |
| 21 |
ok(result, desc); |
| 22 |
|
| 23 |
completedTests++; |
| 24 |
|
| 25 |
if (result) { |
| 26 |
passedTests++; |
| 27 |
} |
| 28 |
|
| 29 |
// REVIEW : if one of these tests fails and this isn't called |
| 30 |
// this means this test will hang until the time out happens :( |
| 31 |
// advice on better ways to synchronize things appreciated ! |
| 32 |
if (completedTests == 12) { |
| 33 |
ok(passedTests == 12, "There are 12 same-origin tests that should pass"); |
| 34 |
|
| 35 |
SimpleTest.finish(); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
function receiveMessage(event) |
| 40 |
{ |
| 41 |
ok_wrapper(event.data.ok, event.data.desc); |
| 42 |
} |
| 43 |
|
| 44 |
// a postMessage handler that is used by sandboxed iframes without |
| 45 |
// 'allow-same-origin' to communicate pass/fail back to this main page. |
| 46 |
// it expects to be called with an object like {ok: true/false, desc: |
| 47 |
// <description of the test> which it then forwards to ok() |
| 48 |
window.addEventListener("message", receiveMessage, false); |
| 49 |
|
| 50 |
function doTest() { |
| 51 |
SimpleTest.waitForExplicitFinish(); |
| 52 |
|
| 53 |
// 1) test that we can't access an iframe sandboxed without "allow-same-origin" |
| 54 |
var if_1 = document.getElementById("if_1"); |
| 55 |
try { |
| 56 |
var b = if_1.contentDocument.body; |
| 57 |
ok_wrapper(false, "accessing body of a sandboxed document should not be allowed"); |
| 58 |
} catch (err){ |
| 59 |
ok_wrapper(true, "accessing body of a sandboxed document should not be allowed"); |
| 60 |
} |
| 61 |
|
| 62 |
// 2) test that we can access an iframe sandboxed with "allow-same-origin" |
| 63 |
var if_2 = document.getElementById("if_2"); |
| 64 |
|
| 65 |
try { |
| 66 |
var b = if_2.contentDocument.body; |
| 67 |
ok_wrapper(true, "accessing body of a sandboxed document with allow-same-origin should be allowed"); |
| 68 |
} catch (err) { |
| 69 |
ok_wrapper(false, "accessing body of a sandboxed document with allow-same-origin should be allowed"); |
| 70 |
} |
| 71 |
|
| 72 |
// 3) test that a sandboxed iframe without 'allow-same-origin' cannot access its parent |
| 73 |
// this is done by file_iframe_b_if3.html which has 'allow-scripts' but not 'allow-same-origin' |
| 74 |
|
| 75 |
// 4) test that a sandboxed iframe with 'allow-same-origin' can access its parent |
| 76 |
// this is done by file_iframe_b_if2.html which has 'allow-same-origin' and 'allow-scripts' |
| 77 |
|
| 78 |
// 5) check that a sandboxed iframe with "allow-same-origin" can access document.cookie |
| 79 |
// this is done by file_iframe_b_if2.html which has 'allow-same-origin' and 'allow-scripts' |
| 80 |
|
| 81 |
// 6) check that a sandboxed iframe with "allow-same-origin" can access window.localStorage |
| 82 |
// this is done by file_iframe_b_if2.html which has 'allow-same-origin' and 'allow-scripts' |
| 83 |
|
| 84 |
// 7) check that a sandboxed iframe with "allow-same-origin" can access window.sessionStorage |
| 85 |
// this is done by file_iframe_b_if2.html which has 'allow-same-origin' and 'allow-scripts' |
| 86 |
|
| 87 |
// 8) check that a sandboxed iframe WITHOUT "allow-same-origin" can NOT access document.cookie |
| 88 |
// this is done by file_iframe_b_if3.html which has 'allow-scripts' but not 'allow-same-origin' |
| 89 |
|
| 90 |
// 9) check that a sandboxed iframe WITHOUT "allow-same-origin" can NOT access window.localStorage |
| 91 |
// this is done by file_iframe_b_if3.html which has 'allow-scripts' but not 'allow-same-origin' |
| 92 |
|
| 93 |
// 10) check that a sandboxed iframe WITHOUT "allow-same-origin" can NOT access window.sessionStorage |
| 94 |
// this is done by file_iframe_b_if3.html which has 'allow-scripts' but not 'allow-same-origin' |
| 95 |
|
| 96 |
// 11) check that XHR works normally in a sandboxed iframe with "allow-same-origin" and "allow-scripts" |
| 97 |
// this is done by file_iframe_b_if2.html which has 'allow-same-origin' and 'allow-scripts' |
| 98 |
|
| 99 |
// 12) check that XHR is blocked in a sandboxed iframe with "allow-scripts" but WITHOUT "allow-same-origin" |
| 100 |
// this is done by file_iframe_b_if3.html which has 'allow-scripts' but not 'allow-same-origin' |
| 101 |
} |
| 102 |
</script> |
| 103 |
<body onload="doTest()"> |
| 104 |
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=341604">Mozilla Bug 341604</a> - Implement HTML5 sandbox attribute for IFRAMEs |
| 105 |
<p id="display"></p> |
| 106 |
<div id="content"> |
| 107 |
<iframe sandbox="" id="if_1" src="file_iframe_sandbox_b_if1.html" height="10" width="10"></iframe> |
| 108 |
<iframe sandbox="allow-same-origin allow-scripts" id="if_2" src="file_iframe_sandbox_b_if2.html" height="10" width="10"></iframe> |
| 109 |
<iframe sandbox="allow-scripts" id="if_3" src="file_iframe_sandbox_b_if3.html" height="10" width="10"></iframe> |
| 110 |
</div> |