[WebSocket] Should raise SYNTAX_ERR when message contains unpaired surrogates
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hybi / unpaired-surrogates-in-close-reason.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
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("Checks whether SYNTAX_ERR is thrown when attemping to close the connection with unpaired surrogates.");
11
12 window.jsTestIsAsync = true;
13 if (window.layoutTestController)
14     layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
15
16 var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/echo");
17
18 ws.onopen = function()
19 {
20     debug("Connected.");
21     try {
22         ws.close(1000, '\uD807');
23         testFailed('SYNTAX_ERR should be thrown.');
24     } catch(e) {
25         if (e.name == 'SYNTAX_ERR')
26             testPassed('SYNTAX_ERR was thrown.');
27         else
28             testFailed('Unexpected exception: ' + e);
29     }
30     ws.close();
31 };
32
33 ws.onmessage = function (event)
34 {
35     var message = event.data;
36     testFailed("onmessage() was called. (message = \"" + message + "\")");
37 };
38
39 ws.onclose = function()
40 {
41     finishJSTest();
42 };
43
44 </script>
45 <script src="../../../../js-test-resources/js-test-post.js"></script>
46 </body>
47 </html>