test_websocket_bigBlob.html (1648B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta> 5 <title>WebSocket test - big blob on content side</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <script type="text/javascript" src="websocket_helpers.js"></script> 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 9 </head> 10 <body> 11 <script class="testbody" type="text/javascript"> 12 13 var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/websocket/tests/file_websocket_bigBlob"); 14 is(ws.readyState, 0, "Initial readyState is 0"); 15 ws.binaryType = "blob"; 16 17 ws.onopen = function() { 18 is(ws.readyState, 1, "Open readyState is 1"); 19 ws.send(new Blob([new Array(1024*1024).join('123456789ABCDEF')])); 20 } 21 22 let receivedBlob; 23 ws.onmessage = function(e) { 24 ok(e.data instanceof Blob, "We should be receiving a Blob"); 25 receivedBlob = e.data; 26 ws.close(); 27 } 28 29 ws.onclose = function() { 30 is(ws.readyState, 3, "Close readyState is 3"); 31 32 // check blob contents 33 var reader = new FileReader(); 34 reader.onload = function() { 35 is(reader.result, new Array(1024*1024).join('123456789ABCDEF'), "All data matches"); 36 } 37 38 reader.onerror = function() { 39 ok(false, "Something bad happen."); 40 } 41 42 reader.onloadend = function() { 43 SimpleTest.finish(); 44 } 45 46 reader.readAsBinaryString(receivedBlob); 47 } 48 49 SimpleTest.requestFlakyTimeout("The web socket tests are really fragile, but avoiding timeouts might be hard, since it's testing stuff on the network. " + 50 "Expect all sorts of flakiness in this test..."); 51 SimpleTest.waitForExplicitFinish(); 52 53 </script> 54 </body> 55 </html>