test_websocket_http2.html (1325B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Basic HTTP/2 WebSocket test</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 9 <body onload="testWebSocket()"> 10 <p id="display"></p> 11 <div id="content" style="display: none"> 12 </div> 13 <pre id="test"> 14 <script class="testbody" type="text/javascript"> 15 16 const kUrl = "wss://example.com"; 17 const data = "123456789ABCDEF"; 18 let ws; 19 20 function testWebSocket() { 21 ws = new WebSocket(kUrl, "test"); 22 23 ws.onopen = function() { 24 ok(true, "onopen is called"); 25 ws.send(data); 26 }; 27 28 ws.onmessage = function(e) { 29 if (e.data instanceof Blob) { 30 let reader = new FileReader(); 31 reader.onload = function(event) { 32 is(data, event.target.result, "data should be the same"); 33 ws.close(); 34 }; 35 reader.readAsText(e.data); 36 } else { 37 is(data, e.data, "data should be the same"); 38 ws.close(); 39 } 40 }; 41 42 ws.onerror = function() { 43 ok(false, "onerror() should not have been called!"); 44 SimpleTest.executeSoon(SimpleTest.finish); 45 }; 46 47 ws.onclose = function(e) { 48 ok(e.wasClean, "ws closed cleanly"); 49 SimpleTest.executeSoon(SimpleTest.finish); 50 }; 51 } 52 53 SimpleTest.waitForExplicitFinish(); 54 55 </script> 56 </pre> 57 </body> 58 </html>