Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / workers / resources / worker-messageport.js
blob1e01b0a52b586b00cbbb28b2352959f7fa150e39
1 onmessage = function(evt) {
2 if (evt.data == "port") {
3 if (evt.ports) {
4 postMessage("PASS: Received message port");
5 evt.ports[0].onmessage = pingBack;
6 evt.ports[0].start();
7 } else {
8 postMessage("FAIL: Did not receive expected MessagePort");
10 } else if (evt.data == "noport") {
11 if (!evt.ports || evt.ports.length) {
12 postMessage("FAIL: Received message port or null ports array");
13 } else {
14 postMessage("PASS: evt.ports = [] as expected");
16 } else if (evt.data == "spam") {
17 for (var i = 0 ; i < 1000 ; i++) {
18 evt.ports[0].postMessage(i);
20 postMessage("spamDone");
21 } else if (evt.data == "getport") {
22 var channel = new MessageChannel();
23 postMessage("port", [channel.port1]);
24 channel.port2.onmessage = pingBack;
25 channel.port2.start();
26 } else {
27 postMessage("Unknown message:" + evt.data);
32 function pingBack(evt) {
33 // Make sure we got the expected data and send a return message over
34 // the port.
35 if (evt.data == "ping") {
36 evt.target.postMessage("pong");
37 } else {
38 postMessage("FAIL: unknown message: " + evt.data);