f464dbb25b9911b506e12dc8dda9f62991e23194
[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 <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>
10 description('Connection should fail immediately, rather than succeeding or staying in limbo until timeout, if a null byte is received before the handshake.');
11
12 window.jsTestIsAsync = true;
13 if (window.testRunner)
14     testRunner.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 1);
15
16 var timedOut = false;
17 var connected = false;
18 var origin;
19
20 function endTest() {
21     shouldBeFalse('timedOut');
22     shouldBeFalse('connected');
23     shouldBeUndefined('origin');
24     clearTimeout(timeoutID);
25     finishJSTest();
26 }
27
28 var url = 'ws://localhost:8880/websocket/tests/hixie76/handshake-fail-by-prepended-null';
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 (state = ' + ws.readyState + ')');
52     timedOut = true;
53     endTest();
54 }
55
56 var timeoutID = setTimeout(timeoutCallback, 3000);
57
58 </script>
59 <script src="../../../../js-test-resources/js-test-post.js"></script>
60 </body>
61 </html>