PageRenderTime 212ms CodeModel.GetById 90ms app.highlight 4ms RepoModel.GetById 117ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/node-websocket-client/test/test-readonly-attrs.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 44 lines | 37 code | 6 blank | 1 comment | 0 complexity | c72def0fc258c21050c1b6e3adcec4e0 MD5 | raw file
 1// Verify that some attributes of a WebSocket object are read-only.
 2
 3var assert = require('assert');
 4var sys = require('sys');
 5var WebSocket = require('../lib/websocket').WebSocket;
 6var WebSocketServer = require('websocket-server/ws').Server;
 7
 8var PORT = 1024 + Math.floor(Math.random() * 4096);
 9
10var wss = new WebSocketServer();
11wss.listen(PORT, 'localhost');
12wss.addListener('connection', function(c) {
13    wss.close();
14});
15var ws = new WebSocket('ws://localhost:' + PORT + '/', 'biff');
16ws.addListener('open', function() {
17    assert.equal(ws.CONNECTING, 0);
18    try {
19        ws.CONNECTING = 13;
20        assert.equal(
21            ws.CONNECTING, 0,
22            'Should not have been able to set read-only CONNECTING attribute'
23        );
24    } catch (e) {
25        assert.equal(e.type, 'no_setter_in_callback');
26    }
27
28    assert.equal(ws.OPEN, 1);
29    assert.equal(ws.CLOSING, 2);
30    assert.equal(ws.CLOSED, 3);
31
32    assert.equal(ws.url, 'ws://localhost:' + PORT + '/');
33    try {
34        ws.url = 'foobar';
35        assert.equal(
36            ws.url, 'ws://localhost:' + PORT + '/',
37            'Should not have been able to set read-only url attribute'
38        );
39    } catch (e) {
40        assert.equal(e.type, 'no_setter_in_callback');
41    }
42
43    ws.close();
44});