2008-01-29 17:31:29 -08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
http://sub1.test1.example.org/tests/dom/tests/mochitest/whatwg/postMessage_joined_helper.html
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>postMessage joined domains, inner frame</title>
|
|
|
|
<script type="application/javascript" src="browserFu.js"></script>
|
|
|
|
<script type="application/javascript">
|
|
|
|
function receiveMessage(evt)
|
|
|
|
{
|
2008-05-02 12:26:47 -07:00
|
|
|
var response, target, providedOrigin;
|
2008-01-29 17:31:29 -08:00
|
|
|
var data = evt.data;
|
|
|
|
if (data === "subframe-test-finished")
|
|
|
|
{
|
|
|
|
target = window.parent;
|
2010-03-12 13:53:36 -08:00
|
|
|
providedOrigin = "http://mochi.test:8888";
|
2008-01-29 17:31:29 -08:00
|
|
|
response = "test-passed";
|
|
|
|
}
|
|
|
|
else if (data === "start-test")
|
|
|
|
{
|
|
|
|
target = window.frames.innermost;
|
2008-05-02 12:26:47 -07:00
|
|
|
providedOrigin = "http://example.org";
|
2008-01-29 17:31:29 -08:00
|
|
|
response = "start-test";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target = window.parent;
|
2010-03-12 13:53:36 -08:00
|
|
|
providedOrigin = "http://mochi.test:8888";
|
2008-01-29 17:31:29 -08:00
|
|
|
response = "not reached";
|
|
|
|
}
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
if (evt.lastEventId !== "")
|
|
|
|
response += " wrong-lastEventId(" + evt.lastEventId + ")";
|
|
|
|
|
2008-01-29 17:31:29 -08:00
|
|
|
if (evt.type !== "message")
|
|
|
|
response += " wrong-type(" + evt.type + ")";
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
if (evt.target !== window)
|
2008-01-29 17:31:29 -08:00
|
|
|
{
|
|
|
|
response += " wrong-target(" + evt.target + ")";
|
|
|
|
response += " location(" + window.location.href + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMozilla && evt.isTrusted === true)
|
|
|
|
{
|
|
|
|
response += " unexpected-trusted-event";
|
|
|
|
}
|
|
|
|
|
2008-02-26 19:48:54 -08:00
|
|
|
var origin;
|
2008-01-29 17:31:29 -08:00
|
|
|
if (data == "subframe-test-finished")
|
2008-02-26 19:48:54 -08:00
|
|
|
origin = "http://example.org";
|
2008-01-29 17:31:29 -08:00
|
|
|
else if (data === "start-test")
|
2010-03-12 13:53:36 -08:00
|
|
|
origin = "http://mochi.test:8888";
|
2008-01-29 17:31:29 -08:00
|
|
|
else
|
2008-02-26 19:48:54 -08:00
|
|
|
origin = "unreached";
|
2008-01-29 17:31:29 -08:00
|
|
|
|
2008-02-26 19:48:54 -08:00
|
|
|
if (evt.origin !== origin)
|
2008-01-29 17:31:29 -08:00
|
|
|
{
|
2008-02-26 19:48:54 -08:00
|
|
|
response += " wrong-origin(" + evt.origin + ")";
|
2008-01-29 17:31:29 -08:00
|
|
|
response += " location(" + window.location.href + ")";
|
|
|
|
}
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
target.postMessage(response, providedOrigin);
|
2008-01-29 17:31:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function setup()
|
|
|
|
{
|
|
|
|
var oldDomain = document.domain;
|
|
|
|
var newDomain = "example.org";
|
|
|
|
|
|
|
|
document.domain = newDomain;
|
|
|
|
|
|
|
|
var target = document.getElementById("location");
|
|
|
|
target.textContent = "Location: " + oldDomain +
|
|
|
|
", effective domain: " + newDomain;
|
|
|
|
|
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>
|
|
|
|
<p id="location">No location!</p>
|
|
|
|
|
|
|
|
<iframe src="http://example.org/tests/dom/tests/mochitest/whatwg/postMessage_joined_helper2.html"
|
|
|
|
name="innermost"></iframe>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|