2011-07-05 Yuta Kitamura <yutak@chromium.org>
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hixie76 / send.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
5 <script src="../../../../js-test-resources/js-test-pre.js"></script>
6 </head>
7 <body>
8 <div id="description"></div>
9 <div id="console"></div>
10 <script type="text/javascript">
11 description("Web Socket send test");
12
13 window.jsTestIsAsync = true;
14
15 function endTest()
16 {
17     clearTimeout(timeoutID);
18     finishJSTest();
19 }
20
21 var ws = new WebSocket("ws://localhost:8880/websocket/tests/hixie76/send");
22
23 var FIRST_MESSAGE_TO_SEND = "This is the first message to send to the server.";
24 var SECOND_MESSAGE_TO_SEND = "This is the second.";
25 // data needs to be global to be accessbile from shouldBe().
26 var data = "";
27
28 ws.onopen = function()
29 {
30     debug("Connected.");
31     ws.send(FIRST_MESSAGE_TO_SEND);
32 };
33
34 ws.onmessage = function(messageEvent)
35 {
36     // The server should echo back the first message.
37     data = messageEvent.data;
38     shouldBe("data", "FIRST_MESSAGE_TO_SEND");
39     ws.onmessage = function(messageEvent) {
40         // The server should echo back the second message.
41         data = messageEvent.data;
42         shouldBe("data", "SECOND_MESSAGE_TO_SEND");
43     };
44     ws.send(SECOND_MESSAGE_TO_SEND);
45 };
46
47 ws.onclose = function()
48 {
49     debug("Closed.");
50     endTest();
51 };
52
53 function timeOutCallback()
54 {
55     testFailed("Timed out in state: " + ws.readyState);
56     endTest();
57 }
58
59 var timeoutID = setTimeout(timeOutCallback, 3000);
60
61 var successfullyParsed = true;
62 </script>
63 <script src="../../../../js-test-resources/js-test-post.js"></script>
64 </body>
65 </html>