1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"/js-test-resources/js-test.js"></script>
8 description("WebSocket message event origin attribute test (String message)");
10 window
.jsTestIsAsync
= true;
14 clearTimeout(timeoutID
);
18 var ws
= new WebSocket("ws://localhost:8880/send");
20 var firstMessageToSend
= "This is the first message to send to the server.";
21 var secondMessageToSend
= "This is the second.";
22 // needs to be global to be accessbile from shouldBe().
26 ws
.onopen = function()
29 ws
.send(firstMessageToSend
);
32 ws
.onmessage = function(messageEvent
)
34 // The server should echo back the first message.
35 data
= messageEvent
.data
;
36 shouldBe("data", "firstMessageToSend");
37 origin
= messageEvent
.origin
;
38 shouldBeEqualToString("origin", "ws://localhost:8880");
39 ws
.onmessage = function(messageEvent
) {
40 // The server should echo back the second message.
41 data
= messageEvent
.data
;
42 shouldBe("data", "secondMessageToSend");
43 origin
= messageEvent
.origin
;
44 shouldBeEqualToString("origin", "ws://localhost:8880");
46 ws
.send(secondMessageToSend
);
49 ws
.onclose = function()
55 function timeOutCallback()
57 testFailed("Timed out in state: " + ws
.readyState
);
61 var timeoutID
= setTimeout(timeOutCallback
, 3000);