<!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 compression enabled/disabled frame receiving.");

window.jsTestIsAsync = true;

var closeEvent;
var ws;
var messageIndex;

var messages = [
    "Hello",
    "DisableCompression", // This disables compression
    "World",
    "EnableCompression", // This enables compression
    "Goodbye"
];

ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/deflate-frame");

ws.onopen = function(event)
{
    messageIndex = 0;
    debug("Sending message: \"" + messages[messageIndex] + "\"");
    ws.send(messages[messageIndex]);
};

ws.onmessage = function(event)
{
    shouldBe("event.data", "'" + messages[messageIndex] + "'");
    if (messageIndex === messages.length - 1)
        ws.close();
    else {
        messageIndex += 1;
        debug("Sending message: \"" + messages[messageIndex] + "\"");
        ws.send(messages[messageIndex]);
    }
};

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

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