]> git.proxmox.com Git - mirror_novnc.git/blobdiff - tests/test.rfb.js
Remove non-JavaScript render code
[mirror_novnc.git] / tests / test.rfb.js
index 88878c298e5b4daa56f3124ec430df5cf2f92c1b..a1d2f9e9e8c77b06392b3fdb8315c735ac672c87 100644 (file)
@@ -4,20 +4,14 @@ 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 './assertions';
-import 'sinon';
-import sinonChai from '../node_modules/sinon-chai/lib/sinon-chai.js'
-chai.use(sinonChai);
+import sinon from '../vendor/sinon.js';
 
 function make_rfb (extra_opts) {
-    if (!extra_opts) {
-        extra_opts = {};
-    }
-
-    extra_opts.target = extra_opts.target || document.createElement('canvas');
-    return new RFB(extra_opts);
+    extra_opts = extra_opts || {};
+    return new RFB(document.createElement('canvas'), extra_opts);
 }
 
 var push8 = function (arr, num) {
@@ -75,24 +69,15 @@ describe('Remote Frame Buffer Protocol Client', function() {
             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 () {
+            it('should not try to connect if we are missing a URL', 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 () {
-                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('');
@@ -127,18 +112,18 @@ describe('Remote Frame Buffer Protocol Client', function() {
             });
         });
 
-        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;
             });
@@ -193,7 +178,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
             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);
             });
 
@@ -201,21 +186,37 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 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 () {
@@ -295,28 +296,23 @@ describe('Remote Frame Buffer Protocol Client', 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;
             });
         });
@@ -347,7 +343,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 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');
             });
 
@@ -386,7 +381,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
             beforeEach(function () {
                 this.clock = sinon.useFakeTimers();
                 client = make_rfb();
-                client.connect('host', 8675);
+                client.connect('wss://host:8675');
             });
 
             afterEach(function () {
@@ -459,38 +454,15 @@ describe('Remote Frame Buffer Protocol Client', 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 () {
+            it('should use a url specified to connect', 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 () {
-                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');
             });
@@ -501,7 +473,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
             beforeEach(function () {
                 this.clock = sinon.useFakeTimers();
                 client = make_rfb();
-                client.connect('host', 8675);
+                client.connect('wss://host:8675');
             });
 
             afterEach(function () {
@@ -580,12 +552,11 @@ describe('Remote Frame Buffer Protocol Client', 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) {
@@ -602,19 +573,10 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 var client;
                 beforeEach(function () {
                     client = make_rfb();
-                    client.connect('host', 8675);
+                    client.connect('wss://host:8675');
                     client._sock._websocket._open();
                 });
 
-                it('should interpret version 000.000 as a repeater', function () {
-                    client._repeaterID = '\x01\x02\x03\x04\x05';
-                    send_ver('000.000', client);
-                    expect(client._rfb_version).to.equal(0);
-
-                    var sent_data = client._sock._websocket._get_sent_data();
-                    expect(new Uint8Array(sent_data.buffer, 0, 5)).to.array.equal(new Uint8Array([1, 2, 3, 4, 5]));
-                });
-
                 it('should interpret version 003.003 as version 3.3', function () {
                     send_ver('003.003', client);
                     expect(client._rfb_version).to.equal(3.3);
@@ -662,26 +624,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 });
             });
 
-            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';
-
-                send_ver('000.000', client);
-                expect(client._rfb_version).to.equal(0);
-                var sent_data = client._sock._websocket._get_sent_data();
-                expect(new Uint8Array(sent_data.buffer, 0, 5)).to.array.equal(new Uint8Array([1, 2, 3, 4, 5]));
-                expect(sent_data).to.have.length(250);
-
-                send_ver('003.008', client);
-                expect(client._rfb_version).to.equal(3.8);
-            });
-
             it('should send back the interpreted version', function () {
                 send_ver('004.000', client);
 
@@ -698,6 +640,29 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 send_ver('003.008', client);
                 expect(client._rfb_init_state).to.equal('Security');
             });
+
+            describe('Repeater', function () {
+                it('should interpret version 000.000 as a repeater', function () {
+                    client = make_rfb();
+                    client.connect('wss://host:8675', { repeaterID: "12345" });
+                    client._sock._websocket._open();
+                    send_ver('000.000', client);
+                    expect(client._rfb_version).to.equal(0);
+
+                    var sent_data = client._sock._websocket._get_sent_data();
+                    expect(new Uint8Array(sent_data.buffer, 0, 9)).to.array.equal(new Uint8Array([73, 68, 58, 49, 50, 51, 52, 53, 0]));
+                    expect(sent_data).to.have.length(250);
+                });
+
+                it('should handle two step repeater negotiation', function () {
+                    client = make_rfb();
+                    client.connect('wss://host:8675', { repeaterID: "12345" });
+                    client._sock._websocket._open();
+                    send_ver('000.000', client);
+                    send_ver('003.008', client);
+                    expect(client._rfb_version).to.equal(3.8);
+                });
+            });
         });
 
         describe('Security', function () {
@@ -705,7 +670,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             beforeEach(function () {
                 client = make_rfb();
-                client.connect('host', 8675);
+                client.connect('wss://host:8675');
                 client._sock._websocket._open();
                 client._rfb_init_state = 'Security';
             });
@@ -769,7 +734,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             beforeEach(function () {
                 client = make_rfb();
-                client.connect('host', 8675);
+                client.connect('wss://host:8675');
                 client._sock._websocket._open();
                 client._rfb_init_state = 'Security';
             });
@@ -818,23 +783,28 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
                 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
 
@@ -847,7 +817,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 });
 
                 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 = [];
@@ -863,48 +833,51 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
                 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); }
 
@@ -917,7 +890,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
                 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;
@@ -1007,7 +980,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             beforeEach(function () {
                 client = make_rfb();
-                client.connect('host', 8675);
+                client.connect('wss://host:8675');
                 client._sock._websocket._open();
                 client._rfb_init_state = 'SecurityResult';
             });
@@ -1040,24 +1013,28 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             beforeEach(function () {
                 client = make_rfb();
-                client.connect('host', 8675);
-                client._sock._websocket._open();
-                client._rfb_init_state = 'SecurityResult';
             });
 
             it('should transition to the ServerInitialisation state', function () {
+                client.connect('wss://host:8675');
+                client._sock._websocket._open();
+                client._rfb_init_state = 'SecurityResult';
                 client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
                 expect(client._rfb_init_state).to.equal('ServerInitialisation');
             });
 
             it('should send 1 if we are in shared mode', function () {
-                client.set_shared(true);
+                client.connect('wss://host:8675', { shared: true });
+                client._sock._websocket._open();
+                client._rfb_init_state = 'SecurityResult';
                 client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
                 expect(client._sock).to.have.sent(new Uint8Array([1]));
             });
 
             it('should send 0 if we are not in shared mode', function () {
-                client.set_shared(false);
+                client.connect('wss://host:8675', { shared: false });
+                client._sock._websocket._open();
+                client._rfb_init_state = 'SecurityResult';
                 client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
                 expect(client._sock).to.have.sent(new Uint8Array([0]));
             });
@@ -1068,7 +1045,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             beforeEach(function () {
                 client = make_rfb();
-                client.connect('host', 8675);
+                client.connect('wss://host:8675');
                 client._sock._websocket._open();
                 client._rfb_init_state = 'ServerInitialisation';
             });
@@ -1149,14 +1126,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 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');
@@ -1178,34 +1147,46 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 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 () {
@@ -1220,7 +1201,7 @@ describe('Remote Frame Buffer Protocol Client', 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';
@@ -1229,18 +1210,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
         });
 
         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,
@@ -1324,40 +1293,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 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 };
@@ -1386,15 +1321,15 @@ describe('Remote Frame Buffer Protocol Client', 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';
                     // 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 () {
@@ -1412,6 +1347,21 @@ describe('Remote Frame Buffer Protocol Client', 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);
@@ -1457,7 +1407,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
                     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';
@@ -1465,7 +1415,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
                         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 () {
@@ -1626,20 +1575,12 @@ describe('Remote Frame Buffer Protocol Client', 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());
                     });
@@ -1660,6 +1601,25 @@ describe('Remote Frame Buffer Protocol Client', function() {
                         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
@@ -1668,7 +1628,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
                                         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);
 
@@ -1688,7 +1647,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
                                         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);
 
@@ -1708,7 +1666,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
                                         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);
 
@@ -1743,40 +1700,13 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 });
 
                 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]));
@@ -1786,11 +1716,12 @@ describe('Remote Frame Buffer Protocol Client', function() {
             });
 
             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 () {
@@ -1870,19 +1801,13 @@ describe('Remote Frame Buffer Protocol Client', 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);
         });
@@ -2017,22 +1942,21 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 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;
             });
         });
@@ -2041,6 +1965,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
             var client;
             beforeEach(function () {
                 client = make_rfb();
+                client.connect('wss://host:8675');
                 this.clock = sinon.useFakeTimers();
             });
 
@@ -2048,7 +1973,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             // 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([]));
@@ -2056,7 +1980,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
             });
 
             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]));
@@ -2064,7 +1987,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
             });
 
             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]));
@@ -2072,7 +1994,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
             });
 
             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());
@@ -2082,14 +2003,12 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             // 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;
@@ -2097,7 +2016,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             // 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');
@@ -2105,7 +2023,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             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;
@@ -2113,7 +2030,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             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;
@@ -2121,7 +2037,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
 
             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');