chromium/third_party/blink/web_tests/http/tests/websocket/send-arraybuffer.html

<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script type="text/javascript">
description("WebSocket: Send ArrayBuffers.");

window.jsTestIsAsync = true;

function startsWith(target, prefix)
{
    return target.indexOf(prefix) === 0;
}

function createArrayBufferContainingHelloWorld()
{
    var hello = "Hello, world!";
    var array = new Uint8Array(hello.length);
    for (var i = 0; i < hello.length; ++i)
        array[i] = hello.charCodeAt(i);
    return array.buffer;
}

function createEmptyArrayBuffer()
{
    return new ArrayBuffer(0);
}

function createArrayBufferContainingAllDistinctBytes()
{
    var array = new Uint8Array(256);
    for (var i = 0; i < 256; ++i)
        array[i] = i;
    return array.buffer;
}

var url = "ws://127.0.0.1:8880/check-binary-messages";
var ws = new WebSocket(url);
var closeEvent;

ws.onopen = function()
{
    ws.send(createArrayBufferContainingHelloWorld());
    ws.send(createEmptyArrayBuffer());
    ws.send(createArrayBufferContainingAllDistinctBytes());
};

ws.onmessage = function(event)
{
    var message = event.data;
    if (startsWith(message, "PASS"))
        testPassed(message);
    else
        testFailed(message);
};

ws.onclose = function(event)
{
    closeEvent = event;
    shouldBeTrue("closeEvent.wasClean");
    finishJSTest();
};

</script>
</body>
</html>