Chromium Code Reviews| 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 with 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("This message can't be received"); |
| 20 log("Closed port receiving: FAIL. Got Message: " + evt.data + " after close "); | 20 openThenClose(); |
| 21 done(); | |
| 22 | |
| 23 function openThenClose() { | |
|
Sami
2014/11/12 16:47:34
Is there a better name we could use here to distin
| |
| 24 setTimeout(function() { | |
| 25 channel.port1.onmessage = function(evt) { | |
| 26 log("Closed port receiving: FAIL. Got Message: " + evt.data + " aft er close"); | |
| 27 } | |
| 28 channel.port1.close(); | |
| 29 }, 0); | |
| 21 } | 30 } |
| 22 channel.port1.close(); | |
| 23 channel.port2.postMessage("This message can't be received"); | |
| 24 done(); | |
| 25 | 31 |
| 26 function done() { | 32 function done() { |
| 27 // Wait a short period of time to ensure no messages come in from previous t ests. | 33 // Wait a short period of time to ensure no messages come in from previous t ests. |
| 28 setTimeout(function() { | 34 setTimeout(function() { |
| 29 log("DONE"); | 35 log("DONE"); |
| 30 if (window.testRunner) | 36 if (window.testRunner) |
| 31 testRunner.notifyDone(); | 37 testRunner.notifyDone(); |
| 32 }, 100); | 38 }, 100); |
| 33 } | 39 } |
| 34 | 40 |
| 35 </script> | 41 </script> |
| 36 </body> | 42 </body> |
| OLD | NEW |