1 description("This test checks the various use cases around sending multiple ports through WorkerGlobalScope.postMessage");
3 if (window.testRunner) {
4 testRunner.dumpAsText();
5 testRunner.waitUntilDone();
8 var worker = new Worker("resources/worker-context-thread-multi-port.js");
10 worker.onmessage = function(event) {
11 // Report results from worker thread.
12 if (event.data == "done")
13 event.ports[0].onmessage = done;
14 else if (event.data == "noport") {
15 if (event.ports && !event.ports.length)
16 testPassed("event.ports is non-null and zero length when no port sent");
18 testFailed("event.ports is null or non-zero length when no port sent");
19 } else if (event.data == "zero ports") {
20 if (event.ports && !event.ports.length)
21 testPassed("event.ports is non-null and zero length when empty array sent");
23 testFailed("event.ports is null or non-zero length when empty array sent");
24 } else if (event.data == "two ports") {
26 testFailed("event.ports should be non-null when ports sent");
29 if (event.ports.length == 2)
30 testPassed("event.ports contains two ports when two ports sent");
32 testFailed("event.ports contained " + event.ports.length + " when two ports sent");
33 } else if (event.data == "failed ports") {
34 if (event.ports.length == 2)
35 testPassed("event.ports contains two ports when two ports re-sent after error");
37 testFailed("event.ports contained " + event.ports.length + " when two ports re-sent after error");
38 } else if (event.data.indexOf("PASS") == 0)
39 testPassed(event.data.substring(4));
40 else if (event.data.indexOf("FAIL") == 0)
41 testFailed(event.data.substring(4));
43 testFailed("Unexpected result: " + event.data);