summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/http/tests/websocket/close-reason-too-long.html
blob: 9525747183fbead002b50b67002ed6dc1bb49dc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script type="text/javascript">
description("Checks whether SyntaxError is thrown when attempting to send too long reason.");

window.jsTestIsAsync = true;

var ws = new WebSocket("ws://localhost:8880/echo");
var message;
var longReason = '';
for (var i = 0; i < 124; ++i)
    longReason += 'a';

ws.onopen = function()
{
    debug("Connected.");
    try {
        ws.close(1000, longReason);
        testFailed('SyntaxError should be thrown.');
    } catch (e) {
        if (e.name == 'SyntaxError')
            testPassed('SyntaxError was thrown: ' + e);
        else
            testFailed('Unexpected exception: ' + e);
    }
    ws.close();
};

ws.onmessage = function (event)
{
    message = event.data;
    testFailed("onmessage() was called. (message = \"" + message + "\")");
};

ws.onclose = function()
{
    finishJSTest();
};

</script>
</body>
</html>