| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| <html> |
| <head> |
| <script src="/js-test-resources/js-test.js"></script> |
| </head> |
| <body> |
| <script> |
| description("WebSocket message event origin attribute test (String message)"); |
| |
| window.jsTestIsAsync = true; |
| |
| function endTest() |
| { |
| clearTimeout(timeoutID); |
| finishJSTest(); |
| } |
| |
| var ws = new WebSocket("ws://localhost:8880/send"); |
| |
| var firstMessageToSend = "This is the first message to send to the server."; |
| var secondMessageToSend = "This is the second."; |
| // needs to be global to be accessbile from shouldBe(). |
| var data = ""; |
| var origin = ""; |
| |
| ws.onopen = function() |
| { |
| debug("Connected."); |
| ws.send(firstMessageToSend); |
| }; |
| |
| ws.onmessage = function(messageEvent) |
| { |
| // The server should echo back the first message. |
| data = messageEvent.data; |
| shouldBe("data", "firstMessageToSend"); |
| origin = messageEvent.origin; |
| shouldBeEqualToString("origin", "ws://localhost:8880"); |
| ws.onmessage = function(messageEvent) { |
| // The server should echo back the second message. |
| data = messageEvent.data; |
| shouldBe("data", "secondMessageToSend"); |
| origin = messageEvent.origin; |
| shouldBeEqualToString("origin", "ws://localhost:8880"); |
| }; |
| ws.send(secondMessageToSend); |
| }; |
| |
| ws.onclose = function() |
| { |
| debug("Closed."); |
| endTest(); |
| }; |
| |
| function timeOutCallback() |
| { |
| testFailed("Timed out in state: " + ws.readyState); |
| endTest(); |
| } |
| |
| var timeoutID = setTimeout(timeOutCallback, 3000); |
| |
| </script> |
| </body> |
| </html> |