4 <script src=
"/js-test-resources/js-test.js"></script>
7 <div id=
"description"></div>
8 <div id=
"console"></div>
9 <script type=
"text/javascript">
10 description("WebSocket: Send ArrayBuffers.");
12 window
.jsTestIsAsync
= true;
14 function startsWith(target
, prefix
)
16 return target
.indexOf(prefix
) === 0;
19 function createArrayBufferContainingHelloWorld()
21 var hello
= "Hello, world!";
22 var array
= new Uint8Array(hello
.length
);
23 for (var i
= 0; i
< hello
.length
; ++i
)
24 array
[i
] = hello
.charCodeAt(i
);
28 function createEmptyArrayBuffer()
30 return new ArrayBuffer(0);
33 function createArrayBufferContainingAllDistinctBytes()
35 var array
= new Uint8Array(256);
36 for (var i
= 0; i
< 256; ++i
)
41 var url
= "ws://127.0.0.1:8880/check-binary-messages";
42 var ws
= new WebSocket(url
);
45 ws
.onopen = function()
47 ws
.send(createArrayBufferContainingHelloWorld());
48 ws
.send(createEmptyArrayBuffer());
49 ws
.send(createArrayBufferContainingAllDistinctBytes());
52 ws
.onmessage = function(event
)
54 var message
= event
.data
;
55 if (startsWith(message
, "PASS"))
61 ws
.onclose = function(event
)
64 shouldBeTrue("closeEvent.wasClean");