OLD | NEW |
1 <body> | 1 <body> |
2 <p>Test Closed MessagePort Whether Receive Message Or Not.</p> | 2 <p>Test whether opening and closing a messageport in different microtasks correc
tly receives an in-flight message.</p> |
3 <p>Should be a START message, followed with DONE.</p> | 3 <p>Should be a START message, followed by a HELLO message then DONE.</p> |
4 <pre id=log></pre> | 4 <pre id=log></pre> |
5 <script> | 5 <script> |
6 function log(message) | 6 function log(message) |
7 { | 7 { |
8 document.getElementById("log").innerHTML += message + "<br>"; | 8 document.getElementById("log").innerHTML += message + "<br>"; |
9 } | 9 } |
10 | 10 |
11 if (window.testRunner) { | 11 if (window.testRunner) { |
12 testRunner.dumpAsText(); | 12 testRunner.dumpAsText(); |
13 testRunner.waitUntilDone(); | 13 testRunner.waitUntilDone(); |
14 } | 14 } |
15 | 15 |
16 log("START"); | 16 log("START"); |
17 | 17 |
18 var channel = new MessageChannel; | 18 var channel = new MessageChannel; |
19 channel.port1.onmessage = function(evt) { | 19 channel.port2.postMessage("HELLO"); |
20 log("Closed port receiving: FAIL. Got Message: " + evt.data + " after close
"); | 20 openThenPostClose(); |
| 21 done(); |
| 22 |
| 23 function openThenPostClose() { |
| 24 setTimeout(function() { |
| 25 channel.port1.onmessage = function(evt) { |
| 26 log("PASS. Got Message: " + evt.data + " before close"); |
| 27 } |
| 28 setTimeout(function() { |
| 29 channel.port1.close(); |
| 30 }, 0); |
| 31 }, 0); |
21 } | 32 } |
22 channel.port1.close(); | |
23 channel.port2.postMessage("This message can't be received"); | |
24 done(); | |
25 | 33 |
26 function done() { | 34 function done() { |
27 // Wait a short period of time to ensure no messages come in from previous t
ests. | 35 // Wait a short period of time to ensure no messages come in from previous t
ests. |
28 setTimeout(function() { | 36 setTimeout(function() { |
29 log("DONE"); | 37 log("DONE"); |
30 if (window.testRunner) | 38 if (window.testRunner) |
31 testRunner.notifyDone(); | 39 testRunner.notifyDone(); |
32 }, 100); | 40 }, 100); |
33 } | 41 } |
34 | 42 |
35 </script> | 43 </script> |
36 </body> | 44 </body> |
OLD | NEW |