OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>test ws split packet</title> | 4 <title>test ws split packet</title> |
5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
6 | 6 var protocol = location.protocol.replace('http', 'ws'); |
7 var href = window.location.href; | 7 var url = protocol + '//' + location.host + '/close-with-split-packet'; |
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 + '/close-with-split-packet'; | |
16 | 8 |
17 // Do connection test. | 9 // Do connection test. |
18 var ws = new WebSocket(url); | 10 var ws = new WebSocket(url); |
19 | 11 |
20 ws.onopen = function() | 12 ws.onopen = function() |
21 { | 13 { |
22 // Close WebSocket connection once it is established. | 14 // Close WebSocket connection once it is established. |
23 ws.close(); | 15 ws.close(); |
24 } | 16 } |
25 | 17 |
26 ws.onclose = function(event) | 18 ws.onclose = function(event) |
27 { | 19 { |
28 // Check wasClean, then set proper title. | 20 // Check wasClean, then set proper title. |
29 if (event.wasClean && event.code === 3004 && event.reason === 'split test') | 21 if (event.wasClean && event.code === 3004 && event.reason === 'split test') |
30 document.title = 'PASS'; | 22 document.title = 'PASS'; |
31 else | 23 else |
32 document.title = 'FAIL'; | 24 document.title = 'FAIL'; |
33 } | 25 } |
34 | 26 |
35 </script> | 27 </script> |
36 </head> | 28 </head> |
37 </html> | 29 </html> |
OLD | NEW |