-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests regarding navigation inside sandboxed iframes. (#6221)
- Loading branch information
Showing
11 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
.../semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Check that sandboxed iframe can perform navigation on the top frame | ||
when allow-top-navigation is set</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<iframe sandbox="allow-top-navigation allow-scripts"></iframe> | ||
<script> | ||
if (opener) { | ||
// We're the popup (i.e. a top frame). Load into the iframe the page | ||
// trying to modifying the top frame and transmit the result to our | ||
// opener. | ||
onmessage = function(e) { | ||
opener.postMessage(e.data, "*") | ||
} | ||
document.querySelector("iframe").src = "support/iframe-that-performs-top-navigation-on-popup.html"; | ||
} else { | ||
// We are the main test page. Open ourselves as a popup, so that we can | ||
// can experiment navigation of the top frame. | ||
async_test(t => { | ||
window.addEventListener("message", t.step_func_done(e => { | ||
assert_equals(e.data, "can navigate"); | ||
e.source.close(); | ||
})); | ||
window.open(location.href); | ||
}, "Frames with `allow-top-navigation` should be able to navigate the top frame."); | ||
} | ||
</script> | ||
</body> | ||
</html> |
34 changes: 34 additions & 0 deletions
34
.../semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Check that sandboxed iframe cannot perform navigation on the top | ||
frame when allow-top-navigation is not set</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<iframe sandbox="allow-scripts"></iframe> | ||
<script> | ||
if (opener) { | ||
// We're the popup (i.e. a top frame). Load into the iframe the page | ||
// trying to modifying the top frame and transmit the result to our | ||
// opener. | ||
onmessage = function(e) { | ||
opener.postMessage(e.data, "*") | ||
} | ||
document.querySelector("iframe").src = "support/iframe-that-performs-top-navigation-on-popup.html"; | ||
} else { | ||
// We are the main test page. Open ourselves as a popup, so that we can | ||
// can experiment navigation of the top frame. | ||
async_test(t => { | ||
window.addEventListener("message", t.step_func_done(e => { | ||
assert_equals(e.data, "cannot navigate"); | ||
e.source.close(); | ||
})); | ||
window.open(location.href); | ||
}, "Frames without `allow-top-navigation` should not be able to navigate the top frame."); | ||
} | ||
</script> | ||
</body> | ||
</html> |
12 changes: 12 additions & 0 deletions
12
html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>Check that sandboxed iframe can not navigate their ancestors</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
var t = async_test(); | ||
onmessage = t.step_func_done(function(e) { | ||
assert_equals(e.data, "can not navigate", "Should have the right message"); | ||
}); | ||
</script> | ||
<iframe sandbox="allow-scripts" src="support/iframe-tried-to-be-navigated-by-its-child.html"></iframe> |
12 changes: 12 additions & 0 deletions
12
html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>Check that unsandboxed iframe can navigate their ancestors</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
var t = async_test(); | ||
onmessage = t.step_func_done(function(e) { | ||
assert_equals(e.data, "can navigate", "Should have the right message"); | ||
}); | ||
</script> | ||
<iframe src="support/iframe-tried-to-be-navigated-by-its-child.html"></iframe> |
12 changes: 12 additions & 0 deletions
12
html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_descendants.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>Check that sandboxed iframe can navigate their descendants</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
var t = async_test(); | ||
onmessage = t.step_func_done(function(e) { | ||
assert_equals(e.data, "can navigate", "Should have the right message"); | ||
}); | ||
</script> | ||
<iframe sandbox="allow-scripts" src="support/iframe-trying-to-navigate-its-child.html"></iframe> |
12 changes: 12 additions & 0 deletions
12
html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_itself.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>Check that sandboxed iframe can navigate itself</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
var t = async_test(); | ||
onmessage = t.step_func_done(function(e) { | ||
assert_equals(e.data, "can navigate", "Should have the right message"); | ||
}); | ||
</script> | ||
<iframe sandbox="allow-scripts" src="support/iframe-trying-to-navigate-itself.html"></iframe> |
14 changes: 14 additions & 0 deletions
14
...dded-content/the-iframe-element/support/iframe-that-performs-top-navigation-on-popup.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<script> | ||
window.onload = function() { | ||
try { | ||
top.location = "data:text/html,\u003c!DOCTYPE html\u003e\u003cscript\u003eopener.postMessage('can navigate', '*');\u003c/script\u003e"; | ||
} catch(e) { | ||
top.postMessage("cannot navigate", "*"); | ||
} | ||
} | ||
</script> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
...element/support/iframe-that-tries-to-navigate-parent-and-sends-result-to-grandparent.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<p>This is a frame that tries to navigate its parent.</p> | ||
<script> | ||
window.onload = function() { | ||
try { | ||
parent.location.href = "data:text/html,\u003c!DOCTYPE html\u003e\u003cp\u003eIf this message appears, then this frame has been navigated by its child.\u003c/p\u003e\u003cscript\u003eparent.postMessage('can navigate', '*');\u003c/script\u003e"; | ||
} catch(e) { | ||
parent.parent.postMessage("can not navigate", "*"); | ||
} | ||
} | ||
</script> |
4 changes: 4 additions & 0 deletions
4
...mbedded-content/the-iframe-element/support/iframe-tried-to-be-navigated-by-its-child.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE html> | ||
<p>If this message appears, then this frame has not been navigated by its child.</p> | ||
<iframe src="iframe-that-tries-to-navigate-parent-and-sends-result-to-grandparent.html"> | ||
</iframe> |
11 changes: 11 additions & 0 deletions
11
...tics/embedded-content/the-iframe-element/support/iframe-trying-to-navigate-its-child.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<iframe src="data:text/html,If this message appears, then this frame has not been navigated by its parent."></iframe> | ||
<script> | ||
window.onload = function() { | ||
try { | ||
document.querySelector("iframe").contentWindow.location.href = "data:text/html,\u003c!DOCTYPE html\u003e\u003cp\u003eIf this message appears, then this frame has been navigated by its parent.\u003c/p\u003e\u003cscript\u003eparent.parent.postMessage('can navigate', '*');\u003c/script\u003e"; | ||
} catch(e) { | ||
parent.postMessage("can not navigate", "*"); | ||
} | ||
} | ||
</script> |
11 changes: 11 additions & 0 deletions
11
...mantics/embedded-content/the-iframe-element/support/iframe-trying-to-navigate-itself.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<p>If this message appears, then this frame has not been navigated.</p> | ||
<script> | ||
window.onload = function() { | ||
try { | ||
location.href = "data:text/html,\u003c!DOCTYPE html\u003e\u003cp\u003eIf this message appears, then this frame has been navigated.\u003c/p\u003e\u003cscript\u003eparent.postMessage('can navigate', '*');\u003c/script\u003e"; | ||
} catch(e) { | ||
parent.postMessage("can not navigate", "*"); | ||
} | ||
} | ||
</script> |