2011-07-05 Yuta Kitamura <yutak@chromium.org>
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hixie76 / handshake-fail-by-prepended-null.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>
11 description('Connection should fail immediately, rather than succeeding or staying in limbo until timeout, if a null byte is received before the handshake.');
12
13 window.jsTestIsAsync = true;
14
15 var timedOut = false;
16 var connected = false;
17 var origin;
18
19 function endTest() {
20     shouldBeFalse('timedOut');
21     shouldBeFalse('connected');
22     shouldBeUndefined('origin');
23     clearTimeout(timeoutID);
24     finishJSTest();
25 }
26
27 var url = 'ws://localhost:8880/websocket/tests/hixie76/handshake-fail-by-prepended-null';
28 var ws = new WebSocket(url);
29
30 ws.onopen = function()
31 {
32     debug('Connected');
33     connected = true;
34 }
35
36 ws.onmessage = function(messageEvent)
37 {
38     origin = messageEvent.data;
39     debug('origin = ' + origin);
40     ws.close();
41 }
42
43 ws.onclose = function()
44 {
45     endTest();
46 }
47
48 function timeoutCallback()
49 {
50     debug('Timed out (state = ' + ws.readyState + ')');
51     timedOut = true;
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>