1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/websocket_hybi/test_send-arraybuffer.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<head> 1.7 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.8 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.9 +</head> 1.10 +<body> 1.11 + 1.12 +<p id="display"></p> 1.13 +<div id="content" style="display: none"> 1.14 +</div> 1.15 +<pre id="test"> 1.16 + 1.17 +<script class="testbody" type="text/javascript"> 1.18 + 1.19 +function debug(msg) { 1.20 + ok(1, msg); 1.21 +} 1.22 + 1.23 +function startsWith(target, prefix) 1.24 +{ 1.25 + return target.indexOf(prefix) === 0; 1.26 +} 1.27 + 1.28 +function createArrayBufferContainingHelloWorld() 1.29 +{ 1.30 + var hello = "Hello, world!"; 1.31 + var array = new Uint8Array(hello.length); 1.32 + for (var i = 0; i < hello.length; ++i) 1.33 + array[i] = hello.charCodeAt(i); 1.34 + return array.buffer; 1.35 +} 1.36 + 1.37 +function createEmptyArrayBuffer() 1.38 +{ 1.39 + return new ArrayBuffer(0); 1.40 +} 1.41 + 1.42 +function createArrayBufferContainingAllDistinctBytes() 1.43 +{ 1.44 + var array = new Uint8Array(256); 1.45 + for (var i = 0; i < 256; ++i) 1.46 + array[i] = i; 1.47 + return array.buffer; 1.48 +} 1.49 + 1.50 +var ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/websocket_hybi/file_check-binary-messages"); 1.51 +var closeEvent; 1.52 + 1.53 +ws.onopen = function() 1.54 +{ 1.55 + ok(true, "onopen reached"); 1.56 + ws.send(createArrayBufferContainingHelloWorld()); 1.57 + ws.send(createEmptyArrayBuffer()); 1.58 + ws.send(createArrayBufferContainingAllDistinctBytes()); 1.59 +}; 1.60 + 1.61 +ws.onmessage = function(event) 1.62 +{ 1.63 + var message = event.data; 1.64 + if (startsWith(message, "PASS")) 1.65 + ok(true, message); 1.66 + else 1.67 + ok(false, message); 1.68 +}; 1.69 + 1.70 +ws.onclose = function(event) 1.71 +{ 1.72 + ok(event.wasClean, "should have closed cleanly"); 1.73 + SimpleTest.finish(); 1.74 +}; 1.75 + 1.76 +ws.onerror = function(event) 1.77 +{ 1.78 + ok(false, "onerror should not have been called"); 1.79 +}; 1.80 + 1.81 +SimpleTest.waitForExplicitFinish(); 1.82 + 1.83 +</script> 1.84 +</body> 1.85 +</html>