Standardize on camelCase in tests

This commit is contained in:
Samuel Mannehed 2020-05-31 21:03:38 +02:00 committed by Lauri Kasanen
parent 59f5648592
commit da228af778
6 changed files with 124 additions and 124 deletions

View File

@ -1,32 +1,32 @@
// noVNC specific assertions
chai.use(function (_chai, utils) {
_chai.Assertion.addMethod('displayed', function (target_data) {
_chai.Assertion.addMethod('displayed', function (targetData) {
const obj = this._obj;
const ctx = obj._target.getContext('2d');
const data_cl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data;
const dataCl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data;
// NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
const data = new Uint8Array(data_cl);
const len = data_cl.length;
new chai.Assertion(len).to.be.equal(target_data.length, "unexpected display size");
const data = new Uint8Array(dataCl);
const len = dataCl.length;
new chai.Assertion(len).to.be.equal(targetData.length, "unexpected display size");
let same = true;
for (let i = 0; i < len; i++) {
if (data[i] != target_data[i]) {
if (data[i] != targetData[i]) {
same = false;
break;
}
}
if (!same) {
// eslint-disable-next-line no-console
console.log("expected data: %o, actual data: %o", target_data, data);
console.log("expected data: %o, actual data: %o", targetData, data);
}
this.assert(same,
"expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
"expected #{this} not to have displayed the image #{act}",
target_data,
targetData,
data);
});
_chai.Assertion.addMethod('sent', function (target_data) {
_chai.Assertion.addMethod('sent', function (targetData) {
const obj = this._obj;
obj.inspect = () => {
const res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
@ -34,13 +34,13 @@ chai.use(function (_chai, utils) {
res.prototype = obj;
return res;
};
const data = obj._websocket._get_sent_data();
const data = obj._websocket._getSentData();
let same = true;
if (data.length != target_data.length) {
if (data.length != targetData.length) {
same = false;
} else {
for (let i = 0; i < data.length; i++) {
if (data[i] != target_data[i]) {
if (data[i] != targetData[i]) {
same = false;
break;
}
@ -48,12 +48,12 @@ chai.use(function (_chai, utils) {
}
if (!same) {
// eslint-disable-next-line no-console
console.log("expected data: %o, actual data: %o", target_data, data);
console.log("expected data: %o, actual data: %o", targetData, data);
}
this.assert(same,
"expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
"expected #{this} not to have sent the data #{act}",
Array.prototype.slice.call(target_data),
Array.prototype.slice.call(targetData),
Array.prototype.slice.call(data));
});

View File

@ -1,7 +1,7 @@
import Base64 from '../core/base64.js';
// PhantomJS can't create Event objects directly, so we need to use this
function make_event(name, props) {
function makeEvent(name, props) {
const evt = document.createEvent('Event');
evt.initEvent(name, true, true);
if (props) {
@ -24,18 +24,18 @@ export default class FakeWebSocket {
this.protocol = protocols[0];
}
this._send_queue = new Uint8Array(20000);
this._sendQueue = new Uint8Array(20000);
this.readyState = FakeWebSocket.CONNECTING;
this.bufferedAmount = 0;
this.__is_fake = true;
this._isFake = true;
}
close(code, reason) {
this.readyState = FakeWebSocket.CLOSED;
if (this.onclose) {
this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
this.onclose(makeEvent("close", { 'code': code, 'reason': reason, 'wasClean': true }));
}
}
@ -45,12 +45,12 @@ export default class FakeWebSocket {
} else {
data = new Uint8Array(data);
}
this._send_queue.set(data, this.bufferedAmount);
this._sendQueue.set(data, this.bufferedAmount);
this.bufferedAmount += data.length;
}
_get_sent_data() {
const res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
_getSentData() {
const res = new Uint8Array(this._sendQueue.buffer, 0, this.bufferedAmount);
this.bufferedAmount = 0;
return res;
}
@ -58,16 +58,16 @@ export default class FakeWebSocket {
_open() {
this.readyState = FakeWebSocket.OPEN;
if (this.onopen) {
this.onopen(make_event('open'));
this.onopen(makeEvent('open'));
}
}
_receive_data(data) {
_receiveData(data) {
// Break apart the data to expose bugs where we assume data is
// neatly packaged
for (let i = 0;i < data.length;i++) {
let buf = data.subarray(i, i+1);
this.onmessage(make_event("message", { 'data': buf }));
this.onmessage(makeEvent("message", { 'data': buf }));
}
}
}
@ -77,20 +77,20 @@ FakeWebSocket.CONNECTING = WebSocket.CONNECTING;
FakeWebSocket.CLOSING = WebSocket.CLOSING;
FakeWebSocket.CLOSED = WebSocket.CLOSED;
FakeWebSocket.__is_fake = true;
FakeWebSocket._isFake = true;
FakeWebSocket.replace = () => {
if (!WebSocket.__is_fake) {
const real_version = WebSocket;
if (!WebSocket._isFake) {
const realVersion = WebSocket;
// eslint-disable-next-line no-global-assign
WebSocket = FakeWebSocket;
FakeWebSocket.__real_version = real_version;
FakeWebSocket._realVersion = realVersion;
}
};
FakeWebSocket.restore = () => {
if (WebSocket.__is_fake) {
if (WebSocket._isFake) {
// eslint-disable-next-line no-global-assign
WebSocket = WebSocket.__real_version;
WebSocket = WebSocket._realVersion;
}
};

View File

@ -1,4 +1,4 @@
/* global VNC_frame_data, VNC_frame_encoding */
/* global vncFrameData, vncFrameEncoding */
import * as WebUtil from '../app/webutil.js';
import RecordingPlayer from './playback.js';
@ -41,7 +41,7 @@ function enableUI() {
document.getElementById('mode1').checked = true;
}
message("Loaded " + VNC_frame_data.length + " frames");
message("Loaded " + vncFrameData.length + " frames");
const startButton = document.getElementById('startButton');
startButton.disabled = false;
@ -49,12 +49,12 @@ function enableUI() {
message("Converting...");
frames = VNC_frame_data;
frames = vncFrameData;
let encoding;
// Only present in older recordings
if (window.VNC_frame_encoding) {
encoding = VNC_frame_encoding;
if (window.vncFrameEncoding) {
encoding = vncFrameEncoding;
} else {
let frame = frames[0];
let start = frame.indexOf('{', 1) + 1;
@ -102,7 +102,7 @@ class IterationPlayer {
this._iteration = undefined;
this._player = undefined;
this._start_time = undefined;
this._startTime = undefined;
this._frames = frames;
@ -115,7 +115,7 @@ class IterationPlayer {
start(realtime) {
this._iteration = 0;
this._start_time = (new Date()).getTime();
this._startTime = (new Date()).getTime();
this._realtime = realtime;
@ -139,7 +139,7 @@ class IterationPlayer {
_finish() {
const endTime = (new Date()).getTime();
const totalDuration = endTime - this._start_time;
const totalDuration = endTime - this._startTime;
const evt = new CustomEvent('finish',
{ detail:

View File

@ -49,10 +49,10 @@ export default class RecordingPlayer {
this._disconnected = disconnected;
this._rfb = undefined;
this._frame_length = this._frames.length;
this._frameLength = this._frames.length;
this._frame_index = 0;
this._start_time = undefined;
this._frameIndex = 0;
this._startTime = undefined;
this._realtime = true;
this._trafficManagement = true;
@ -72,8 +72,8 @@ export default class RecordingPlayer {
this._enablePlaybackMode();
// reset the frame index and timer
this._frame_index = 0;
this._start_time = (new Date()).getTime();
this._frameIndex = 0;
this._startTime = (new Date()).getTime();
this._realtime = realtime;
this._trafficManagement = (trafficManagement === undefined) ? !realtime : trafficManagement;
@ -97,22 +97,22 @@ export default class RecordingPlayer {
_queueNextPacket() {
if (!this._running) { return; }
let frame = this._frames[this._frame_index];
let frame = this._frames[this._frameIndex];
// skip send frames
while (this._frame_index < this._frame_length && frame.fromClient) {
this._frame_index++;
frame = this._frames[this._frame_index];
while (this._frameIndex < this._frameLength && frame.fromClient) {
this._frameIndex++;
frame = this._frames[this._frameIndex];
}
if (this._frame_index >= this._frame_length) {
if (this._frameIndex >= this._frameLength) {
Log.Debug('Finished, no more frames');
this._finish();
return;
}
if (this._realtime) {
const toffset = (new Date()).getTime() - this._start_time;
const toffset = (new Date()).getTime() - this._startTime;
let delay = frame.timestamp - toffset;
if (delay < 1) delay = 1;
@ -134,10 +134,10 @@ export default class RecordingPlayer {
return;
}
const frame = this._frames[this._frame_index];
const frame = this._frames[this._frameIndex];
this._rfb._sock._recv_message({'data': frame.data});
this._frame_index++;
this._frameIndex++;
this._queueNextPacket();
}
@ -155,13 +155,13 @@ export default class RecordingPlayer {
this._running = false;
this._rfb._sock._eventHandlers.close({code: 1000, reason: ""});
delete this._rfb;
this.onfinish((new Date()).getTime() - this._start_time);
this.onfinish((new Date()).getTime() - this._startTime);
}
}
_handleDisconnect(evt) {
this._running = false;
this._disconnected(evt.detail.clean, this._frame_index);
this._disconnected(evt.detail.clean, this._frameIndex);
}
_handleCredentials(evt) {

View File

@ -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._sock._websocket._receiveData(new Uint8Array(data));
client.clipboardPasteFrom('extended test');
expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce;
@ -450,7 +450,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
sinon.spy(client._display, "viewportChangeSize");
client._sock._websocket._receive_data(new Uint8Array(incoming));
client._sock._websocket._receiveData(new Uint8Array(incoming));
// FIXME: Display implicitly calls viewportChangeSize() when
// resizing the framebuffer, hence calledTwice.
@ -647,7 +647,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
sinon.spy(client._display, "autoscale");
client._sock._websocket._receive_data(new Uint8Array(incoming));
client._sock._websocket._receiveData(new Uint8Array(incoming));
expect(client._display.autoscale).to.have.been.calledOnce;
expect(client._display.autoscale).to.have.been.calledWith(70, 80);
@ -702,7 +702,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._supportsSetDesktopSize = false;
client._sock._websocket._receive_data(new Uint8Array(incoming));
client._sock._websocket._receiveData(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);
@ -711,7 +711,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
// Second message should not trigger a resize
client._sock._websocket._receive_data(new Uint8Array(incoming));
client._sock._websocket._receiveData(new Uint8Array(incoming));
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
});
@ -794,7 +794,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00 ];
client._sock._websocket._receive_data(new Uint8Array(incoming));
client._sock._websocket._receiveData(new Uint8Array(incoming));
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
});
@ -1012,7 +1012,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
}
arr[0] = 'R'; arr[1] = 'F'; arr[2] = 'B'; arr[3] = ' ';
arr[11] = '\n';
client._sock._websocket._receive_data(arr);
client._sock._websocket._receiveData(arr);
}
describe('version parsing', function () {
@ -1090,7 +1090,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
sendVer('000.000', client);
expect(client._rfbVersion).to.equal(0);
const sentData = client._sock._websocket._get_sent_data();
const sentData = client._sock._websocket._getSentData();
expect(new Uint8Array(sentData.buffer, 0, 9)).to.array.equal(new Uint8Array([73, 68, 58, 49, 50, 51, 52, 53, 0]));
expect(sentData).to.have.length(250);
});
@ -1113,14 +1113,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
const authSchemeRaw = [1, 2, 3, 4];
const authScheme = (authSchemeRaw[0] << 24) + (authSchemeRaw[1] << 16) +
(authSchemeRaw[2] << 8) + authSchemeRaw[3];
client._sock._websocket._receive_data(new Uint8Array(authSchemeRaw));
client._sock._websocket._receiveData(new Uint8Array(authSchemeRaw));
expect(client._rfbAuthScheme).to.equal(authScheme);
});
it('should prefer no authentication is possible', function () {
client._rfbVersion = 3.7;
const authSchemes = [2, 1, 3];
client._sock._websocket._receive_data(new Uint8Array(authSchemes));
client._sock._websocket._receiveData(new Uint8Array(authSchemes));
expect(client._rfbAuthScheme).to.equal(1);
expect(client._sock).to.have.sent(new Uint8Array([1, 1]));
});
@ -1128,7 +1128,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should choose for the most prefered scheme possible for versions >= 3.7', function () {
client._rfbVersion = 3.7;
const authSchemes = [2, 22, 16];
client._sock._websocket._receive_data(new Uint8Array(authSchemes));
client._sock._websocket._receiveData(new Uint8Array(authSchemes));
expect(client._rfbAuthScheme).to.equal(22);
expect(client._sock).to.have.sent(new Uint8Array([22]));
});
@ -1137,7 +1137,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
sinon.spy(client, "_fail");
client._rfbVersion = 3.7;
const authSchemes = [1, 32];
client._sock._websocket._receive_data(new Uint8Array(authSchemes));
client._sock._websocket._receiveData(new Uint8Array(authSchemes));
expect(client._fail).to.have.been.calledOnce;
});
@ -1145,7 +1145,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbVersion = 3.7;
const failureData = [0, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115];
sinon.spy(client, '_fail');
client._sock._websocket._receive_data(new Uint8Array(failureData));
client._sock._websocket._receiveData(new Uint8Array(failureData));
expect(client._fail).to.have.been.calledOnce;
expect(client._fail).to.have.been.calledWith(
@ -1156,7 +1156,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbVersion = 3.7;
const authSchemes = [1, 1];
client._negotiateAuthentication = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array(authSchemes));
client._sock._websocket._receiveData(new Uint8Array(authSchemes));
expect(client._rfbInitState).to.equal('Authentication');
expect(client._negotiateAuthentication).to.have.been.calledOnce;
});
@ -1168,7 +1168,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
});
function sendSecurity(type, cl) {
cl._sock._websocket._receive_data(new Uint8Array([1, type]));
cl._sock._websocket._receiveData(new Uint8Array([1, type]));
}
it('should fail on auth scheme 0 (pre 3.7) with the given message', function () {
@ -1182,7 +1182,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
}
sinon.spy(client, '_fail');
client._sock._websocket._receive_data(new Uint8Array(data));
client._sock._websocket._receiveData(new Uint8Array(data));
expect(client._fail).to.have.been.calledWith(
'Security negotiation failed on authentication scheme (reason: Whoopsies)');
});
@ -1219,7 +1219,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const challenge = [];
for (let i = 0; i < 16; i++) { challenge[i] = i; }
client._sock._websocket._receive_data(new Uint8Array(challenge));
client._sock._websocket._receiveData(new Uint8Array(challenge));
expect(client._rfbCredentials).to.be.empty;
expect(spy).to.have.been.calledOnce;
@ -1229,11 +1229,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should encrypt the password with DES and then send it back', function () {
client._rfbCredentials = { password: 'passwd' };
sendSecurity(2, client);
client._sock._websocket._get_sent_data(); // skip the choice of auth reply
client._sock._websocket._getSentData(); // skip the choice of auth reply
const challenge = [];
for (let i = 0; i < 16; i++) { challenge[i] = i; }
client._sock._websocket._receive_data(new Uint8Array(challenge));
client._sock._websocket._receiveData(new Uint8Array(challenge));
const desPass = RFB.genDES('passwd', challenge);
expect(client._sock).to.have.sent(new Uint8Array(desPass));
@ -1245,7 +1245,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const challenge = [];
for (let i = 0; i < 16; i++) { challenge[i] = i; }
client._sock._websocket._receive_data(new Uint8Array(challenge));
client._sock._websocket._receiveData(new Uint8Array(challenge));
expect(client._rfbInitState).to.equal('SecurityResult');
});
@ -1308,7 +1308,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbInitState = 'Security';
client._rfbVersion = 3.8;
sendSecurity(16, client);
client._sock._websocket._get_sent_data(); // skip the security reply
client._sock._websocket._getSentData(); // skip the security reply
});
function sendNumStrPairs(pairs, client) {
@ -1325,11 +1325,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
}
}
client._sock._websocket._receive_data(new Uint8Array(data));
client._sock._websocket._receiveData(new Uint8Array(data));
}
it('should skip tunnel negotiation if no tunnels are requested', function () {
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0]));
expect(client._rfbTightVNC).to.be.true;
});
@ -1351,7 +1351,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should continue to sub-auth negotiation after tunnel negotiation', function () {
sendNumStrPairs([[0, 'TGHT', 'NOTUNNEL']], client);
client._sock._websocket._get_sent_data(); // skip the tunnel choice here
client._sock._websocket._getSentData(); // skip the tunnel choice here
sendNumStrPairs([[1, 'STDV', 'NOAUTH__']], client);
expect(client._sock).to.have.sent(new Uint8Array([0, 0, 0, 1]));
expect(client._rfbInitState).to.equal('SecurityResult');
@ -1397,7 +1397,7 @@ describe('Remote Frame Buffer Protocol Client', 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._websocket._receiveData(new Uint8Array([0, 0, 0, 0]));
expect(client._rfbInitState).to.equal('ServerInitialisation');
});
@ -1405,7 +1405,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbVersion = 3.8;
sinon.spy(client, '_fail');
const failureData = [0, 0, 0, 1, 0, 0, 0, 6, 119, 104, 111, 111, 112, 115];
client._sock._websocket._receive_data(new Uint8Array(failureData));
client._sock._websocket._receiveData(new Uint8Array(failureData));
expect(client._fail).to.have.been.calledWith(
'Security negotiation failed on security result (reason: whoops)');
});
@ -1413,7 +1413,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._rfbVersion = 3.7;
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 1]));
client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 1]));
expect(client._fail).to.have.been.calledWith(
'Security handshake failed');
});
@ -1421,7 +1421,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._websocket._receive_data(new Uint8Array([0, 0, 0, 2]));
client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 2]));
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.status).to.equal(2);
});
@ -1432,7 +1432,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client.addEventListener("securityfailure", spy);
const failureData = [0, 0, 0, 1, 0, 0, 0, 12, 115, 117, 99, 104,
32, 102, 97, 105, 108, 117, 114, 101];
client._sock._websocket._receive_data(new Uint8Array(failureData));
client._sock._websocket._receiveData(new Uint8Array(failureData));
expect(spy.args[0][0].detail.status).to.equal(1);
expect(spy.args[0][0].detail.reason).to.equal('such failure');
});
@ -1442,7 +1442,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const spy = sinon.spy();
client.addEventListener("securityfailure", spy);
const failureData = [0, 0, 0, 1, 0, 0, 0, 0];
client._sock._websocket._receive_data(new Uint8Array(failureData));
client._sock._websocket._receiveData(new Uint8Array(failureData));
expect(spy.args[0][0].detail.status).to.equal(1);
expect('reason' in spy.args[0][0].detail).to.be.false;
});
@ -1451,7 +1451,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbVersion = 3.6;
const spy = sinon.spy();
client.addEventListener("securityfailure", spy);
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 2]));
client._sock._websocket._receiveData(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;
});
@ -1462,7 +1462,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const client = makeRFB();
client._rfbConnectionState = 'connecting';
client._rfbInitState = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0]));
expect(client._rfbInitState).to.equal('ServerInitialisation');
});
@ -1470,7 +1470,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const client = makeRFB('wss://host:8675', { shared: true });
client._rfbConnectionState = 'connecting';
client._rfbInitState = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0]));
expect(client._sock).to.have.sent(new Uint8Array([1]));
});
@ -1478,7 +1478,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const client = makeRFB('wss://host:8675', { shared: false });
client._rfbConnectionState = 'connecting';
client._rfbInitState = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 0]));
expect(client._sock).to.have.sent(new Uint8Array([0]));
});
});
@ -1517,15 +1517,15 @@ describe('Remote Frame Buffer Protocol Client', function () {
push8(data, 0);
push8(data, 0);
client._sock._websocket._receive_data(new Uint8Array(data));
client._sock._websocket._receiveData(new Uint8Array(data));
const nameData = [];
let nameLen = [];
pushString(nameData, fullOpts.name);
push32(nameLen, nameData.length);
client._sock._websocket._receive_data(new Uint8Array(nameLen));
client._sock._websocket._receive_data(new Uint8Array(nameData));
client._sock._websocket._receiveData(new Uint8Array(nameLen));
client._sock._websocket._receiveData(new Uint8Array(nameData));
}
it('should set the framebuffer width and height', function () {
@ -1560,7 +1560,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
for (let i = 0; i < 16 + 32 + 48; i++) {
tightData.push(i);
}
client._sock._websocket._receive_data(new Uint8Array(tightData));
client._sock._websocket._receiveData(new Uint8Array(tightData));
expect(client._rfbConnectionState).to.equal('connected');
});
@ -1684,7 +1684,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
data = data.concat(rectData[i]);
}
client._sock._websocket._receive_data(new Uint8Array(data));
client._sock._websocket._receiveData(new Uint8Array(data));
}
it('should send an update request if there is sufficient data', function () {
@ -1692,14 +1692,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
RFB.messages.fbUpdateRequest(expectedMsg, true, 0, 0, 640, 20);
client._framebufferUpdate = () => true;
client._sock._websocket._receive_data(new Uint8Array([0]));
client._sock._websocket._receiveData(new Uint8Array([0]));
expect(client._sock).to.have.sent(expectedMsg._sQ);
});
it('should not send an update request if we need more data', function () {
client._sock._websocket._receive_data(new Uint8Array([0]));
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
client._sock._websocket._receiveData(new Uint8Array([0]));
expect(client._sock._websocket._getSentData()).to.have.length(0);
});
it('should resume receiving an update if we previously did not have enough data', function () {
@ -1707,21 +1707,21 @@ describe('Remote Frame Buffer Protocol Client', function () {
RFB.messages.fbUpdateRequest(expectedMsg, true, 0, 0, 640, 20);
// just enough to set FBU.rects
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 3]));
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
client._sock._websocket._receiveData(new Uint8Array([0, 0, 0, 3]));
expect(client._sock._websocket._getSentData()).to.have.length(0);
client._framebufferUpdate = function () { this._sock.rQskipBytes(1); return true; }; // we magically have enough data
// 247 should *not* be used as the message type here
client._sock._websocket._receive_data(new Uint8Array([247]));
client._sock._websocket._receiveData(new Uint8Array([247]));
expect(client._sock).to.have.sent(expectedMsg._sQ);
});
it('should not send a request in continuous updates mode', function () {
client._enabledContinuousUpdates = true;
client._framebufferUpdate = () => true;
client._sock._websocket._receive_data(new Uint8Array([0]));
client._sock._websocket._receiveData(new Uint8Array([0]));
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
expect(client._sock._websocket._getSentData()).to.have.length(0);
});
it('should fail on an unsupported encoding', function () {
@ -2388,7 +2388,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._websocket._receive_data(new Uint8Array([250, 0, 10, 1]));
client._sock._websocket._receiveData(new Uint8Array([250, 0, 10, 1]));
expect(client._rfbXvpVer).to.equal(10);
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.capabilities.power).to.be.true;
@ -2397,7 +2397,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should fail on unknown XVP message types', function () {
sinon.spy(client, "_fail");
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 237]));
client._sock._websocket._receiveData(new Uint8Array([250, 0, 10, 237]));
expect(client._fail).to.have.been.calledOnce;
});
});
@ -2411,7 +2411,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._sock._websocket._receiveData(new Uint8Array(data));
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.text).to.equal(expectedStr);
});
@ -2437,7 +2437,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._sock._websocket._receiveData(new Uint8Array(data));
// Check that we give an response caps when we receive one
expect(RFB.messages.extendedClipboardCaps).to.have.been.calledOnce;
@ -2463,7 +2463,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._sock._websocket._receiveData(new Uint8Array(data));
});
describe('Handle Provide', function () {
@ -2487,7 +2487,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._sock._websocket._receiveData(new Uint8Array(data));
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.text).to.equal(expectedData);
client.removeEventListener("clipboard", spy);
@ -2514,7 +2514,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const spy = sinon.spy();
client.addEventListener("clipboard", spy);
client._sock._websocket._receive_data(sendData);
client._sock._websocket._receiveData(sendData);
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.text).to.equal(expectedData);
client.removeEventListener("clipboard", spy);
@ -2546,7 +2546,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
const spy = sinon.spy();
client.addEventListener("clipboard", spy);
client._sock._websocket._receive_data(sendData);
client._sock._websocket._receiveData(sendData);
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.text).to.equal(expectedData);
client.removeEventListener("clipboard", spy);
@ -2570,7 +2570,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
data = data.concat(flags);
let expectedData = [0x01];
client._sock._websocket._receive_data(new Uint8Array(data));
client._sock._websocket._receiveData(new Uint8Array(data));
expect(RFB.messages.extendedClipboardRequest).to.have.been.calledOnce;
expect(RFB.messages.extendedClipboardRequest).to.have.been.calledWith(client._sock, expectedData);
@ -2593,7 +2593,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
data = data.concat(flags);
let expectedData = [];
client._sock._websocket._receive_data(new Uint8Array(data));
client._sock._websocket._receiveData(new Uint8Array(data));
expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce;
expect(RFB.messages.extendedClipboardNotify).to.have.been.calledWith(client._sock, expectedData);
@ -2611,7 +2611,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client.clipboardPasteFrom("HejHej");
RFB.messages.extendedClipboardNotify.resetHistory();
client._sock._websocket._receive_data(new Uint8Array(data));
client._sock._websocket._receiveData(new Uint8Array(data));
expect(RFB.messages.extendedClipboardNotify).to.have.been.calledOnce;
expect(RFB.messages.extendedClipboardNotify).to.have.been.calledWith(client._sock, expectedData);
@ -2637,7 +2637,7 @@ 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._sock._websocket._receiveData(new Uint8Array(data));
expect(RFB.messages.extendedClipboardProvide).to.have.been.calledOnce;
expect(RFB.messages.extendedClipboardProvide).to.have.been.calledWith(client._sock, expectedData, ["HejHej"]);
@ -2650,7 +2650,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._websocket._receive_data(new Uint8Array([2]));
client._sock._websocket._receiveData(new Uint8Array([2]));
expect(spy).to.have.been.calledOnce;
});
@ -2664,7 +2664,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
RFB.messages.clientFence(expectedMsg, (1<<0) | (1<<1), payload);
RFB.messages.clientFence(incomingMsg, 0xffffffff, payload);
client._sock._websocket._receive_data(incomingMsg._sQ);
client._sock._websocket._receiveData(incomingMsg._sQ);
expect(client._sock).to.have.sent(expectedMsg._sQ);
@ -2674,7 +2674,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
RFB.messages.clientFence(expectedMsg, (1<<0), payload);
RFB.messages.clientFence(incomingMsg, (1<<0) | (1<<31), payload);
client._sock._websocket._receive_data(incomingMsg._sQ);
client._sock._websocket._receiveData(incomingMsg._sQ);
expect(client._sock).to.have.sent(expectedMsg._sQ);
});
@ -2686,7 +2686,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(client._enabledContinuousUpdates).to.be.false;
client._sock._websocket._receive_data(new Uint8Array([150]));
client._sock._websocket._receiveData(new Uint8Array([150]));
expect(client._enabledContinuousUpdates).to.be.true;
expect(client._sock).to.have.sent(expectedMsg._sQ);
@ -2696,7 +2696,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._enabledContinuousUpdates = true;
client._supportsContinuousUpdates = true;
client._sock._websocket._receive_data(new Uint8Array([150]));
client._sock._websocket._receiveData(new Uint8Array([150]));
expect(client._enabledContinuousUpdates).to.be.false;
});
@ -2707,7 +2707,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._resize(450, 160);
expect(client._sock._websocket._get_sent_data()).to.have.length(0);
expect(client._sock._websocket._getSentData()).to.have.length(0);
client._enabledContinuousUpdates = true;
@ -2718,7 +2718,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should fail on an unknown message type', function () {
sinon.spy(client, "_fail");
client._sock._websocket._receive_data(new Uint8Array([87]));
client._sock._websocket._receiveData(new Uint8Array([87]));
expect(client._fail).to.have.been.calledOnce;
});
});
@ -2892,13 +2892,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._normalMsg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([]));
client._sock._websocket._receiveData(new Uint8Array([]));
expect(client._normalMsg).to.not.have.been.called;
});
it('should handle a message in the connected state as a normal message', function () {
client._normalMsg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
client._sock._websocket._receiveData(new Uint8Array([1, 2, 3]));
expect(client._normalMsg).to.have.been.called;
});
@ -2906,14 +2906,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._rfbConnectionState = 'connecting';
client._rfbInitState = 'ProtocolVersion';
client._initMsg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
client._sock._websocket._receiveData(new Uint8Array([1, 2, 3]));
expect(client._initMsg).to.have.been.called;
});
it('should process all normal messages directly', function () {
const spy = sinon.spy();
client.addEventListener("bell", spy);
client._sock._websocket._receive_data(new Uint8Array([0x02, 0x02]));
client._sock._websocket._receiveData(new Uint8Array([0x02, 0x02]));
expect(spy).to.have.been.calledTwice;
});

View File

@ -456,7 +456,7 @@ describe('Websock', function () {
it('should properly pass the encoded data off to the actual WebSocket', function () {
sock.send([1, 2, 3]);
expect(sock._websocket._get_sent_data()).to.array.equal(new Uint8Array([1, 2, 3]));
expect(sock._websocket._getSentData()).to.array.equal(new Uint8Array([1, 2, 3]));
});
});
});