-// requires local modules: util, websock, rfb, input/util, input/keysym, input/keysymdef, input/devices, inflator, des, display
-// requires test modules: fake.websocket, assertions
/* jshint expr: true */
var assert = chai.assert;
var expect = chai.expect;
+import RFB from '../core/rfb.js';
+import Websock from '../core/websock.js';
+import { encodings } from '../core/encodings.js';
+
+import FakeWebSocket from './fake.websocket.js';
+import sinon from '../vendor/sinon.js';
+
function make_rfb (extra_opts) {
if (!extra_opts) {
extra_opts = {};
beforeEach(function () { client._updateConnectionState = sinon.spy(); });
it('should set the current state to "connecting"', function () {
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
expect(client._updateConnectionState).to.have.been.calledOnce;
expect(client._updateConnectionState).to.have.been.calledWith('connecting');
});
- it('should not try to connect if we are missing a host', function () {
- client._fail = sinon.spy();
- client._rfb_connection_state = '';
- client.connect(undefined, 8675);
- expect(client._fail).to.have.been.calledOnce;
- expect(client._updateConnectionState).to.not.have.been.called;
- expect(client._rfb_connection_state).to.equal('');
- });
-
- it('should not try to connect if we are missing a port', function () {
+ it('should not try to connect if we are missing a URL', function () {
client._fail = sinon.spy();
client._rfb_connection_state = '';
- client.connect('abc');
+ client.connect(undefined);
expect(client._fail).to.have.been.calledOnce;
expect(client._updateConnectionState).to.not.have.been.called;
expect(client._rfb_connection_state).to.equal('');
});
});
- describe('#sendPassword', function () {
+ describe('#sendCredentials', function () {
beforeEach(function () { this.clock = sinon.useFakeTimers(); });
afterEach(function () { this.clock.restore(); });
- it('should set the rfb password properly"', function () {
- client.sendPassword('pass');
- expect(client._rfb_password).to.equal('pass');
+ it('should set the rfb credentials properly"', function () {
+ client.sendCredentials({ password: 'pass' });
+ expect(client._rfb_credentials).to.deep.equal({ password: 'pass' });
});
it('should call init_msg "soon"', function () {
client._init_msg = sinon.spy();
- client.sendPassword('pass');
+ client.sendCredentials({ password: 'pass' });
this.clock.tick(5);
expect(client._init_msg).to.have.been.calledOnce;
});
it('should send a single key with the given code and state (down = true)', function () {
var expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
RFB.messages.keyEvent(expected, 123, 1);
- client.sendKey(123, true);
+ client.sendKey(123, 'Key123', true);
expect(client._sock).to.have.sent(expected._sQ);
});
var expected = {_sQ: new Uint8Array(16), _sQlen: 0, flush: function () {}};
RFB.messages.keyEvent(expected, 123, 1);
RFB.messages.keyEvent(expected, 123, 0);
- client.sendKey(123);
+ client.sendKey(123, 'Key123');
expect(client._sock).to.have.sent(expected._sQ);
});
it('should not send the key if we are not in a normal state', function () {
client._rfb_connection_state = "broken";
- client.sendKey(123);
+ client.sendKey(123, 'Key123');
expect(client._sock.flush).to.not.have.been.called;
});
it('should not send the key if we are set as view_only', function () {
client._view_only = true;
- client.sendKey(123);
+ client.sendKey(123, 'Key123');
expect(client._sock.flush).to.not.have.been.called;
});
+
+ it('should send QEMU extended events if supported', function () {
+ client._qemuExtKeyEventSupported = true;
+ var expected = {_sQ: new Uint8Array(12), _sQlen: 0, flush: function () {}};
+ RFB.messages.QEMUExtendedKeyEvent(expected, 0x20, true, 0x0039);
+ client.sendKey(0x20, 'Space', true);
+ expect(client._sock).to.have.sent(expected._sQ);
+ });
+
+ it('should not send QEMU extended events if unknown key code', function () {
+ client._qemuExtKeyEventSupported = true;
+ var expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
+ RFB.messages.keyEvent(expected, 123, 1);
+ client.sendKey(123, 'FooBar', true);
+ expect(client._sock).to.have.sent(expected._sQ);
+ });
});
describe('#clipboardPasteFrom', function () {
client._rfb_xvp_ver = 1;
});
- it('should send the shutdown signal on #xvpShutdown', function () {
- client.xvpShutdown();
+ it('should send the shutdown signal on #machineShutdown', function () {
+ client.machineShutdown();
expect(client._sock).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x02]));
});
- it('should send the reboot signal on #xvpReboot', function () {
- client.xvpReboot();
+ it('should send the reboot signal on #machineReboot', function () {
+ client.machineReboot();
expect(client._sock).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x03]));
});
- it('should send the reset signal on #xvpReset', function () {
- client.xvpReset();
+ it('should send the reset signal on #machineReset', function () {
+ client.machineReset();
expect(client._sock).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x04]));
});
- it('should support sending arbitrary XVP operations via #xvpOp', function () {
- client.xvpOp(1, 7);
- expect(client._sock).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x07]));
- });
-
it('should not send XVP operations with higher versions than we support', function () {
- expect(client.xvpOp(2, 7)).to.be.false;
+ client._xvpOp(2, 7);
expect(client._sock.flush).to.not.have.been.called;
});
});
client.set_onUpdateState(sinon.spy());
client._updateConnectionState('connecting');
var spy = client.get_onUpdateState();
- expect(spy).to.have.been.calledOnce;
expect(spy.args[0][1]).to.equal('connecting');
});
beforeEach(function () {
this.clock = sinon.useFakeTimers();
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
});
afterEach(function () {
var client;
beforeEach(function () { client = make_rfb(); });
- it('should reset the variable states', function () {
- sinon.spy(client, '_init_vars');
- client._updateConnectionState('connecting');
- expect(client._init_vars).to.have.been.calledOnce;
- });
-
it('should actually connect to the websocket', function () {
sinon.spy(client._sock, 'open');
client._updateConnectionState('connecting');
expect(client._sock.open).to.have.been.calledOnce;
});
- it('should use wss:// to connect if encryption is enabled', function () {
- sinon.spy(client._sock, 'open');
- client.set_encrypt(true);
- client._updateConnectionState('connecting');
- expect(client._sock.open.args[0][0]).to.contain('wss://');
- });
-
- it('should use ws:// to connect if encryption is not enabled', function () {
- sinon.spy(client._sock, 'open');
- client.set_encrypt(true);
- client._updateConnectionState('connecting');
- expect(client._sock.open.args[0][0]).to.contain('wss://');
- });
-
- it('should use a uri with the host, port, and path specified to connect', function () {
+ it('should use a url specified to connect', function () {
sinon.spy(client._sock, 'open');
- client.set_encrypt(false);
- client._rfb_host = 'HOST';
- client._rfb_port = 8675;
- client._rfb_path = 'PATH';
+ client._url = 'ws://HOST:8675/PATH';
client._updateConnectionState('connecting');
expect(client._sock.open).to.have.been.calledWith('ws://HOST:8675/PATH');
});
beforeEach(function () {
this.clock = sinon.useFakeTimers();
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
});
afterEach(function () {
describe('Protocol Initialization States', function () {
describe('ProtocolVersion', function () {
+ var client;
beforeEach(function () {
- this.clock = sinon.useFakeTimers();
- });
-
- afterEach(function () {
- this.clock.restore();
+ client = make_rfb();
+ client.connect('wss://host:8675');
+ client._sock._websocket._open();
});
function send_ver (ver, client) {
var client;
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
});
});
});
- var client;
- beforeEach(function () {
- client = make_rfb();
- client.connect('host', 8675);
- client._sock._websocket._open();
- });
-
it('should handle two step repeater negotiation', function () {
client._repeaterID = '\x01\x02\x03\x04\x05';
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_init_state = 'Security';
});
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_init_state = 'Security';
});
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_init_state = 'Security';
client._rfb_version = 3.8;
});
- it('should call the passwordRequired callback if missing a password', function () {
- client.set_onPasswordRequired(sinon.spy());
+ it('should call the onCredentialsRequired callback if missing a password', function () {
+ client.set_onCredentialsRequired(sinon.spy());
send_security(2, client);
- var spy = client.get_onPasswordRequired();
- expect(client._rfb_password.length).to.equal(0);
+ var challenge = [];
+ for (var i = 0; i < 16; i++) { challenge[i] = i; }
+ client._sock._websocket._receive_data(new Uint8Array(challenge));
+
+ var spy = client.get_onCredentialsRequired();
+ expect(client._rfb_credentials).to.be.empty;
expect(spy).to.have.been.calledOnce;
+ expect(spy.args[0][1]).to.have.members(["password"]);
});
it('should encrypt the password with DES and then send it back', function () {
- client._rfb_password = 'passwd';
+ client._rfb_credentials = { password: 'passwd' };
send_security(2, client);
client._sock._websocket._get_sent_data(); // skip the choice of auth reply
});
it('should transition to SecurityResult immediately after sending the password', function () {
- client._rfb_password = 'passwd';
+ client._rfb_credentials = { password: 'passwd' };
send_security(2, client);
var challenge = [];
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_init_state = 'Security';
client._rfb_version = 3.8;
});
it('should fall through to standard VNC authentication upon completion', function () {
- client.set_xvp_password_sep('#');
- client._rfb_password = 'user#target#password';
+ client._rfb_credentials = { username: 'user',
+ target: 'target',
+ password: 'password' };
client._negotiate_std_vnc_auth = sinon.spy();
send_security(22, client);
expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce;
});
- it('should call the passwordRequired callback if the password is missing', function() {
- client.set_onPasswordRequired(sinon.spy());
- client._rfb_password = '';
+ it('should call the onCredentialsRequired callback if all credentials are missing', function() {
+ client.set_onCredentialsRequired(sinon.spy());
+ client._rfb_credentials = {};
send_security(22, client);
- var spy = client.get_onPasswordRequired();
- expect(client._rfb_password.length).to.equal(0);
+ var spy = client.get_onCredentialsRequired();
+ expect(client._rfb_credentials).to.be.empty;
expect(spy).to.have.been.calledOnce;
+ expect(spy.args[0][1]).to.have.members(["username", "password", "target"]);
});
- it('should call the passwordRequired callback if the password is improperly formatted', function() {
- client.set_onPasswordRequired(sinon.spy());
- client._rfb_password = 'user@target';
+ it('should call the onCredentialsRequired callback if some credentials are missing', function() {
+ client.set_onCredentialsRequired(sinon.spy());
+ client._rfb_credentials = { username: 'user',
+ target: 'target' };
send_security(22, client);
- var spy = client.get_onPasswordRequired();
+ var spy = client.get_onCredentialsRequired();
expect(spy).to.have.been.calledOnce;
+ expect(spy.args[0][1]).to.have.members(["username", "password", "target"]);
});
- it('should split the password, send the first two parts, and pass on the last part', function () {
- client.set_xvp_password_sep('#');
- client._rfb_password = 'user#target#password';
+ it('should send user and target separately', function () {
+ client._rfb_credentials = { username: 'user',
+ target: 'target',
+ password: 'password' };
client._negotiate_std_vnc_auth = sinon.spy();
send_security(22, client);
- expect(client._rfb_password).to.equal('password');
-
var expected = [22, 4, 6]; // auth selection, len user, len target
for (var i = 0; i < 10; i++) { expected[i+3] = 'usertarget'.charCodeAt(i); }
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_init_state = 'Security';
client._rfb_version = 3.8;
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_init_state = 'SecurityResult';
});
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_init_state = 'SecurityResult';
});
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_init_state = 'ServerInitialisation';
});
expect(client._rfb_connection_state).to.equal('connected');
});
- it('should set the true color mode on the display to the configuration variable', function () {
- client.set_true_color(false);
- sinon.spy(client._display, 'set_true_color');
- send_server_init({ true_color: 1 }, client);
- expect(client._display.set_true_color).to.have.been.calledOnce;
- expect(client._display.set_true_color).to.have.been.calledWith(false);
- });
-
it('should call the resize callback and resize the display', function () {
client.set_onFBResize(sinon.spy());
sinon.spy(client._display, 'resize');
expect(client._mouse.grab).to.have.been.calledOnce;
});
- it('should set the BPP and depth to 4 and 3 respectively if in true color mode', function () {
- client.set_true_color(true);
- send_server_init({}, client);
- expect(client._fb_Bpp).to.equal(4);
- expect(client._fb_depth).to.equal(3);
- });
+ describe('Initial Update Request', function () {
+ beforeEach(function () {
+ sinon.spy(RFB.messages, "pixelFormat");
+ sinon.spy(RFB.messages, "clientEncodings");
+ sinon.spy(RFB.messages, "fbUpdateRequest");
+ });
- it('should set the BPP and depth to 1 and 1 respectively if not in true color mode', function () {
- client.set_true_color(false);
- send_server_init({}, client);
- expect(client._fb_Bpp).to.equal(1);
- expect(client._fb_depth).to.equal(1);
- });
-
- // TODO(directxman12): test the various options in this configuration matrix
- it('should reply with the pixel format, client encodings, and initial update request', function () {
- client.set_true_color(true);
- client.set_local_cursor(false);
- // we skip the cursor encoding
- var expected = {_sQ: new Uint8Array(34 + 4 * (client._encodings.length - 1)),
- _sQlen: 0,
- flush: function () {}};
- RFB.messages.pixelFormat(expected, 4, 3, true);
- RFB.messages.clientEncodings(expected, client._encodings, false, true);
- RFB.messages.fbUpdateRequest(expected, false, 0, 0, 27, 32);
+ afterEach(function () {
+ RFB.messages.pixelFormat.restore();
+ RFB.messages.clientEncodings.restore();
+ RFB.messages.fbUpdateRequest.restore();
+ });
- send_server_init({ width: 27, height: 32 }, client);
- expect(client._sock).to.have.sent(expected._sQ);
+ // TODO(directxman12): test the various options in this configuration matrix
+ it('should reply with the pixel format, client encodings, and initial update request', function () {
+ send_server_init({ width: 27, height: 32 }, client);
+
+ expect(RFB.messages.pixelFormat).to.have.been.calledOnce;
+ expect(RFB.messages.pixelFormat).to.have.been.calledWith(client._sock, 24, true);
+ expect(RFB.messages.pixelFormat).to.have.been.calledBefore(RFB.messages.clientEncodings);
+ expect(RFB.messages.clientEncodings).to.have.been.calledOnce;
+ expect(RFB.messages.clientEncodings.getCall(0).args[1]).to.include(encodings.encodingTight);
+ expect(RFB.messages.clientEncodings).to.have.been.calledBefore(RFB.messages.fbUpdateRequest);
+ expect(RFB.messages.fbUpdateRequest).to.have.been.calledOnce;
+ expect(RFB.messages.fbUpdateRequest).to.have.been.calledWith(client._sock, false, 0, 0, 27, 32);
+ });
+
+ it('should reply with restricted settings for Intel AMT servers', function () {
+ send_server_init({ width: 27, height: 32, name: "Intel(r) AMT KVM"}, client);
+
+ expect(RFB.messages.pixelFormat).to.have.been.calledOnce;
+ expect(RFB.messages.pixelFormat).to.have.been.calledWith(client._sock, 8, true);
+ expect(RFB.messages.pixelFormat).to.have.been.calledBefore(RFB.messages.clientEncodings);
+ expect(RFB.messages.clientEncodings).to.have.been.calledOnce;
+ expect(RFB.messages.clientEncodings.getCall(0).args[1]).to.not.include(encodings.encodingTight);
+ expect(RFB.messages.clientEncodings.getCall(0).args[1]).to.not.include(encodings.encodingHextile);
+ expect(RFB.messages.clientEncodings).to.have.been.calledBefore(RFB.messages.fbUpdateRequest);
+ expect(RFB.messages.fbUpdateRequest).to.have.been.calledOnce;
+ expect(RFB.messages.fbUpdateRequest).to.have.been.calledWith(client._sock, false, 0, 0, 27, 32);
+ });
});
it('should transition to the "connected" state', function () {
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_connection_state = 'connected';
client._fb_name = 'some device';
});
describe('Framebuffer Update Handling', function () {
- var client;
-
- beforeEach(function () {
- client = make_rfb();
- client.connect('host', 8675);
- client._sock._websocket._open();
- client._rfb_connection_state = 'connected';
- client._fb_name = 'some device';
- client._fb_width = 640;
- client._fb_height = 20;
- });
-
var target_data_arr = [
0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
});
- it('should parse out information from a header before any actual data comes in', function () {
- client.set_onFBUReceive(sinon.spy());
- var rect_info = { x: 8, y: 11, width: 27, height: 32, encoding: 0x02, encodingName: 'RRE' };
- send_fbu_msg([rect_info], [[]], client);
-
- var spy = client.get_onFBUReceive();
- expect(spy).to.have.been.calledOnce;
- expect(spy).to.have.been.calledWith(sinon.match.any, rect_info);
- });
-
- it('should fire onFBUComplete when the update is complete', function () {
- client.set_onFBUComplete(sinon.spy());
- var rect_info = { x: 8, y: 11, width: 27, height: 32, encoding: -224, encodingName: 'last_rect' };
- send_fbu_msg([rect_info], [[]], client); // last_rect
-
- var spy = client.get_onFBUComplete();
- expect(spy).to.have.been.calledOnce;
- expect(spy).to.have.been.calledWith(sinon.match.any, rect_info);
- });
-
- it('should not fire onFBUComplete if we have not finished processing the update', function () {
- client.set_onFBUComplete(sinon.spy());
- var rect_info = { x: 8, y: 11, width: 27, height: 32, encoding: 0x00, encodingName: 'RAW' };
- send_fbu_msg([rect_info], [[]], client);
- expect(client.get_onFBUComplete()).to.not.have.been.called;
- });
-
- it('should call the appropriate encoding handler', function () {
- client._encHandlers[0x02] = sinon.spy();
- var rect_info = { x: 8, y: 11, width: 27, height: 32, encoding: 0x02 };
- send_fbu_msg([rect_info], [[]], client);
- expect(client._encHandlers[0x02]).to.have.been.calledOnce;
- });
-
it('should fail on an unsupported encoding', function () {
sinon.spy(client, "_fail");
var rect_info = { x: 8, y: 11, width: 27, height: 32, encoding: 234 };
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_connection_state = 'connected';
client._fb_name = 'some device';
// a really small frame
client._fb_width = 4;
client._fb_height = 4;
+ client._fb_depth = 24;
client._display.resize(4, 4);
- client._fb_Bpp = 4;
});
it('should handle the RAW encoding', function () {
expect(client._display).to.have.displayed(target_data);
});
+ it('should handle the RAW encoding in low colour mode', function () {
+ var info = [{ x: 0, y: 0, width: 2, height: 2, encoding: 0x00 },
+ { x: 2, y: 0, width: 2, height: 2, encoding: 0x00 },
+ { x: 0, y: 2, width: 4, height: 1, encoding: 0x00 },
+ { x: 0, y: 3, width: 4, height: 1, encoding: 0x00 }];
+ var rects = [
+ [0x03, 0x03, 0x03, 0x03],
+ [0x0c, 0x0c, 0x0c, 0x0c],
+ [0x0c, 0x0c, 0x03, 0x03],
+ [0x0c, 0x0c, 0x03, 0x03]];
+ client._fb_depth = 8;
+ send_fbu_msg(info, rects, client);
+ expect(client._display).to.have.displayed(target_data_check);
+ });
+
it('should handle the COPYRECT encoding', function () {
// seed some initial data to copy
client._display.blitRgbxImage(0, 0, 4, 2, new Uint8Array(target_data_check_arr.slice(0, 32)), 0);
var client;
beforeEach(function () {
client = make_rfb();
- client.connect('host', 8675);
+ client.connect('wss://host:8675');
client._sock._websocket._open();
client._rfb_connection_state = 'connected';
client._fb_name = 'some device';
client._fb_width = 4;
client._fb_height = 4;
client._display.resize(4, 4);
- client._fb_Bpp = 4;
});
it('should handle a tile with fg, bg specified, normal subrects', function () {
});
describe('the ExtendedDesktopSize pseudo-encoding handler', function () {
- var client;
-
beforeEach(function () {
- client = make_rfb();
- client.connect('host', 8675);
- client._sock._websocket._open();
- client._rfb_connection_state = 'connected';
- client._fb_name = 'some device';
client._supportsSetDesktopSize = false;
// a really small frame
client._fb_width = 4;
client._fb_height = 4;
client._display.resize(4, 4);
- client._fb_Bpp = 4;
sinon.spy(client._display, 'resize');
client.set_onFBResize(sinon.spy());
});
return data;
}
+ it('should call callback when resize is supported', function () {
+ client.set_onCapabilities(sinon.spy());
+
+ expect(client._supportsSetDesktopSize).to.be.false;
+ expect(client.get_capabilities().resize).to.be.false;
+
+ var reason_for_change = 0; // server initiated
+ var status_code = 0; // No error
+
+ send_fbu_msg([{ x: reason_for_change, y: status_code,
+ width: 4, height: 4, encoding: -308 }],
+ make_screen_data(1), client);
+
+ expect(client._supportsSetDesktopSize).to.be.true;
+ expect(client.get_onCapabilities()).to.have.been.calledOnce;
+ expect(client.get_onCapabilities().args[0][1].resize).to.be.true;
+ expect(client.get_capabilities().resize).to.be.true;
+ }),
+
it('should handle a resize requested by this client', function () {
var reason_for_change = 1; // requested by this client
var status_code = 0; // No error
width: 20, height: 50, encoding: -308 }],
make_screen_data(1), client);
- expect(client._supportsSetDesktopSize).to.be.true;
expect(client._fb_width).to.equal(20);
expect(client._fb_height).to.equal(50);
width: 20, height: 50, encoding: -308 }],
make_screen_data(1), client);
- expect(client._supportsSetDesktopSize).to.be.true;
expect(client._fb_width).to.equal(20);
expect(client._fb_height).to.equal(50);
width: 60, height: 50, encoding: -308 }],
make_screen_data(3), client);
- expect(client._supportsSetDesktopSize).to.be.true;
expect(client._fb_width).to.equal(60);
expect(client._fb_height).to.equal(50);
});
it('should handle the last_rect pseudo-encoding', function () {
- client.set_onFBUReceive(sinon.spy());
send_fbu_msg([{ x: 0, y: 0, width: 0, height: 0, encoding: -224}], [[]], client, 100);
expect(client._FBU.rects).to.equal(0);
- expect(client.get_onFBUReceive()).to.have.been.calledOnce;
});
});
});
- it('should set the colour map on the display on SetColourMapEntries', function () {
- var expected_cm = [];
- var data = [1, 0, 0, 1, 0, 4];
- var i;
- for (i = 0; i < 4; i++) {
- expected_cm[i + 1] = [i * 10, i * 10 + 1, i * 10 + 2];
- push16(data, expected_cm[i + 1][2] << 8);
- push16(data, expected_cm[i + 1][1] << 8);
- push16(data, expected_cm[i + 1][0] << 8);
- }
-
- client._sock._websocket._receive_data(new Uint8Array(data));
- expect(client._display.get_colourMap()).to.deep.equal(expected_cm);
- });
-
describe('XVP Message Handling', function () {
- beforeEach(function () {
- client = make_rfb();
- client.connect('host', 8675);
- client._sock._websocket._open();
- client._rfb_connection_state = 'connected';
- client._fb_name = 'some device';
- client._fb_width = 27;
- client._fb_height = 32;
- });
-
it('should send a notification on XVP_FAIL', function () {
client.set_onNotification(sinon.spy());
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 0]));
});
it('should set the XVP version and fire the callback with the version on XVP_INIT', function () {
- client.set_onXvpInit(sinon.spy());
+ client.set_onCapabilities(sinon.spy());
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 1]));
expect(client._rfb_xvp_ver).to.equal(10);
- expect(client.get_onXvpInit()).to.have.been.calledOnce;
- expect(client.get_onXvpInit()).to.have.been.calledWith(10);
+ expect(client.get_onCapabilities()).to.have.been.calledOnce;
+ expect(client.get_onCapabilities().args[0][1].power).to.be.true;
+ expect(client.get_capabilities().power).to.be.true;
});
it('should fail on unknown XVP message types', function () {
var expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: function() {}};
RFB.messages.enableContinuousUpdates(expected_msg, true, 0, 0, 90, 700);
- client._FBU.width = 450;
- client._FBU.height = 160;
-
- client._encHandlers.handle_FB_resize();
+ client._resize(450, 160);
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
client._enabledContinuousUpdates = true;
- client._FBU.width = 90;
- client._FBU.height = 700;
-
- client._encHandlers.handle_FB_resize();
+ client._resize(90, 700);
expect(client._sock).to.have.sent(expected_msg._sQ);
});
});
it('if enabled, viewportDragging should occur on mouse movement while a button is down', function () {
+ var oldX = 123;
+ var oldY = 109;
+ var newX = 123 + 11 * window.devicePixelRatio;
+ var newY = 109 + 4 * window.devicePixelRatio;
+
client._viewportDrag = true;
client._viewportDragging = true;
client._viewportHasMoved = false;
- client._viewportDragPos = { x: 23, y: 9 };
+ client._viewportDragPos = { x: oldX, y: oldY };
client._display.viewportChangePos = sinon.spy();
- client._mouse._onMouseMove(10, 4);
+ client._mouse._onMouseMove(newX, newY);
expect(client._viewportDragging).to.be.true;
expect(client._viewportHasMoved).to.be.true;
- expect(client._viewportDragPos).to.deep.equal({ x: 10, y: 4 });
+ expect(client._viewportDragPos).to.deep.equal({ x: newX, y: newY });
expect(client._display.viewportChangePos).to.have.been.calledOnce;
- expect(client._display.viewportChangePos).to.have.been.calledWith(13, 5);
+ expect(client._display.viewportChangePos).to.have.been.calledWith(oldX - newX, oldY - newY);
});
});
client._sock.open('ws://', 'binary');
client._sock._websocket._open();
sinon.spy(client._sock, 'flush');
+ client._rfb_connection_state = 'connected';
+ client._view_only = false;
});
it('should send a key message on a key press', function () {
var keyevent = {};
- keyevent.type = 'keydown';
- keyevent.keysym = {};
- keyevent.keysym.keysym = 1234;
- client._keyboard._onKeyPress(keyevent);
+ client._keyboard._onKeyEvent(0x41, 'KeyA', true);
var key_msg = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
- RFB.messages.keyEvent(key_msg, 1234, 1);
+ RFB.messages.keyEvent(key_msg, 0x41, 1);
expect(client._sock).to.have.sent(key_msg._sQ);
});
it('should not send messages in view-only mode', function () {
client._view_only = true;
- client._keyboard._onKeyPress(1234, 1);
+ client._keyboard._onKeyEvent('a', 'KeyA', true);
expect(client._sock.flush).to.not.have.been.called;
});
});
var client;
beforeEach(function () {
client = make_rfb();
+ client.connect('wss://host:8675');
this.clock = sinon.useFakeTimers();
});
// message events
it ('should do nothing if we receive an empty message and have nothing in the queue', function () {
- client.connect('host', 8675);
client._rfb_connection_state = 'connected';
client._normal_msg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([]));
});
it('should handle a message in the connected state as a normal message', function () {
- client.connect('host', 8675);
client._rfb_connection_state = 'connected';
client._normal_msg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
});
it('should handle a message in any non-disconnected/failed state like an init message', function () {
- client.connect('host', 8675);
client._rfb_init_state = 'ProtocolVersion';
client._init_msg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
});
it('should process all normal messages directly', function () {
- client.connect('host', 8675);
client._sock._websocket._open();
client._rfb_connection_state = 'connected';
client.set_onBell(sinon.spy());
// open events
it('should update the state to ProtocolVersion on open (if the state is "connecting")', function () {
- client.connect('host', 8675);
client._sock._websocket._open();
expect(client._rfb_init_state).to.equal('ProtocolVersion');
});
it('should fail if we are not currently ready to connect and we get an "open" event', function () {
sinon.spy(client, "_fail");
- client.connect('host', 8675);
client._rfb_connection_state = 'some_other_state';
client._sock._websocket._open();
expect(client._fail).to.have.been.calledOnce;
// close events
it('should transition to "disconnected" from "disconnecting" on a close event', function () {
- client.connect('host', 8675);
client._rfb_connection_state = 'disconnecting';
client._sock._websocket.close();
expect(client._rfb_connection_state).to.equal('disconnected');
it('should fail if we get a close event while connecting', function () {
sinon.spy(client, "_fail");
- client.connect('host', 8675);
client._rfb_connection_state = 'connecting';
client._sock._websocket.close();
expect(client._fail).to.have.been.calledOnce;
it('should fail if we get a close event while disconnected', function () {
sinon.spy(client, "_fail");
- client.connect('host', 8675);
client._rfb_connection_state = 'disconnected';
client._sock._websocket.close();
expect(client._fail).to.have.been.calledOnce;
it('should unregister close event handler', function () {
sinon.spy(client._sock, 'off');
- client.connect('host', 8675);
client._rfb_connection_state = 'disconnecting';
client._sock._websocket.close();
expect(client._sock.off).to.have.been.calledWith('close');