Implement dissimilar-origin postMessage.

This commit is contained in:
Alan Jeffrey 2017-02-14 16:06:28 -06:00
parent f5c67fda04
commit f9c5d0c117
12 changed files with 191 additions and 13 deletions

View file

@ -9378,6 +9378,16 @@
{}
]
],
"mozilla/cross-origin-objects/cross-origin-postMessage-child1.html": [
[
{}
]
],
"mozilla/cross-origin-objects/cross-origin-postMessage-child2.html": [
[
{}
]
],
"mozilla/details_ui_closed_ref.html": [
[
{}
@ -12532,6 +12542,12 @@
}
]
],
"mozilla/cross-origin-objects/cross-origin-postMessage.html": [
[
"/_mozilla/mozilla/cross-origin-objects/cross-origin-postMessage.html",
{}
]
],
"mozilla/deterministic-raf.html": [
[
"/_mozilla/mozilla/deterministic-raf.html",
@ -25101,6 +25117,18 @@
"5d5a3ba4099dfabddbed1ea98ad8fe1f5c00a3d3",
"testharness"
],
"mozilla/cross-origin-objects/cross-origin-postMessage-child1.html": [
"6669b133609e17e368a124ddfc52ace940e74156",
"support"
],
"mozilla/cross-origin-objects/cross-origin-postMessage-child2.html": [
"a37cd21178fd25a829be30b0367bd0812db4c211",
"support"
],
"mozilla/cross-origin-objects/cross-origin-postMessage.html": [
"0163758c92997c6723c9d21be49ef7f51d8b3daf",
"testharness"
],
"mozilla/details_ui_closed.html": [
"2acbe3afbec267bad4dd986803e636740a707507",
"reftest"

View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title> postMessage to dissimilar-origin iframe </title>
</head>
<body>
<script>
window.addEventListener("message", function(e) {
window.location.href = e.data;
});
</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title> postMessage to dissimilar-origin iframe </title>
</head>
<body>
<script>
window.parent.postMessage("OK", "*");
</script>
</body>
</html>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title> postMessage to dissimilar-origin iframe </title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>
<iframe id="child"></iframe>
<script>
async_test(function(t) {
// child1 is a dissimilar-origin document
var childURL1 = new URL("cross-origin-postMessage-child1.html", document.location);
childURL1.hostname = "127.0.0.1";
// child2 is a same-origin document
var childURL2 = new URL("cross-origin-postMessage-child2.html", document.location);
// Load child1 into the iframe
var childIframe = document.getElementById("child");
childIframe.src = childURL1;
// Once child1 has loaded, post a message to it, asking it to navigate to child2
childIframe.addEventListener("load", t.step_func(function() {
childIframe.contentWindow.postMessage(childURL2.toString(), "*");
}));
// Wait for child2 to post an OK message back to us.
// (We don't yet have support for event.source or window.parent,
// so we have to wait for the child to become same-origin.)
window.addEventListener("message", t.step_func(function(e) {
assert_equals(e.data, "OK");
assert_equals(childIframe.contentWindow.location.href, childURL2.toString());
t.done();
}));
});
</script>
</body>
</html>