Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>test ws connection</title> | 4 <title>Connect to a WebSocket server</title> |
| 5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
| 6 | |
| 7 var href = window.location.href; | 6 var href = window.location.href; |
|
Adam Rice
2014/07/14 10:17:20
See https://code.google.com/p/chromium/codesearch#
yhirano
2014/07/14 11:24:35
Done.
| |
| 8 var hostBegin = href.indexOf('/') + 2; | 7 var hostBegin = href.indexOf('/') + 2; |
| 9 var hostEnd = href.lastIndexOf(':'); | 8 var hostEnd = href.lastIndexOf(':'); |
| 10 var host = href.slice(hostBegin, hostEnd); | 9 var host = href.slice(hostBegin, hostEnd); |
| 11 var portBegin = hostEnd + 1; | 10 var portBegin = hostEnd + 1; |
| 12 var portEnd = href.lastIndexOf('/'); | 11 var portEnd = href.lastIndexOf('/'); |
| 13 var port = href.slice(portBegin, portEnd); | 12 var port = href.slice(portBegin, portEnd); |
| 14 var scheme = href.indexOf('https') >= 0 ? 'wss' : 'ws'; | 13 var scheme = href.indexOf('https') >= 0 ? 'wss' : 'ws'; |
| 15 var url = scheme + '://' + host + ':' + port + '/echo-with-no-extension'; | 14 var url = scheme + '://' + host + ':' + port + '/count-connection'; |
| 16 | 15 |
| 17 // Do connection test. | |
| 18 var ws = new WebSocket(url); | 16 var ws = new WebSocket(url); |
| 19 | 17 |
| 20 ws.onopen = function() | 18 ws.onopen = function() { |
| 21 { | 19 document.title = 'CONNECTED'; |
| 22 // Set document title to 'PASS'. The test observer catches this title changes | 20 }; |
| 23 // to know the result. | |
| 24 document.title = 'PASS'; | |
| 25 } | |
| 26 | 21 |
| 27 ws.onclose = function() | 22 ws.onclose = function() { |
| 28 { | 23 document.title = 'CLOSED'; |
| 29 // Set document title to 'FAIL'. | 24 }; |
| 30 document.title = 'FAIL'; | |
| 31 } | |
| 32 | |
| 33 </script> | 25 </script> |
| 34 </head> | 26 </head> |
| 35 </html> | 27 </html> |
| OLD | NEW |