Index: LayoutTests/fast/events/message-port-clone.html |
diff --git a/LayoutTests/fast/events/message-port-clone.html b/LayoutTests/fast/events/message-port-clone.html |
index 014d0d2fe8c44b31c5ba7af7071bf265d772f511..af14bf02db2ab963c60827105eb2a2eeb0f3bfba 100644 |
--- a/LayoutTests/fast/events/message-port-clone.html |
+++ b/LayoutTests/fast/events/message-port-clone.html |
@@ -1,58 +1,29 @@ |
+<html> |
+<head> |
+<script src="../js/resources/js-test-pre.js"></script> |
+</head> |
<body> |
-<p>Tests various use cases when cloning MessagePorts.</p> |
-<p>Should be a series of SUCCESS messages, followed with DONE.</p> |
-<pre id=log></pre> |
<script> |
- |
-function gc() |
-{ |
- if (window.GCController) |
- return GCController.collect(); |
- |
- for (var i = 0; i < 10000; i++) { // force garbage collection (FF requires about 9K allocations before a collect). |
- var s = new String("abc"); |
- } |
-} |
- |
-function log(message) |
-{ |
- document.getElementById("log").innerHTML += message + "<br>"; |
-} |
- |
-if (window.testRunner) { |
- testRunner.dumpAsText(); |
- testRunner.waitUntilDone(); |
-} |
+description("Tests various use cases when cloning MessagePorts."); |
+window.jsTestIsAsync = true; |
var channel = new MessageChannel; |
channel.port1.onmessage = channel.port2.onmessage = function(evt) { |
- fail("FAIL: Should not have received message: " + evt.data); |
-} |
-try { |
- channel.port1.postMessage("msg", [channel.port1]); |
- log("FAIL: Posting port to itself should throw an exception."); |
-} catch (ex) { |
- log("SUCCESS: Posting port to itself: " + ex); |
+ testFailed("Should not have received message: " + evt.data); |
} |
-try { |
- channel.port1.postMessage("msg", [channel.port2]); |
- log("FAIL: Posting port to entangled pair should throw an exception."); |
-} catch (ex) { |
- log("SUCCESS: Posting entangled port: " + ex); |
-} |
+// Posting port to itself should throw an exception. |
+shouldThrow("channel.port1.postMessage('msg', [channel.port1])", "'DataCloneError: An object could not be cloned.'"); |
+ |
+// Posting port to entangled pair should throw an exception. |
+shouldThrow("channel.port1.postMessage('msg', [channel.port2])", "'DataCloneError: An object could not be cloned.'"); |
channel = new MessageChannel; |
var channel2 = new MessageChannel; |
channel.port1.postMessage("msg", [channel2.port1]); |
// Should not be able to post a cloned port. |
-try { |
- channel.port1.postMessage("msg", [channel2.port1]); |
- log("FAIL: Posting cloned port should throw an exception."); |
-} catch (ex) { |
- log("SUCCESS: Posting cloned port."); |
-} |
+shouldThrow("channel.port1.postMessage('msg', [channel2.port1])", "'DataCloneError: An object could not be cloned.'"); |
// Test posting messages to a port in cloned state. |
@@ -64,16 +35,17 @@ channel2.port2.postMessage("1"); |
channel.port1.postMessage("msg", [channel2.port1]); |
channel2.port2.postMessage("2"); |
channel2.port2.postMessage("3"); |
+var testEvent; |
+var messageIndex = 1; |
channel.port2.onmessage = function(evt) { |
- var messageIndex = 1; |
- if (evt.ports.length != 1) |
- log("FAIL: Got message without wrong number of ports: " + evt.ports.length); |
+ testEvent = evt; |
+ shouldBe("testEvent.ports.length", "1"); |
evt.ports[0].onmessage = function(evt) { |
- if (evt.data != messageIndex) |
- log("FAIL: Got message " + evt.data + ", expected " + messageIndex); |
+ testEvent = evt; |
+ shouldBe("parseInt(testEvent.data)", "" + messageIndex); |
messageIndex++; |
if (messageIndex == 4) { |
- log("SUCCESS: Posted messages to cloned port."); |
+ testPassed("Posted messages to cloned port."); |
testDoublyClonedPort(); |
} |
} |
@@ -91,10 +63,8 @@ function testDoublyClonedPort() |
} |
channel.port2.onmessage = function(evt) { |
evt.ports[0].onmessage = function (evt) { |
- if (evt.data == "testme") |
- log("SUCCESS: Cloned both endpoints of a channel."); |
- else |
- log("FAIL: Invalid message arrived: " + evt.data); |
+ testEvent = evt; |
+ shouldBe("testEvent.data", "'testme'"); |
testPostClosePort(); |
} |
} |
@@ -109,22 +79,15 @@ function testPostClosePort() |
channel2.port2.close(); |
channel.port1.postMessage("closed", [channel2.port2]); |
channel.port2.onmessage = function(evt) { |
- if (!evt.ports || evt.ports.length != 1) |
- log("FAIL: Closed port not sent."); |
- else if (evt.data != "closed") |
- log("FAIL: Unexpected message: " + evt.data); |
- else |
- log("SUCCESS: Got closed port with event message " + evt.data); |
- done(); |
- } |
-} |
+ testEvent = evt; |
+ shouldNotBe("testEvent.ports", "null"); |
+ shouldBe("testEvent.ports.length", "1"); |
+ shouldBe("testEvent.data", "'closed'"); |
-function done() |
-{ |
- log("DONE"); |
- |
- if (window.testRunner) |
- testRunner.notifyDone(); |
+ finishJSTest(); |
+ } |
} |
</script> |
+<script src="../js/resources/js-test-post.js"></script> |
</body> |
+</html> |