1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"/js-test-resources/js-test.js"></script>
7 <div id=
"description"></div>
8 <div id=
"console"></div>
9 <script type=
"text/javascript">
10 description("WebSocket send test");
12 window
.jsTestIsAsync
= true;
16 clearTimeout(timeoutID
);
20 var ws
= new WebSocket("ws://localhost:8880/send");
22 var FIRST_MESSAGE_TO_SEND
= "This is the first message to send to the server.";
23 var SECOND_MESSAGE_TO_SEND
= "This is the second.";
24 // data needs to be global to be accessbile from shouldBe().
27 ws
.onopen = function()
30 ws
.send(FIRST_MESSAGE_TO_SEND
);
33 ws
.onmessage = function(messageEvent
)
35 // The server should echo back the first message.
36 data
= messageEvent
.data
;
37 shouldBe("data", "FIRST_MESSAGE_TO_SEND");
38 ws
.onmessage = function(messageEvent
) {
39 // The server should echo back the second message.
40 data
= messageEvent
.data
;
41 shouldBe("data", "SECOND_MESSAGE_TO_SEND");
43 ws
.send(SECOND_MESSAGE_TO_SEND
);
46 ws
.onclose = function()
52 function timeOutCallback()
54 testFailed("Timed out in state: " + ws
.readyState
);
58 var timeoutID
= setTimeout(timeOutCallback
, 3000);