Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320)
[chromium-blink-merge.git] / content / test / data / workers / pass_messageport_to_sharedworker.html
blobe0821e010a621e55c9a0ec0bc8445be57e96db33
1 <html>
2 <head>
3 <title>Passing MessagePort to a SharedWorker</title>
4 <script src="worker_utils.js"></script>
5 <script>
6 function log(message)
8 document.getElementById("result").innerHTML += message + "<br>";
11 var worker = null;
12 var message_channel = null;
14 function do_test() {
15 worker = new SharedWorker("messageport_worker.js");
16 worker.port.onmessage = process_message_from_worker;
19 function process_message_from_worker(event) {
20 log("Message from worker: " + event.data);
21 if (event.data == "Worker connected.") {
22 log("Sending a port to the worker.");
23 message_channel = new MessageChannel();
24 worker.port.postMessage({message: "Sending a port.", port: message_channel.port2}, [message_channel.port2]);
25 } else if (event.data == "Worker got a port.") {
26 // Communicate with the worker via the message channel.
27 message_channel.port1.onmessage = function (event) {
28 log("Message from worker (via channel): " + event.data);
29 if (event.data == "Worker got a message via the passed port.")
30 onSuccess();
31 else
32 onFailure();
34 message_channel.port1.start();
35 log("Sending a message to the worker via the channel.");
36 message_channel.port1.postMessage({message: "Message via the channel."});
40 </script>
41 </head>
42 <body onload="do_test()">
43 <div id=statusPanel></div>
44 <div id=result></div>
45 </body>
46 </html>