Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / websocket / send-onmessage-origin.html
blob7633d2f2282ede47a501f8fc7f98d02873f7705f
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="/js-test-resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description("WebSocket message event origin attribute test (String message)");
10 window.jsTestIsAsync = true;
12 function endTest()
14 clearTimeout(timeoutID);
15 finishJSTest();
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().
23 var data = "";
24 var origin = "";
26 ws.onopen = function()
28 debug("Connected.");
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()
51 debug("Closed.");
52 endTest();
55 function timeOutCallback()
57 testFailed("Timed out in state: " + ws.readyState);
58 endTest();
61 var timeoutID = setTimeout(timeOutCallback, 3000);
63 </script>
64 </body>
65 </html>