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