PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. // Verify that some attributes of a WebSocket object are read-only.
  2. var assert = require('assert');
  3. var sys = require('sys');
  4. var WebSocket = require('../lib/websocket').WebSocket;
  5. var WebSocketServer = require('websocket-server/ws').Server;
  6. var PORT = 1024 + Math.floor(Math.random() * 4096);
  7. var wss = new WebSocketServer();
  8. wss.listen(PORT, 'localhost');
  9. wss.addListener('connection', function(c) {
  10. wss.close();
  11. });
  12. var ws = new WebSocket('ws://localhost:' + PORT + '/', 'biff');
  13. ws.addListener('open', function() {
  14. assert.equal(ws.CONNECTING, 0);
  15. try {
  16. ws.CONNECTING = 13;
  17. assert.equal(
  18. ws.CONNECTING, 0,
  19. 'Should not have been able to set read-only CONNECTING attribute'
  20. );
  21. } catch (e) {
  22. assert.equal(e.type, 'no_setter_in_callback');
  23. }
  24. assert.equal(ws.OPEN, 1);
  25. assert.equal(ws.CLOSING, 2);
  26. assert.equal(ws.CLOSED, 3);
  27. assert.equal(ws.url, 'ws://localhost:' + PORT + '/');
  28. try {
  29. ws.url = 'foobar';
  30. assert.equal(
  31. ws.url, 'ws://localhost:' + PORT + '/',
  32. 'Should not have been able to set read-only url attribute'
  33. );
  34. } catch (e) {
  35. assert.equal(e.type, 'no_setter_in_callback');
  36. }
  37. ws.close();
  38. });