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