1 description("This test checks the various use cases around sending multiple ports through Worker.postMessage");
3 if (window.testRunner) {
4 testRunner.dumpAsText();
5 testRunner.waitUntilDone();
8 var channel = new MessageChannel();
9 var channel2 = new MessageChannel();
10 var channel3 = new MessageChannel();
11 var channel4 = new MessageChannel();
13 var worker = new Worker("resources/worker-thread-multi-port.js");
14 worker.postMessage("noargs");
15 worker.postMessage("noport");
16 worker.postMessage("zero ports", []);
17 worker.postMessage("two ports", [channel2.port1, channel2.port2]);
19 // Now test various failure cases
20 shouldThrow("worker.postMessage()");
21 shouldThrow('worker.postMessage("null port", [channel3.port1, null, channel3.port2])');
22 shouldThrow('worker.postMessage("notAPort", [channel3.port1, {}, channel3.port2])');
23 // Should be OK to send channel3.port1/2 (should not have been disentangled by the previous failed calls).
24 worker.postMessage("failed ports", [channel3.port1, channel3.port2]);
26 shouldThrow('worker.postMessage("notAnArray", channel3.port1)')
27 shouldThrow('worker.postMessage("notASequence", [{length: 3}])');
29 worker.postMessage("done", [channel.port2]);
30 worker.onmessage = function(event) {
31 // Report results from worker thread.
32 if (event.data == "done")
33 channel.port1.onmessage = done;
34 else if (event.data.indexOf("PASS") == 0)
35 testPassed(event.data.substring(4));
36 else if (event.data.indexOf("FAIL") == 0)
37 testFailed(event.data.substring(4));
39 testFailed("Unexpected result: " + event.data);