<!DOCTYPE HTML><!-- webkit-test-runner [ dumpJSConsoleLogInStdErr=true ] -->
<html>
<head>
<script src="../../../../js-test-resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description('Connection should fail immediately, rather than succeeding or staying in limbo until timeout, if handshake is longer than 1024 bytes.');

window.jsTestIsAsync = true;

var timedOut = false;
var connected = false;
let wsOrigin;

function endTest() {
    shouldBeFalse('timedOut');
    shouldBeFalse('connected');
    shouldBeUndefined('wsOrigin');
    clearTimeout(timeoutID);
    finishJSTest();
}

var url = 'ws://localhost:8880/websocket/tests/hybi/handshake-fail-by-maxlength';
var ws = new WebSocket(url);

ws.onopen = function()
{
    debug('Connected');
    connected = true;
}

ws.onmessage = function(messageEvent)
{
    wsOrigin = messageEvent.data;
    debug('wsOrigin = ' + wsOrigin);
    ws.close();
}

ws.onclose = function()
{
    endTest();
}

function timeoutCallback()
{
    debug('Timed out (state = ' + ws.readyState + ')');
    timedOut = true;
    endTest();
}

var timeoutID = setTimeout(timeoutCallback, 3000);

</script>
<script src="../../../../js-test-resources/js-test-post.js"></script>
</body>
</html>
