Skip to content

Commit

Permalink
Bug 1800279 - Add a test which checks document URI handling in sandbo…
Browse files Browse the repository at this point in the history
…xed top level pages. r=aiunusov

Differential Revision: https://phabricator.services.mozilla.com/D161936
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Nov 14, 2022
1 parent eec3bcd commit f2df7f5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
34 changes: 34 additions & 0 deletions dom/base/test/file_sandbox_and_document_uri.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html>
<head>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/ChromeTask.js"></script>
<script>
function test() {
location.hash = "foobar"
if (!document.documentURI.includes("#foobar")) {
opener.postMessage("Wrong documentURI", "*");
window.close();
} else {
ChromeTask.spawn(null, () => {
return {
documentURI: actorParent.documentURI.spec,
principalURI: actorParent.documentPrincipal.URI.spec
};
}).then((uriAndPrincipal) => {
if (!uriAndPrincipal.documentURI.includes("#foobar")) {
opener.postMessage("Wrong documentURI in the parent process", "*");
} else if (!uriAndPrincipal.principalURI.includes("moz-nullprincipal")) {
opener.postMessage("Wrong document principal in the parent process", "*");
} else {
opener.postMessage("done", "*");
}
window.close();
});
}
}
</script>
</head>
<body onload="setTimeout(test)">
</body>
</html>
2 changes: 2 additions & 0 deletions dom/base/test/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,8 @@ scheme = https
[test_range_bounds.html]
[test_reentrant_flush.html]
[test_root_iframe.html]
[test_sandbox_and_document_uri.html]
support-files = file_sandbox_and_document_uri.html
[test_screen_orientation.html]
[test_script_loader_crossorigin_data_url.html]
[test_script_loader_js_cache.html]
Expand Down
31 changes: 31 additions & 0 deletions dom/base/test/test_sandbox_and_document_uri.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test sandbox inheritance and document uri handling</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
add_task(async function() {
await new Promise((resolve) => {
window.onmessage = (event) => {
is(event.data, "done");
resolve();
}
});
});
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<iframe sandbox="allow-popups allow-scripts" srcdoc=
"<script>
window.onmessage = function(event) { parent.postMessage(event.data, '*'); }
/* Open a cross-origin page */
window.onload = function() { window.open('http://example.org/tests/dom/base/test/file_sandbox_and_document_uri.html'); }
</script>"
></iframe>
</body>
</html>

0 comments on commit f2df7f5

Please sign in to comment.