blob: b871e910b7865858c95acecaf83f39fe52773e9d [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../../js-test-resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("Web Socket message event origin attribute test (String message)");
window.jsTestIsAsync = true;
function endTest()
{
clearTimeout(timeoutID);
finishJSTest();
}
var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/send");
var firstMessageToSend = "This is the first message to send to the server.";
var secondMessageToSend = "This is the second.";
// needs to be global to be accessbile from shouldBe().
var data = "";
var origin = "";
ws.onopen = function()
{
debug("Connected.");
ws.send(firstMessageToSend);
};
ws.onmessage = function(messageEvent)
{
// The server should echo back the first message.
data = messageEvent.data;
shouldBe("data", "firstMessageToSend");
origin = messageEvent.origin;
shouldBeEqualToString("origin", "ws://localhost:8880");
ws.onmessage = function(messageEvent) {
// The server should echo back the second message.
data = messageEvent.data;
shouldBe("data", "secondMessageToSend");
origin = messageEvent.origin;
shouldBeEqualToString("origin", "ws://localhost:8880");
};
ws.send(secondMessageToSend);
};
ws.onclose = function()
{
debug("Closed.");
endTest();
};
function timeOutCallback()
{
testFailed("Timed out in state: " + ws.readyState);
endTest();
}
var timeoutID = setTimeout(timeOutCallback, 3000);
</script>
<script src="../../../../js-test-resources/js-test-post.js"></script>
</body>
</html>