<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test-pre.js"></script>
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script type="text/javascript">
description("Simple upgrade insecure Web Socket test");

window.jsTestIsAsync = true;

if (window.testRunner)
    testRunner.setAllowsAnySSLCertificate(true);

function endTest()
{
    clearTimeout(timeoutID);
    finishJSTest();
}

var ws = new WebSocket("ws://127.0.0.1:9323/websocket/tests/hybi/simple");
debug("Created a socket to '" + ws.URL + "'; readyState " + ws.readyState + ".");
debug("The 'ws' protocol should be upgraded to 'wss'. If this happens, we will connect properly and the test will succeed.");

ws.onopen = function()
{
    debug("Connected; readyState " + ws.readyState);
    debug("Resolved URL: " + ws.URL)
};

ws.onmessage = function(messageEvent)
{
    debug("Received: '" + messageEvent.data + "'; readyState " + ws.readyState);
};

ws.onclose = function()
{
    debug("Closed; readyState " + ws.readyState + ".");
    endTest();
};

ws.onerror = function(errorEvent)
{
    debug("Error: '" + errorEvent.data + "'; readyState " + ws.readyState);
    endTest();
}

function timeOutCallback()
{
    debug("Timed out in state: " + ws.readyState);
    endTest();
}

var timeoutID = setTimeout(timeOutCallback, 300);

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