summaryrefslogtreecommitdiff
path: root/node_modules/socket.io/support/node-websocket-client/test/test-readonly-attrs.js
blob: de896b37696a5bb1a74cb33188c558fee74e6836 (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
// Verify that some attributes of a WebSocket object are read-only.

var assert = require('assert');
var sys = require('sys');
var WebSocket = require('../lib/websocket').WebSocket;
var WebSocketServer = require('websocket-server/ws/server').Server;

var PORT = 1024 + Math.floor(Math.random() * 4096);

var wss = new WebSocketServer();
wss.listen(PORT, 'localhost');
wss.on('connection', function(c) {
    c.close();
    wss.close();
});
var ws = new WebSocket('ws://localhost:' + PORT + '/', 'biff');
ws.on('open', function() {
    assert.equal(ws.CONNECTING, 0);
    try {
        ws.CONNECTING = 13;
        assert.equal(
            ws.CONNECTING, 0,
            'Should not have been able to set read-only CONNECTING attribute'
        );
    } catch (e) {
        assert.equal(e.type, 'no_setter_in_callback');
    }

    assert.equal(ws.OPEN, 1);
    assert.equal(ws.CLOSING, 2);
    assert.equal(ws.CLOSED, 3);

    assert.equal(ws.url, 'ws://localhost:' + PORT + '/');
    try {
        ws.url = 'foobar';
        assert.equal(
            ws.url, 'ws://localhost:' + PORT + '/',
            'Should not have been able to set read-only url attribute'
        );
    } catch (e) {
        assert.equal(e.type, 'no_setter_in_callback');
    }
});