6033b5b4bf83c112f00c8edf4b4f65cd6752cd24
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hybi / handshake-fail-by-mismatch-protocol-header.html
1 <!DOCTYPE HTML>
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("Test whether WebSocket handshake fails if the server sends mismatched Sec-WebSocket-Protocol header.");
11
12 window.jsTestIsAsync = true;
13 if (window.testRunner)
14     testRunner.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
15
16 var url = "ws://localhost:8880/websocket/tests/hybi/handshake-fail-by-mismatch-protocol-header";
17 var closeEvent;
18 var ws;
19 var protocolCase = ["", "MatchProtocol", ["MatchProtocol1", "MatchProtocol2"]];
20
21 function doTest(index)
22 {
23     if (protocolCase[index] === "")
24         ws = new WebSocket(url);
25     else
26         ws = new WebSocket(url, protocolCase[index]);
27
28     ws.onopen = function()
29     {
30         testFailed("Connection established.");
31         ws.close();
32     };
33
34     ws.onclose = function(event)
35     {
36         closeEvent = event;
37         shouldBeFalse("closeEvent.wasClean");
38         if (index === protocolCase.length - 1) {
39             finishJSTest();
40             return;
41         }
42         doTest(index + 1);        
43     };
44 }
45
46 doTest(0);
47
48 </script>
49 <script src="../../../../js-test-resources/js-test-post.js"></script>
50 </body>
51 </html>