blob: 406f9234d9d1782dd6e4661aa9e8444926e896df [file] [log] [blame]
Andrew Top61a84952019-04-30 15:07:33 -07001<!DOCTYPE html>
2<html>
3<head>
4 <title>W3C WebSocket API - Send binary data - ArrayBufferView - Int32Array - WebSocket</title>
5 <script type="text/javascript" src="/resources/testharness.js"></script>
6 <script type="text/javascript" src="/resources/testharnessreport.js"></script>
7 <script type="text/javascript" src="websocket.js?pipe=sub"></script>
8</head>
9<body>
10 <div id="log"></div>
11 <script type="text/javascript">
12
13 var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int32Array - Connection should be opened");
14 var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int32Array - Message should be received");
15 var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int32Array - Connection should be closed");
16
17 var data = "";
18 var datasize = 8;
19 var view;
20 var wsocket = CreateWebSocket(true, false, false);
21 var isOpenCalled = false;
22
23 wsocket.addEventListener('open', testOpen.step_func(function (evt) {
24 wsocket.binaryType = "arraybuffer";
25 data = new ArrayBuffer(datasize);
26 view = new Int32Array(data);
27 for(var i = 0; i < 2; i++) {
28 view[i] = i;
29 }
30 wsocket.send(view);
31 isOpenCalled = true;
32 testOpen.done();
33 }), true);
34
35 wsocket.addEventListener('message', testMessage.step_func(function (evt) {
36 var resultView = new Int32Array(evt.data);
37 for(var i = 0; i < resultView.length; i++) {
38 assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same");
39 }
40 wsocket.close();
41 testMessage.done();
42 }), true);
43
44 wsocket.addEventListener('close', testClose.step_func(function (evt) {
45 assert_true(isOpenCalled, "WebSocket connection should be open");
46 assert_equals(evt.wasClean, true, "wasClean should be true");
47 testClose.done();
48 }), true);
49 </script>
50</body>
51</html>