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 var protocol = location.protocol.replace('http', 'ws'); | 6 |
7 var url = protocol + '//' + location.host + '/echo-with-no-extension'; | 7 var href = window.location.href; |
| 8 var queryBegin = href.indexOf('?url='); |
| 9 if (queryBegin == -1) { |
| 10 console.log("Failed to find ?url= in URL"); |
| 11 document.title = 'FAIL'; |
| 12 throw "FAILURE"; |
| 13 } |
| 14 var url = href.slice(queryBegin + 5); |
| 15 |
8 // Do connection test. | 16 // Do connection test. |
9 var ws = new WebSocket(url); | 17 var ws = new WebSocket(url); |
10 | 18 |
11 ws.onopen = function() | 19 ws.onopen = function() |
12 { | 20 { |
13 // Set document title to 'PASS'. The test observer catches this title changes | 21 // Set document title to 'PASS'. The test observer catches this title changes |
14 // to know the result. | 22 // to know the result. |
15 document.title = 'PASS'; | 23 document.title = 'PASS'; |
16 } | 24 } |
17 | 25 |
18 ws.onclose = function() | 26 ws.onclose = function() |
19 { | 27 { |
20 // Set document title to 'FAIL'. | 28 // Set document title to 'FAIL'. |
21 document.title = 'FAIL'; | 29 document.title = 'FAIL'; |
22 } | 30 } |
23 | 31 |
24 </script> | 32 </script> |
25 </head> | 33 </head> |
26 </html> | 34 </html> |
OLD | NEW |