4 <script src=
"/js-test-resources/js-test.js"></script>
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) {
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
) + "\"");
40 ws
.onclose = function()
42 setTimeout("runTest(" + (codePoint
+ 1) + ")", 0);
45 shouldThrow("new WebSocket(url, \"" + escapeUnicodeCharacter(codePoint
) + "\")");
46 setTimeout("runTest(" + (codePoint
+ 1) + ")", 0);