2008-01-29 17:31:29 -08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>postMessage called through another frame</title>
|
|
|
|
<script type="application/javascript">
|
2008-05-02 12:26:47 -07:00
|
|
|
var PATH = "/tests/dom/tests/mochitest/whatwg/postMessage_onOther.html";
|
|
|
|
|
2008-01-29 17:31:29 -08:00
|
|
|
function receiveMessage(evt)
|
|
|
|
{
|
2008-05-02 12:26:47 -07:00
|
|
|
if (evt.lastEventId !== "")
|
|
|
|
{
|
|
|
|
fail("unexpected non-empty lastEventId");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (window.location.href)
|
|
|
|
{
|
|
|
|
case "http://example.com" + PATH:
|
|
|
|
receiveTopDomain(evt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "http://test1.example.com" + PATH:
|
|
|
|
receiveSubDomain(evt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fail("unexpected location");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function fail(msg)
|
|
|
|
{
|
|
|
|
window.parent.postMessage("FAIL " + msg, "*");
|
|
|
|
}
|
|
|
|
|
|
|
|
// The parent frame sends "start-test" to the subdomain frame to start.
|
|
|
|
// The subdomain frame then sets document.domain to the top domain so that
|
|
|
|
// the top domain frame can access it. It then sends a message to the top
|
|
|
|
// domain frame to tell it to do likewise; once that happens, the top domain
|
|
|
|
// frame can then call a method on the subdomain frame window, which will
|
|
|
|
// call a method *on the top domain window* to send a message to the parent
|
|
|
|
// window. We thus expect to see an event whose source is the subdomain
|
|
|
|
// window -- *not* the top domain window. Therefore, its .origin should be:
|
|
|
|
//
|
|
|
|
// http://test1.example.com
|
|
|
|
//
|
|
|
|
// and not
|
|
|
|
//
|
|
|
|
// http://example.com
|
|
|
|
|
|
|
|
function receiveSubDomain(evt)
|
|
|
|
{
|
2010-03-12 13:53:36 -08:00
|
|
|
if (evt.origin !== "http://mochi.test:8888")
|
2008-05-02 12:26:47 -07:00
|
|
|
{
|
|
|
|
fail("wrong top-domain origin: " + evt.origin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (evt.data !== "start-test")
|
|
|
|
{
|
|
|
|
fail("wrong top-domain message: " + evt.origin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.domain = "example.com";
|
|
|
|
window.parent.topDomainFrame.postMessage("domain-switch",
|
|
|
|
"http://example.com");
|
|
|
|
}
|
|
|
|
|
|
|
|
function receiveTopDomain(evt)
|
|
|
|
{
|
|
|
|
if (evt.origin !== "http://test1.example.com")
|
|
|
|
{
|
|
|
|
fail("wrong subdomain origin: " + evt.origin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (evt.data !== "domain-switch")
|
|
|
|
{
|
|
|
|
fail("wrong subdomain message: " + evt.origin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (evt.source !== window.parent.subDomainFrame)
|
|
|
|
{
|
|
|
|
fail("wrong source on message from subdomain");
|
|
|
|
return;
|
|
|
|
}
|
2008-01-29 17:31:29 -08:00
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
document.domain = "example.com";
|
|
|
|
window.parent.subDomainFrame.testSiblingPostMessage();
|
2008-01-29 17:31:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSiblingPostMessage()
|
|
|
|
{
|
2010-03-12 13:53:36 -08:00
|
|
|
window.parent.postMessage("test-finished", "http://mochi.test:8888");
|
2008-01-29 17:31:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function setup()
|
|
|
|
{
|
|
|
|
var target = document.getElementById("location");
|
2008-05-02 12:26:47 -07:00
|
|
|
target.textContent = location.hostname + ":" + (location.port || 80);
|
2008-01-29 17:31:29 -08:00
|
|
|
}
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
window.addEventListener("message", receiveMessage, false);
|
2008-01-29 17:31:29 -08:00
|
|
|
window.addEventListener("load", setup, false);
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1 id="location">No location!</h1>
|
|
|
|
</body>
|
|
|
|
</html>
|