2008-02-26 19:48:54 -08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=417075
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>postMessage from about:blank, data URLs</title>
|
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="browserFu.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=417075">Mozilla Bug 417075</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none"></div>
|
|
|
|
|
2010-03-09 08:55:39 -08:00
|
|
|
<iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
|
2008-02-26 19:48:54 -08:00
|
|
|
id="sameDomain"></iframe>
|
|
|
|
<iframe src="http://example.com/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
|
|
|
|
id="otherDomain"></iframe>
|
|
|
|
<iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
|
|
|
|
id="otherDomainPort"></iframe>
|
2010-03-09 08:55:39 -08:00
|
|
|
<iframe src="ftp://mochi.test:27534/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
|
2008-02-26 19:48:54 -08:00
|
|
|
id="localNoExist"></iframe>
|
|
|
|
|
|
|
|
<iframe src="http://sub1.παράδειγμα.δοκιμή/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
|
|
|
|
id="idnKidWhitelist"></iframe>
|
|
|
|
|
|
|
|
<iframe src="http://sub1.exämple.test/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
|
|
|
|
id="idnKidNoWhitelist"></iframe>
|
|
|
|
|
|
|
|
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="application/javascript"><![CDATA[
|
|
|
|
/** Test for Bug 417075 **/
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
function errorCheck(i, called, errorCode, actualCode)
|
|
|
|
{
|
|
|
|
ok(!called, "receiver should not have been called for test #" + i);
|
|
|
|
is(actualCode, errorCode, "wrong error thrown in test #" + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
var tests =
|
|
|
|
[
|
|
|
|
// 0
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", ""],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "null"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "a"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "http :"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "http: //"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR,
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasThrowsNoExceptionBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
// 5
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "http ://"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["TODO", " http://localhost:8888"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR,
|
|
|
|
|
2010-03-09 08:55:39 -08:00
|
|
|
returnOrigin: "http://mochi.test:8888",
|
2008-05-02 12:26:47 -07:00
|
|
|
hasThrowsNoExceptionBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "hä"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "http://lo\0k.com"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "http: //localhost:8888"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR,
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasThrowsNoExceptionBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
// 10
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "http://localhost :8888"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", "http:// localhost:8888"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR,
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasThrowsNoExceptionBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["TODO", "http://\nlocalhost:8888"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR,
|
|
|
|
|
2010-03-09 08:55:39 -08:00
|
|
|
returnOrigin: "http://mochi.test:8888",
|
2008-05-02 12:26:47 -07:00
|
|
|
hasThrowsNoExceptionBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["TODO", "http://localhost:8888\0"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR,
|
|
|
|
|
2010-03-09 08:55:39 -08:00
|
|
|
returnOrigin: "http://mochi.test:8888",
|
2008-05-02 12:26:47 -07:00
|
|
|
hasThrowsNoExceptionBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["TODO", "http://localhost:8888\n"],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR,
|
|
|
|
|
2010-03-09 08:55:39 -08:00
|
|
|
returnOrigin: "http://mochi.test:8888",
|
2008-05-02 12:26:47 -07:00
|
|
|
hasThrowsNoExceptionBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
// 15
|
|
|
|
{
|
2008-05-02 12:26:47 -07:00
|
|
|
args: ["PASS", "*"],
|
2008-02-26 19:48:54 -08:00
|
|
|
source: "sameDomain",
|
2010-03-09 08:55:39 -08:00
|
|
|
returnOrigin: "http://mochi.test:8888"
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
2010-03-09 08:55:39 -08:00
|
|
|
args: ["PASS", "http://mochi.test:8888"],
|
2008-02-26 19:48:54 -08:00
|
|
|
source: "sameDomain",
|
2010-03-09 08:55:39 -08:00
|
|
|
returnOrigin: "http://mochi.test:8888"
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.com"],
|
|
|
|
source: "otherDomain",
|
|
|
|
returnOrigin: "http://example.com"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.com/"],
|
|
|
|
source: "otherDomain",
|
|
|
|
returnOrigin: "http://example.com"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.com:80"],
|
|
|
|
source: "otherDomain",
|
|
|
|
returnOrigin: "http://example.com"
|
|
|
|
},
|
|
|
|
// 20
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.com:80/"],
|
|
|
|
source: "otherDomain",
|
|
|
|
returnOrigin: "http://example.com"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.com:80/foobar"],
|
|
|
|
source: "otherDomain",
|
|
|
|
returnOrigin: "http://example.com"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.com/foobar"],
|
|
|
|
source: "otherDomain",
|
|
|
|
returnOrigin: "http://example.com"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.com:8000"],
|
|
|
|
source: "otherDomain",
|
|
|
|
expectNoCallback: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.com:8000/"],
|
|
|
|
source: "otherDomain",
|
|
|
|
expectNoCallback: true
|
|
|
|
},
|
|
|
|
// 25
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.org:8000"],
|
|
|
|
source: "otherDomainPort",
|
|
|
|
returnOrigin: "http://example.org:8000"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.org:8000/"],
|
|
|
|
source: "otherDomainPort",
|
|
|
|
returnOrigin: "http://example.org:8000"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.org:8000/tests/dom/test/mochitest/whatwg/postMessage_origin_helper.xhtml"],
|
|
|
|
source: "otherDomainPort",
|
|
|
|
returnOrigin: "http://example.org:8000"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.org:8000/tests/dom/test/mochitest/whatwg/this_file_does_not_exist.xhtml"],
|
|
|
|
source: "otherDomainPort",
|
|
|
|
returnOrigin: "http://example.org:8000"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.org"],
|
|
|
|
source: "otherDomainPort",
|
|
|
|
expectNoCallback: true
|
|
|
|
},
|
|
|
|
// 30
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.org:80"],
|
|
|
|
source: "otherDomainPort",
|
|
|
|
expectNoCallback: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.org/"],
|
|
|
|
source: "otherDomainPort",
|
|
|
|
expectNoCallback: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://example.org"],
|
|
|
|
source: "otherDomain",
|
|
|
|
expectNoCallback: true
|
|
|
|
},
|
|
|
|
{
|
2010-03-09 08:55:39 -08:00
|
|
|
args: ["PASS", "ftp://mochi.test:8888"],
|
2008-02-26 19:48:54 -08:00
|
|
|
source: "sameDomain",
|
|
|
|
expectNoCallback: true
|
|
|
|
},
|
|
|
|
{
|
2010-03-09 08:55:39 -08:00
|
|
|
args: ["PASS", "http://mochi.test:8888"],
|
2008-02-26 19:48:54 -08:00
|
|
|
source: "sameDomain",
|
2010-03-09 08:55:39 -08:00
|
|
|
returnOrigin: "http://mochi.test:8888"
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
// 35
|
|
|
|
{
|
2010-03-09 08:55:39 -08:00
|
|
|
args: ["PASS", "http://mochi.test:27534"],
|
2008-02-26 19:48:54 -08:00
|
|
|
source: "sameDomain",
|
|
|
|
expectNoCallback: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.παράδειγμα.δοκιμή"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.παράδειγμα.δοκιμή:80"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.παράδειγμα.δοκιμή:80/"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.παράδειγμα.δοκιμή:80/foobar"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
// 40
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.παράδειγμα.δοκιμή/foobar"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp:80"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp:80/"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--hxajbheg2az3al.xn--jxalpdlp:80/foo"],
|
|
|
|
source: "idnKidWhitelist",
|
|
|
|
returnOrigin: "http://sub1.παράδειγμα.δοκιμή"
|
|
|
|
},
|
|
|
|
// 45
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.exämple.test"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.exämple.test:80"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.exämple.test:80/"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.exämple.test/"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.exämple.test/foobar"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
// 50
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--exmple-cua.test"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--exmple-cua.test:80"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--exmple-cua.test:80/"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--exmple-cua.test/"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
args: ["PASS", "http://sub1.xn--exmple-cua.test/foobar"],
|
|
|
|
source: "idnKidNoWhitelist",
|
|
|
|
returnOrigin: "http://sub1.exämple.test",
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
hasWrongReturnOriginBug: true
|
2008-02-26 19:48:54 -08:00
|
|
|
},
|
2008-02-26 22:03:38 -08:00
|
|
|
// 55
|
|
|
|
{
|
|
|
|
args: ["NOT-RECEIVED", undefined],
|
|
|
|
source: "sameDomain",
|
|
|
|
code: DOMException.SYNTAX_ERR
|
|
|
|
},
|
2008-02-26 19:48:54 -08:00
|
|
|
];
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
function allTests(callback)
|
2008-02-26 19:48:54 -08:00
|
|
|
{
|
|
|
|
var test, target, called;
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
function eventCheck(evt)
|
2008-02-26 19:48:54 -08:00
|
|
|
{
|
2008-05-02 12:26:47 -07:00
|
|
|
ok(test === tests[i],
|
|
|
|
"i and test are out of sync! async is hard, let's go shopping");
|
|
|
|
|
|
|
|
var originCheck = test.hasWrongReturnOriginBug ? todo_is : is;
|
2008-02-26 19:48:54 -08:00
|
|
|
originCheck(evt.origin, test.returnOrigin, "wrong origin for #" + i);
|
|
|
|
if (test.args[0] == "TODO")
|
|
|
|
todo_is(evt.data, "PASS", "wrong data");
|
|
|
|
else
|
|
|
|
is(evt.data, "PASS", "wrong data");
|
2008-05-02 12:26:47 -07:00
|
|
|
is(evt.lastEventId, "",
|
|
|
|
"postMessage creates events with empty lastEventId");
|
2008-02-26 19:48:54 -08:00
|
|
|
ok(evt.source === target, "wrong source");
|
|
|
|
called = true;
|
|
|
|
}
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
function nextTest()
|
2008-02-26 19:48:54 -08:00
|
|
|
{
|
2008-05-02 12:26:47 -07:00
|
|
|
i++;
|
2008-02-26 19:48:54 -08:00
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
if (i === end)
|
|
|
|
{
|
|
|
|
removeListener(listener);
|
|
|
|
|
|
|
|
setTimeout(callback, 0);
|
|
|
|
return;
|
|
|
|
}
|
2008-02-26 19:48:54 -08:00
|
|
|
|
|
|
|
test = tests[i];
|
|
|
|
|
|
|
|
target = $(test.source).contentWindow;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
called = false;
|
|
|
|
target.postMessage.apply(target, test.args);
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
2008-05-02 12:26:47 -07:00
|
|
|
// Since an exception was thrown, we know at this point that we're not
|
|
|
|
// waiting on anything else in the queue of script to run, and we can just
|
|
|
|
// call nextTest directly.
|
|
|
|
errorCheck(i, called, e.code, test.code);
|
|
|
|
nextTest();
|
|
|
|
return;
|
2008-02-26 19:48:54 -08:00
|
|
|
}
|
2008-05-02 12:26:47 -07:00
|
|
|
|
|
|
|
// We've set up the event generated by postMessage to be dispatched, and
|
|
|
|
// it's sitting in a queue somewhere. However, it hasn't arrived yet, and
|
|
|
|
// the target document hasn't received the event -- so we need to continue
|
|
|
|
// our tests later.
|
|
|
|
setTimeout(function()
|
|
|
|
{
|
|
|
|
// The event was dispatched, and the target frame's code processed it and
|
|
|
|
// responded -- so now *that* response is sitting in the queue of script to
|
|
|
|
// execute. Process pending script one more time so we know we've gotten
|
|
|
|
// the response.
|
|
|
|
setTimeout(function()
|
|
|
|
{
|
|
|
|
// Finally, we've posted our message and received our response, and
|
|
|
|
// there's nothing further coming down the pipe.
|
|
|
|
if (test.hasThrowsNoExceptionBug)
|
|
|
|
todo(false, "should throw on test #" + i);
|
|
|
|
else
|
|
|
|
ok(test.expectNoCallback ^ called, "should have been called #" + i);
|
|
|
|
|
|
|
|
nextTest();
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
2008-02-26 19:48:54 -08:00
|
|
|
}
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
var listener = registerMessageListener(eventCheck);
|
|
|
|
|
|
|
|
var i = -1, end = tests.length;
|
|
|
|
nextTest();
|
2008-02-26 19:48:54 -08:00
|
|
|
}
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
function registerMessageListener(func, callback)
|
2008-02-26 19:48:54 -08:00
|
|
|
{
|
|
|
|
function receive(evt)
|
2008-05-02 12:26:47 -07:00
|
|
|
{
|
|
|
|
func(evt);
|
|
|
|
if (callback)
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("message", receive, false);
|
|
|
|
|
|
|
|
return receive;
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeListener(listener)
|
|
|
|
{
|
|
|
|
window.removeEventListener("message", listener, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function oddballTests(callback)
|
|
|
|
{
|
|
|
|
var called = false;
|
|
|
|
|
|
|
|
function eventChecks(evt)
|
2008-02-26 19:48:54 -08:00
|
|
|
{
|
2010-03-09 08:55:39 -08:00
|
|
|
is(evt.origin, "http://mochi.test:8888", "wrong sender");
|
2008-02-26 19:48:54 -08:00
|
|
|
is(evt.data, "PASS", "wrong data");
|
2008-05-02 12:26:47 -07:00
|
|
|
is(evt.lastEventId, "",
|
|
|
|
"postMessage creates events with empty lastEventId");
|
2008-02-26 19:48:54 -08:00
|
|
|
ok(evt.source === window, "wrong source");
|
|
|
|
called = true;
|
|
|
|
}
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
var listener = registerMessageListener(eventChecks, function()
|
2008-02-26 19:48:54 -08:00
|
|
|
{
|
|
|
|
is(called, true, "should have been called");
|
2008-05-02 12:26:47 -07:00
|
|
|
removeListener(listener);
|
|
|
|
|
2008-02-26 19:48:54 -08:00
|
|
|
called = false;
|
2008-05-02 12:26:47 -07:00
|
|
|
listener = registerMessageListener(eventChecks, function()
|
|
|
|
{
|
|
|
|
is(called, true, "should have been called");
|
|
|
|
|
|
|
|
removeListener(listener);
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
2010-03-09 08:55:39 -08:00
|
|
|
window.postMessage("PASS", "http://mochi.test:8888");
|
2008-05-02 12:26:47 -07:00
|
|
|
});
|
|
|
|
|
2010-03-09 08:55:39 -08:00
|
|
|
window.postMessage("PASS", "http://mochi.test:8888");
|
2008-02-26 19:48:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function run()
|
|
|
|
{
|
2008-05-02 12:26:47 -07:00
|
|
|
oddballTests(function()
|
|
|
|
{
|
|
|
|
allTests(function()
|
|
|
|
{
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
});
|
2008-02-26 19:48:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", run, false);
|
|
|
|
]]></script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|