WebSocket: Accept multiple subprotocols
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hybi / invalid-subprotocol-characters.html
1 <!DOCTYPE html>
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("WebSocket should fail if subprotocol contains a forbidden character.");
12
13 window.jsTestIsAsync = true;
14 if (window.layoutTestController)
15     layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
16
17 function escapeUnicodeCharacter(codePoint)
18 {
19     var hexCode = codePoint.toString(16);
20     while (hexCode.length < 4)
21         hexCode = "0" + hexCode;
22     return "\\u" + hexCode;
23 }
24
25 var url = "ws://127.0.0.1:8880/websocket/tests/hybi/accept-first-subprotocol";
26 var separators = "()<>@,;:\\\"/[]?={} \t";
27
28 function runTest(codePoint)
29 {
30     if (codePoint == 128) {
31         finishJSTest();
32         return;
33     }
34
35     var character = String.fromCharCode(codePoint);
36     if (codePoint >= 0x21 && codePoint <= 0x7E && separators.indexOf(character) === -1) {
37         var ws = new WebSocket(url, character);
38         ws.onopen = function()
39         {
40             testPassed("WebSocket correctly accepted subprotocol \"" + escapeUnicodeCharacter(codePoint) + "\"");
41             ws.close();
42         };
43         ws.onclose = function()
44         {
45             setTimeout("runTest(" + (codePoint + 1) + ")", 0);
46         };
47     } else {
48         shouldThrow("new WebSocket(url, \"" + escapeUnicodeCharacter(codePoint) + "\")", "'Error: SYNTAX_ERR: DOM Exception 12'");
49         setTimeout("runTest(" + (codePoint + 1) + ")", 0);
50     }
51 }
52
53 runTest(0);
54
55 var successfullyParsed = true;
56 </script>
57 <script src="../../../../js-test-resources/js-test-post.js"></script>
58 </body>
59 </html>