Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / workers / worker-messageport.html
blobaa81d7c88fd47826ddfbf476b81a835bb0710a7b
1 <body>
2 <p>Test that pages and workers can send MessagePorts to one another.
3 Should print "DONE" when done.</p>
4 <div id=result></div>
5 <script>
6 function log(message)
8 document.getElementById("result").innerHTML += message + "<br>";
11 if (window.testRunner) {
12 testRunner.dumpAsText();
13 testRunner.waitUntilDone();
16 var worker = new Worker("resources/worker-messageport.js");
17 var channel = new MessageChannel();
19 // Send messages with and without ports to the worker to make sure it gets them.
20 worker.postMessage("noport");
21 worker.onmessage = function(evt) {
22 log(evt.data);
23 worker.postMessage("port", [channel.port1]);
24 worker.onmessage = function(evt) {
25 log(evt.data);
29 // Send a message on the new port to make sure it gets to the worker.
30 channel.port2.postMessage("ping");
32 // Wait for the response.
33 channel.port2.onmessage = function(evt) {
34 if (evt.data == "pong") {
35 log("PASS: Received response from Worker via MessagePort");
36 worker.onmessage = awaitPortFromWorker;
37 worker.postMessage("getport");
38 } else {
39 log("FAIL: Received unknown event: " + evt.data);
42 channel.port2.start();
44 // Invoked once the first batch of tests are done, to test sending from the worker.
45 function awaitPortFromWorker(evt)
47 if (evt.data == "port") {
48 if (!evt.ports) {
49 log("FAIL: Did not get port from worker");
50 } else if (evt.ports.length != 1) {
51 log("FAIL: Got the wrong number of ports from worker: " + evt.ports.length);
52 } else {
53 log("PASS: Got port from worker");
54 evt.ports[0].postMessage("ping");
55 evt.ports[0].onmessage = function(evt) {
56 if (evt.data == "pong") {
57 log("PASS: Received final response from worker");
58 } else {
59 log("FAIL: Got unexpected response: " + evt.data);
61 startSpamTest();
63 evt.ports[0].start();
65 } else {
66 log(evt.data);
70 function startSpamTest()
72 var channel = new MessageChannel();
73 worker.onmessage = function () { gotSpam(channel.port1); }
74 worker.postMessage("spam", [channel.port2]);
77 function gotSpam(port)
79 var spamCount = 0;
80 port.onmessage = function(evt) {
81 if (evt.data != spamCount)
82 log("FAIL: Got out of order message: " + spamCount);
83 spamCount++;
84 if (spamCount == 1000) {
85 log("PASS: Got 1000 messages");
86 done();
91 function done()
93 log("DONE");
94 if (window.testRunner)
95 testRunner.notifyDone();
98 </script>
99 </body>
100 </html>