test_send-arraybuffer.html (1689B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 6 </head> 7 <body> 8 9 <p id="display"></p> 10 <div id="content" style="display: none"> 11 </div> 12 <pre id="test"> 13 14 <script class="testbody" type="text/javascript"> 15 16 function debug(msg) { 17 ok(1, msg); 18 } 19 20 function startsWith(target, prefix) 21 { 22 return target.indexOf(prefix) === 0; 23 } 24 25 function createArrayBufferContainingHelloWorld() 26 { 27 var hello = "Hello, world!"; 28 var array = new Uint8Array(hello.length); 29 for (var i = 0; i < hello.length; ++i) 30 array[i] = hello.charCodeAt(i); 31 return array.buffer; 32 } 33 34 function createEmptyArrayBuffer() 35 { 36 return new ArrayBuffer(0); 37 } 38 39 function createArrayBufferContainingAllDistinctBytes() 40 { 41 var array = new Uint8Array(256); 42 for (var i = 0; i < 256; ++i) 43 array[i] = i; 44 return array.buffer; 45 } 46 47 var ws = new WebSocket("ws://mochi.test:8888/tests/dom/websocket/tests/websocket_hybi/file_check-binary-messages"); 48 49 ws.onopen = function() 50 { 51 ok(true, "onopen reached"); 52 ws.send(createArrayBufferContainingHelloWorld()); 53 ws.send(createEmptyArrayBuffer()); 54 ws.send(createArrayBufferContainingAllDistinctBytes()); 55 }; 56 57 ws.onmessage = function(event) 58 { 59 var message = event.data; 60 if (startsWith(message, "PASS")) 61 ok(true, message); 62 else 63 ok(false, message); 64 }; 65 66 ws.onclose = function(event) 67 { 68 ok(event.wasClean, "should have closed cleanly"); 69 SimpleTest.finish(); 70 }; 71 72 ws.onerror = function() 73 { 74 ok(false, "onerror should not have been called"); 75 }; 76 77 SimpleTest.waitForExplicitFinish(); 78 79 </script> 80 </body> 81 </html>