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>test ws connection</title> |
| 5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
| 6 | 6 var scheme = location.protocol.replace('http', 'ws'); |
|
Adam Rice
2014/07/14 12:12:14
Clever! But I think the URL will end up like ws:12
yhirano
2014/07/15 01:50:03
Oops, sorry. Fixed.
| |
| 7 var href = window.location.href; | 7 var url = scheme + location.host + '/echo-with-no-extension'; |
| 8 var hostBegin = href.indexOf('/') + 2; | |
| 9 var hostEnd = href.lastIndexOf(':'); | |
| 10 var host = href.slice(hostBegin, hostEnd); | |
| 11 var portBegin = hostEnd + 1; | |
| 12 var portEnd = href.lastIndexOf('/'); | |
| 13 var port = href.slice(portBegin, portEnd); | |
| 14 var scheme = href.indexOf('https') >= 0 ? 'wss' : 'ws'; | |
| 15 var url = scheme + '://' + host + ':' + port + '/echo-with-no-extension'; | |
| 16 | |
| 17 // Do connection test. | 8 // Do connection test. |
| 18 var ws = new WebSocket(url); | 9 var ws = new WebSocket(url); |
| 19 | 10 |
| 20 ws.onopen = function() | 11 ws.onopen = function() |
| 21 { | 12 { |
| 22 // Set document title to 'PASS'. The test observer catches this title changes | 13 // Set document title to 'PASS'. The test observer catches this title changes |
| 23 // to know the result. | 14 // to know the result. |
| 24 document.title = 'PASS'; | 15 document.title = 'PASS'; |
| 25 } | 16 } |
| 26 | 17 |
| 27 ws.onclose = function() | 18 ws.onclose = function() |
| 28 { | 19 { |
| 29 // Set document title to 'FAIL'. | 20 // Set document title to 'FAIL'. |
| 30 document.title = 'FAIL'; | 21 document.title = 'FAIL'; |
| 31 } | 22 } |
| 32 | 23 |
| 33 </script> | 24 </script> |
| 34 </head> | 25 </head> |
| 35 </html> | 26 </html> |
| OLD | NEW |