Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 let port; | |
| 2 let received = false; | |
| 3 | |
| 4 function reportFailure(details) { | |
| 5 port.postMessage('FAIL: ' + details); | |
| 6 } | |
| 7 | |
| 8 onmessage = event => { | |
| 9 port = event.source; | |
| 10 | |
| 11 const ws = new WebSocket('ws://localhost:8880/echo'); | |
| 12 ws.onopen = () => { | |
| 13 ws.send('Hello'); | |
| 14 }; | |
| 15 ws.onmessage = msg => { | |
| 16 if (msg.data !== 'Hello') { | |
| 17 reportFailure('Unexpected reply: ' + msg.data); | |
| 18 return; | |
| 19 } | |
| 20 | |
| 21 received = true; | |
| 22 ws.close(); | |
| 23 }; | |
| 24 ws.onclose = () => { | |
| 25 if (!received) { | |
| 26 reportFailure('Closed before receiving reply'); | |
|
falken
2016/12/08 15:48:24
nit: won't make a difference but could return; her
tyoshino (SeeGerritForStatus)
2016/12/08 16:07:05
Ooo. Good catch. Fixed.
| |
| 27 } | |
| 28 | |
| 29 port.postMessage('PASS'); | |
| 30 }; | |
| 31 ws.onerror = () => { | |
| 32 reportFailure('Got an error event'); | |
| 33 }; | |
| 34 }; | |
| OLD | NEW |