From 5e72400c5a444e582e5f9d9d48e3fb56eab81677 Mon Sep 17 00:00:00 2001 From: Ryan Castner Date: Mon, 6 Apr 2020 17:38:33 -0400 Subject: [PATCH] Update test references --- tests/assertions.js | 4 +- tests/test.rfb.js | 328 +++++++++++++++++++++--------------------- tests/test.websock.js | 9 +- 3 files changed, 170 insertions(+), 171 deletions(-) diff --git a/tests/assertions.js b/tests/assertions.js index f734e0c5..8f57f988 100644 --- a/tests/assertions.js +++ b/tests/assertions.js @@ -29,12 +29,12 @@ chai.use(function (_chai, utils) { _chai.Assertion.addMethod('sent', function (target_data) { const obj = this._obj; obj.inspect = () => { - const res = { _webChannel: obj._webChannel, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen), + const res = { _rawChannel: obj._rawChannel, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen), _sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen) }; res.prototype = obj; return res; }; - const data = obj._webChannel._get_sent_data(); + const data = obj._rawChannel._get_sent_data(); let same = true; if (data.length != target_data.length) { same = false; diff --git a/tests/test.rfb.js b/tests/test.rfb.js index efe8f7b0..0c04c754 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -143,7 +143,7 @@ describe('Remote Frame Buffer Protocol Client', function () { url = url || 'wss://host:8675'; const rfb = new RFB(container, url, options); clock.tick(); - rfb._sock._rawChannel._open(); + rfb._webchannel._rawChannel._open(); rfb._rfb_connection_state = 'connected'; sinon.spy(rfb, "_disconnect"); rfbs.push(rfb); @@ -161,10 +161,10 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should actually connect to the websocket', function () { const client = new RFB(document.createElement('div'), 'ws://HOST:8675/PATH'); - sinon.spy(client._sock, 'open'); + sinon.spy(client._webchannel, 'open'); this.clock.tick(); - expect(client._sock.open).to.have.been.calledOnce; - expect(client._sock.open).to.have.been.calledWith('ws://HOST:8675/PATH'); + expect(client._webchannel.open).to.have.been.calledOnce; + expect(client._webchannel.open).to.have.been.calledWith('ws://HOST:8675/PATH'); }); }); @@ -186,21 +186,21 @@ describe('Remote Frame Buffer Protocol Client', function () { }); it('should unregister error event handler', function () { - sinon.spy(client._sock, 'off'); + sinon.spy(client._webchannel, 'off'); client.disconnect(); - expect(client._sock.off).to.have.been.calledWith('error'); + expect(client._webchannel.off).to.have.been.calledWith('error'); }); it('should unregister message event handler', function () { - sinon.spy(client._sock, 'off'); + sinon.spy(client._webchannel, 'off'); client.disconnect(); - expect(client._sock.off).to.have.been.calledWith('message'); + expect(client._webchannel.off).to.have.been.calledWith('message'); }); it('should unregister open event handler', function () { - sinon.spy(client._sock, 'off'); + sinon.spy(client._webchannel, 'off'); client.disconnect(); - expect(client._sock.off).to.have.been.calledWith('open'); + expect(client._webchannel.off).to.have.been.calledWith('open'); }); }); @@ -242,21 +242,21 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.keyEvent(expected, 0xFFE3, 0); client.sendCtrlAltDel(); - expect(client._sock).to.have.sent(expected._sQ); + expect(client._webchannel).to.have.sent(expected._sQ); }); it('should not send the keys if we are not in a normal state', function () { - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._rfb_connection_state = "connecting"; client.sendCtrlAltDel(); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); it('should not send the keys if we are set as view_only', function () { - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._viewOnly = true; client.sendCtrlAltDel(); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); }); @@ -265,7 +265,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: () => {}}; RFB.messages.keyEvent(expected, 123, 1); client.sendKey(123, 'Key123', true); - expect(client._sock).to.have.sent(expected._sQ); + expect(client._webchannel).to.have.sent(expected._sQ); }); it('should send both a down and up event if the state is not specified', function () { @@ -273,21 +273,21 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.keyEvent(expected, 123, 1); RFB.messages.keyEvent(expected, 123, 0); client.sendKey(123, 'Key123'); - expect(client._sock).to.have.sent(expected._sQ); + expect(client._webchannel).to.have.sent(expected._sQ); }); it('should not send the key if we are not in a normal state', function () { - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._rfb_connection_state = "connecting"; client.sendKey(123, 'Key123'); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); it('should not send the key if we are set as view_only', function () { - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._viewOnly = true; client.sendKey(123, 'Key123'); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); it('should send QEMU extended events if supported', function () { @@ -295,7 +295,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const expected = {_sQ: new Uint8Array(12), _sQlen: 0, flush: () => {}}; RFB.messages.QEMUExtendedKeyEvent(expected, 0x20, true, 0x0039); client.sendKey(0x20, 'Space', true); - expect(client._sock).to.have.sent(expected._sQ); + expect(client._webchannel).to.have.sent(expected._sQ); }); it('should not send QEMU extended events if unknown key code', function () { @@ -303,7 +303,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: () => {}}; RFB.messages.keyEvent(expected, 123, 1); client.sendKey(123, 'FooBar', true); - expect(client._sock).to.have.sent(expected._sQ); + expect(client._webchannel).to.have.sent(expected._sQ); }); }); @@ -339,7 +339,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client.clipboardPasteFrom('abc'); expect(RFB.messages.clientCutText).to.have.been.calledOnce; - expect(RFB.messages.clientCutText).to.have.been.calledWith(client._sock, + expect(RFB.messages.clientCutText).to.have.been.calledWith(client._webchannel, new Uint8Array([97, 98, 99])); }); @@ -352,7 +352,7 @@ describe('Remote Frame Buffer Protocol Client', function () { push32(data, toUnsigned32bit(-8)); data = data.concat(flags); data = data.concat(fileSizes); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); client.clipboardPasteFrom('extended test'); expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce; @@ -360,20 +360,20 @@ describe('Remote Frame Buffer Protocol Client', function () { }); it('should flush multiple times for large clipboards', function () { - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); let long_text = ""; - for (let i = 0; i < client._sock._sQbufferSize + 100; i++) { + for (let i = 0; i < client._webchannel._sQbufferSize + 100; i++) { long_text += 'a'; } client.clipboardPasteFrom(long_text); - expect(client._sock.flush).to.have.been.calledTwice; + expect(client._webchannel.flush).to.have.been.calledTwice; }); it('should not send the text if we are not in a normal state', function () { - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._rfb_connection_state = "connecting"; client.clipboardPasteFrom('abc'); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); }); @@ -384,23 +384,23 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should send the shutdown signal on #machineShutdown', function () { client.machineShutdown(); - expect(client._sock).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x02])); + expect(client._webchannel).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x02])); }); it('should send the reboot signal on #machineReboot', function () { client.machineReboot(); - expect(client._sock).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x03])); + expect(client._webchannel).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x03])); }); it('should send the reset signal on #machineReset', function () { client.machineReset(); - expect(client._sock).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x04])); + expect(client._webchannel).to.have.sent(new Uint8Array([0xFA, 0x00, 0x01, 0x04])); }); it('should not send XVP operations with higher versions than we support', function () { - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._xvpOp(2, 7); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); }); }); @@ -450,7 +450,7 @@ describe('Remote Frame Buffer Protocol Client', function () { sinon.spy(client._display, "viewportChangeSize"); - client._sock._rawChannel._receive_data(new Uint8Array(incoming)); + client._webchannel._rawChannel._receive_data(new Uint8Array(incoming)); // FIXME: Display implicitly calls viewportChangeSize() when // resizing the framebuffer, hence calledTwice. @@ -640,7 +640,7 @@ describe('Remote Frame Buffer Protocol Client', function () { sinon.spy(client._display, "autoscale"); - client._sock._rawChannel._receive_data(new Uint8Array(incoming)); + client._webchannel._rawChannel._receive_data(new Uint8Array(incoming)); expect(client._display.autoscale).to.have.been.calledOnce; expect(client._display.autoscale).to.have.been.calledWith(70, 80); @@ -695,7 +695,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._supportsSetDesktopSize = false; - client._sock._rawChannel._receive_data(new Uint8Array(incoming)); + client._webchannel._rawChannel._receive_data(new Uint8Array(incoming)); expect(RFB.messages.setDesktopSize).to.have.been.calledOnce; expect(RFB.messages.setDesktopSize).to.have.been.calledWith(sinon.match.object, 70, 80, 0, 0); @@ -704,7 +704,7 @@ describe('Remote Frame Buffer Protocol Client', function () { // Second message should not trigger a resize - client._sock._rawChannel._receive_data(new Uint8Array(incoming)); + client._webchannel._rawChannel._receive_data(new Uint8Array(incoming)); expect(RFB.messages.setDesktopSize).to.not.have.been.called; }); @@ -787,7 +787,7 @@ describe('Remote Frame Buffer Protocol Client', function () { 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 ]; - client._sock._rawChannel._receive_data(new Uint8Array(incoming)); + client._webchannel._rawChannel._receive_data(new Uint8Array(incoming)); expect(RFB.messages.setDesktopSize).to.not.have.been.called; }); @@ -857,9 +857,9 @@ describe('Remote Frame Buffer Protocol Client', function () { }); it('should close the WebSocket connection', function () { - sinon.spy(client._sock, 'close'); + sinon.spy(client._webchannel, 'close'); client._fail(); - expect(client._sock.close).to.have.been.calledOnce; + expect(client._webchannel.close).to.have.been.calledOnce; }); it('should transition to disconnected', function () { @@ -895,9 +895,9 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should open the websocket connection', function () { const client = new RFB(document.createElement('div'), 'ws://HOST:8675/PATH'); - sinon.spy(client._sock, 'open'); + sinon.spy(client._webchannel, 'open'); this.clock.tick(); - expect(client._sock.open).to.have.been.calledOnce; + expect(client._webchannel.open).to.have.been.calledOnce; }); }); @@ -918,7 +918,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should not result in a connect event if the state is not "connected"', function () { const spy = sinon.spy(); client.addEventListener("connect", spy); - client._sock._rawChannel.open = () => {}; // explicitly don't call onopen + client._webchannel._rawChannel.open = () => {}; // explicitly don't call onopen client._updateConnectionState('connecting'); expect(spy).to.not.have.been.called; }); @@ -932,7 +932,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should force disconnect if we do not call WebChannel.onclose within the disconnection timeout', function () { sinon.spy(client, '_updateConnectionState'); - client._sock._rawChannel.close = () => {}; // explicitly don't call onclose + client._webchannel._rawChannel.close = () => {}; // explicitly don't call onclose client._updateConnectionState('disconnecting'); this.clock.tick(3 * 1000); expect(client._updateConnectionState).to.have.been.calledTwice; @@ -943,21 +943,21 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should not fail if WebChannel.onclose gets called within the disconnection timeout', function () { client._updateConnectionState('disconnecting'); this.clock.tick(3 * 1000 / 2); - client._sock._rawChannel.close(); + client._webchannel._rawChannel.close(); this.clock.tick(3 * 1000 / 2 + 1); expect(client._rfb_connection_state).to.equal('disconnected'); }); it('should close the WebSocket connection', function () { - sinon.spy(client._sock, 'close'); + sinon.spy(client._webchannel, 'close'); client._updateConnectionState('disconnecting'); - expect(client._sock.close).to.have.been.calledOnce; + expect(client._webchannel.close).to.have.been.calledOnce; }); it('should not result in a disconnect event', function () { const spy = sinon.spy(); client.addEventListener("disconnect", spy); - client._sock._rawChannel.close = () => {}; // explicitly don't call onclose + client._webchannel._rawChannel.close = () => {}; // explicitly don't call onclose client._updateConnectionState('disconnecting'); expect(spy).to.not.have.been.called; }); @@ -1005,7 +1005,7 @@ describe('Remote Frame Buffer Protocol Client', function () { } arr[0] = 'R'; arr[1] = 'F'; arr[2] = 'B'; arr[3] = ' '; arr[11] = '\n'; - client._sock._rawChannel._receive_data(arr); + client._webchannel._rawChannel._receive_data(arr); } describe('version parsing', function () { @@ -1065,7 +1065,7 @@ describe('Remote Frame Buffer Protocol Client', function () { expected[i] = expected_str.charCodeAt(i); } - expect(client._sock).to.have.sent(new Uint8Array(expected)); + expect(client._webchannel).to.have.sent(new Uint8Array(expected)); }); it('should transition to the Security state on successful negotiation', function () { @@ -1083,7 +1083,7 @@ describe('Remote Frame Buffer Protocol Client', function () { send_ver('000.000', client); expect(client._rfb_version).to.equal(0); - const sent_data = client._sock._rawChannel._get_sent_data(); + const sent_data = client._webchannel._rawChannel._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); }); @@ -1106,31 +1106,31 @@ describe('Remote Frame Buffer Protocol Client', function () { const auth_scheme_raw = [1, 2, 3, 4]; const auth_scheme = (auth_scheme_raw[0] << 24) + (auth_scheme_raw[1] << 16) + (auth_scheme_raw[2] << 8) + auth_scheme_raw[3]; - client._sock._rawChannel._receive_data(new Uint8Array(auth_scheme_raw)); + client._webchannel._rawChannel._receive_data(new Uint8Array(auth_scheme_raw)); expect(client._rfb_auth_scheme).to.equal(auth_scheme); }); it('should prefer no authentication is possible', function () { client._rfb_version = 3.7; const auth_schemes = [2, 1, 3]; - client._sock._rawChannel._receive_data(new Uint8Array(auth_schemes)); + client._webchannel._rawChannel._receive_data(new Uint8Array(auth_schemes)); expect(client._rfb_auth_scheme).to.equal(1); - expect(client._sock).to.have.sent(new Uint8Array([1, 1])); + expect(client._webchannel).to.have.sent(new Uint8Array([1, 1])); }); it('should choose for the most prefered scheme possible for versions >= 3.7', function () { client._rfb_version = 3.7; const auth_schemes = [2, 22, 16]; - client._sock._rawChannel._receive_data(new Uint8Array(auth_schemes)); + client._webchannel._rawChannel._receive_data(new Uint8Array(auth_schemes)); expect(client._rfb_auth_scheme).to.equal(22); - expect(client._sock).to.have.sent(new Uint8Array([22])); + expect(client._webchannel).to.have.sent(new Uint8Array([22])); }); it('should fail if there are no supported schemes for versions >= 3.7', function () { sinon.spy(client, "_fail"); client._rfb_version = 3.7; const auth_schemes = [1, 32]; - client._sock._rawChannel._receive_data(new Uint8Array(auth_schemes)); + client._webchannel._rawChannel._receive_data(new Uint8Array(auth_schemes)); expect(client._fail).to.have.been.calledOnce; }); @@ -1138,7 +1138,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfb_version = 3.7; const failure_data = [0, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115]; sinon.spy(client, '_fail'); - client._sock._rawChannel._receive_data(new Uint8Array(failure_data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(failure_data)); expect(client._fail).to.have.been.calledOnce; expect(client._fail).to.have.been.calledWith( @@ -1149,7 +1149,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfb_version = 3.7; const auth_schemes = [1, 1]; client._negotiate_authentication = sinon.spy(); - client._sock._rawChannel._receive_data(new Uint8Array(auth_schemes)); + client._webchannel._rawChannel._receive_data(new Uint8Array(auth_schemes)); expect(client._rfb_init_state).to.equal('Authentication'); expect(client._negotiate_authentication).to.have.been.calledOnce; }); @@ -1161,7 +1161,7 @@ describe('Remote Frame Buffer Protocol Client', function () { }); function send_security(type, cl) { - cl._sock._rawChannel._receive_data(new Uint8Array([1, type])); + cl._webchannel._rawChannel._receive_data(new Uint8Array([1, type])); } it('should fail on auth scheme 0 (pre 3.7) with the given message', function () { @@ -1175,7 +1175,7 @@ describe('Remote Frame Buffer Protocol Client', function () { } sinon.spy(client, '_fail'); - client._sock._rawChannel._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); expect(client._fail).to.have.been.calledWith( 'Security negotiation failed on authentication scheme (reason: Whoopsies)'); }); @@ -1212,7 +1212,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const challenge = []; for (let i = 0; i < 16; i++) { challenge[i] = i; } - client._sock._rawChannel._receive_data(new Uint8Array(challenge)); + client._webchannel._rawChannel._receive_data(new Uint8Array(challenge)); expect(client._rfb_credentials).to.be.empty; expect(spy).to.have.been.calledOnce; @@ -1222,14 +1222,14 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should encrypt the password with DES and then send it back', function () { client._rfb_credentials = { password: 'passwd' }; send_security(2, client); - client._sock._rawChannel._get_sent_data(); // skip the choice of auth reply + client._webchannel._rawChannel._get_sent_data(); // skip the choice of auth reply const challenge = []; for (let i = 0; i < 16; i++) { challenge[i] = i; } - client._sock._rawChannel._receive_data(new Uint8Array(challenge)); + client._webchannel._rawChannel._receive_data(new Uint8Array(challenge)); const des_pass = RFB.genDES('passwd', challenge); - expect(client._sock).to.have.sent(new Uint8Array(des_pass)); + expect(client._webchannel).to.have.sent(new Uint8Array(des_pass)); }); it('should transition to SecurityResult immediately after sending the password', function () { @@ -1238,7 +1238,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const challenge = []; for (let i = 0; i < 16; i++) { challenge[i] = i; } - client._sock._rawChannel._receive_data(new Uint8Array(challenge)); + client._webchannel._rawChannel._receive_data(new Uint8Array(challenge)); expect(client._rfb_init_state).to.equal('SecurityResult'); }); @@ -1292,7 +1292,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const expected = [22, 4, 6]; // auth selection, len user, len target for (let i = 0; i < 10; i++) { expected[i+3] = 'usertarget'.charCodeAt(i); } - expect(client._sock).to.have.sent(new Uint8Array(expected)); + expect(client._webchannel).to.have.sent(new Uint8Array(expected)); }); }); @@ -1301,7 +1301,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfb_init_state = 'Security'; client._rfb_version = 3.8; send_security(16, client); - client._sock._rawChannel._get_sent_data(); // skip the security reply + client._webchannel._rawChannel._get_sent_data(); // skip the security reply }); function send_num_str_pairs(pairs, client) { @@ -1318,11 +1318,11 @@ describe('Remote Frame Buffer Protocol Client', function () { } } - client._sock._rawChannel._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); } it('should skip tunnel negotiation if no tunnels are requested', function () { - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); expect(client._rfb_tightvnc).to.be.true; }); @@ -1334,19 +1334,19 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should choose the notunnel tunnel type', function () { send_num_str_pairs([[0, 'TGHT', 'NOTUNNEL'], [123, 'OTHR', 'SOMETHNG']], client); - expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 0])); + expect(client._webchannel).to.have.sent(new Uint8Array([0, 0, 0, 0])); }); it('should choose the notunnel tunnel type for Siemens devices', function () { send_num_str_pairs([[1, 'SICR', 'SCHANNEL'], [2, 'SICR', 'SCHANLPW']], client); - expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 0])); + expect(client._webchannel).to.have.sent(new Uint8Array([0, 0, 0, 0])); }); it('should continue to sub-auth negotiation after tunnel negotiation', function () { send_num_str_pairs([[0, 'TGHT', 'NOTUNNEL']], client); - client._sock._rawChannel._get_sent_data(); // skip the tunnel choice here + client._webchannel._rawChannel._get_sent_data(); // skip the tunnel choice here send_num_str_pairs([[1, 'STDV', 'NOAUTH__']], client); - expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 1])); + expect(client._webchannel).to.have.sent(new Uint8Array([0, 0, 0, 1])); expect(client._rfb_init_state).to.equal('SecurityResult'); }); @@ -1354,7 +1354,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfb_tightvnc = true; client._negotiate_std_vnc_auth = sinon.spy(); send_num_str_pairs([[1, 'STDV', 'NOAUTH__'], [2, 'STDV', 'VNCAUTH_']], client); - expect(client._sock).to.have.sent([0, 0, 0, 1]); + expect(client._webchannel).to.have.sent([0, 0, 0, 1]); expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce; expect(client._rfb_auth_scheme).to.equal(2); });*/ // while this would make sense, the original code doesn't actually do this @@ -1362,7 +1362,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should accept the "no auth" auth type and transition to SecurityResult', function () { client._rfb_tightvnc = true; send_num_str_pairs([[1, 'STDV', 'NOAUTH__']], client); - expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 1])); + expect(client._webchannel).to.have.sent(new Uint8Array([0, 0, 0, 1])); expect(client._rfb_init_state).to.equal('SecurityResult'); }); @@ -1370,7 +1370,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfb_tightvnc = true; client._negotiate_std_vnc_auth = sinon.spy(); send_num_str_pairs([[2, 'STDV', 'VNCAUTH__']], client); - expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 2])); + expect(client._webchannel).to.have.sent(new Uint8Array([0, 0, 0, 2])); expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce; expect(client._rfb_auth_scheme).to.equal(2); }); @@ -1390,7 +1390,7 @@ describe('Remote Frame Buffer Protocol Client', function () { }); it('should fall through to ServerInitialisation on a response code of 0', function () { - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); expect(client._rfb_init_state).to.equal('ServerInitialisation'); }); @@ -1398,7 +1398,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfb_version = 3.8; sinon.spy(client, '_fail'); const failure_data = [0, 0, 0, 1, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115]; - client._sock._rawChannel._receive_data(new Uint8Array(failure_data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(failure_data)); expect(client._fail).to.have.been.calledWith( 'Security negotiation failed on security result (reason: whoops)'); }); @@ -1406,7 +1406,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should fail on an error code of 1 with a standard message for version < 3.8', function () { sinon.spy(client, '_fail'); client._rfb_version = 3.7; - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 1])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 1])); expect(client._fail).to.have.been.calledWith( 'Security handshake failed'); }); @@ -1414,7 +1414,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should result in securityfailure event when receiving a non zero status', function () { const spy = sinon.spy(); client.addEventListener("securityfailure", spy); - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 2])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 2])); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.status).to.equal(2); }); @@ -1425,7 +1425,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client.addEventListener("securityfailure", spy); const failure_data = [0, 0, 0, 1, 0, 0, 0, 12, 115, 117, 99, 104, 32, 102, 97, 105, 108, 117, 114, 101]; - client._sock._rawChannel._receive_data(new Uint8Array(failure_data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(failure_data)); expect(spy.args[0][0].detail.status).to.equal(1); expect(spy.args[0][0].detail.reason).to.equal('such failure'); }); @@ -1435,7 +1435,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("securityfailure", spy); const failure_data = [0, 0, 0, 1, 0, 0, 0, 0]; - client._sock._rawChannel._receive_data(new Uint8Array(failure_data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(failure_data)); expect(spy.args[0][0].detail.status).to.equal(1); expect('reason' in spy.args[0][0].detail).to.be.false; }); @@ -1444,7 +1444,7 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfb_version = 3.6; const spy = sinon.spy(); client.addEventListener("securityfailure", spy); - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 2])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 2])); expect(spy.args[0][0].detail.status).to.equal(2); expect('reason' in spy.args[0][0].detail).to.be.false; }); @@ -1455,7 +1455,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const client = make_rfb(); client._rfb_connection_state = 'connecting'; client._rfb_init_state = 'SecurityResult'; - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); expect(client._rfb_init_state).to.equal('ServerInitialisation'); }); @@ -1463,16 +1463,16 @@ describe('Remote Frame Buffer Protocol Client', function () { const client = make_rfb('wss://host:8675', { shared: true }); client._rfb_connection_state = 'connecting'; client._rfb_init_state = 'SecurityResult'; - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); - expect(client._sock).to.have.sent(new Uint8Array([1])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); + expect(client._webchannel).to.have.sent(new Uint8Array([1])); }); it('should send 0 if we are not in shared mode', function () { const client = make_rfb('wss://host:8675', { shared: false }); client._rfb_connection_state = 'connecting'; client._rfb_init_state = 'SecurityResult'; - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); - expect(client._sock).to.have.sent(new Uint8Array([0])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 0])); + expect(client._webchannel).to.have.sent(new Uint8Array([0])); }); }); @@ -1510,15 +1510,15 @@ describe('Remote Frame Buffer Protocol Client', function () { push8(data, 0); push8(data, 0); - client._sock._rawChannel._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); const name_data = []; let name_len = []; pushString(name_data, full_opts.name); push32(name_len, name_data.length); - client._sock._rawChannel._receive_data(new Uint8Array(name_len)); - client._sock._rawChannel._receive_data(new Uint8Array(name_data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(name_len)); + client._webchannel._rawChannel._receive_data(new Uint8Array(name_data)); } it('should set the framebuffer width and height', function () { @@ -1553,7 +1553,7 @@ describe('Remote Frame Buffer Protocol Client', function () { for (let i = 0; i < 16 + 32 + 48; i++) { tight_data.push(i); } - client._sock._rawChannel._receive_data(new Uint8Array(tight_data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(tight_data)); expect(client._rfb_connection_state).to.equal('connected'); }); @@ -1592,27 +1592,27 @@ describe('Remote Frame Buffer Protocol Client', 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.calledWith(client._webchannel, 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); + expect(RFB.messages.fbUpdateRequest).to.have.been.calledWith(client._webchannel, 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.calledWith(client._webchannel, 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); + expect(RFB.messages.fbUpdateRequest).to.have.been.calledWith(client._webchannel, false, 0, 0, 27, 32); }); }); @@ -1677,7 +1677,7 @@ describe('Remote Frame Buffer Protocol Client', function () { data = data.concat(rect_data[i]); } - client._sock._rawChannel._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); } it('should send an update request if there is sufficient data', function () { @@ -1685,14 +1685,14 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.fbUpdateRequest(expected_msg, true, 0, 0, 640, 20); client._framebufferUpdate = () => true; - client._sock._rawChannel._receive_data(new Uint8Array([0])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0])); - expect(client._sock).to.have.sent(expected_msg._sQ); + expect(client._webchannel).to.have.sent(expected_msg._sQ); }); it('should not send an update request if we need more data', function () { - client._sock._rawChannel._receive_data(new Uint8Array([0])); - expect(client._sock._rawChannel._get_sent_data()).to.have.length(0); + client._webchannel._rawChannel._receive_data(new Uint8Array([0])); + expect(client._webchannel._rawChannel._get_sent_data()).to.have.length(0); }); it('should resume receiving an update if we previously did not have enough data', function () { @@ -1700,21 +1700,21 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.fbUpdateRequest(expected_msg, true, 0, 0, 640, 20); // just enough to set FBU.rects - client._sock._rawChannel._receive_data(new Uint8Array([0, 0, 0, 3])); - expect(client._sock._rawChannel._get_sent_data()).to.have.length(0); + client._webchannel._rawChannel._receive_data(new Uint8Array([0, 0, 0, 3])); + expect(client._webchannel._rawChannel._get_sent_data()).to.have.length(0); - client._framebufferUpdate = function () { this._sock.rQskipBytes(1); return true; }; // we magically have enough data + client._framebufferUpdate = function () { this._webchannel.rQskipBytes(1); return true; }; // we magically have enough data // 247 should *not* be used as the message type here - client._sock._rawChannel._receive_data(new Uint8Array([247])); - expect(client._sock).to.have.sent(expected_msg._sQ); + client._webchannel._rawChannel._receive_data(new Uint8Array([247])); + expect(client._webchannel).to.have.sent(expected_msg._sQ); }); it('should not send a request in continuous updates mode', function () { client._enabledContinuousUpdates = true; client._framebufferUpdate = () => true; - client._sock._rawChannel._receive_data(new Uint8Array([0])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0])); - expect(client._sock._rawChannel._get_sent_data()).to.have.length(0); + expect(client._webchannel._rawChannel._get_sent_data()).to.have.length(0); }); it('should fail on an unsupported encoding', function () { @@ -2382,7 +2382,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should set the XVP version and fire the callback with the version on XVP_INIT', function () { const spy = sinon.spy(); client.addEventListener("capabilities", spy); - client._sock._rawChannel._receive_data(new Uint8Array([250, 0, 10, 1])); + client._webchannel._rawChannel._receive_data(new Uint8Array([250, 0, 10, 1])); expect(client._rfb_xvp_ver).to.equal(10); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.capabilities.power).to.be.true; @@ -2391,7 +2391,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should fail on unknown XVP message types', function () { sinon.spy(client, "_fail"); - client._sock._rawChannel._receive_data(new Uint8Array([250, 0, 10, 237])); + client._webchannel._rawChannel._receive_data(new Uint8Array([250, 0, 10, 237])); expect(client._fail).to.have.been.calledOnce; }); }); @@ -2405,7 +2405,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("clipboard", spy); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.text).to.equal(expected_str); }); @@ -2431,7 +2431,7 @@ describe('Remote Frame Buffer Protocol Client', function () { push32(data, toUnsigned32bit(-12)); data = data.concat(flags); data = data.concat(fileSizes); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); // Check that we give an response caps when we receive one expect(RFB.messages.extendedClipboardCaps).to.have.been.calledOnce; @@ -2457,7 +2457,7 @@ describe('Remote Frame Buffer Protocol Client', function () { push32(data, toUnsigned32bit(-8)); data = data.concat(flags); data = data.concat(fileSizes); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); }); describe('Handle Provide', function () { @@ -2481,7 +2481,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("clipboard", spy); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.text).to.equal(expectedData); client.removeEventListener("clipboard", spy); @@ -2508,7 +2508,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("clipboard", spy); - client._sock._websocket._receive_data(sendData); + client._webchannel._rawChannel._receive_data(sendData); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.text).to.equal(expectedData); client.removeEventListener("clipboard", spy); @@ -2540,7 +2540,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const spy = sinon.spy(); client.addEventListener("clipboard", spy); - client._sock._websocket._receive_data(sendData); + client._webchannel._rawChannel._receive_data(sendData); expect(spy).to.have.been.calledOnce; expect(spy.args[0][0].detail.text).to.equal(expectedData); client.removeEventListener("clipboard", spy); @@ -2564,10 +2564,10 @@ describe('Remote Frame Buffer Protocol Client', function () { data = data.concat(flags); let expectedData = [0x01]; - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); expect(RFB.messages.extendedClipboardRequest).to.have.been.calledOnce; - expect(RFB.messages.extendedClipboardRequest).to.have.been.calledWith(client._sock, expectedData); + expect(RFB.messages.extendedClipboardRequest).to.have.been.calledWith(client._webchannel, expectedData); }); }); @@ -2587,10 +2587,10 @@ describe('Remote Frame Buffer Protocol Client', function () { data = data.concat(flags); let expectedData = []; - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce; - expect(RFB.messages.extendedClipboardNotify).to.have.been.calledWith(client._sock, expectedData); + expect(RFB.messages.extendedClipboardNotify).to.have.been.calledWith(client._webchannel, expectedData); }); it('should send a Notify message with supported formats when receiving a Peek', function () { @@ -2605,10 +2605,10 @@ describe('Remote Frame Buffer Protocol Client', function () { client.clipboardPasteFrom("HejHej"); RFB.messages.extendedClipboardNotify.resetHistory(); - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce; - expect(RFB.messages.extendedClipboardNotify).to.have.been.calledWith(client._sock, expectedData); + expect(RFB.messages.extendedClipboardNotify).to.have.been.calledWith(client._webchannel, expectedData); }); }); @@ -2631,10 +2631,10 @@ describe('Remote Frame Buffer Protocol Client', function () { client.clipboardPasteFrom("HejHej"); expect(RFB.messages.extendedClipboardProvide).to.not.have.been.called; - client._sock._websocket._receive_data(new Uint8Array(data)); + client._webchannel._rawChannel._receive_data(new Uint8Array(data)); expect(RFB.messages.extendedClipboardProvide).to.have.been.calledOnce; - expect(RFB.messages.extendedClipboardProvide).to.have.been.calledWith(client._sock, expectedData, ["HejHej"]); + expect(RFB.messages.extendedClipboardProvide).to.have.been.calledWith(client._webchannel, expectedData, ["HejHej"]); }); }); }); @@ -2644,7 +2644,7 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should fire the bell callback on Bell', function () { const spy = sinon.spy(); client.addEventListener("bell", spy); - client._sock._rawChannel._receive_data(new Uint8Array([2])); + client._webchannel._rawChannel._receive_data(new Uint8Array([2])); expect(spy).to.have.been.calledOnce; }); @@ -2658,9 +2658,9 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.clientFence(expected_msg, (1<<0) | (1<<1), payload); RFB.messages.clientFence(incoming_msg, 0xffffffff, payload); - client._sock._rawChannel._receive_data(incoming_msg._sQ); + client._webchannel._rawChannel._receive_data(incoming_msg._sQ); - expect(client._sock).to.have.sent(expected_msg._sQ); + expect(client._webchannel).to.have.sent(expected_msg._sQ); expected_msg._sQlen = 0; incoming_msg._sQlen = 0; @@ -2668,9 +2668,9 @@ describe('Remote Frame Buffer Protocol Client', function () { RFB.messages.clientFence(expected_msg, (1<<0), payload); RFB.messages.clientFence(incoming_msg, (1<<0) | (1<<31), payload); - client._sock._rawChannel._receive_data(incoming_msg._sQ); + client._webchannel._rawChannel._receive_data(incoming_msg._sQ); - expect(client._sock).to.have.sent(expected_msg._sQ); + expect(client._webchannel).to.have.sent(expected_msg._sQ); }); it('should enable continuous updates on first EndOfContinousUpdates', function () { @@ -2680,17 +2680,17 @@ describe('Remote Frame Buffer Protocol Client', function () { expect(client._enabledContinuousUpdates).to.be.false; - client._sock._rawChannel._receive_data(new Uint8Array([150])); + client._webchannel._rawChannel._receive_data(new Uint8Array([150])); expect(client._enabledContinuousUpdates).to.be.true; - expect(client._sock).to.have.sent(expected_msg._sQ); + expect(client._webchannel).to.have.sent(expected_msg._sQ); }); it('should disable continuous updates on subsequent EndOfContinousUpdates', function () { client._enabledContinuousUpdates = true; client._supportsContinuousUpdates = true; - client._sock._rawChannel._receive_data(new Uint8Array([150])); + client._webchannel._rawChannel._receive_data(new Uint8Array([150])); expect(client._enabledContinuousUpdates).to.be.false; }); @@ -2701,18 +2701,18 @@ describe('Remote Frame Buffer Protocol Client', function () { client._resize(450, 160); - expect(client._sock._rawChannel._get_sent_data()).to.have.length(0); + expect(client._webchannel._rawChannel._get_sent_data()).to.have.length(0); client._enabledContinuousUpdates = true; client._resize(90, 700); - expect(client._sock).to.have.sent(expected_msg._sQ); + expect(client._webchannel).to.have.sent(expected_msg._sQ); }); it('should fail on an unknown message type', function () { sinon.spy(client, "_fail"); - client._sock._rawChannel._receive_data(new Uint8Array([87])); + client._webchannel._rawChannel._receive_data(new Uint8Array([87])); expect(client._fail).to.have.been.calledOnce; }); }); @@ -2726,30 +2726,30 @@ describe('Remote Frame Buffer Protocol Client', function () { describe('Mouse event handlers', function () { it('should not send button messages in view-only mode', function () { client._viewOnly = true; - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._handleMouseButton(0, 0, 1, 0x001); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); it('should not send movement messages in view-only mode', function () { client._viewOnly = true; - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._handleMouseMove(0, 0); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); it('should send a pointer event on mouse button presses', function () { client._handleMouseButton(10, 12, 1, 0x001); const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: () => {}}; RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x001); - expect(client._sock).to.have.sent(pointer_msg._sQ); + expect(client._webchannel).to.have.sent(pointer_msg._sQ); }); it('should send a mask of 1 on mousedown', function () { client._handleMouseButton(10, 12, 1, 0x001); const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: () => {}}; RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x001); - expect(client._sock).to.have.sent(pointer_msg._sQ); + expect(client._webchannel).to.have.sent(pointer_msg._sQ); }); it('should send a mask of 0 on mouseup', function () { @@ -2757,14 +2757,14 @@ describe('Remote Frame Buffer Protocol Client', function () { client._handleMouseButton(10, 12, 0, 0x001); const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: () => {}}; RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x000); - expect(client._sock).to.have.sent(pointer_msg._sQ); + expect(client._webchannel).to.have.sent(pointer_msg._sQ); }); it('should send a pointer event on mouse movement', function () { client._handleMouseMove(10, 12); const pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: () => {}}; RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x000); - expect(client._sock).to.have.sent(pointer_msg._sQ); + expect(client._webchannel).to.have.sent(pointer_msg._sQ); }); it('should set the button mask so that future mouse movements use it', function () { @@ -2773,7 +2773,7 @@ describe('Remote Frame Buffer Protocol Client', function () { const pointer_msg = {_sQ: new Uint8Array(12), _sQlen: 0, flush: () => {}}; RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x010); RFB.messages.pointerEvent(pointer_msg, 13, 9, 0x010); - expect(client._sock).to.have.sent(pointer_msg._sQ); + expect(client._webchannel).to.have.sent(pointer_msg._sQ); }); }); @@ -2782,14 +2782,14 @@ describe('Remote Frame Buffer Protocol Client', function () { client._handleKeyEvent(0x41, 'KeyA', true); const key_msg = {_sQ: new Uint8Array(8), _sQlen: 0, flush: () => {}}; RFB.messages.keyEvent(key_msg, 0x41, 1); - expect(client._sock).to.have.sent(key_msg._sQ); + expect(client._webchannel).to.have.sent(key_msg._sQ); }); it('should not send messages in view-only mode', function () { client._viewOnly = true; - sinon.spy(client._sock, 'flush'); + sinon.spy(client._webchannel, 'flush'); client._handleKeyEvent('a', 'KeyA', true); - expect(client._sock.flush).to.not.have.been.called; + expect(client._webchannel.flush).to.not.have.been.called; }); }); @@ -2797,13 +2797,13 @@ 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._normal_msg = sinon.spy(); - client._sock._rawChannel._receive_data(new Uint8Array([])); + client._webchannel._rawChannel._receive_data(new Uint8Array([])); expect(client._normal_msg).to.not.have.been.called; }); it('should handle a message in the connected state as a normal message', function () { client._normal_msg = sinon.spy(); - client._sock._rawChannel._receive_data(new Uint8Array([1, 2, 3])); + client._webchannel._rawChannel._receive_data(new Uint8Array([1, 2, 3])); expect(client._normal_msg).to.have.been.called; }); @@ -2811,14 +2811,14 @@ describe('Remote Frame Buffer Protocol Client', function () { client._rfb_connection_state = 'connecting'; client._rfb_init_state = 'ProtocolVersion'; client._init_msg = sinon.spy(); - client._sock._rawChannel._receive_data(new Uint8Array([1, 2, 3])); + client._webchannel._rawChannel._receive_data(new Uint8Array([1, 2, 3])); expect(client._init_msg).to.have.been.called; }); it('should process all normal messages directly', function () { const spy = sinon.spy(); client.addEventListener("bell", spy); - client._sock._rawChannel._receive_data(new Uint8Array([0x02, 0x02])); + client._webchannel._rawChannel._receive_data(new Uint8Array([0x02, 0x02])); expect(spy).to.have.been.calledTwice; }); @@ -2826,40 +2826,40 @@ describe('Remote Frame Buffer Protocol Client', function () { it('should update the state to ProtocolVersion on open (if the state is "connecting")', function () { client = new RFB(document.createElement('div'), 'wss://host:8675'); this.clock.tick(); - client._sock._rawChannel._open(); + client._webchannel._rawChannel._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._rfb_connection_state = 'connected'; - client._sock._rawChannel._open(); + client._webchannel._rawChannel._open(); expect(client._fail).to.have.been.calledOnce; }); // close events it('should transition to "disconnected" from "disconnecting" on a close event', function () { - const real = client._sock._rawChannel.close; - client._sock._rawChannel.close = () => {}; + const real = client._webchannel._rawChannel.close; + client._webchannel._rawChannel.close = () => {}; client.disconnect(); expect(client._rfb_connection_state).to.equal('disconnecting'); - client._sock._rawChannel.close = real; - client._sock._rawChannel.close(); + client._webchannel._rawChannel.close = real; + client._webchannel._rawChannel.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._rfb_connection_state = 'connecting'; - client._sock._rawChannel.close(); + client._webchannel._rawChannel.close(); expect(client._fail).to.have.been.calledOnce; }); it('should unregister close event handler', function () { - sinon.spy(client._sock, 'off'); + sinon.spy(client._webchannel, 'off'); client.disconnect(); - client._sock._rawChannel.close(); - expect(client._sock.off).to.have.been.calledWith('close'); + client._webchannel._rawChannel.close(); + expect(client._webchannel.off).to.have.been.calledWith('close'); }); // error events do nothing diff --git a/tests/test.websock.js b/tests/test.websock.js index b98ac161..2b49d74e 100644 --- a/tests/test.websock.js +++ b/tests/test.websock.js @@ -194,7 +194,6 @@ describe('WebChannel', function () { }); it('should actually send on the websocket', function () { - sock._channelStates = sock._getChannelStates("WebSocket"); sock._rawChannel.bufferedAmount = 8; sock._rawChannel.readyState = WebSocket.OPEN; sock._sQ = new Uint8Array([1, 2, 3]); @@ -270,7 +269,7 @@ describe('WebChannel', function () { }); it('should open the actual websocket', function () { - sock.open({ uri: 'ws://localhost:8675', protocols: 'binary' }); + sock.open('ws://localhost:8675', 'binary'); expect(WebSocket).to.have.been.calledWith('ws://localhost:8675', 'binary'); }); @@ -279,7 +278,7 @@ describe('WebChannel', function () { describe('closing', function () { beforeEach(function () { - sock.open({ uri: 'ws://' }); + sock.open('ws://'); sock._rawChannel.close = sinon.spy(); }); @@ -325,7 +324,7 @@ describe('WebChannel', function () { sock.on('open', sinon.spy()); sock.on('close', sinon.spy()); sock.on('error', sinon.spy()); - sock.open({ uri: 'ws://' }); + sock.open('ws://'); }); it('should call _recv_message on a message', function () { @@ -444,7 +443,7 @@ describe('WebChannel', function () { let sock; beforeEach(function () { sock = new WebChannel(); - sock.open({ uri: 'ws://', protocols: 'binary' }); + sock.open('ws://', 'binary'); sock._rawChannel._open(); });