Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / websocket / invalid-subprotocol-characters.html
blobceb3f1a5d0b184221be3dfbba7e0aa21880b32d2
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/js-test-resources/js-test.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.");
12 window.jsTestIsAsync = true;
14 function escapeUnicodeCharacter(codePoint)
16 var hexCode = codePoint.toString(16);
17 while (hexCode.length < 4)
18 hexCode = "0" + hexCode;
19 return "\\u" + hexCode;
22 var url = "ws://127.0.0.1:8880/accept-first-subprotocol";
23 var separators = "()<>@,;:\\\"/[]?={} \t";
25 function runTest(codePoint)
27 if (codePoint == 128) {
28 finishJSTest();
29 return;
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()
37 testPassed("WebSocket correctly accepted subprotocol \"" + escapeUnicodeCharacter(codePoint) + "\"");
38 ws.close();
40 ws.onclose = function()
42 setTimeout("runTest(" + (codePoint + 1) + ")", 0);
44 } else {
45 shouldThrow("new WebSocket(url, \"" + escapeUnicodeCharacter(codePoint) + "\")");
46 setTimeout("runTest(" + (codePoint + 1) + ")", 0);
50 runTest(0);
52 </script>
53 </body>
54 </html>