2011-07-05 Yuta Kitamura <yutak@chromium.org>
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hixie76 / handshake-fail-by-cross-origin.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("Make sure Web Socket connection failed if origin mismatches.");
12
13 window.jsTestIsAsync = true;
14
15 var connected = false;
16 var origin;
17
18 function endTest()
19 {
20     shouldBeFalse("connected");
21     shouldBeUndefined("origin");
22     clearTimeout(timeoutID);
23     finishJSTest();
24 }
25
26 var url = "ws://localhost:8880/websocket/tests/hixie76/fixed-origin";
27 debug("document.domain=" + document.domain);
28 debug("ws.url=" + url);
29 var ws = new WebSocket(url);
30
31 ws.onopen = function()
32 {
33     debug("Connected");
34     connected = true;
35 };
36
37 ws.onmessage = function (messageEvent)
38 {
39     origin = messageEvent.data;
40     debug("origin=" + origin);
41     ws.close();
42 };
43
44 ws.onclose = function()
45 {
46     endTest();
47 };
48
49 function timeOutCallback()
50 {
51     debug("Timed out in state: " + ws.readyState);
52     endTest();
53 }
54
55 var timeoutID = setTimeout(timeOutCallback, 3000);
56
57 var successfullyParsed = true;
58 </script>
59 <script src="../../../../js-test-resources/js-test-post.js"></script>
60 </body>
61 </html>