<!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("Test whether WebSocket rejects frames whose reserved bit is on.");

window.jsTestIsAsync = true;

// "compressed=true&bitNumber=1" must not be included in compressedAndBitNumberParameters array.
var compressedAndBitNumberParameters = ["compressed=false&bitNumber=1",
                                        "compressed=false&bitNumber=2",
                                        "compressed=false&bitNumber=3",
                                        "compressed=true&bitNumber=2",
                                        "compressed=true&bitNumber=3"];
var closeEvent;

function doTest(curTestIndex)
{
    var url = "ws://localhost:8880/websocket/tests/hybi/reserved-bits?" + compressedAndBitNumberParameters[curTestIndex];
    var ws = new WebSocket(url);

    debug("Case " + compressedAndBitNumberParameters[curTestIndex] + ": Test started.");

    ws.onopen = function()
    {
        debug("onopen() was called.");
    };

    ws.onmessage = function(event)
    {
        var message = event.data;
        testFailed("onmessage() was called. (message = \"" + message + "\")");
    };

    ws.onclose = function(event)
    {
        debug("onclose() was called.");
        closeEvent = event;
        shouldBeFalse("closeEvent.wasClean");
        if (curTestIndex === compressedAndBitNumberParameters.length - 1)
            finishJSTest();
        else
            doTest(curTestIndex + 1);
    };
}

doTest(0);

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