Update tests
This commit is contained in:
parent
1ab3479130
commit
6fd81e741b
|
|
@ -29,12 +29,12 @@ chai.use(function (_chai, utils) {
|
||||||
_chai.Assertion.addMethod('sent', function (target_data) {
|
_chai.Assertion.addMethod('sent', function (target_data) {
|
||||||
const obj = this._obj;
|
const obj = this._obj;
|
||||||
obj.inspect = () => {
|
obj.inspect = () => {
|
||||||
const res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
|
const res = { _webChannel: obj._webChannel, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
|
||||||
_sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen) };
|
_sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen) };
|
||||||
res.prototype = obj;
|
res.prototype = obj;
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
const data = obj._websocket._get_sent_data();
|
const data = obj._webChannel._get_sent_data();
|
||||||
let same = true;
|
let same = true;
|
||||||
if (data.length != target_data.length) {
|
if (data.length != target_data.length) {
|
||||||
same = false;
|
same = false;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
|
|
||||||
import RFB from '../core/rfb.js';
|
import RFB from '../core/rfb.js';
|
||||||
import Websock from '../core/websock.js';
|
import WebChannel from '../core/websock.js';
|
||||||
import { encodings } from '../core/encodings.js';
|
import { encodings } from '../core/encodings.js';
|
||||||
|
|
||||||
import FakeWebSocket from './fake.websocket.js';
|
import FakeWebSocket from './fake.websocket.js';
|
||||||
|
|
@ -62,12 +62,12 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
window.requestAnimationFrame = setTimeout;
|
window.requestAnimationFrame = setTimeout;
|
||||||
// Use a single set of buffers instead of reallocating to
|
// Use a single set of buffers instead of reallocating to
|
||||||
// speed up tests
|
// speed up tests
|
||||||
const sock = new Websock();
|
const sock = new WebChannel();
|
||||||
const _sQ = new Uint8Array(sock._sQbufferSize);
|
const _sQ = new Uint8Array(sock._sQbufferSize);
|
||||||
const rQ = new Uint8Array(sock._rQbufferSize);
|
const rQ = new Uint8Array(sock._rQbufferSize);
|
||||||
|
|
||||||
Websock.prototype._old_allocate_buffers = Websock.prototype._allocate_buffers;
|
WebChannel.prototype._old_allocate_buffers = WebChannel.prototype._allocate_buffers;
|
||||||
Websock.prototype._allocate_buffers = function () {
|
WebChannel.prototype._allocate_buffers = function () {
|
||||||
this._sQ = _sQ;
|
this._sQ = _sQ;
|
||||||
this._rQ = rQ;
|
this._rQ = rQ;
|
||||||
};
|
};
|
||||||
|
|
@ -75,7 +75,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
Websock.prototype._allocate_buffers = Websock.prototype._old_allocate_buffers;
|
WebChannel.prototype._allocate_buffers = WebChannel.prototype._old_allocate_buffers;
|
||||||
this.clock.restore();
|
this.clock.restore();
|
||||||
window.requestAnimationFrame = raf;
|
window.requestAnimationFrame = raf;
|
||||||
});
|
});
|
||||||
|
|
@ -110,7 +110,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
url = url || 'wss://host:8675';
|
url = url || 'wss://host:8675';
|
||||||
const rfb = new RFB(container, url, options);
|
const rfb = new RFB(container, url, options);
|
||||||
clock.tick();
|
clock.tick();
|
||||||
rfb._sock._websocket._open();
|
rfb._sock._webChannel._open();
|
||||||
rfb._rfb_connection_state = 'connected';
|
rfb._rfb_connection_state = 'connected';
|
||||||
sinon.spy(rfb, "_disconnect");
|
sinon.spy(rfb, "_disconnect");
|
||||||
rfbs.push(rfb);
|
rfbs.push(rfb);
|
||||||
|
|
@ -390,7 +390,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
sinon.spy(client._display, "viewportChangeSize");
|
sinon.spy(client._display, "viewportChangeSize");
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(incoming));
|
client._sock._webChannel._receive_data(new Uint8Array(incoming));
|
||||||
|
|
||||||
// FIXME: Display implicitly calls viewportChangeSize() when
|
// FIXME: Display implicitly calls viewportChangeSize() when
|
||||||
// resizing the framebuffer, hence calledTwice.
|
// resizing the framebuffer, hence calledTwice.
|
||||||
|
|
@ -580,7 +580,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
sinon.spy(client._display, "autoscale");
|
sinon.spy(client._display, "autoscale");
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(incoming));
|
client._sock._webChannel._receive_data(new Uint8Array(incoming));
|
||||||
|
|
||||||
expect(client._display.autoscale).to.have.been.calledOnce;
|
expect(client._display.autoscale).to.have.been.calledOnce;
|
||||||
expect(client._display.autoscale).to.have.been.calledWith(70, 80);
|
expect(client._display.autoscale).to.have.been.calledWith(70, 80);
|
||||||
|
|
@ -635,7 +635,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
client._supportsSetDesktopSize = false;
|
client._supportsSetDesktopSize = false;
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(incoming));
|
client._sock._webChannel._receive_data(new Uint8Array(incoming));
|
||||||
|
|
||||||
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
|
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
|
||||||
expect(RFB.messages.setDesktopSize).to.have.been.calledWith(sinon.match.object, 70, 80, 0, 0);
|
expect(RFB.messages.setDesktopSize).to.have.been.calledWith(sinon.match.object, 70, 80, 0, 0);
|
||||||
|
|
@ -644,7 +644,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
// Second message should not trigger a resize
|
// Second message should not trigger a resize
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(incoming));
|
client._sock._webChannel._receive_data(new Uint8Array(incoming));
|
||||||
|
|
||||||
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
|
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
@ -727,7 +727,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04,
|
||||||
0x00, 0x00, 0x00, 0x00 ];
|
0x00, 0x00, 0x00, 0x00 ];
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(incoming));
|
client._sock._webChannel._receive_data(new Uint8Array(incoming));
|
||||||
|
|
||||||
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
|
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
@ -858,7 +858,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should not result in a connect event if the state is not "connected"', function () {
|
it('should not result in a connect event if the state is not "connected"', function () {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("connect", spy);
|
client.addEventListener("connect", spy);
|
||||||
client._sock._websocket.open = () => {}; // explicitly don't call onopen
|
client._sock._webChannel.open = () => {}; // explicitly don't call onopen
|
||||||
client._updateConnectionState('connecting');
|
client._updateConnectionState('connecting');
|
||||||
expect(spy).to.not.have.been.called;
|
expect(spy).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
@ -870,9 +870,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client = make_rfb();
|
client = make_rfb();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should force disconnect if we do not call Websock.onclose within the disconnection timeout', function () {
|
it('should force disconnect if we do not call WebChannel.onclose within the disconnection timeout', function () {
|
||||||
sinon.spy(client, '_updateConnectionState');
|
sinon.spy(client, '_updateConnectionState');
|
||||||
client._sock._websocket.close = () => {}; // explicitly don't call onclose
|
client._sock._webChannel.close = () => {}; // explicitly don't call onclose
|
||||||
client._updateConnectionState('disconnecting');
|
client._updateConnectionState('disconnecting');
|
||||||
this.clock.tick(3 * 1000);
|
this.clock.tick(3 * 1000);
|
||||||
expect(client._updateConnectionState).to.have.been.calledTwice;
|
expect(client._updateConnectionState).to.have.been.calledTwice;
|
||||||
|
|
@ -880,10 +880,10 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
expect(client._rfb_connection_state).to.equal("disconnected");
|
expect(client._rfb_connection_state).to.equal("disconnected");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not fail if Websock.onclose gets called within the disconnection timeout', function () {
|
it('should not fail if WebChannel.onclose gets called within the disconnection timeout', function () {
|
||||||
client._updateConnectionState('disconnecting');
|
client._updateConnectionState('disconnecting');
|
||||||
this.clock.tick(3 * 1000 / 2);
|
this.clock.tick(3 * 1000 / 2);
|
||||||
client._sock._websocket.close();
|
client._sock._webChannel.close();
|
||||||
this.clock.tick(3 * 1000 / 2 + 1);
|
this.clock.tick(3 * 1000 / 2 + 1);
|
||||||
expect(client._rfb_connection_state).to.equal('disconnected');
|
expect(client._rfb_connection_state).to.equal('disconnected');
|
||||||
});
|
});
|
||||||
|
|
@ -897,7 +897,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should not result in a disconnect event', function () {
|
it('should not result in a disconnect event', function () {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("disconnect", spy);
|
client.addEventListener("disconnect", spy);
|
||||||
client._sock._websocket.close = () => {}; // explicitly don't call onclose
|
client._sock._webChannel.close = () => {}; // explicitly don't call onclose
|
||||||
client._updateConnectionState('disconnecting');
|
client._updateConnectionState('disconnecting');
|
||||||
expect(spy).to.not.have.been.called;
|
expect(spy).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
@ -945,7 +945,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
}
|
}
|
||||||
arr[0] = 'R'; arr[1] = 'F'; arr[2] = 'B'; arr[3] = ' ';
|
arr[0] = 'R'; arr[1] = 'F'; arr[2] = 'B'; arr[3] = ' ';
|
||||||
arr[11] = '\n';
|
arr[11] = '\n';
|
||||||
client._sock._websocket._receive_data(arr);
|
client._sock._webChannel._receive_data(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('version parsing', function () {
|
describe('version parsing', function () {
|
||||||
|
|
@ -1023,7 +1023,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
send_ver('000.000', client);
|
send_ver('000.000', client);
|
||||||
expect(client._rfb_version).to.equal(0);
|
expect(client._rfb_version).to.equal(0);
|
||||||
|
|
||||||
const sent_data = client._sock._websocket._get_sent_data();
|
const sent_data = client._sock._webChannel._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(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);
|
expect(sent_data).to.have.length(250);
|
||||||
});
|
});
|
||||||
|
|
@ -1046,14 +1046,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
const auth_scheme_raw = [1, 2, 3, 4];
|
const auth_scheme_raw = [1, 2, 3, 4];
|
||||||
const auth_scheme = (auth_scheme_raw[0] << 24) + (auth_scheme_raw[1] << 16) +
|
const auth_scheme = (auth_scheme_raw[0] << 24) + (auth_scheme_raw[1] << 16) +
|
||||||
(auth_scheme_raw[2] << 8) + auth_scheme_raw[3];
|
(auth_scheme_raw[2] << 8) + auth_scheme_raw[3];
|
||||||
client._sock._websocket._receive_data(new Uint8Array(auth_scheme_raw));
|
client._sock._webChannel._receive_data(new Uint8Array(auth_scheme_raw));
|
||||||
expect(client._rfb_auth_scheme).to.equal(auth_scheme);
|
expect(client._rfb_auth_scheme).to.equal(auth_scheme);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prefer no authentication is possible', function () {
|
it('should prefer no authentication is possible', function () {
|
||||||
client._rfb_version = 3.7;
|
client._rfb_version = 3.7;
|
||||||
const auth_schemes = [2, 1, 3];
|
const auth_schemes = [2, 1, 3];
|
||||||
client._sock._websocket._receive_data(new Uint8Array(auth_schemes));
|
client._sock._webChannel._receive_data(new Uint8Array(auth_schemes));
|
||||||
expect(client._rfb_auth_scheme).to.equal(1);
|
expect(client._rfb_auth_scheme).to.equal(1);
|
||||||
expect(client._sock).to.have.sent(new Uint8Array([1, 1]));
|
expect(client._sock).to.have.sent(new Uint8Array([1, 1]));
|
||||||
});
|
});
|
||||||
|
|
@ -1061,7 +1061,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should choose for the most prefered scheme possible for versions >= 3.7', function () {
|
it('should choose for the most prefered scheme possible for versions >= 3.7', function () {
|
||||||
client._rfb_version = 3.7;
|
client._rfb_version = 3.7;
|
||||||
const auth_schemes = [2, 22, 16];
|
const auth_schemes = [2, 22, 16];
|
||||||
client._sock._websocket._receive_data(new Uint8Array(auth_schemes));
|
client._sock._webChannel._receive_data(new Uint8Array(auth_schemes));
|
||||||
expect(client._rfb_auth_scheme).to.equal(22);
|
expect(client._rfb_auth_scheme).to.equal(22);
|
||||||
expect(client._sock).to.have.sent(new Uint8Array([22]));
|
expect(client._sock).to.have.sent(new Uint8Array([22]));
|
||||||
});
|
});
|
||||||
|
|
@ -1070,7 +1070,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
sinon.spy(client, "_fail");
|
sinon.spy(client, "_fail");
|
||||||
client._rfb_version = 3.7;
|
client._rfb_version = 3.7;
|
||||||
const auth_schemes = [1, 32];
|
const auth_schemes = [1, 32];
|
||||||
client._sock._websocket._receive_data(new Uint8Array(auth_schemes));
|
client._sock._webChannel._receive_data(new Uint8Array(auth_schemes));
|
||||||
expect(client._fail).to.have.been.calledOnce;
|
expect(client._fail).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1078,7 +1078,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client._rfb_version = 3.7;
|
client._rfb_version = 3.7;
|
||||||
const failure_data = [0, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115];
|
const failure_data = [0, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115];
|
||||||
sinon.spy(client, '_fail');
|
sinon.spy(client, '_fail');
|
||||||
client._sock._websocket._receive_data(new Uint8Array(failure_data));
|
client._sock._webChannel._receive_data(new Uint8Array(failure_data));
|
||||||
|
|
||||||
expect(client._fail).to.have.been.calledOnce;
|
expect(client._fail).to.have.been.calledOnce;
|
||||||
expect(client._fail).to.have.been.calledWith(
|
expect(client._fail).to.have.been.calledWith(
|
||||||
|
|
@ -1089,7 +1089,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client._rfb_version = 3.7;
|
client._rfb_version = 3.7;
|
||||||
const auth_schemes = [1, 1];
|
const auth_schemes = [1, 1];
|
||||||
client._negotiate_authentication = sinon.spy();
|
client._negotiate_authentication = sinon.spy();
|
||||||
client._sock._websocket._receive_data(new Uint8Array(auth_schemes));
|
client._sock._webChannel._receive_data(new Uint8Array(auth_schemes));
|
||||||
expect(client._rfb_init_state).to.equal('Authentication');
|
expect(client._rfb_init_state).to.equal('Authentication');
|
||||||
expect(client._negotiate_authentication).to.have.been.calledOnce;
|
expect(client._negotiate_authentication).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
@ -1101,7 +1101,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
function send_security(type, cl) {
|
function send_security(type, cl) {
|
||||||
cl._sock._websocket._receive_data(new Uint8Array([1, type]));
|
cl._sock._webChannel._receive_data(new Uint8Array([1, type]));
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should fail on auth scheme 0 (pre 3.7) with the given message', function () {
|
it('should fail on auth scheme 0 (pre 3.7) with the given message', function () {
|
||||||
|
|
@ -1115,7 +1115,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
sinon.spy(client, '_fail');
|
sinon.spy(client, '_fail');
|
||||||
client._sock._websocket._receive_data(new Uint8Array(data));
|
client._sock._webChannel._receive_data(new Uint8Array(data));
|
||||||
expect(client._fail).to.have.been.calledWith(
|
expect(client._fail).to.have.been.calledWith(
|
||||||
'Security negotiation failed on authentication scheme (reason: Whoopsies)');
|
'Security negotiation failed on authentication scheme (reason: Whoopsies)');
|
||||||
});
|
});
|
||||||
|
|
@ -1152,7 +1152,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
const challenge = [];
|
const challenge = [];
|
||||||
for (let i = 0; i < 16; i++) { challenge[i] = i; }
|
for (let i = 0; i < 16; i++) { challenge[i] = i; }
|
||||||
client._sock._websocket._receive_data(new Uint8Array(challenge));
|
client._sock._webChannel._receive_data(new Uint8Array(challenge));
|
||||||
|
|
||||||
expect(client._rfb_credentials).to.be.empty;
|
expect(client._rfb_credentials).to.be.empty;
|
||||||
expect(spy).to.have.been.calledOnce;
|
expect(spy).to.have.been.calledOnce;
|
||||||
|
|
@ -1162,11 +1162,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should encrypt the password with DES and then send it back', function () {
|
it('should encrypt the password with DES and then send it back', function () {
|
||||||
client._rfb_credentials = { password: 'passwd' };
|
client._rfb_credentials = { password: 'passwd' };
|
||||||
send_security(2, client);
|
send_security(2, client);
|
||||||
client._sock._websocket._get_sent_data(); // skip the choice of auth reply
|
client._sock._webChannel._get_sent_data(); // skip the choice of auth reply
|
||||||
|
|
||||||
const challenge = [];
|
const challenge = [];
|
||||||
for (let i = 0; i < 16; i++) { challenge[i] = i; }
|
for (let i = 0; i < 16; i++) { challenge[i] = i; }
|
||||||
client._sock._websocket._receive_data(new Uint8Array(challenge));
|
client._sock._webChannel._receive_data(new Uint8Array(challenge));
|
||||||
|
|
||||||
const des_pass = RFB.genDES('passwd', challenge);
|
const des_pass = RFB.genDES('passwd', challenge);
|
||||||
expect(client._sock).to.have.sent(new Uint8Array(des_pass));
|
expect(client._sock).to.have.sent(new Uint8Array(des_pass));
|
||||||
|
|
@ -1178,7 +1178,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
const challenge = [];
|
const challenge = [];
|
||||||
for (let i = 0; i < 16; i++) { challenge[i] = i; }
|
for (let i = 0; i < 16; i++) { challenge[i] = i; }
|
||||||
client._sock._websocket._receive_data(new Uint8Array(challenge));
|
client._sock._webChannel._receive_data(new Uint8Array(challenge));
|
||||||
|
|
||||||
expect(client._rfb_init_state).to.equal('SecurityResult');
|
expect(client._rfb_init_state).to.equal('SecurityResult');
|
||||||
});
|
});
|
||||||
|
|
@ -1241,7 +1241,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client._rfb_init_state = 'Security';
|
client._rfb_init_state = 'Security';
|
||||||
client._rfb_version = 3.8;
|
client._rfb_version = 3.8;
|
||||||
send_security(16, client);
|
send_security(16, client);
|
||||||
client._sock._websocket._get_sent_data(); // skip the security reply
|
client._sock._webChannel._get_sent_data(); // skip the security reply
|
||||||
});
|
});
|
||||||
|
|
||||||
function send_num_str_pairs(pairs, client) {
|
function send_num_str_pairs(pairs, client) {
|
||||||
|
|
@ -1258,11 +1258,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(data));
|
client._sock._webChannel._receive_data(new Uint8Array(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should skip tunnel negotiation if no tunnels are requested', function () {
|
it('should skip tunnel negotiation if no tunnels are requested', function () {
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 0]));
|
||||||
expect(client._rfb_tightvnc).to.be.true;
|
expect(client._rfb_tightvnc).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1284,7 +1284,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
it('should continue to sub-auth negotiation after tunnel negotiation', function () {
|
it('should continue to sub-auth negotiation after tunnel negotiation', function () {
|
||||||
send_num_str_pairs([[0, 'TGHT', 'NOTUNNEL']], client);
|
send_num_str_pairs([[0, 'TGHT', 'NOTUNNEL']], client);
|
||||||
client._sock._websocket._get_sent_data(); // skip the tunnel choice here
|
client._sock._webChannel._get_sent_data(); // skip the tunnel choice here
|
||||||
send_num_str_pairs([[1, 'STDV', 'NOAUTH__']], client);
|
send_num_str_pairs([[1, 'STDV', 'NOAUTH__']], client);
|
||||||
expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 1]));
|
expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 1]));
|
||||||
expect(client._rfb_init_state).to.equal('SecurityResult');
|
expect(client._rfb_init_state).to.equal('SecurityResult');
|
||||||
|
|
@ -1330,7 +1330,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fall through to ServerInitialisation on a response code of 0', function () {
|
it('should fall through to ServerInitialisation on a response code of 0', function () {
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 0]));
|
||||||
expect(client._rfb_init_state).to.equal('ServerInitialisation');
|
expect(client._rfb_init_state).to.equal('ServerInitialisation');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1338,7 +1338,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client._rfb_version = 3.8;
|
client._rfb_version = 3.8;
|
||||||
sinon.spy(client, '_fail');
|
sinon.spy(client, '_fail');
|
||||||
const failure_data = [0, 0, 0, 1, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115];
|
const failure_data = [0, 0, 0, 1, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115];
|
||||||
client._sock._websocket._receive_data(new Uint8Array(failure_data));
|
client._sock._webChannel._receive_data(new Uint8Array(failure_data));
|
||||||
expect(client._fail).to.have.been.calledWith(
|
expect(client._fail).to.have.been.calledWith(
|
||||||
'Security negotiation failed on security result (reason: whoops)');
|
'Security negotiation failed on security result (reason: whoops)');
|
||||||
});
|
});
|
||||||
|
|
@ -1346,7 +1346,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 () {
|
it('should fail on an error code of 1 with a standard message for version < 3.8', function () {
|
||||||
sinon.spy(client, '_fail');
|
sinon.spy(client, '_fail');
|
||||||
client._rfb_version = 3.7;
|
client._rfb_version = 3.7;
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 1]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 1]));
|
||||||
expect(client._fail).to.have.been.calledWith(
|
expect(client._fail).to.have.been.calledWith(
|
||||||
'Security handshake failed');
|
'Security handshake failed');
|
||||||
});
|
});
|
||||||
|
|
@ -1354,7 +1354,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should result in securityfailure event when receiving a non zero status', function () {
|
it('should result in securityfailure event when receiving a non zero status', function () {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("securityfailure", spy);
|
client.addEventListener("securityfailure", spy);
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 2]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 2]));
|
||||||
expect(spy).to.have.been.calledOnce;
|
expect(spy).to.have.been.calledOnce;
|
||||||
expect(spy.args[0][0].detail.status).to.equal(2);
|
expect(spy.args[0][0].detail.status).to.equal(2);
|
||||||
});
|
});
|
||||||
|
|
@ -1365,7 +1365,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client.addEventListener("securityfailure", spy);
|
client.addEventListener("securityfailure", spy);
|
||||||
const failure_data = [0, 0, 0, 1, 0, 0, 0, 12, 115, 117, 99, 104,
|
const failure_data = [0, 0, 0, 1, 0, 0, 0, 12, 115, 117, 99, 104,
|
||||||
32, 102, 97, 105, 108, 117, 114, 101];
|
32, 102, 97, 105, 108, 117, 114, 101];
|
||||||
client._sock._websocket._receive_data(new Uint8Array(failure_data));
|
client._sock._webChannel._receive_data(new Uint8Array(failure_data));
|
||||||
expect(spy.args[0][0].detail.status).to.equal(1);
|
expect(spy.args[0][0].detail.status).to.equal(1);
|
||||||
expect(spy.args[0][0].detail.reason).to.equal('such failure');
|
expect(spy.args[0][0].detail.reason).to.equal('such failure');
|
||||||
});
|
});
|
||||||
|
|
@ -1375,7 +1375,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("securityfailure", spy);
|
client.addEventListener("securityfailure", spy);
|
||||||
const failure_data = [0, 0, 0, 1, 0, 0, 0, 0];
|
const failure_data = [0, 0, 0, 1, 0, 0, 0, 0];
|
||||||
client._sock._websocket._receive_data(new Uint8Array(failure_data));
|
client._sock._webChannel._receive_data(new Uint8Array(failure_data));
|
||||||
expect(spy.args[0][0].detail.status).to.equal(1);
|
expect(spy.args[0][0].detail.status).to.equal(1);
|
||||||
expect('reason' in spy.args[0][0].detail).to.be.false;
|
expect('reason' in spy.args[0][0].detail).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
@ -1384,7 +1384,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client._rfb_version = 3.6;
|
client._rfb_version = 3.6;
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("securityfailure", spy);
|
client.addEventListener("securityfailure", spy);
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 2]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 2]));
|
||||||
expect(spy.args[0][0].detail.status).to.equal(2);
|
expect(spy.args[0][0].detail.status).to.equal(2);
|
||||||
expect('reason' in spy.args[0][0].detail).to.be.false;
|
expect('reason' in spy.args[0][0].detail).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
@ -1395,7 +1395,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
const client = make_rfb();
|
const client = make_rfb();
|
||||||
client._rfb_connection_state = 'connecting';
|
client._rfb_connection_state = 'connecting';
|
||||||
client._rfb_init_state = 'SecurityResult';
|
client._rfb_init_state = 'SecurityResult';
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 0]));
|
||||||
expect(client._rfb_init_state).to.equal('ServerInitialisation');
|
expect(client._rfb_init_state).to.equal('ServerInitialisation');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1403,7 +1403,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
const client = make_rfb('wss://host:8675', { shared: true });
|
const client = make_rfb('wss://host:8675', { shared: true });
|
||||||
client._rfb_connection_state = 'connecting';
|
client._rfb_connection_state = 'connecting';
|
||||||
client._rfb_init_state = 'SecurityResult';
|
client._rfb_init_state = 'SecurityResult';
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 0]));
|
||||||
expect(client._sock).to.have.sent(new Uint8Array([1]));
|
expect(client._sock).to.have.sent(new Uint8Array([1]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1411,7 +1411,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
const client = make_rfb('wss://host:8675', { shared: false });
|
const client = make_rfb('wss://host:8675', { shared: false });
|
||||||
client._rfb_connection_state = 'connecting';
|
client._rfb_connection_state = 'connecting';
|
||||||
client._rfb_init_state = 'SecurityResult';
|
client._rfb_init_state = 'SecurityResult';
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 0]));
|
||||||
expect(client._sock).to.have.sent(new Uint8Array([0]));
|
expect(client._sock).to.have.sent(new Uint8Array([0]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -1450,15 +1450,15 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
push8(data, 0);
|
push8(data, 0);
|
||||||
push8(data, 0);
|
push8(data, 0);
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(data));
|
client._sock._webChannel._receive_data(new Uint8Array(data));
|
||||||
|
|
||||||
const name_data = [];
|
const name_data = [];
|
||||||
let name_len = [];
|
let name_len = [];
|
||||||
pushString(name_data, full_opts.name);
|
pushString(name_data, full_opts.name);
|
||||||
push32(name_len, name_data.length);
|
push32(name_len, name_data.length);
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(name_len));
|
client._sock._webChannel._receive_data(new Uint8Array(name_len));
|
||||||
client._sock._websocket._receive_data(new Uint8Array(name_data));
|
client._sock._webChannel._receive_data(new Uint8Array(name_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should set the framebuffer width and height', function () {
|
it('should set the framebuffer width and height', function () {
|
||||||
|
|
@ -1493,7 +1493,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
for (let i = 0; i < 16 + 32 + 48; i++) {
|
for (let i = 0; i < 16 + 32 + 48; i++) {
|
||||||
tight_data.push(i);
|
tight_data.push(i);
|
||||||
}
|
}
|
||||||
client._sock._websocket._receive_data(new Uint8Array(tight_data));
|
client._sock._webChannel._receive_data(new Uint8Array(tight_data));
|
||||||
|
|
||||||
expect(client._rfb_connection_state).to.equal('connected');
|
expect(client._rfb_connection_state).to.equal('connected');
|
||||||
});
|
});
|
||||||
|
|
@ -1617,7 +1617,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
data = data.concat(rect_data[i]);
|
data = data.concat(rect_data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(data));
|
client._sock._webChannel._receive_data(new Uint8Array(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should send an update request if there is sufficient data', function () {
|
it('should send an update request if there is sufficient data', function () {
|
||||||
|
|
@ -1625,14 +1625,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
RFB.messages.fbUpdateRequest(expected_msg, true, 0, 0, 640, 20);
|
RFB.messages.fbUpdateRequest(expected_msg, true, 0, 0, 640, 20);
|
||||||
|
|
||||||
client._framebufferUpdate = () => true;
|
client._framebufferUpdate = () => true;
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0]));
|
client._sock._webChannel._receive_data(new Uint8Array([0]));
|
||||||
|
|
||||||
expect(client._sock).to.have.sent(expected_msg._sQ);
|
expect(client._sock).to.have.sent(expected_msg._sQ);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not send an update request if we need more data', function () {
|
it('should not send an update request if we need more data', function () {
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0]));
|
client._sock._webChannel._receive_data(new Uint8Array([0]));
|
||||||
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
|
expect(client._sock._webChannel._get_sent_data()).to.have.length(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resume receiving an update if we previously did not have enough data', function () {
|
it('should resume receiving an update if we previously did not have enough data', function () {
|
||||||
|
|
@ -1640,21 +1640,21 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
RFB.messages.fbUpdateRequest(expected_msg, true, 0, 0, 640, 20);
|
RFB.messages.fbUpdateRequest(expected_msg, true, 0, 0, 640, 20);
|
||||||
|
|
||||||
// just enough to set FBU.rects
|
// just enough to set FBU.rects
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 3]));
|
client._sock._webChannel._receive_data(new Uint8Array([0, 0, 0, 3]));
|
||||||
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
|
expect(client._sock._webChannel._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._sock.rQskipBytes(1); return true; }; // we magically have enough data
|
||||||
// 247 should *not* be used as the message type here
|
// 247 should *not* be used as the message type here
|
||||||
client._sock._websocket._receive_data(new Uint8Array([247]));
|
client._sock._webChannel._receive_data(new Uint8Array([247]));
|
||||||
expect(client._sock).to.have.sent(expected_msg._sQ);
|
expect(client._sock).to.have.sent(expected_msg._sQ);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not send a request in continuous updates mode', function () {
|
it('should not send a request in continuous updates mode', function () {
|
||||||
client._enabledContinuousUpdates = true;
|
client._enabledContinuousUpdates = true;
|
||||||
client._framebufferUpdate = () => true;
|
client._framebufferUpdate = () => true;
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0]));
|
client._sock._webChannel._receive_data(new Uint8Array([0]));
|
||||||
|
|
||||||
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
|
expect(client._sock._webChannel._get_sent_data()).to.have.length(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail on an unsupported encoding', function () {
|
it('should fail on an unsupported encoding', function () {
|
||||||
|
|
@ -2322,7 +2322,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 () {
|
it('should set the XVP version and fire the callback with the version on XVP_INIT', function () {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("capabilities", spy);
|
client.addEventListener("capabilities", spy);
|
||||||
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 1]));
|
client._sock._webChannel._receive_data(new Uint8Array([250, 0, 10, 1]));
|
||||||
expect(client._rfb_xvp_ver).to.equal(10);
|
expect(client._rfb_xvp_ver).to.equal(10);
|
||||||
expect(spy).to.have.been.calledOnce;
|
expect(spy).to.have.been.calledOnce;
|
||||||
expect(spy.args[0][0].detail.capabilities.power).to.be.true;
|
expect(spy.args[0][0].detail.capabilities.power).to.be.true;
|
||||||
|
|
@ -2331,7 +2331,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
it('should fail on unknown XVP message types', function () {
|
it('should fail on unknown XVP message types', function () {
|
||||||
sinon.spy(client, "_fail");
|
sinon.spy(client, "_fail");
|
||||||
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 237]));
|
client._sock._webChannel._receive_data(new Uint8Array([250, 0, 10, 237]));
|
||||||
expect(client._fail).to.have.been.calledOnce;
|
expect(client._fail).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -2344,7 +2344,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("clipboard", spy);
|
client.addEventListener("clipboard", spy);
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array(data));
|
client._sock._webChannel._receive_data(new Uint8Array(data));
|
||||||
expect(spy).to.have.been.calledOnce;
|
expect(spy).to.have.been.calledOnce;
|
||||||
expect(spy.args[0][0].detail.text).to.equal(expected_str);
|
expect(spy.args[0][0].detail.text).to.equal(expected_str);
|
||||||
});
|
});
|
||||||
|
|
@ -2352,7 +2352,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should fire the bell callback on Bell', function () {
|
it('should fire the bell callback on Bell', function () {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("bell", spy);
|
client.addEventListener("bell", spy);
|
||||||
client._sock._websocket._receive_data(new Uint8Array([2]));
|
client._sock._webChannel._receive_data(new Uint8Array([2]));
|
||||||
expect(spy).to.have.been.calledOnce;
|
expect(spy).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -2366,7 +2366,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
RFB.messages.clientFence(expected_msg, (1<<0) | (1<<1), payload);
|
RFB.messages.clientFence(expected_msg, (1<<0) | (1<<1), payload);
|
||||||
RFB.messages.clientFence(incoming_msg, 0xffffffff, payload);
|
RFB.messages.clientFence(incoming_msg, 0xffffffff, payload);
|
||||||
|
|
||||||
client._sock._websocket._receive_data(incoming_msg._sQ);
|
client._sock._webChannel._receive_data(incoming_msg._sQ);
|
||||||
|
|
||||||
expect(client._sock).to.have.sent(expected_msg._sQ);
|
expect(client._sock).to.have.sent(expected_msg._sQ);
|
||||||
|
|
||||||
|
|
@ -2376,7 +2376,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
RFB.messages.clientFence(expected_msg, (1<<0), payload);
|
RFB.messages.clientFence(expected_msg, (1<<0), payload);
|
||||||
RFB.messages.clientFence(incoming_msg, (1<<0) | (1<<31), payload);
|
RFB.messages.clientFence(incoming_msg, (1<<0) | (1<<31), payload);
|
||||||
|
|
||||||
client._sock._websocket._receive_data(incoming_msg._sQ);
|
client._sock._webChannel._receive_data(incoming_msg._sQ);
|
||||||
|
|
||||||
expect(client._sock).to.have.sent(expected_msg._sQ);
|
expect(client._sock).to.have.sent(expected_msg._sQ);
|
||||||
});
|
});
|
||||||
|
|
@ -2388,7 +2388,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
expect(client._enabledContinuousUpdates).to.be.false;
|
expect(client._enabledContinuousUpdates).to.be.false;
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array([150]));
|
client._sock._webChannel._receive_data(new Uint8Array([150]));
|
||||||
|
|
||||||
expect(client._enabledContinuousUpdates).to.be.true;
|
expect(client._enabledContinuousUpdates).to.be.true;
|
||||||
expect(client._sock).to.have.sent(expected_msg._sQ);
|
expect(client._sock).to.have.sent(expected_msg._sQ);
|
||||||
|
|
@ -2398,7 +2398,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client._enabledContinuousUpdates = true;
|
client._enabledContinuousUpdates = true;
|
||||||
client._supportsContinuousUpdates = true;
|
client._supportsContinuousUpdates = true;
|
||||||
|
|
||||||
client._sock._websocket._receive_data(new Uint8Array([150]));
|
client._sock._webChannel._receive_data(new Uint8Array([150]));
|
||||||
|
|
||||||
expect(client._enabledContinuousUpdates).to.be.false;
|
expect(client._enabledContinuousUpdates).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
@ -2409,7 +2409,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
client._resize(450, 160);
|
client._resize(450, 160);
|
||||||
|
|
||||||
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
|
expect(client._sock._webChannel._get_sent_data()).to.have.length(0);
|
||||||
|
|
||||||
client._enabledContinuousUpdates = true;
|
client._enabledContinuousUpdates = true;
|
||||||
|
|
||||||
|
|
@ -2420,7 +2420,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
it('should fail on an unknown message type', function () {
|
it('should fail on an unknown message type', function () {
|
||||||
sinon.spy(client, "_fail");
|
sinon.spy(client, "_fail");
|
||||||
client._sock._websocket._receive_data(new Uint8Array([87]));
|
client._sock._webChannel._receive_data(new Uint8Array([87]));
|
||||||
expect(client._fail).to.have.been.calledOnce;
|
expect(client._fail).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -2505,13 +2505,13 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
// message events
|
// message events
|
||||||
it('should do nothing if we receive an empty message and have nothing in the queue', function () {
|
it('should do nothing if we receive an empty message and have nothing in the queue', function () {
|
||||||
client._normal_msg = sinon.spy();
|
client._normal_msg = sinon.spy();
|
||||||
client._sock._websocket._receive_data(new Uint8Array([]));
|
client._sock._webChannel._receive_data(new Uint8Array([]));
|
||||||
expect(client._normal_msg).to.not.have.been.called;
|
expect(client._normal_msg).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle a message in the connected state as a normal message', function () {
|
it('should handle a message in the connected state as a normal message', function () {
|
||||||
client._normal_msg = sinon.spy();
|
client._normal_msg = sinon.spy();
|
||||||
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
|
client._sock._webChannel._receive_data(new Uint8Array([1, 2, 3]));
|
||||||
expect(client._normal_msg).to.have.been.called;
|
expect(client._normal_msg).to.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -2519,14 +2519,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
client._rfb_connection_state = 'connecting';
|
client._rfb_connection_state = 'connecting';
|
||||||
client._rfb_init_state = 'ProtocolVersion';
|
client._rfb_init_state = 'ProtocolVersion';
|
||||||
client._init_msg = sinon.spy();
|
client._init_msg = sinon.spy();
|
||||||
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
|
client._sock._webChannel._receive_data(new Uint8Array([1, 2, 3]));
|
||||||
expect(client._init_msg).to.have.been.called;
|
expect(client._init_msg).to.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should process all normal messages directly', function () {
|
it('should process all normal messages directly', function () {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
client.addEventListener("bell", spy);
|
client.addEventListener("bell", spy);
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0x02, 0x02]));
|
client._sock._webChannel._receive_data(new Uint8Array([0x02, 0x02]));
|
||||||
expect(spy).to.have.been.calledTwice;
|
expect(spy).to.have.been.calledTwice;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -2534,39 +2534,39 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should update the state to ProtocolVersion on open (if the state is "connecting")', 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');
|
client = new RFB(document.createElement('div'), 'wss://host:8675');
|
||||||
this.clock.tick();
|
this.clock.tick();
|
||||||
client._sock._websocket._open();
|
client._sock._webChannel._open();
|
||||||
expect(client._rfb_init_state).to.equal('ProtocolVersion');
|
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 () {
|
it('should fail if we are not currently ready to connect and we get an "open" event', function () {
|
||||||
sinon.spy(client, "_fail");
|
sinon.spy(client, "_fail");
|
||||||
client._rfb_connection_state = 'connected';
|
client._rfb_connection_state = 'connected';
|
||||||
client._sock._websocket._open();
|
client._sock._webChannel._open();
|
||||||
expect(client._fail).to.have.been.calledOnce;
|
expect(client._fail).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
// close events
|
// close events
|
||||||
it('should transition to "disconnected" from "disconnecting" on a close event', function () {
|
it('should transition to "disconnected" from "disconnecting" on a close event', function () {
|
||||||
const real = client._sock._websocket.close;
|
const real = client._sock._webChannel.close;
|
||||||
client._sock._websocket.close = () => {};
|
client._sock._webChannel.close = () => {};
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
expect(client._rfb_connection_state).to.equal('disconnecting');
|
expect(client._rfb_connection_state).to.equal('disconnecting');
|
||||||
client._sock._websocket.close = real;
|
client._sock._webChannel.close = real;
|
||||||
client._sock._websocket.close();
|
client._sock._webChannel.close();
|
||||||
expect(client._rfb_connection_state).to.equal('disconnected');
|
expect(client._rfb_connection_state).to.equal('disconnected');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if we get a close event while connecting', function () {
|
it('should fail if we get a close event while connecting', function () {
|
||||||
sinon.spy(client, "_fail");
|
sinon.spy(client, "_fail");
|
||||||
client._rfb_connection_state = 'connecting';
|
client._rfb_connection_state = 'connecting';
|
||||||
client._sock._websocket.close();
|
client._sock._webChannel.close();
|
||||||
expect(client._fail).to.have.been.calledOnce;
|
expect(client._fail).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should unregister close event handler', function () {
|
it('should unregister close event handler', function () {
|
||||||
sinon.spy(client._sock, 'off');
|
sinon.spy(client._sock, 'off');
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
client._sock._websocket.close();
|
client._sock._webChannel.close();
|
||||||
expect(client._sock.off).to.have.been.calledWith('close');
|
expect(client._sock.off).to.have.been.calledWith('close');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
|
|
||||||
import Websock from '../core/websock.js';
|
import WebChannel from '../core/websock.js';
|
||||||
import FakeWebSocket from './fake.websocket.js';
|
import FakeWebSocket from './fake.websocket.js';
|
||||||
|
|
||||||
describe('Websock', function () {
|
describe('WebChannel', function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe('Queue methods', function () {
|
describe('Queue methods', function () {
|
||||||
|
|
@ -11,7 +11,7 @@ describe('Websock', function () {
|
||||||
const RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
|
const RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock = new Websock();
|
sock = new WebChannel();
|
||||||
// skip init
|
// skip init
|
||||||
sock._allocate_buffers();
|
sock._allocate_buffers();
|
||||||
sock._rQ.set(RQ_TEMPLATE);
|
sock._rQ.set(RQ_TEMPLATE);
|
||||||
|
|
@ -188,30 +188,31 @@ describe('Websock', function () {
|
||||||
|
|
||||||
describe('flush', function () {
|
describe('flush', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock._websocket = {
|
sock._webChannel = {
|
||||||
send: sinon.spy()
|
send: sinon.spy()
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should actually send on the websocket', function () {
|
it('should actually send on the websocket', function () {
|
||||||
sock._websocket.bufferedAmount = 8;
|
sock._channelStates = sock._getChannelStates("WebSocket");
|
||||||
sock._websocket.readyState = WebSocket.OPEN;
|
sock._webChannel.bufferedAmount = 8;
|
||||||
|
sock._webChannel.readyState = WebSocket.OPEN;
|
||||||
sock._sQ = new Uint8Array([1, 2, 3]);
|
sock._sQ = new Uint8Array([1, 2, 3]);
|
||||||
sock._sQlen = 3;
|
sock._sQlen = 3;
|
||||||
const encoded = sock._encode_message();
|
const encoded = sock._encode_message();
|
||||||
|
|
||||||
sock.flush();
|
sock.flush();
|
||||||
expect(sock._websocket.send).to.have.been.calledOnce;
|
expect(sock._webChannel.send).to.have.been.calledOnce;
|
||||||
expect(sock._websocket.send).to.have.been.calledWith(encoded);
|
expect(sock._webChannel.send).to.have.been.calledWith(encoded);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not call send if we do not have anything queued up', function () {
|
it('should not call send if we do not have anything queued up', function () {
|
||||||
sock._sQlen = 0;
|
sock._sQlen = 0;
|
||||||
sock._websocket.bufferedAmount = 8;
|
sock._webChannel.bufferedAmount = 8;
|
||||||
|
|
||||||
sock.flush();
|
sock.flush();
|
||||||
|
|
||||||
expect(sock._websocket.send).not.to.have.been.called;
|
expect(sock._webChannel.send).not.to.have.been.called;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -252,7 +253,7 @@ describe('Websock', function () {
|
||||||
|
|
||||||
let sock;
|
let sock;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock = new Websock();
|
sock = new WebChannel();
|
||||||
// eslint-disable-next-line no-global-assign
|
// eslint-disable-next-line no-global-assign
|
||||||
WebSocket = sinon.spy();
|
WebSocket = sinon.spy();
|
||||||
WebSocket.OPEN = old_WS.OPEN;
|
WebSocket.OPEN = old_WS.OPEN;
|
||||||
|
|
@ -269,7 +270,7 @@ describe('Websock', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should open the actual websocket', function () {
|
it('should open the actual websocket', function () {
|
||||||
sock.open('ws://localhost:8675', 'binary');
|
sock.open({ uri: 'ws://localhost:8675', protocols: 'binary' });
|
||||||
expect(WebSocket).to.have.been.calledWith('ws://localhost:8675', 'binary');
|
expect(WebSocket).to.have.been.calledWith('ws://localhost:8675', 'binary');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -278,38 +279,38 @@ describe('Websock', function () {
|
||||||
|
|
||||||
describe('closing', function () {
|
describe('closing', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock.open('ws://');
|
sock.open({ uri: 'ws://' });
|
||||||
sock._websocket.close = sinon.spy();
|
sock._webChannel.close = sinon.spy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close the actual websocket if it is open', function () {
|
it('should close the actual websocket if it is open', function () {
|
||||||
sock._websocket.readyState = WebSocket.OPEN;
|
sock._webChannel.readyState = WebSocket.OPEN;
|
||||||
sock.close();
|
sock.close();
|
||||||
expect(sock._websocket.close).to.have.been.calledOnce;
|
expect(sock._webChannel.close).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close the actual websocket if it is connecting', function () {
|
it('should close the actual websocket if it is connecting', function () {
|
||||||
sock._websocket.readyState = WebSocket.CONNECTING;
|
sock._webChannel.readyState = WebSocket.CONNECTING;
|
||||||
sock.close();
|
sock.close();
|
||||||
expect(sock._websocket.close).to.have.been.calledOnce;
|
expect(sock._webChannel.close).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not try to close the actual websocket if closing', function () {
|
it('should not try to close the actual websocket if closing', function () {
|
||||||
sock._websocket.readyState = WebSocket.CLOSING;
|
sock._webChannel.readyState = WebSocket.CLOSING;
|
||||||
sock.close();
|
sock.close();
|
||||||
expect(sock._websocket.close).not.to.have.been.called;
|
expect(sock._webChannel.close).not.to.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not try to close the actual websocket if closed', function () {
|
it('should not try to close the actual websocket if closed', function () {
|
||||||
sock._websocket.readyState = WebSocket.CLOSED;
|
sock._webChannel.readyState = WebSocket.CLOSED;
|
||||||
sock.close();
|
sock.close();
|
||||||
expect(sock._websocket.close).not.to.have.been.called;
|
expect(sock._webChannel.close).not.to.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset onmessage to not call _recv_message', function () {
|
it('should reset onmessage to not call _recv_message', function () {
|
||||||
sinon.spy(sock, '_recv_message');
|
sinon.spy(sock, '_recv_message');
|
||||||
sock.close();
|
sock.close();
|
||||||
sock._websocket.onmessage(null);
|
sock._webChannel.onmessage(null);
|
||||||
try {
|
try {
|
||||||
expect(sock._recv_message).not.to.have.been.called;
|
expect(sock._recv_message).not.to.have.been.called;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -324,26 +325,26 @@ describe('Websock', function () {
|
||||||
sock.on('open', sinon.spy());
|
sock.on('open', sinon.spy());
|
||||||
sock.on('close', sinon.spy());
|
sock.on('close', sinon.spy());
|
||||||
sock.on('error', sinon.spy());
|
sock.on('error', sinon.spy());
|
||||||
sock.open('ws://');
|
sock.open({ uri: 'ws://' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call _recv_message on a message', function () {
|
it('should call _recv_message on a message', function () {
|
||||||
sock._websocket.onmessage(null);
|
sock._webChannel.onmessage(null);
|
||||||
expect(sock._recv_message).to.have.been.calledOnce;
|
expect(sock._recv_message).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the open event handler on opening', function () {
|
it('should call the open event handler on opening', function () {
|
||||||
sock._websocket.onopen();
|
sock._webChannel.onopen();
|
||||||
expect(sock._eventHandlers.open).to.have.been.calledOnce;
|
expect(sock._eventHandlers.open).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the close event handler on closing', function () {
|
it('should call the close event handler on closing', function () {
|
||||||
sock._websocket.onclose();
|
sock._webChannel.onclose();
|
||||||
expect(sock._eventHandlers.close).to.have.been.calledOnce;
|
expect(sock._eventHandlers.close).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the error event handler on error', function () {
|
it('should call the error event handler on error', function () {
|
||||||
sock._websocket.onerror();
|
sock._webChannel.onerror();
|
||||||
expect(sock._eventHandlers.error).to.have.been.calledOnce;
|
expect(sock._eventHandlers.error).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -357,7 +358,7 @@ describe('Websock', function () {
|
||||||
describe('WebSocket Receiving', function () {
|
describe('WebSocket Receiving', function () {
|
||||||
let sock;
|
let sock;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock = new Websock();
|
sock = new WebChannel();
|
||||||
sock._allocate_buffers();
|
sock._allocate_buffers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -442,9 +443,9 @@ describe('Websock', function () {
|
||||||
describe('as binary data', function () {
|
describe('as binary data', function () {
|
||||||
let sock;
|
let sock;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock = new Websock();
|
sock = new WebChannel();
|
||||||
sock.open('ws://', 'binary');
|
sock.open({ uri: 'ws://', protocols: 'binary' });
|
||||||
sock._websocket._open();
|
sock._webChannel._open();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should only send the send queue up to the send queue length', function () {
|
it('should only send the send queue up to the send queue length', function () {
|
||||||
|
|
@ -456,7 +457,7 @@ describe('Websock', function () {
|
||||||
|
|
||||||
it('should properly pass the encoded data off to the actual WebSocket', function () {
|
it('should properly pass the encoded data off to the actual WebSocket', function () {
|
||||||
sock.send([1, 2, 3]);
|
sock.send([1, 2, 3]);
|
||||||
expect(sock._websocket._get_sent_data()).to.array.equal(new Uint8Array([1, 2, 3]));
|
expect(sock._webChannel._get_sent_data()).to.array.equal(new Uint8Array([1, 2, 3]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue