mirror of
https://github.com/servo/servo.git
synced 2025-08-11 08:25:32 +01:00
Update web-platform-tests to revision 0d318188757a9c996e20b82db201fd04de5aa255
This commit is contained in:
parent
b2a5225831
commit
1a81b18b9f
12321 changed files with 544385 additions and 6 deletions
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> MessageChannel: port message queue is initially disabled </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
|
||||
var TestResult = true;
|
||||
|
||||
var t = async_test("Test Description: A port message queue can be enabled or disabled, and is initially disabled.");
|
||||
|
||||
var channel = new MessageChannel();
|
||||
|
||||
channel.port2.addEventListener("message", TestMessageEvent, true);
|
||||
|
||||
channel.port1.postMessage("ping");
|
||||
|
||||
setTimeout(t.step_func(VerifyResult), 100);
|
||||
|
||||
function TestMessageEvent(evt)
|
||||
{
|
||||
TestResult = false;
|
||||
}
|
||||
|
||||
function VerifyResult()
|
||||
{
|
||||
assert_true(TestResult, "Port message queue is initially disabled?");
|
||||
t.done();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> MessageChannel: port.onmessage enables message queue </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
|
||||
var TestResult = false;
|
||||
var description = "The first time a MessagePort object's onmessage IDL attribute is set, the port's "
|
||||
+ "port message queue must be enabled, as if the start() method had been called.";
|
||||
|
||||
var t = async_test("Test Description: " + description);
|
||||
|
||||
var channel = new MessageChannel();
|
||||
|
||||
channel.port2.onmessage = TestMessageEvent;
|
||||
|
||||
channel.port1.postMessage("ping");
|
||||
|
||||
setTimeout(t.step_func(VerifyResult), 100);
|
||||
|
||||
function TestMessageEvent(evt)
|
||||
{
|
||||
TestResult = true;
|
||||
}
|
||||
|
||||
function VerifyResult()
|
||||
{
|
||||
assert_true(TestResult, "Port message queue is enabled?");
|
||||
t.done();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage() with a host object raises DataCloneError </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
|
||||
var description = "Throw a DataCloneError when a host object (e.g. a DOM node) is used with postMessage.";
|
||||
|
||||
test(function()
|
||||
{
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.start();
|
||||
|
||||
assert_throws("DATA_CLONE_ERR", function()
|
||||
{
|
||||
channel.port1.postMessage(navigator);
|
||||
});
|
||||
}, description);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,42 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage(): clone a port </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var OriginalPort = null;
|
||||
var ClonedPort = null;
|
||||
var description = "Test Description: When the user agent is to clone a port original port, with "
|
||||
+ "the clone being owned by owner, it must return a new MessagePort object";
|
||||
|
||||
var t = async_test("Test Description: " + description);
|
||||
|
||||
var ChannelA = new MessageChannel();
|
||||
var ChannelB = new MessageChannel();
|
||||
OriginalPort = ChannelB.port2;
|
||||
|
||||
ChannelA.port2.onmessage = t.step_func(function(evt)
|
||||
{
|
||||
if(evt.data == "ports")
|
||||
{
|
||||
ClonedPort = evt.ports[0];
|
||||
|
||||
assert_not_equals(ClonedPort, OriginalPort, "new cloned port object should not equal to the original port!");
|
||||
|
||||
ClonedPort.onmessage = function(e)
|
||||
{
|
||||
test(function(){ assert_equals(e.data, "ping"); }, "Data sent through remote port is received by the new cloned port");
|
||||
t.done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ChannelA.port1.postMessage("ports", [OriginalPort]);
|
||||
ChannelB.port1.postMessage("ping");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage() DataCloneError: cloning source port </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
|
||||
var description = "Test Description: Throw a DataCloneError if transfer array in postMessage contains source port.";
|
||||
|
||||
test(function()
|
||||
{
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.start();
|
||||
|
||||
assert_throws("DATA_CLONE_ERR", function()
|
||||
{
|
||||
channel.port1.postMessage("ports", [channel.port1]);
|
||||
});
|
||||
}, description);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage(): MessageEvent properties </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
|
||||
var TargetPort = null;
|
||||
var description = "The postMessage() method - Create an event that uses the MessageEvent interface, "
|
||||
+ "with the name message, which does not bubble and is not cancelable.";
|
||||
|
||||
var t = async_test("Test Description: " + description);
|
||||
|
||||
var channel = new MessageChannel();
|
||||
|
||||
TargetPort = channel.port2;
|
||||
TargetPort.start();
|
||||
TargetPort.addEventListener("message", t.step_func(TestMessageEvent), true);
|
||||
|
||||
channel.port1.postMessage("ping");
|
||||
|
||||
function TestMessageEvent(evt)
|
||||
{
|
||||
ExpectedResult = [true, "message", false, false];
|
||||
ActualResult = [(evt instanceof MessageEvent), evt.type, evt.bubbles, evt.cancelable];
|
||||
|
||||
assert_array_equals(ActualResult, ExpectedResult);
|
||||
t.done();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage(): read-only ports array </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
|
||||
var TargetPort = null;
|
||||
var description = "The postMessage() method - Make new ports into a read only array.";
|
||||
|
||||
var t = async_test("Test Description: " + description);
|
||||
|
||||
var channel = new MessageChannel();
|
||||
|
||||
TargetPort = channel.port2;
|
||||
TargetPort.start();
|
||||
TargetPort.addEventListener("message", t.step_func(TestMessageEvent), true);
|
||||
|
||||
var channel2 = new MessageChannel();
|
||||
|
||||
channel.port1.postMessage("ports", [channel2.port1]);
|
||||
|
||||
function TestMessageEvent(evt)
|
||||
{
|
||||
var channel3 = new MessageChannel();
|
||||
evt.ports.push(channel3.port1);
|
||||
evt.ports.push(channel3.port1);
|
||||
|
||||
assert_equals(evt.ports.length, 1, "ports is a read only array with length == 1.");
|
||||
t.done();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage(): target port and source port </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
|
||||
var TARGET = null;
|
||||
var SOURCE = null;
|
||||
var description = "The postMessage() method - Let target port be the port with which source "
|
||||
+ "port is entangled, if any.";
|
||||
|
||||
var t = async_test("Test Description: " + description);
|
||||
|
||||
var channel = new MessageChannel();
|
||||
SOURCE = channel.port1;
|
||||
TARGET = channel.port2;
|
||||
TARGET.start();
|
||||
TARGET.addEventListener("message", t.step_func(TestMessageEvent), true);
|
||||
|
||||
SOURCE.postMessage("ping");
|
||||
|
||||
function TestMessageEvent(evt)
|
||||
{
|
||||
assert_equals(evt.target, TARGET);
|
||||
assert_not_equals(evt.target, SOURCE);
|
||||
t.done();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> MessageEvent interface and properties </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"Create an event that uses the MessageEvent interface, with the event type message, " +
|
||||
"which does not bubble, is not cancelable, and has no default action.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = "foo";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
var ExpectedResult = [true, true, false, false, false];
|
||||
var ActualResult = [];
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, "*");
|
||||
}
|
||||
|
||||
window.addEventListener("message", t.step_func(function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
ActualResult = [(e instanceof MessageEvent), (e.type == "message"), e.bubbles, e.cancelable, e.defaultPrevented];
|
||||
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
|
||||
t.done();
|
||||
|
||||
}), false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
10
tests/wpt/web-platform-tests/webmessaging/README.md
Normal file
10
tests/wpt/web-platform-tests/webmessaging/README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
This directory contains the HTML5 Web Messaging test suite.
|
||||
|
||||
The following document contains a list of each test file in the test suite and the results of running the test file on several browsers <http://www.w3.org/wiki/Webapps/Interop/WebMessaging>.
|
||||
|
||||
To run this test suite within a browser, go to: <http://w3c-test.org/web-platform-tests/master/webmessaging/>.
|
||||
|
||||
The latest Editor's Draft of HTML5 Web Messaging is: <http://dev.w3.org/html5/postmsg/>.
|
||||
|
||||
The latest W3C Technical Report of HTML5 Web Messaging is <http://www.w3.org/TR/webmessaging/>.
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Transferred objects are no longer usable on the sending side </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"Objects listed in transfer are transferred, not just cloned, meaning that they are " +
|
||||
"no longer usable on the sending side.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = {test: "e.ports[0].postMessage('TRANSFERRED')"};
|
||||
var TARGET = document.querySelector("iframe");
|
||||
var ExpectedResult = ["PING", "TRANSFERRED"];
|
||||
var ActualResult = [];
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
assert_own_property(window, "MessageChannel", "window");
|
||||
|
||||
var channel = new MessageChannel();
|
||||
|
||||
channel.port2.onmessage = t.step_func(VerifyResult);
|
||||
|
||||
channel.port1.postMessage("PING");
|
||||
|
||||
TARGET.contentWindow.postMessage(DATA, "*", [channel.port1]);
|
||||
|
||||
channel.port1.postMessage("PONG");
|
||||
|
||||
}, "MessageChannel is supported.");
|
||||
}
|
||||
|
||||
function VerifyResult(e)
|
||||
{
|
||||
ActualResult.push(e.data)
|
||||
|
||||
if (ActualResult.length >= ExpectedResult.length)
|
||||
{
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
58
tests/wpt/web-platform-tests/webmessaging/event.data.sub.htm
Normal file
58
tests/wpt/web-platform-tests/webmessaging/event.data.sub.htm
Normal file
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> event.data returns the data of the message </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: event.data returns the data of the message.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var PORT = location.port !== "" ? ":" + location.port : "";
|
||||
var DATA = "STRING";
|
||||
var TYPE = "string";
|
||||
var TARGET1 = document.querySelectorAll("iframe")[0];
|
||||
var TARGET2 = document.querySelectorAll("iframe")[1];
|
||||
var XORIGIN = "{{location[scheme]}}://{{domains[www]}}" + PORT;
|
||||
var SORIGIN = "{{location[scheme]}}://{{host}}" + PORT;
|
||||
var ExpectedResult = [DATA, TYPE, DATA, TYPE];
|
||||
var ActualResult = [];
|
||||
var loaded = 0;
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
loaded++;
|
||||
|
||||
if (loaded == 2)
|
||||
{
|
||||
TARGET1.contentWindow.postMessage(DATA, XORIGIN);
|
||||
TARGET2.contentWindow.postMessage(DATA, SORIGIN);
|
||||
}
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
if (e.data.toString() === "STRING") {
|
||||
ActualResult.push(e.data, typeof(e.data));
|
||||
|
||||
if (ActualResult.length >= ExpectedResult.length) {
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,56 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> event.origin returns the origin of the message </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: event.origin returns the origin of the message.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var PORT = location.port !== "" ? ":" + location.port : "";
|
||||
var TARGET1 = document.querySelectorAll("iframe")[0];
|
||||
var TARGET2 = document.querySelectorAll("iframe")[1];
|
||||
var XORIGIN = "{{location[scheme]}}://{{domains[www]}}" + PORT;
|
||||
var SORIGIN = "{{location[scheme]}}://{{host}}" + PORT;
|
||||
var ExpectedResult = ["#1", XORIGIN, "#2", SORIGIN];
|
||||
var ActualResult = [];
|
||||
var loaded = 0;
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
loaded++;
|
||||
|
||||
if (loaded == 2)
|
||||
{
|
||||
TARGET1.contentWindow.postMessage("#1", XORIGIN);
|
||||
TARGET2.contentWindow.postMessage("#2", SORIGIN);
|
||||
}
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
// testharness.js uses postMessage so we must check what data we want to receive
|
||||
if (e.data.toString() === "#1" || e.data.toString() === "#2") {
|
||||
ActualResult.push(e.data, e.origin);
|
||||
if (ActualResult.length === ExpectedResult.length) {
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,49 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> event.ports returns the MessagePort array sent with the message </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: event.ports returns the MessagePort array sent with the message.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = {test: "e.source.postMessage(e.ports.toString(), '*', e.ports)"};
|
||||
var TARGET = document.querySelector("iframe");
|
||||
var ExpectedResult = "";
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
assert_own_property(window, "MessageChannel", "window");
|
||||
|
||||
var channel = new MessageChannel();
|
||||
var ports = [channel.port1, channel.port2];
|
||||
ExpectedResult = ports.toString();
|
||||
TARGET.contentWindow.postMessage(DATA, "*", ports);
|
||||
|
||||
}, "MessageChannel is supported.");
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
assert_equals(e.data, ExpectedResult, "e.data");
|
||||
assert_true(e.ports[0] instanceof MessagePort, e.ports[0] + " instanceof MessageChannel");
|
||||
assert_true(e.ports[1] instanceof MessagePort, e.ports[1] + " instanceof MessageChannel");
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
51
tests/wpt/web-platform-tests/webmessaging/event.source.htm
Normal file
51
tests/wpt/web-platform-tests/webmessaging/event.source.htm
Normal file
|
@ -0,0 +1,51 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Same-origin: event.source returns the WindowProxy of the source window </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: Same-origin: event.source returns the WindowProxy of the source window.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = "foo";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
var SORIGIN = location.protocol + "//" + location.host;
|
||||
var ExpectedResult = [SORIGIN, "AccessCookieAllowed"];
|
||||
var ActualResult = [];
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, SORIGIN);
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sdomainCookie = e.source.document.cookie;
|
||||
ActualResult.push(e.origin, "AccessCookieAllowed");
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
ActualResult.push(e.origin, "AccessCookieDenied");
|
||||
}
|
||||
|
||||
assert_true(e.source === TARGET.contentWindow);
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,51 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Corss-origin: event.source returns the WindowProxy of the source window </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
var description = "Test Description: Cross-origin: event.source returns the WindowProxy of the source window.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var PORT = location.port !== "" ? ":" + location.port : "";
|
||||
var DATA = "foo";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
var XORIGIN = "{{location[scheme]}}://{{domains[www1]}}" + PORT;
|
||||
var ExpectedResult = [XORIGIN, "AccessCookieDenied"];
|
||||
var ActualResult = [];
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, XORIGIN);
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sdomainCookie = e.source.document.cookie;
|
||||
ActualResult.push(e.origin, "AccessCookieAllowed");
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
ActualResult.push(e.origin, "AccessCookieDenied");
|
||||
}
|
||||
|
||||
assert_true(e.source.parent === window);
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<title>basic messagechannel test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function(t) {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.postMessage(1);
|
||||
channel.port2.onmessage = t.step_func(
|
||||
function(e) {
|
||||
assert_equals(e.data, 1);
|
||||
t.done();
|
||||
});
|
||||
channel.port2.start();
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>without start()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function(t) {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.postMessage(1);
|
||||
var i = 0;
|
||||
channel.port2.addEventListener('message', function() { i++; }, false);
|
||||
setTimeout(t.step_func(function() { assert_equals(i, 0); t.done();}), 50);
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<title>onmessage implied start()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function(t) {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.postMessage(1);
|
||||
channel.port2.onmessage = function() {
|
||||
setTimeout(t.step_func(function() {
|
||||
t.done();
|
||||
}), 50);
|
||||
channel.port2.onmessage = t.step_func(function() {
|
||||
assert_unreached();
|
||||
});
|
||||
}; // implies start()
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,8 @@
|
|||
<!doctype html>
|
||||
<title>004-1</title>
|
||||
<script>
|
||||
onmessage = function(e) {
|
||||
var port = e.ports[0];
|
||||
port.postMessage(e.data);
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,10 @@
|
|||
<!doctype html>
|
||||
<title>004-2</title>
|
||||
<script>
|
||||
onmessage = function(e) {
|
||||
var port = e.ports[0];
|
||||
port.onmessage = function(e) { // implied start()
|
||||
parent.postMessage(e.data, '*');
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<title>cross-document channel</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src=004-1.html></iframe><iframe src=004-2.html></iframe>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var t = async_test();
|
||||
onload = t.step_func(
|
||||
function() {
|
||||
var channel = new MessageChannel();
|
||||
window[0].postMessage(1, '*', [channel.port1]);
|
||||
window[1].postMessage(2, '*', [channel.port2]);
|
||||
channel = null;
|
||||
window.onmessage = t.step_func(
|
||||
function(e) {
|
||||
assert_equals(e.data, 1);
|
||||
t.done();
|
||||
});
|
||||
}
|
||||
);
|
||||
</script>
|
|
@ -0,0 +1,44 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage with ArrayBuffer object </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: postMessage with ArrayBuffer object.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA;
|
||||
var TYPE = "object";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
DATA = new ArrayBuffer(32);
|
||||
TARGET.contentWindow.postMessage(DATA, "*");
|
||||
}, "ArrayBuffer is supported.");
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
assert_equals(typeof(e.data), TYPE);
|
||||
assert_equals(e.data.toString(), DATA.toString());
|
||||
assert_equals(e.data.byteLength, 32);
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage with Date object </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: Messages can contain JavaScript values (e.g., Dates).";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = new Date();
|
||||
var TYPE = "object";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, "*");
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
assert_equals(typeof(e.data), TYPE);
|
||||
assert_equals(e.data.valueOf(), DATA.valueOf());
|
||||
assert_not_equals(e.data, DATA, "Object is cloned");
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage with Document object </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"postMessage with Document object: Throw a DataCloneError if message could not be cloned.";
|
||||
|
||||
var DATA = document;
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
assert_throws("DATA_CLONE_ERR", function()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, "*");
|
||||
});
|
||||
}, description);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage with Function object </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"postMessage with Function object: Throw a DataCloneError if message could not be cloned.";
|
||||
|
||||
var DATA = new Function();
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
assert_throws("DATA_CLONE_ERR", function()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, "*");
|
||||
});
|
||||
}, description);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,76 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage to same-origin iframe with MessagePort array [100 ports] </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: postMessage to same-origin iframe with MessagePort array containing 100 ports.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var TOTALPORTS = 100;
|
||||
var LocalPorts = [];
|
||||
var RemotePorts = [];
|
||||
var PassedResult = 0;
|
||||
var sum = 0;
|
||||
var TARGET = document.querySelector("iframe").contentWindow;
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
assert_own_property(window, "MessageChannel", "window");
|
||||
|
||||
var channels = [];
|
||||
|
||||
for (var i=0; i<TOTALPORTS; i++)
|
||||
{
|
||||
channels[i] = new MessageChannel();
|
||||
LocalPorts[i] = channels[i].port1;
|
||||
LocalPorts[i].foo = i;
|
||||
RemotePorts[i] = channels[i].port2;
|
||||
|
||||
LocalPorts[i].onmessage = t.step_func(function(e)
|
||||
{
|
||||
assert_equals(e.target.foo, e.data);
|
||||
|
||||
PassedResult++;
|
||||
sum += e.data;
|
||||
|
||||
if (PassedResult == TOTALPORTS)
|
||||
{
|
||||
assert_equals(sum, 4950);
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TARGET.postMessage("ports", "*", RemotePorts);
|
||||
|
||||
}, "MessageChannel is supported.");
|
||||
}
|
||||
|
||||
window.onmessage = function(e)
|
||||
{
|
||||
if (e.data === "ports")
|
||||
{
|
||||
for (var i=0; i<TOTALPORTS; i++)
|
||||
{
|
||||
LocalPorts[i].postMessage(LocalPorts[i].foo);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,76 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage to cross-origin iframe with MessagePort array [100 ports] </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: postMessage to cross-origin iframe with MessagePort array containing 100 ports.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var TOTALPORTS = 100;
|
||||
var LocalPorts = [];
|
||||
var RemotePorts = [];
|
||||
var PassedResult = 0;
|
||||
var sum = 0;
|
||||
var TARGET = document.querySelector("iframe").contentWindow;
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
assert_own_property(window, "MessageChannel", "window");
|
||||
|
||||
var channels = [];
|
||||
|
||||
for (var i=0; i<TOTALPORTS; i++)
|
||||
{
|
||||
channels[i] = new MessageChannel();
|
||||
LocalPorts[i] = channels[i].port1;
|
||||
LocalPorts[i].foo = i;
|
||||
RemotePorts[i] = channels[i].port2;
|
||||
|
||||
LocalPorts[i].onmessage = t.step_func(function(e)
|
||||
{
|
||||
assert_equals(e.target.foo, e.data);
|
||||
|
||||
PassedResult++;
|
||||
sum += e.data;
|
||||
|
||||
if (PassedResult == TOTALPORTS)
|
||||
{
|
||||
assert_equals(sum, 4950);
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TARGET.postMessage("ports", "*", RemotePorts);
|
||||
|
||||
}, "MessageChannel is supported.");
|
||||
}
|
||||
|
||||
window.onmessage = function(e)
|
||||
{
|
||||
if (e.data === "ports")
|
||||
{
|
||||
for (var i=0; i<TOTALPORTS; i++)
|
||||
{
|
||||
LocalPorts[i].postMessage(LocalPorts[i].foo);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,39 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage with arrays </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: Messages can be structured objects, e.g., arrays.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = [1,2,3,4,5,6,7,8];
|
||||
var TYPE = "object";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, "*");
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
assert_equals(typeof(e.data), TYPE);
|
||||
assert_array_equals(e.data, DATA);
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Cross-origin postMessage with targetOrigin == "*" </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: To send the message to the target regardless of origin, set the target origin to '*'.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var PORT = location.port !== "" ? ":" + location.port : "";
|
||||
var TARGET1 = document.querySelectorAll("iframe")[0];
|
||||
var TARGET2 = document.querySelectorAll("iframe")[1];
|
||||
var XORIGIN = "{{location[scheme]}}://{{domains[www]}}" + PORT;
|
||||
var SORIGIN = "{{location[scheme]}}://{{host}}" + PORT;
|
||||
var ExpectedResult = ["#1", XORIGIN, "#2", SORIGIN];
|
||||
var ActualResult = [];
|
||||
var loaded = 0;
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
loaded++;
|
||||
|
||||
if (loaded == 2)
|
||||
{
|
||||
TARGET1.contentWindow.postMessage("#1", "*");
|
||||
TARGET2.contentWindow.postMessage("#2", "*");
|
||||
}
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
ActualResult.push(e.data, e.origin);
|
||||
|
||||
if (ActualResult.length >= ExpectedResult.length)
|
||||
{
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage with duplicate transfer objects raises DataCloneError exception </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"postMessage with duplicate transfer objects raises DataCloneError exception.";
|
||||
|
||||
var DATA = "ports";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
assert_throws("DATA_CLONE_ERR", function()
|
||||
{
|
||||
assert_own_property(window, "MessageChannel", "window");
|
||||
var channel = new MessageChannel();
|
||||
TARGET.contentWindow.postMessage(DATA, "*", [channel.port1, channel.port1]);
|
||||
});
|
||||
}, description);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage with invalid targetOrigin raises SyntaxError exception </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"If the value of the targetOrigin argument is neither a single U+002A ASTERISK character (*), " +
|
||||
"a single U+002F SOLIDUS character (/), nor an absolute URL, then throw a SyntaxError exception " +
|
||||
"and abort the overall set of steps.";
|
||||
|
||||
var DATA = "InvalidOrigin";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
test(function()
|
||||
{
|
||||
assert_throws("SYNTAX_ERR", function()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, DATA);
|
||||
});
|
||||
}, description);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> postMessage with nested objects </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: Messages can be structured objects, e.g., nested objects.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = {foo: {bar: "wow"}};
|
||||
var TYPE = "object";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, "*");
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
assert_equals(typeof(e.data), TYPE);
|
||||
assert_equals(typeof(e.data.foo), TYPE);
|
||||
assert_object_equals(e.data, DATA);
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,51 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Same-origin: Origin of the target window doesn't match the given origin </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"Same-origin: If the origin of the target window doesn't match the given origin, " +
|
||||
"the message is discarded.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var PORT = location.port !== "" ? ":" + location.port : "";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
var XORIGIN = "{{location[scheme]}}://{{domains[www1]}}" + PORT;
|
||||
var SORIGIN = "{{location[scheme]}}://{{host}}" + PORT;
|
||||
var ExpectedResult = ["#0", SORIGIN, "#3", SORIGIN];
|
||||
var ActualResult = [];
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage("#0", SORIGIN);
|
||||
TARGET.contentWindow.postMessage("#1", "http://www.invalid-domain.com");
|
||||
TARGET.contentWindow.postMessage("#2", XORIGIN);
|
||||
TARGET.contentWindow.postMessage("#3", "*");
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
ActualResult.push(e.data, e.origin);
|
||||
|
||||
if (ActualResult.length >= ExpectedResult.length)
|
||||
{
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,51 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Cross-origin: Origin of the target window doesn't match the given origin </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"Cross-origin: If the origin of the target window doesn't match the given origin, " +
|
||||
"the message is discarded.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var PORT = location.port !== "" ? ":" + location.port : "";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
var XORIGIN = "{{location[scheme]}}://{{domains[www1]}}" + PORT;
|
||||
var SORIGIN = "{{location[scheme]}}://{{host}}" + PORT;
|
||||
var ExpectedResult = ["#0", XORIGIN, "#3", XORIGIN];
|
||||
var ActualResult = [];
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage("#0", XORIGIN);
|
||||
TARGET.contentWindow.postMessage("#1", "http://www.invalid-domain.com");
|
||||
TARGET.contentWindow.postMessage("#2", SORIGIN);
|
||||
TARGET.contentWindow.postMessage("#3", "*");
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
ActualResult.push(e.data, e.origin);
|
||||
|
||||
if (ActualResult.length >= ExpectedResult.length)
|
||||
{
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Same-origin postMessage with targetOrigin == "/" </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"To restrict the message to same-origin targets only, without needing to explicitly " +
|
||||
"state the origin, set the target origin to '/'.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = "/";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
var SORIGIN = location.protocol + "//" + location.host;
|
||||
var ExpectedResult = [DATA, SORIGIN];
|
||||
var ActualResult = [];
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
TARGET.contentWindow.postMessage(DATA, "/");
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
ActualResult.push(e.data, e.origin);
|
||||
assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,48 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Cross-origin postMessage with targetOrigin == "/" </title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id=log></div>
|
||||
|
||||
<div style="display:none">
|
||||
<iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
var description = "Test Description: " +
|
||||
"If the targetOrigin argument is a single literal U+002F SOLIDUS character (/), and " +
|
||||
"the Document of the Window object on which the method was invoked does not have the " +
|
||||
"same origin as the entry script's document, then abort these steps silently.";
|
||||
|
||||
var t = async_test(description);
|
||||
|
||||
var DATA = "NoExceptionRaised";
|
||||
var TARGET = document.querySelector("iframe");
|
||||
|
||||
function PostMessageTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
TARGET.contentWindow.postMessage("/", "/");
|
||||
TARGET.contentWindow.postMessage(DATA, "*");
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
TARGET.contentWindow.postMessage("ExceptionRaised", "*");
|
||||
}
|
||||
}
|
||||
|
||||
window.onmessage = t.step_func(function(e)
|
||||
{
|
||||
assert_equals(e.data, DATA, "e.data");
|
||||
t.done();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Child window for Web Messaging tests </title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
if (window.opener)
|
||||
{
|
||||
window.onload = function()
|
||||
{
|
||||
try
|
||||
{
|
||||
window.opener.postMessage("MSG_ONLOAD_FIRED", "*");
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onmessage = function(e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (typeof(e.data) == "object" && typeof(e.data.test) == "string")
|
||||
{
|
||||
eval(e.data.test);
|
||||
}
|
||||
else if (e.data == "*" || e.data == "/")
|
||||
{
|
||||
e.source.postMessage(e.data, e.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
e.source.postMessage(e.data, e.origin);
|
||||
}
|
||||
|
||||
if (e.data == "ports")
|
||||
{
|
||||
var total = e.ports.length;
|
||||
for (var i=0; i<total; i++)
|
||||
{
|
||||
e.ports[i].onmessage = function (evt)
|
||||
{
|
||||
evt.target.postMessage(evt.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
39
tests/wpt/web-platform-tests/webmessaging/support/compare.js
Normal file
39
tests/wpt/web-platform-tests/webmessaging/support/compare.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
function sameDate(d1, d2) {
|
||||
return (d1 instanceof Date && d2 instanceof Date && d1.valueOf() == d2.valueOf());
|
||||
}
|
||||
|
||||
function sameRE(r1, r2) {
|
||||
return (r1 instanceof RegExp && r2 instanceof RegExp && r1.toString() == r2.toString());
|
||||
}
|
||||
|
||||
function assert_array_equals_(observed, expected, msg) {
|
||||
if (observed.length == expected.length) {
|
||||
for (var i = 0; i < observed.length; i++) {
|
||||
if (observed[i] instanceof Date) {
|
||||
observed[i] = sameDate(observed[i], expected[i]);
|
||||
expected[i] = true;
|
||||
} else if (observed[i] instanceof RegExp) {
|
||||
observed[i] = sameRE(observed[i], expected[i]);
|
||||
expected[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert_array_equals(observed, expected, msg);
|
||||
}
|
||||
|
||||
function assert_object_equals_(observed, expected, msg) {
|
||||
for (var p in observed) {
|
||||
if (observed[p] instanceof Date) {
|
||||
observed[p] = sameDate(observed[p], expected[p]);
|
||||
expected[p] = true;
|
||||
} else if (observed[p] instanceof RegExp) {
|
||||
observed[p] = sameRE(observed[p], expected[p]);
|
||||
expected[p] = true;
|
||||
} else if (observed[p] instanceof Array || String(observed[p]) === '[object Object]') {
|
||||
observed[p] = String(observed[p]) === String(expected[p]);
|
||||
expected[p] = true;
|
||||
}
|
||||
assert_equals(observed[p], expected[p], msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<title>resolving broken url</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_throws('SYNTAX_ERR', function() {
|
||||
postMessage('', 'http://foo bar', []);
|
||||
}, 'should have failed to resolve');
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>resolving url with stuff in host-specific</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', location.protocol + '//' + location.host + '//', []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<title>resolving 'example.org'</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_throws('SYNTAX_ERR', function() {
|
||||
postMessage('', 'example.org', []);
|
||||
}, 'targetOrigin is not an absolute url');
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>special value '/'</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', '/', []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, '');
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>resolving a same origin targetOrigin</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', location.protocol + '//' + location.host, []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, '');
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>resolving a same origin targetOrigin with trailing slash</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', location.protocol + '//' + location.host + '/', []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, '');
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>targetOrigin '*'</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', '*', []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, '');
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
113
tests/wpt/web-platform-tests/webmessaging/with-ports/010.html
Normal file
113
tests/wpt/web-platform-tests/webmessaging/with-ports/010.html
Normal file
|
@ -0,0 +1,113 @@
|
|||
<!doctype html>
|
||||
<title>message clone</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../support/compare.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var err = new Error('foo');
|
||||
var date = new Date();
|
||||
|
||||
var test_array = [ undefined,
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
1,
|
||||
NaN,
|
||||
Infinity,
|
||||
'foo',
|
||||
date,
|
||||
/foo/,
|
||||
null/*self*/,
|
||||
null/*err*/];
|
||||
|
||||
var cloned_array = [ undefined,
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
1,
|
||||
NaN,
|
||||
Infinity,
|
||||
'foo',
|
||||
date,
|
||||
/foo/,
|
||||
null/*self*/,
|
||||
null/*err*/];
|
||||
|
||||
var test_object = {a: undefined,
|
||||
b: null,
|
||||
c: false,
|
||||
d: true,
|
||||
e: 1,
|
||||
f: NaN,
|
||||
g: Infinity,
|
||||
h: 'foo',
|
||||
i: date,
|
||||
j: /foo/,
|
||||
k: null/*self*/,
|
||||
l: [],
|
||||
m: {},
|
||||
n: null /*err*/};
|
||||
|
||||
var cloned_object = {a:undefined, b:null, c:false, d:true, e:1, f:NaN, g:Infinity, h:'foo', i: date, j: /foo/, k:null, l: [], m: {}, n:null};
|
||||
|
||||
var tests = [undefined, null,
|
||||
false, true,
|
||||
1, NaN, Infinity,
|
||||
'foo',
|
||||
date,
|
||||
/foo/,
|
||||
/* ImageData, File, FileData, FileList, */
|
||||
null /*self*/,
|
||||
test_array,
|
||||
test_object,
|
||||
null /*err*/];
|
||||
|
||||
for (var i = 0; i < tests.length; ++i) {
|
||||
postMessage(tests[i], '*', []);
|
||||
}
|
||||
|
||||
var test_undefined = async_test('undefined');
|
||||
var test_null = async_test('null');
|
||||
var test_false = async_test('false');
|
||||
var test_true = async_test('true');
|
||||
var test_1 = async_test('1');
|
||||
var test_NaN = async_test('NaN');
|
||||
var test_Infinity = async_test('Infinity');
|
||||
var test_string = async_test('string');
|
||||
var test_date = async_test('date');
|
||||
var test_regex = async_test('regex');
|
||||
var test_self = async_test('self');
|
||||
var test_array = async_test('array');
|
||||
var test_object = async_test('object');
|
||||
var test_error = async_test('error');
|
||||
var test_unreached = async_test('unreached');
|
||||
|
||||
var j = 0;
|
||||
onmessage = function(e) {
|
||||
switch (j) {
|
||||
case 0: test_undefined.step(function() { assert_equals(e.data, undefined); this.done(); }); break;
|
||||
case 1: test_null.step(function() { assert_equals(e.data, null); this.done(); }); break;
|
||||
case 2: test_false.step(function() { assert_false(e.data); this.done(); }); break;
|
||||
case 3: test_true.step(function() { assert_true(e.data); this.done(); }); break;
|
||||
case 4: test_1.step(function() { assert_equals(e.data, 1); this.done(); }); break;
|
||||
case 5: test_NaN.step(function() { assert_equals(e.data, NaN); this.done(); }); break;
|
||||
case 6: test_Infinity.step(function() { assert_equals(e.data, Infinity); this.done(); }); break;
|
||||
case 7: test_string.step(function() { assert_equals(e.data, 'foo'); this.done(); }); break;
|
||||
case 8: test_date.step(function() { assert_true(sameDate(e.data, date)); this.done(); }); break;
|
||||
case 9: test_regex.step(function() { assert_equals('' + e.data, '/foo/'); assert_equals(e.data instanceof RegExp, true, 'e.data instanceof RegExp'); this.done(); }); break;
|
||||
// not testing it any more, as cloning host objects will now raise exceptions. TODO: add (exceptional) tests for these.
|
||||
case 10: test_self.step(function() { assert_equals(e.data, null); this.done(); }); break;
|
||||
case 11: test_array.step(function() { assert_array_equals_(e.data, cloned_array, 'array'); this.done(); }); break;
|
||||
case 12: test_object.step(function() { assert_object_equals_(e.data, cloned_object, 'object'); this.done(); }); break;
|
||||
case 13:
|
||||
test_error.step(function() { assert_equals(e.data, null, 'new Error()'); this.done(); });
|
||||
setTimeout(test_unreached.step_func(function() { assert_equals(j, 14); this.done(); }), 50);
|
||||
break;
|
||||
default: test_unreached.step(function() { assert_unreached('got an unexpected message event ('+i+')'); });
|
||||
};
|
||||
j++;
|
||||
}
|
||||
|
||||
|
||||
</script>
|
|
@ -0,0 +1,29 @@
|
|||
<!doctype html>
|
||||
<title>posting an imagedata (from a cloned canvas) in an array</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
|
||||
var canvas = document.createElement('canvas');
|
||||
var clone = canvas.cloneNode(true);
|
||||
var ctx = clone.getContext('2d');
|
||||
var imagedata = ctx.getImageData(0, 0, 300, 150);
|
||||
postMessage([imagedata], '*', []);
|
||||
|
||||
onmessage = this.step_func(function(e) {
|
||||
function processPixels(imagedata) {
|
||||
var pixeldata = imagedata.data;
|
||||
for (var i = 0; i < pixeldata.length; i = i+4) {
|
||||
pixeldata[i] = 128;
|
||||
assert_equals(pixeldata[i], 128);
|
||||
}
|
||||
}
|
||||
processPixels(e.data[0]);
|
||||
this.done();
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<title>loop in array in structured clone</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var x = [];
|
||||
x[0] = x;
|
||||
postMessage(x, '*', []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, e.data[0]);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<title>loop in object in structured clone</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var x = {};
|
||||
x.foo = x;
|
||||
postMessage(x, '*', []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, e.data.foo);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<title>structured clone vs reference</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function(t) {
|
||||
var x = [];
|
||||
y = [x,x];
|
||||
postMessage(y, '*', []);
|
||||
onmessage = t.step_func(function(e) {
|
||||
assert_equals(e.data[0], e.data[1], 'e.data[0] === e.data[1]');
|
||||
assert_not_equals(e.data[0], x, 'e.data[0] !== x');
|
||||
t.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,15 @@
|
|||
<!doctype html>
|
||||
<title>different origin</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', 'http://example.org', []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_unreached();
|
||||
});
|
||||
setTimeout(this.step_func(function(){ this.done(); }), 50);
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<title>origin of the script that invoked the method, data:</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="data:text/html,"></iframe>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
window[0].postMessage('', '*', []);
|
||||
window[0].onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<title>origin of the script that invoked the method, about:blank</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="about:blank"></iframe>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
window[0].postMessage('', '*', []);
|
||||
window[0].onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<title>origin of the script that invoked the method, javascript:</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="javascript:''"></iframe>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
window[0].postMessage('', '*', []);
|
||||
window[0].onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<title>origin of the script that invoked the method, scheme/host/port</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="../without-ports/019-1.html"></iframe>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
window[0].postMessage('', location.protocol.toUpperCase() + '//' + location.host.toUpperCase() + '/', []);
|
||||
window[0].onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<title>cross-origin test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="../without-ports/020-1.html"></iframe>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var iframe = document.createElement('iframe');
|
||||
var url_prefix = location.href.replace('://', '://www1.').replace(/\/with(out)?-ports\/[^\/]+$/, '');
|
||||
var url = url_prefix + '/without-ports/020-1.html';
|
||||
iframe.src = url;
|
||||
document.body.appendChild(iframe);
|
||||
</script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var t = async_test();
|
||||
onload = t.step_func(function() {
|
||||
window[0].postMessage(1, location.href, []);
|
||||
window[1].postMessage(2, url, []);
|
||||
var i = 0;
|
||||
onmessage = t.step_func(function(e) {
|
||||
i++;
|
||||
assert_equals(e.data[0], i);
|
||||
assert_equals(e.data[1], location.protocol + '//' + location.host);
|
||||
if (i === 2) {
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
setTimeout(t.step_func(function() { assert_unreached("Only got " + i + " events before timeout, expected 2") }), 1000);
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<title>cross-origin test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="../without-ports/020-1.html"></iframe>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var iframe = document.createElement('iframe');
|
||||
var url_prefix = location.href.replace('://', '://www1.').replace(/\/with(out)?-ports\/[^\/]+$/, '');
|
||||
var url = url_prefix + '/without-ports/020-1.html';
|
||||
iframe.src = url;
|
||||
document.body.appendChild(iframe);
|
||||
</script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var t = async_test();
|
||||
onload = t.step_func(function() {
|
||||
window[0].postMessage(1, '*', []);
|
||||
window[1].postMessage(2, '*', []);
|
||||
var i = 0;
|
||||
onmessage = t.step_func(function(e) {
|
||||
i++;
|
||||
assert_equals(e.data[0], i);
|
||||
assert_equals(e.data[1], location.protocol + '//' + location.host);
|
||||
if (i === 2) {
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
setTimeout(t.step_func(function() { assert_unreached("Only got " + i + " events before timeout, expected 2") }), 1000);
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<!doctype html>
|
||||
<title>null ports</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function(t) {
|
||||
postMessage('', '*', null);
|
||||
onmessage = t.step_func(function(e) {
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<!doctype html>
|
||||
<title>undefined as ports</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', '*', undefined);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<title>1 as ports</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_throws(new TypeError(), function() {
|
||||
postMessage('', '*', 1);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<title>object with length as transferable</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_throws(new TypeError(), function() {
|
||||
postMessage('', '*', {length:1});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<title>message channel as ports</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function(t) {
|
||||
var channel = new MessageChannel();
|
||||
channel[0] = channel.port1;
|
||||
channel[1] = channel.port2;
|
||||
channel.length = 2;
|
||||
postMessage('', '*', channel);
|
||||
onmessage = t.step_func(function(e) {
|
||||
assert_equals(e.ports.length, 2);
|
||||
t.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<title>resolving broken url</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_throws('SYNTAX_ERR', function() {
|
||||
postMessage('', 'http://foo bar');
|
||||
}, 'should have failed to resolve');
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>resolving url with stuff in host-specific</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', location.protocol + '//' + location.host + '//');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<title>resolving 'example.org'</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_throws('SYNTAX_ERR', function() {
|
||||
postMessage('', 'example.org');
|
||||
}, 'targetOrigin is not an absolute url');
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>special value '/'</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', '/');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, '');
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>resolving a same origin targetOrigin</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', location.protocol + '//' + location.host);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, '');
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>resolving a same origin targetOrigin with trailing slash</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', location.protocol + '//' + location.host + '/');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, '');
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>targetOrigin '*'</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', '*');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, '');
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<title>just one argument</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_throws(new TypeError(), function() {
|
||||
postMessage('');
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<title>zero arguments</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_throws(new TypeError(), function() {
|
||||
postMessage();
|
||||
});
|
||||
});
|
||||
</script>
|
112
tests/wpt/web-platform-tests/webmessaging/without-ports/010.html
Normal file
112
tests/wpt/web-platform-tests/webmessaging/without-ports/010.html
Normal file
|
@ -0,0 +1,112 @@
|
|||
<!doctype html>
|
||||
<title>message clone</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../support/compare.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var err = new Error('foo');
|
||||
var date = new Date();
|
||||
|
||||
var test_array = [ undefined,
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
1,
|
||||
NaN,
|
||||
Infinity,
|
||||
'foo',
|
||||
date,
|
||||
/foo/,
|
||||
null/*self*/,
|
||||
null/*err*/];
|
||||
|
||||
var cloned_array = [ undefined,
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
1,
|
||||
NaN,
|
||||
Infinity,
|
||||
'foo',
|
||||
date,
|
||||
/foo/,
|
||||
null/*self*/,
|
||||
null/*err*/];
|
||||
|
||||
var test_object = {a: undefined,
|
||||
b: null,
|
||||
c: false,
|
||||
d: true,
|
||||
e: 1,
|
||||
f: NaN,
|
||||
g: Infinity,
|
||||
h: 'foo',
|
||||
i: date,
|
||||
j: /foo/,
|
||||
k: null/*self*/,
|
||||
l: [],
|
||||
m: {},
|
||||
n: null /*err*/};
|
||||
|
||||
var cloned_object = {a:undefined, b:null, c:false, d:true, e:1, f:NaN, g:Infinity, h:'foo', i: date, j: /foo/, k:null, l: [], m: {}, n:null};
|
||||
|
||||
var tests = [undefined, null,
|
||||
false, true,
|
||||
1, NaN, Infinity,
|
||||
'foo',
|
||||
date,
|
||||
/foo/,
|
||||
/* ImageData, File, FileData, FileList, */
|
||||
null /*self*/,
|
||||
test_array,
|
||||
test_object,
|
||||
null /*err*/];
|
||||
|
||||
for (var i = 0; i < tests.length; ++i) {
|
||||
postMessage(tests[i], '*');
|
||||
}
|
||||
|
||||
var test_undefined = async_test('undefined');
|
||||
var test_null = async_test('null');
|
||||
var test_false = async_test('false');
|
||||
var test_true = async_test('true');
|
||||
var test_1 = async_test('1');
|
||||
var test_NaN = async_test('NaN');
|
||||
var test_Infinity = async_test('Infinity');
|
||||
var test_string = async_test('string');
|
||||
var test_date = async_test('date');
|
||||
var test_regex = async_test('regex');
|
||||
var test_self = async_test('self');
|
||||
var test_array = async_test('array');
|
||||
var test_object = async_test('object');
|
||||
var test_error = async_test('error');
|
||||
var test_unreached = async_test('unreached');
|
||||
|
||||
var j = 0;
|
||||
onmessage = function(e) {
|
||||
switch (j) {
|
||||
case 0: test_undefined.step(function() { assert_equals(e.data, undefined); this.done(); }); break;
|
||||
case 1: test_null.step(function() { assert_equals(e.data, null); this.done(); }); break;
|
||||
case 2: test_false.step(function() { assert_false(e.data); this.done(); }); break;
|
||||
case 3: test_true.step(function() { assert_true(e.data); this.done(); }); break;
|
||||
case 4: test_1.step(function() { assert_equals(e.data, 1); this.done(); }); break;
|
||||
case 5: test_NaN.step(function() { assert_equals(e.data, NaN); this.done(); }); break;
|
||||
case 6: test_Infinity.step(function() { assert_equals(e.data, Infinity); this.done(); }); break;
|
||||
case 7: test_string.step(function() { assert_equals(e.data, 'foo'); this.done(); }); break;
|
||||
case 8: test_date.step(function() { assert_true(sameDate(e.data, date)); this.done(); }); break;
|
||||
case 9: test_regex.step(function() { assert_equals('' + e.data, '/foo/'); assert_equals(e.data instanceof RegExp, true, 'e.data instanceof RegExp'); this.done(); }); break;
|
||||
// not testing it any more, as cloning host objects will now raise exceptions. TODO: add (exceptional) tests for these.
|
||||
case 10: test_self.step(function() { assert_equals(e.data, null); this.done(); }); break;
|
||||
case 11: test_array.step(function() { assert_array_equals_(e.data, cloned_array, 'array'); this.done(); }); break;
|
||||
case 12: test_object.step(function() { assert_object_equals_(e.data, cloned_object, 'object'); this.done(); }); break;
|
||||
case 13:
|
||||
test_error.step(function() { assert_equals(e.data, null, 'new Error()'); this.done(); });
|
||||
setTimeout(test_unreached.step_func(function() { assert_equals(j, 14); this.done(); }), 50);
|
||||
break;
|
||||
default: test_unreached.step(function() { assert_unreached('got an unexpected message event ('+i+')'); });
|
||||
};
|
||||
j++;
|
||||
}
|
||||
|
||||
</script>
|
|
@ -0,0 +1,29 @@
|
|||
<!doctype html>
|
||||
<title>posting an imagedata (from a cloned canvas) in an array</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
|
||||
var canvas = document.createElement('canvas');
|
||||
var clone = canvas.cloneNode(true);
|
||||
var ctx = clone.getContext('2d');
|
||||
var imagedata = ctx.getImageData(0, 0, 300, 150);
|
||||
postMessage([imagedata], '*');
|
||||
|
||||
onmessage = this.step_func(function(e) {
|
||||
function processPixels(imagedata) {
|
||||
var pixeldata = imagedata.data;
|
||||
for (var i = 0; i < pixeldata.length; i = i+4) {
|
||||
pixeldata[i] = 128;
|
||||
assert_equals(pixeldata[i], 128);
|
||||
}
|
||||
}
|
||||
processPixels(e.data[0]);
|
||||
this.done();
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<title>loop in array in structured clone</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var x = [];
|
||||
x[0] = x;
|
||||
postMessage(x, '*');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, e.data[0]);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<title>loop in object in structured clone</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var x = {};
|
||||
x.foo = x;
|
||||
postMessage(x, '*');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data, e.data.foo);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<title>structured clone vs reference</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
async_test(function(t) {
|
||||
var x = [];
|
||||
y = [x,x];
|
||||
postMessage(y, '*');
|
||||
onmessage = t.step_func(function(e) {
|
||||
assert_equals(e.data[0], e.data[1], 'e.data[0] === e.data[1]');
|
||||
assert_not_equals(e.data[0], x, 'e.data[0] !== x');
|
||||
t.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,15 @@
|
|||
<!doctype html>
|
||||
<title>different origin</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
postMessage('', 'http://example.org', []);
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_unreached();
|
||||
});
|
||||
setTimeout(this.step_func(function(){ this.done(); }), 50);
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<title>origin of the script that invoked the method, data:</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="data:text/html,"></iframe>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
window[0].postMessage('', '*');
|
||||
window[0].onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<title>origin of the script that invoked the method, about:blank</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="about:blank"></iframe>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
window[0].postMessage('', '*');
|
||||
window[0].onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<title>origin of the script that invoked the method, javascript:</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="javascript:''"></iframe>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
window[0].postMessage('', '*');
|
||||
window[0].onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
<!-- blank -->
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<title>origin of the script that invoked the method, scheme/host/port</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="../without-ports/019-1.html"></iframe>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
window[0].postMessage('', location.protocol.toUpperCase() + '//' + location.host.toUpperCase() + '/');
|
||||
window[0].onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.origin, location.protocol + '//' + location.host);
|
||||
assert_array_equals(e.ports, []);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<script>
|
||||
onmessage = function(e) {
|
||||
parent.postMessage([e.data, e.origin], '*');
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<title>cross-origin test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="../without-ports/020-1.html"></iframe>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var iframe = document.createElement('iframe');
|
||||
var url_prefix = location.href.replace('://', '://www1.').replace(/\/with(out)?-ports\/[^\/]+$/, '');
|
||||
var url = url_prefix + '/without-ports/020-1.html';
|
||||
iframe.src = url;
|
||||
document.body.appendChild(iframe);
|
||||
</script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var t = async_test();
|
||||
onload = t.step_func(function() {
|
||||
window[0].postMessage(1, location.href);
|
||||
window[1].postMessage(2, url);
|
||||
var i = 0;
|
||||
onmessage = t.step_func(function(e) {
|
||||
i++;
|
||||
assert_equals(e.data[0], i);
|
||||
assert_equals(e.data[1], location.protocol + '//' + location.host);
|
||||
if (i == 2) {
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
setTimeout(t.step_func(function() {assert_unreached("Only got " + i + " events before timeout, expected 2")}), 1000);
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<title>cross-origin test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe src="../without-ports/020-1.html"></iframe>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var iframe = document.createElement('iframe');
|
||||
var url_prefix = location.href.replace('://', '://www1.').replace(/\/with(out)?-ports\/[^\/]+$/, '');
|
||||
var url = url_prefix + '/without-ports/020-1.html';
|
||||
iframe.src = url;
|
||||
document.body.appendChild(iframe);
|
||||
</script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var t = async_test();
|
||||
onload = t.step_func(function() {
|
||||
window[0].postMessage(1, '*');
|
||||
window[1].postMessage(2, '*');
|
||||
var i = 0;
|
||||
onmessage = t.step_func(function(e) {
|
||||
i++;
|
||||
assert_equals(e.data[0], i);
|
||||
assert_equals(e.data[1], location.protocol + '//' + location.host);
|
||||
if (i === 2) {
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
setTimeout(t.step_func(function() { assert_unreached("Only got " + i + " events before timeout, expected 2")}), 1000);
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<!doctype html>
|
||||
<title>Object cloning: own properties only, don't follow prototype</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var Parent = function(){
|
||||
this.c = "xyz";
|
||||
};
|
||||
|
||||
var Child = function(a, b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
};
|
||||
Child.prototype = new Parent;
|
||||
|
||||
async_test(function() {
|
||||
var obj = new Child(1, 2);
|
||||
var ch = new MessageChannel();
|
||||
ch.port1.onmessage = this.step_func(function(e) {
|
||||
for (var i in e.data.obj)
|
||||
assert_not_equals(i, 'c');
|
||||
this.done();
|
||||
});
|
||||
ch.port2.start();
|
||||
ch.port2.postMessage({obj: obj});
|
||||
});
|
||||
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<title>Object cloning: throw an exception if function values encountered</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var obj = { f : function(){}};
|
||||
var ch = new MessageChannel();
|
||||
ch.port1.onmessage = function(){};
|
||||
ch.port2.start();
|
||||
assert_throws('DATA_CLONE_ERR', function() { ch.port2.postMessage({obj: obj}); });
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,10 @@
|
|||
var ch = new MessageChannel();
|
||||
var pass1 = false;
|
||||
var pass2 = false;
|
||||
try {
|
||||
pass1 = ch.port1 instanceof MessagePort;
|
||||
try { var p = new MessagePort(); } catch(e) { pass2 = e instanceof TypeError; }
|
||||
} catch (e) {
|
||||
;
|
||||
}
|
||||
postMessage([pass1, pass2]);
|
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<title>MessagePort constructor properties</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var ch = new MessageChannel();
|
||||
assert_true(ch.port1 instanceof MessagePort, "MessageChannel's port not an instance of MessagePort");
|
||||
assert_throws(new TypeError(), function () { var p = new MessagePort();}, "MessagePort is [[Callable]]");
|
||||
var w = new Worker("025-1.js");
|
||||
w.onmessage = this.step_func(function(e) {
|
||||
assert_true(e.data[0], "Worker MessageChannel's port not an instance of MessagePort");
|
||||
assert_true(e.data[1], "Worker MessagePort is [[Callable]]");
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<title>Cloning objects with getter properties</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var obj = {};
|
||||
obj.__defineGetter__( "field", function(){ throw new Error("getter_should_propagate_exceptions"); });
|
||||
|
||||
assert_throws(new Error("getter_should_propagate_exceptions"), function() {
|
||||
postMessage(obj, '*');
|
||||
});
|
||||
this.done();
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<title>Cloning objects, preserving sharing</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var obj1 = {o: 1};
|
||||
var obj2 = {d: obj1};
|
||||
var obj3 = {d: obj1};
|
||||
var obj_dag = {b: obj2, c: obj3};
|
||||
|
||||
postMessage(obj_dag, '*');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data.b.d, e.data.c.d);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<title>Cloning objects, preserving sharing #2</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<canvas id="a" width=30 height=30></canvas>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var img_data = null;
|
||||
var canvas = document.getElementsByTagName("canvas")[0];
|
||||
var context = canvas.getContext("2d");
|
||||
img_data = context.getImageData(0, 0, 30, 30);
|
||||
var obj = {a: img_data, b: {c: img_data, d: 3}};
|
||||
postMessage(obj, '*');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data.a, e.data.b.c);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<title>Check that getters don't linger after deletion wrt cloning</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var obj = {};
|
||||
obj.__defineGetter__( "a", function(){ return 2; } );
|
||||
obj.__defineSetter__( "a", function(v){ return; } );
|
||||
delete obj.a;
|
||||
obj.a = 2;
|
||||
|
||||
postMessage(obj, '*');
|
||||
onmessage = this.step_func(function(e) {
|
||||
assert_equals(e.data.a, 2);
|
||||
this.done();
|
||||
});
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue