Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / websocket / send-arraybuffer.html
blobf2ebf332c1a45603999f403f4656c63be3307aca
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/js-test-resources/js-test.js"></script>
5 </head>
6 <body>
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);
25 return array.buffer;
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)
37 array[i] = i;
38 return array.buffer;
41 var url = "ws://127.0.0.1:8880/check-binary-messages";
42 var ws = new WebSocket(url);
43 var closeEvent;
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"))
56 testPassed(message);
57 else
58 testFailed(message);
61 ws.onclose = function(event)
63 closeEvent = event;
64 shouldBeTrue("closeEvent.wasClean");
65 finishJSTest();
68 </script>
69 </body>
70 </html>