2 <p>Test MessagePort messaging/entangle/detangle across threads. Should print "SUCCESS" when done.</p>
7 document.getElementById("result").innerHTML += message + "<br>";
10 if (window.layoutTestController) {
11 layoutTestController.dumpAsText();
12 layoutTestController.waitUntilDone();
16 var channel = new MessageChannel();
17 var numMessages = 50000;
19 // Create a channel which we will use to clone and re-clone one end of a
21 var cloneChannel = new MessageChannel();
22 var stopCloning = false;
23 cloneChannel.port1.onmessage = cloneChannel.port2.onmessage = resendPort;
24 cloneChannel.port1.start();
25 cloneChannel.port2.start();
26 cloneChannel.port1.postMessage("", [channel.port2]);
28 // Create worker with other end of port and have it send messages back to us
29 // while we clone our end of the port repeatedly.
30 var worker = new Worker("resources/worker-cloneport.js");
31 worker.postMessage("postBack " + numMessages, [channel.port1]);
33 // Test posting back 50000 messages, make sure ordering is fine
34 worker.onmessage = function(evt) {
35 if (evt.data == "postBackDone") {
38 // Log message from worker
43 // Keep cloning the passed port until we're told to stop.
44 function resendPort(evt)
47 log("FAIL: evt.ports not set");
48 if (evt.ports.length != 1)
49 log("FAIL: ports.length = " + evt.ports.length);
52 evt.target.postMessage("", evt.ports);
54 // Make sure the messages arrived in order.
56 // Queue up a task to execute once the messages have been processed. The timeout value is set fairly large to account for Chromium's different message delivery architecture.
57 // This only fires in the case of a test failure, so it does not slow down test running.
58 var timer = setTimeout(function() {
59 log("FAILURE: Received: " + itemNum + " events - expected: " + numMessages);
61 evt.ports[0].onmessage = function(event) {
63 if (event.data == itemNum) {
65 if (itemNum == numMessages) {
66 log("SUCCESS - received " + numMessages + " messages.");
70 log("FAILURE: Out of order message: expected #: " + itemNum + ", received: " + event.data);
76 setTimeout(reportDone, 100); // Make sure no unexpected events come in.
85 if (window.GCController)
86 return GCController.collect();
88 for (var i = 0; i < 10000; i++) { // force garbage collection (FF requires about 9K allocations before a collect).
89 var s = new String("abc");
95 if (window.layoutTestController)
96 layoutTestController.notifyDone();