chromium/third_party/blink/web_tests/http/tests/websocket/simple-stress.html

<p>Test sending many messages, and sending a large message.</p>
<p>Should say PASS:</p>
<pre id=log>Running the test...
</pre>
<script>
var numSmallMessages = 1000;

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function log(message)
{
    document.getElementById("log").innerHTML += message + "\n";
}

var ws = new WebSocket("ws://127.0.0.1:8880/echo");

ws.onopen = function() {
    for (i = 0; i < numSmallMessages; ++i) {
        ws.send(i);
    }

}

var lastMessage = -1;
ws.onmessage = function(msg) {
    if (parseInt(msg.data) != lastMessage + 1)
        log("FAIL - out of sequence response. Expected " + lastMessage + 1 + ", got " + msg.data);
    ++lastMessage;
    if (lastMessage == numSmallMessages - 1)
        testLargeString();
}

function testLargeString()
{
    // Build a string 256K in length.
    var str = " ";
    for (i = 0; i < 18; ++i)
        str += str;

    ws.send(str);
    ws.onmessage = function(msg) {
        log(msg.data.length == str.length ? "PASS" : "FAIL - wrong response length");
        ws.send("Goodbye");
        ws.onmessage = null;
        if (window.testRunner)
            setTimeout("testRunner.notifyDone()", 0);
    }
}
</script>