OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>test to close hanging wss connection</title> | 4 <title>test to close hanging wss connection</title> |
5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
6 | 6 |
7 var href = window.location.href; | 7 var href = window.location.href; |
| 8 var hostBegin = href.indexOf('/') + 2; |
| 9 var hostEnd = href.lastIndexOf(':'); |
| 10 var host = href.slice(hostBegin, hostEnd); |
8 var queryBegin = href.lastIndexOf('?') + 1; | 11 var queryBegin = href.lastIndexOf('?') + 1; |
9 var port = href.slice(queryBegin); | 12 var port = href.slice(queryBegin); |
10 var url = 'wss://localhost:' + port; | 13 var url = 'wss://' + host + ':' + port; |
11 | 14 |
12 // Do connection test. | 15 // Do connection test. |
13 var ws = new WebSocket(url); | 16 var ws = new WebSocket(url); |
14 ws.onopen = function() { | 17 ws.onopen = function() { |
15 // Set document title to 'FAIL'. The test observer catches this title change | 18 // Set document title to 'FAIL'. The test observer catches this title change |
16 // to know the result. | 19 // to know the result. |
17 document.title = 'FAIL'; | 20 document.title = 'FAIL'; |
18 } | 21 } |
19 ws.onclose = function() { | 22 ws.onclose = function() { |
20 // Set document title to 'PASS'. The test observer catches this title change | 23 // Set document title to 'PASS'. The test observer catches this title change |
21 // to know the result. | 24 // to know the result. |
22 document.title = 'PASS'; | 25 document.title = 'PASS'; |
23 } | 26 } |
24 | 27 |
25 </script> | 28 </script> |
26 </head> | 29 </head> |
27 </html> | 30 </html> |
OLD | NEW |