<!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 type="text/javascript">
description("WebSocket should fail if subprotocol contains a forbidden character.");

window.jsTestIsAsync = true;

function escapeUnicodeCharacter(codePoint)
{
    var hexCode = codePoint.toString(16);
    while (hexCode.length < 4)
        hexCode = "0" + hexCode;
    return "\\u" + hexCode;
}

var url = "ws://127.0.0.1:8880/websocket/tests/hybi/accept-first-subprotocol";
var separators = "()<>@,;:\\\"/[]?={} \t";

function runTest(codePoint)
{
    if (codePoint == 128) {
        finishJSTest();
        return;
    }

    var character = String.fromCharCode(codePoint);
    if (codePoint >= 0x21 && codePoint <= 0x7E && separators.indexOf(character) === -1) {
        var ws = new WebSocket(url, character);
        ws.onopen = function()
        {
            testPassed("WebSocket correctly accepted subprotocol \"" + escapeUnicodeCharacter(codePoint) + "\"");
            ws.close();
        };
        ws.onclose = function()
        {
            setTimeout("runTest(" + (codePoint + 1) + ")", 0);
        };
    } else {
        shouldThrowErrorName("new WebSocket(url, \"" + escapeUnicodeCharacter(codePoint) + "\")", "SyntaxError");
        setTimeout("runTest(" + (codePoint + 1) + ")", 0);
    }
}

runTest(0);

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