summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webmessaging
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/webmessaging')
-rw-r--r--testing/web-platform/tests/webmessaging/Channel_postMessage_DataCloneErr.htm26
-rw-r--r--testing/web-platform/tests/webmessaging/Channel_postMessage_clone_port.htm42
-rw-r--r--testing/web-platform/tests/webmessaging/Channel_postMessage_clone_port_error.htm26
-rw-r--r--testing/web-platform/tests/webmessaging/Channel_postMessage_event_properties.htm36
-rw-r--r--testing/web-platform/tests/webmessaging/Channel_postMessage_ports_readonly_array.htm38
-rw-r--r--testing/web-platform/tests/webmessaging/Channel_postMessage_target_source.htm35
-rw-r--r--testing/web-platform/tests/webmessaging/MessageEvent.html21
-rw-r--r--testing/web-platform/tests/webmessaging/MessageEvent_properties.htm32
-rw-r--r--testing/web-platform/tests/webmessaging/MessagePort_initial_disabled.htm13
-rw-r--r--testing/web-platform/tests/webmessaging/MessagePort_onmessage_start.htm13
-rw-r--r--testing/web-platform/tests/webmessaging/OWNERS6
-rw-r--r--testing/web-platform/tests/webmessaging/README.md10
-rw-r--r--testing/web-platform/tests/webmessaging/Transferred_objects_unusable.sub.htm60
-rw-r--r--testing/web-platform/tests/webmessaging/event.data.sub.htm58
-rw-r--r--testing/web-platform/tests/webmessaging/event.origin.sub.htm56
-rw-r--r--testing/web-platform/tests/webmessaging/event.ports.sub.htm49
-rw-r--r--testing/web-platform/tests/webmessaging/event.source.htm51
-rw-r--r--testing/web-platform/tests/webmessaging/event.source.xorigin.sub.htm51
-rw-r--r--testing/web-platform/tests/webmessaging/message-channels/001.html17
-rw-r--r--testing/web-platform/tests/webmessaging/message-channels/002.html14
-rw-r--r--testing/web-platform/tests/webmessaging/message-channels/003.html19
-rw-r--r--testing/web-platform/tests/webmessaging/message-channels/004-1.html8
-rw-r--r--testing/web-platform/tests/webmessaging/message-channels/004-2.html10
-rw-r--r--testing/web-platform/tests/webmessaging/message-channels/004.html22
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_ArrayBuffer.sub.htm44
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_Date.sub.htm40
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_Document.htm36
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_Function.htm36
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_MessagePorts_sorigin.htm76
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_MessagePorts_xorigin.sub.htm76
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_arrays.sub.htm39
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_asterisk_xorigin.sub.htm55
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_dup_transfer_objects.htm38
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_invalid_targetOrigin.htm38
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_objects.sub.htm40
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_origin_mismatch.sub.htm51
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_origin_mismatch_xorigin.sub.htm51
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_solidus_sorigin.htm43
-rw-r--r--testing/web-platform/tests/webmessaging/postMessage_solidus_xorigin.sub.htm48
-rw-r--r--testing/web-platform/tests/webmessaging/support/ChildWindowPostMessage.htm58
-rw-r--r--testing/web-platform/tests/webmessaging/support/compare.js39
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/001.html12
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/002.html14
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/003.html12
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/004.html14
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/005.html14
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/006.html14
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/007.html14
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/010.html113
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/011.html29
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/012.html16
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/013.html17
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/014.html17
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/015.html15
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/016.html18
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/017.html18
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/018.html18
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/019.html18
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/020.html30
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/021.html30
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/023.html15
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/024.html15
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/025.html13
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/026.html13
-rw-r--r--testing/web-platform/tests/webmessaging/with-ports/027.html19
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/001.html12
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/002.html14
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/003.html12
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/004.html14
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/005.html14
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/006.html14
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/007.html14
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/008.html12
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/009.html12
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/010.html112
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/011.html29
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/012.html16
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/013.html17
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/014.html17
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/015.html15
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/016.html18
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/017.html18
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/018.html17
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/019-1.html1
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/019.html18
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/020-1.html5
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/020.html30
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/021.html30
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/023.html29
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/024.html14
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/025-1.js15
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/025.html13
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/026.html16
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/027.html19
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/028.html19
-rw-r--r--testing/web-platform/tests/webmessaging/without-ports/029.html20
96 files changed, 2635 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webmessaging/Channel_postMessage_DataCloneErr.htm b/testing/web-platform/tests/webmessaging/Channel_postMessage_DataCloneErr.htm
new file mode 100644
index 000000000..9f4cd6b9b
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/Channel_postMessage_DataCloneErr.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/Channel_postMessage_clone_port.htm b/testing/web-platform/tests/webmessaging/Channel_postMessage_clone_port.htm
new file mode 100644
index 000000000..0e2e2fcd1
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/Channel_postMessage_clone_port.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/Channel_postMessage_clone_port_error.htm b/testing/web-platform/tests/webmessaging/Channel_postMessage_clone_port_error.htm
new file mode 100644
index 000000000..c33feaa5f
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/Channel_postMessage_clone_port_error.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/Channel_postMessage_event_properties.htm b/testing/web-platform/tests/webmessaging/Channel_postMessage_event_properties.htm
new file mode 100644
index 000000000..4be7203fc
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/Channel_postMessage_event_properties.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/Channel_postMessage_ports_readonly_array.htm b/testing/web-platform/tests/webmessaging/Channel_postMessage_ports_readonly_array.htm
new file mode 100644
index 000000000..de2952dc1
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/Channel_postMessage_ports_readonly_array.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/Channel_postMessage_target_source.htm b/testing/web-platform/tests/webmessaging/Channel_postMessage_target_source.htm
new file mode 100644
index 000000000..4b00e68d4
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/Channel_postMessage_target_source.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/MessageEvent.html b/testing/web-platform/tests/webmessaging/MessageEvent.html
new file mode 100644
index 000000000..e95b3efc2
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/MessageEvent.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>MessageEvent</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id=log></div>
+<script>
+var prefixes = ['moz', 'ms', 'o', 'webkit'];
+prefixes.forEach(function(prefix) {
+ var name = prefix + "InitMessageEvent";
+
+ test(function() {
+ assert_false(name in MessageEvent.prototype);
+ }, name + " on the prototype");
+
+ test(function() {
+ var event = new MessageEvent("message");
+ assert_false(name in event);
+ }, name + " on the instance");
+});
+</script>
diff --git a/testing/web-platform/tests/webmessaging/MessageEvent_properties.htm b/testing/web-platform/tests/webmessaging/MessageEvent_properties.htm
new file mode 100644
index 000000000..389add98d
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/MessageEvent_properties.htm
@@ -0,0 +1,32 @@
+<!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="do_test()" src="./support/ChildWindowPostMessage.htm"></iframe>
+</div>
+
+<script>
+async_test(function() {
+ window.do_test = this.step_func(function() {
+ document.querySelector("iframe").contentWindow.postMessage("foo", "*");
+ })
+
+ window.addEventListener("message", this.step_func_done(function(e) {
+ e.preventDefault();
+ assert_true(e instanceof MessageEvent, "Should be MessageEvent");
+ assert_equals(e.type, "message");
+ assert_false(e.bubbles, "bubbles");
+ assert_false(e.cancelable, "cancelable");
+ assert_false(e.defaultPrevented, "defaultPrevented");
+ }), false);
+});
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/webmessaging/MessagePort_initial_disabled.htm b/testing/web-platform/tests/webmessaging/MessagePort_initial_disabled.htm
new file mode 100644
index 000000000..58447dc2d
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/MessagePort_initial_disabled.htm
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<title>MessageChannel: port message queue is initially disabled</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.port2.addEventListener("message", t.unreached_func(), true);
+ channel.port1.postMessage("ping");
+ setTimeout(t.step_func_done(), 100);
+});
+</script>
diff --git a/testing/web-platform/tests/webmessaging/MessagePort_onmessage_start.htm b/testing/web-platform/tests/webmessaging/MessagePort_onmessage_start.htm
new file mode 100644
index 000000000..dc4dc1e54
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/MessagePort_onmessage_start.htm
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<title>MessageChannel: port.onmessage enables message queue</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.port2.onmessage = t.step_func_done();
+ channel.port1.postMessage("ping");
+ setTimeout(t.unreached_func(), 100);
+});
+</script>
diff --git a/testing/web-platform/tests/webmessaging/OWNERS b/testing/web-platform/tests/webmessaging/OWNERS
new file mode 100644
index 000000000..bff9fad87
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/OWNERS
@@ -0,0 +1,6 @@
+@zqzhang
+@sideshowbarker
+@plehegar
+@aogilvie
+@Ms2ger
+@jdm
diff --git a/testing/web-platform/tests/webmessaging/README.md b/testing/web-platform/tests/webmessaging/README.md
new file mode 100644
index 000000000..06b3a1147
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/README.md
@@ -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/>.
+
diff --git a/testing/web-platform/tests/webmessaging/Transferred_objects_unusable.sub.htm b/testing/web-platform/tests/webmessaging/Transferred_objects_unusable.sub.htm
new file mode 100644
index 000000000..55c3dbdba
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/Transferred_objects_unusable.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/event.data.sub.htm b/testing/web-platform/tests/webmessaging/event.data.sub.htm
new file mode 100644
index 000000000..97584c4a3
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/event.data.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/event.origin.sub.htm b/testing/web-platform/tests/webmessaging/event.origin.sub.htm
new file mode 100644
index 000000000..ce944ae34
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/event.origin.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/event.ports.sub.htm b/testing/web-platform/tests/webmessaging/event.ports.sub.htm
new file mode 100644
index 000000000..a4ca24b15
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/event.ports.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/event.source.htm b/testing/web-platform/tests/webmessaging/event.source.htm
new file mode 100644
index 000000000..e270d7def
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/event.source.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/event.source.xorigin.sub.htm b/testing/web-platform/tests/webmessaging/event.source.xorigin.sub.htm
new file mode 100644
index 000000000..6190c9624
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/event.source.xorigin.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/message-channels/001.html b/testing/web-platform/tests/webmessaging/message-channels/001.html
new file mode 100644
index 000000000..12fac8229
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/message-channels/001.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>
diff --git a/testing/web-platform/tests/webmessaging/message-channels/002.html b/testing/web-platform/tests/webmessaging/message-channels/002.html
new file mode 100644
index 000000000..8b7126718
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/message-channels/002.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/message-channels/003.html b/testing/web-platform/tests/webmessaging/message-channels/003.html
new file mode 100644
index 000000000..7addaeb0f
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/message-channels/003.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/message-channels/004-1.html b/testing/web-platform/tests/webmessaging/message-channels/004-1.html
new file mode 100644
index 000000000..b5dd282cd
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/message-channels/004-1.html
@@ -0,0 +1,8 @@
+<!doctype html>
+<title>004-1</title>
+<script>
+onmessage = function(e) {
+ var port = e.ports[0];
+ port.postMessage(e.data);
+}
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/webmessaging/message-channels/004-2.html b/testing/web-platform/tests/webmessaging/message-channels/004-2.html
new file mode 100644
index 000000000..1b8ef0a7a
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/message-channels/004-2.html
@@ -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> \ No newline at end of file
diff --git a/testing/web-platform/tests/webmessaging/message-channels/004.html b/testing/web-platform/tests/webmessaging/message-channels/004.html
new file mode 100644
index 000000000..19921fef8
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/message-channels/004.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_ArrayBuffer.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_ArrayBuffer.sub.htm
new file mode 100644
index 000000000..457cf94fa
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_ArrayBuffer.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_Date.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_Date.sub.htm
new file mode 100644
index 000000000..0f89738f3
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_Date.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_Document.htm b/testing/web-platform/tests/webmessaging/postMessage_Document.htm
new file mode 100644
index 000000000..97765fae8
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_Document.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_Function.htm b/testing/web-platform/tests/webmessaging/postMessage_Function.htm
new file mode 100644
index 000000000..c53e8fcc3
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_Function.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_MessagePorts_sorigin.htm b/testing/web-platform/tests/webmessaging/postMessage_MessagePorts_sorigin.htm
new file mode 100644
index 000000000..6526e972c
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_MessagePorts_sorigin.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_MessagePorts_xorigin.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_MessagePorts_xorigin.sub.htm
new file mode 100644
index 000000000..cf2b8eb4c
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_MessagePorts_xorigin.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_arrays.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_arrays.sub.htm
new file mode 100644
index 000000000..41e4a75ed
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_arrays.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_asterisk_xorigin.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_asterisk_xorigin.sub.htm
new file mode 100644
index 000000000..a12524625
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_asterisk_xorigin.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_dup_transfer_objects.htm b/testing/web-platform/tests/webmessaging/postMessage_dup_transfer_objects.htm
new file mode 100644
index 000000000..a28c96400
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_dup_transfer_objects.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_invalid_targetOrigin.htm b/testing/web-platform/tests/webmessaging/postMessage_invalid_targetOrigin.htm
new file mode 100644
index 000000000..d6e16460f
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_invalid_targetOrigin.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_objects.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_objects.sub.htm
new file mode 100644
index 000000000..dab207188
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_objects.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_origin_mismatch.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_origin_mismatch.sub.htm
new file mode 100644
index 000000000..6c8ac8353
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_origin_mismatch.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_origin_mismatch_xorigin.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_origin_mismatch_xorigin.sub.htm
new file mode 100644
index 000000000..d8e38e291
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_origin_mismatch_xorigin.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_solidus_sorigin.htm b/testing/web-platform/tests/webmessaging/postMessage_solidus_sorigin.htm
new file mode 100644
index 000000000..92f5afb79
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_solidus_sorigin.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/postMessage_solidus_xorigin.sub.htm b/testing/web-platform/tests/webmessaging/postMessage_solidus_xorigin.sub.htm
new file mode 100644
index 000000000..eebc85432
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/postMessage_solidus_xorigin.sub.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/support/ChildWindowPostMessage.htm b/testing/web-platform/tests/webmessaging/support/ChildWindowPostMessage.htm
new file mode 100644
index 000000000..13d4103a8
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/support/ChildWindowPostMessage.htm
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/support/compare.js b/testing/web-platform/tests/webmessaging/support/compare.js
new file mode 100644
index 000000000..5341b3743
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/support/compare.js
@@ -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);
+ }
+}
diff --git a/testing/web-platform/tests/webmessaging/with-ports/001.html b/testing/web-platform/tests/webmessaging/with-ports/001.html
new file mode 100644
index 000000000..e3687f162
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/001.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/002.html b/testing/web-platform/tests/webmessaging/with-ports/002.html
new file mode 100644
index 000000000..f7d085937
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/002.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/003.html b/testing/web-platform/tests/webmessaging/with-ports/003.html
new file mode 100644
index 000000000..3c0d4296b
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/003.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/004.html b/testing/web-platform/tests/webmessaging/with-ports/004.html
new file mode 100644
index 000000000..d129ad119
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/004.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/005.html b/testing/web-platform/tests/webmessaging/with-ports/005.html
new file mode 100644
index 000000000..e80396891
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/005.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/006.html b/testing/web-platform/tests/webmessaging/with-ports/006.html
new file mode 100644
index 000000000..4e3f1ede8
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/006.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/007.html b/testing/web-platform/tests/webmessaging/with-ports/007.html
new file mode 100644
index 000000000..c049a1337
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/007.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/010.html b/testing/web-platform/tests/webmessaging/with-ports/010.html
new file mode 100644
index 000000000..05080e3f7
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/010.html
@@ -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 ('+j+')'); });
+ };
+ j++;
+ }
+
+
+</script>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/011.html b/testing/web-platform/tests/webmessaging/with-ports/011.html
new file mode 100644
index 000000000..782b3208b
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/011.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/012.html b/testing/web-platform/tests/webmessaging/with-ports/012.html
new file mode 100644
index 000000000..6efe4c114
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/012.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/013.html b/testing/web-platform/tests/webmessaging/with-ports/013.html
new file mode 100644
index 000000000..248958ea1
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/013.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/014.html b/testing/web-platform/tests/webmessaging/with-ports/014.html
new file mode 100644
index 000000000..3c970c42a
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/014.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/with-ports/015.html b/testing/web-platform/tests/webmessaging/with-ports/015.html
new file mode 100644
index 000000000..a17c97be1
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/015.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/016.html b/testing/web-platform/tests/webmessaging/with-ports/016.html
new file mode 100644
index 000000000..7257c95d0
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/016.html
@@ -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>
+
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/017.html b/testing/web-platform/tests/webmessaging/with-ports/017.html
new file mode 100644
index 000000000..94cd3e6ae
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/017.html
@@ -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>
+
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/018.html b/testing/web-platform/tests/webmessaging/with-ports/018.html
new file mode 100644
index 000000000..5525206e4
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/018.html
@@ -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>
+
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/019.html b/testing/web-platform/tests/webmessaging/with-ports/019.html
new file mode 100644
index 000000000..2c65d5816
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/019.html
@@ -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>
+
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/020.html b/testing/web-platform/tests/webmessaging/with-ports/020.html
new file mode 100644
index 000000000..4fc2c4e2d
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/020.html
@@ -0,0 +1,30 @@
+<!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>
+onload = function() {
+ window[0].postMessage(1, location.href, []);
+ window[1].postMessage(2, url, []);
+ var i = 0;
+ onmessage = function(e) {
+ i++;
+ assert_equals(e.data[0], i);
+ assert_equals(e.data[1], location.protocol + '//' + location.host);
+ if (i === 2) {
+ done();
+ }
+ };
+};
+</script>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/021.html b/testing/web-platform/tests/webmessaging/with-ports/021.html
new file mode 100644
index 000000000..37a0767fe
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/021.html
@@ -0,0 +1,30 @@
+<!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>
+onload = function() {
+ window[0].postMessage(1, '*', []);
+ window[1].postMessage(2, '*', []);
+ var i = 0;
+ onmessage = function(e) {
+ i++;
+ assert_equals(e.data[0], i);
+ assert_equals(e.data[1], location.protocol + '//' + location.host);
+ if (i === 2) {
+ done();
+ }
+ };
+};
+</script>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/023.html b/testing/web-platform/tests/webmessaging/with-ports/023.html
new file mode 100644
index 000000000..664289585
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/023.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/024.html b/testing/web-platform/tests/webmessaging/with-ports/024.html
new file mode 100644
index 000000000..e6c0dcba0
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/024.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/025.html b/testing/web-platform/tests/webmessaging/with-ports/025.html
new file mode 100644
index 000000000..9a0e5cf6f
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/025.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/026.html b/testing/web-platform/tests/webmessaging/with-ports/026.html
new file mode 100644
index 000000000..cf5c5e18a
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/026.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/with-ports/027.html b/testing/web-platform/tests/webmessaging/with-ports/027.html
new file mode 100644
index 000000000..c85e02dc7
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/with-ports/027.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/001.html b/testing/web-platform/tests/webmessaging/without-ports/001.html
new file mode 100644
index 000000000..8f77c31fc
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/001.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/002.html b/testing/web-platform/tests/webmessaging/without-ports/002.html
new file mode 100644
index 000000000..ef3eceb2a
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/002.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/003.html b/testing/web-platform/tests/webmessaging/without-ports/003.html
new file mode 100644
index 000000000..5021e09f4
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/003.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/004.html b/testing/web-platform/tests/webmessaging/without-ports/004.html
new file mode 100644
index 000000000..9a9eb81a5
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/004.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/005.html b/testing/web-platform/tests/webmessaging/without-ports/005.html
new file mode 100644
index 000000000..ed05a476b
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/005.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/006.html b/testing/web-platform/tests/webmessaging/without-ports/006.html
new file mode 100644
index 000000000..47479ea01
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/006.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/007.html b/testing/web-platform/tests/webmessaging/without-ports/007.html
new file mode 100644
index 000000000..eb2b5c52e
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/007.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/008.html b/testing/web-platform/tests/webmessaging/without-ports/008.html
new file mode 100644
index 000000000..30bf607f3
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/008.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/009.html b/testing/web-platform/tests/webmessaging/without-ports/009.html
new file mode 100644
index 000000000..779383da2
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/009.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/010.html b/testing/web-platform/tests/webmessaging/without-ports/010.html
new file mode 100644
index 000000000..062316f68
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/010.html
@@ -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 ('+j+')'); });
+ };
+ j++;
+ }
+
+</script>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/011.html b/testing/web-platform/tests/webmessaging/without-ports/011.html
new file mode 100644
index 000000000..cac2990c4
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/011.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/012.html b/testing/web-platform/tests/webmessaging/without-ports/012.html
new file mode 100644
index 000000000..8eb46539b
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/012.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/013.html b/testing/web-platform/tests/webmessaging/without-ports/013.html
new file mode 100644
index 000000000..34ba76221
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/013.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/014.html b/testing/web-platform/tests/webmessaging/without-ports/014.html
new file mode 100644
index 000000000..f200aa467
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/014.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/015.html b/testing/web-platform/tests/webmessaging/without-ports/015.html
new file mode 100644
index 000000000..a17c97be1
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/015.html
@@ -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>
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/016.html b/testing/web-platform/tests/webmessaging/without-ports/016.html
new file mode 100644
index 000000000..da1d8e595
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/016.html
@@ -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>
+
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/017.html b/testing/web-platform/tests/webmessaging/without-ports/017.html
new file mode 100644
index 000000000..a4a048362
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/017.html
@@ -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>
+
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/018.html b/testing/web-platform/tests/webmessaging/without-ports/018.html
new file mode 100644
index 000000000..207ae36ed
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/018.html
@@ -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>
+
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/019-1.html b/testing/web-platform/tests/webmessaging/without-ports/019-1.html
new file mode 100644
index 000000000..513123ee6
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/019-1.html
@@ -0,0 +1 @@
+<!-- blank --> \ No newline at end of file
diff --git a/testing/web-platform/tests/webmessaging/without-ports/019.html b/testing/web-platform/tests/webmessaging/without-ports/019.html
new file mode 100644
index 000000000..f271a9e71
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/019.html
@@ -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>
+
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/020-1.html b/testing/web-platform/tests/webmessaging/without-ports/020-1.html
new file mode 100644
index 000000000..225bd7a41
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/020-1.html
@@ -0,0 +1,5 @@
+<script>
+onmessage = function(e) {
+ parent.postMessage([e.data, e.origin], '*');
+}
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/webmessaging/without-ports/020.html b/testing/web-platform/tests/webmessaging/without-ports/020.html
new file mode 100644
index 000000000..e35a1128a
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/020.html
@@ -0,0 +1,30 @@
+<!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>
+onload = function() {
+ window[0].postMessage(1, location.href);
+ window[1].postMessage(2, url);
+ var i = 0;
+ onmessage = function(e) {
+ i++;
+ assert_equals(e.data[0], i);
+ assert_equals(e.data[1], location.protocol + '//' + location.host);
+ if (i == 2) {
+ done();
+ }
+ };
+};
+</script>
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/021.html b/testing/web-platform/tests/webmessaging/without-ports/021.html
new file mode 100644
index 000000000..b240fa0ca
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/021.html
@@ -0,0 +1,30 @@
+<!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>
+onload = function() {
+ window[0].postMessage(1, '*');
+ window[1].postMessage(2, '*');
+ var i = 0;
+ onmessage = function(e) {
+ i++;
+ assert_equals(e.data[0], i);
+ assert_equals(e.data[1], location.protocol + '//' + location.host);
+ if (i === 2) {
+ done();
+ }
+ };
+};
+</script>
+
diff --git a/testing/web-platform/tests/webmessaging/without-ports/023.html b/testing/web-platform/tests/webmessaging/without-ports/023.html
new file mode 100644
index 000000000..1e12ac4a5
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/023.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/024.html b/testing/web-platform/tests/webmessaging/without-ports/024.html
new file mode 100644
index 000000000..8d9999459
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/024.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/025-1.js b/testing/web-platform/tests/webmessaging/without-ports/025-1.js
new file mode 100644
index 000000000..c088fc981
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/025-1.js
@@ -0,0 +1,15 @@
+importScripts("/resources/testharness.js");
+
+test(function() {
+ var ch = new MessageChannel();
+ assert_true(ch.port1 instanceof MessagePort,
+ "Worker MessageChannel's port not an instance of MessagePort");
+}, "Worker MessageChannel's port should be an instance of MessagePort");
+
+test(function() {
+ assert_throws(new TypeError(), function() {
+ new MessagePort()
+ }, "MessagePort is [[Callable]]");
+}, "Worker MessagePort should not be [[Callable]]");
+
+done();
diff --git a/testing/web-platform/tests/webmessaging/without-ports/025.html b/testing/web-platform/tests/webmessaging/without-ports/025.html
new file mode 100644
index 000000000..47bec6bd8
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/025.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>MessagePort constructor properties</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id=log></div>
+<script>
+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]]");
+});
+fetch_tests_from_worker(new Worker("025-1.js"));
+</script>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/026.html b/testing/web-platform/tests/webmessaging/without-ports/026.html
new file mode 100644
index 000000000..e8d799c5d
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/026.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/027.html b/testing/web-platform/tests/webmessaging/without-ports/027.html
new file mode 100644
index 000000000..36aa9446a
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/027.html
@@ -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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/028.html b/testing/web-platform/tests/webmessaging/without-ports/028.html
new file mode 100644
index 000000000..d51ad7d3b
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/028.html
@@ -0,0 +1,19 @@
+<!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 canvas = document.getElementsByTagName("canvas")[0];
+ var context = canvas.getContext("2d");
+ var 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>
diff --git a/testing/web-platform/tests/webmessaging/without-ports/029.html b/testing/web-platform/tests/webmessaging/without-ports/029.html
new file mode 100644
index 000000000..4b1b38f74
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/without-ports/029.html
@@ -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>