Merge branch 'camelcase' of https://github.com/samhed/noVNC
This commit is contained in:
+14
-14
@@ -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));
|
||||
});
|
||||
|
||||
|
||||
+16
-16
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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:
|
||||
|
||||
+15
-15
@@ -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) {
|
||||
|
||||
@@ -17,12 +17,14 @@ function _inflator(compText, expected) {
|
||||
strm.output = new Uint8Array(chunkSize);
|
||||
}
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
strm.input = compText;
|
||||
strm.avail_in = strm.input.length;
|
||||
strm.next_in = 0;
|
||||
|
||||
strm.next_out = 0;
|
||||
strm.avail_out = expected.length;
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
let ret = inflate(strm, 0);
|
||||
|
||||
|
||||
+45
-49
@@ -4,28 +4,28 @@ import Base64 from '../core/base64.js';
|
||||
import Display from '../core/display.js';
|
||||
|
||||
describe('Display/Canvas Helper', function () {
|
||||
const checked_data = new Uint8Array([
|
||||
const checkedData = new Uint8Array([
|
||||
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
|
||||
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
|
||||
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
|
||||
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
|
||||
]);
|
||||
|
||||
const basic_data = new Uint8Array([0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255]);
|
||||
const basicData = new Uint8Array([0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255]);
|
||||
|
||||
function make_image_canvas(input_data) {
|
||||
function makeImageCanvas(inputData) {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 4;
|
||||
canvas.height = 4;
|
||||
const ctx = canvas.getContext('2d');
|
||||
const data = ctx.createImageData(4, 4);
|
||||
for (let i = 0; i < checked_data.length; i++) { data.data[i] = input_data[i]; }
|
||||
for (let i = 0; i < checkedData.length; i++) { data.data[i] = inputData[i]; }
|
||||
ctx.putImageData(data, 0, 0);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
function make_image_png(input_data) {
|
||||
const canvas = make_image_canvas(input_data);
|
||||
function makeImagePng(inputData) {
|
||||
const canvas = makeImageCanvas(inputData);
|
||||
const url = canvas.toDataURL();
|
||||
const data = url.split(",")[1];
|
||||
return Base64.decode(data);
|
||||
@@ -44,11 +44,11 @@ describe('Display/Canvas Helper', function () {
|
||||
it('should take viewport location into consideration when drawing images', function () {
|
||||
display.resize(4, 4);
|
||||
display.viewportChangeSize(2, 2);
|
||||
display.drawImage(make_image_canvas(basic_data), 1, 1);
|
||||
display.drawImage(makeImageCanvas(basicData), 1, 1);
|
||||
display.flip();
|
||||
|
||||
const expected = new Uint8Array(16);
|
||||
for (let i = 0; i < 8; i++) { expected[i] = basic_data[i]; }
|
||||
for (let i = 0; i < 8; i++) { expected[i] = basicData[i]; }
|
||||
for (let i = 8; i < 16; i++) { expected[i] = 0; }
|
||||
expect(display).to.have.displayed(expected);
|
||||
});
|
||||
@@ -123,8 +123,8 @@ describe('Display/Canvas Helper', function () {
|
||||
|
||||
it('should change the size of the logical canvas', function () {
|
||||
display.resize(5, 7);
|
||||
expect(display._fb_width).to.equal(5);
|
||||
expect(display._fb_height).to.equal(7);
|
||||
expect(display._fbWidth).to.equal(5);
|
||||
expect(display._fbHeight).to.equal(7);
|
||||
});
|
||||
|
||||
it('should keep the framebuffer data', function () {
|
||||
@@ -275,7 +275,7 @@ describe('Display/Canvas Helper', function () {
|
||||
display.flip();
|
||||
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
||||
const expected = [];
|
||||
for (let i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) {
|
||||
for (let i = 0; i < 4 * display._fbWidth * display._fbHeight; i += 4) {
|
||||
expected[i] = 0xff;
|
||||
expected[i+1] = expected[i+2] = 0;
|
||||
expected[i+3] = 0xff;
|
||||
@@ -288,7 +288,7 @@ describe('Display/Canvas Helper', function () {
|
||||
display.fillRect(0, 0, 2, 2, [0xff, 0, 0]);
|
||||
display.fillRect(2, 2, 2, 2, [0xff, 0, 0]);
|
||||
display.flip();
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
expect(display).to.have.displayed(checkedData);
|
||||
});
|
||||
|
||||
it('should support copying an portion of the canvas via #copyImage', function () {
|
||||
@@ -296,14 +296,14 @@ describe('Display/Canvas Helper', function () {
|
||||
display.fillRect(0, 0, 2, 2, [0xff, 0, 0x00]);
|
||||
display.copyImage(0, 0, 2, 2, 2, 2);
|
||||
display.flip();
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
expect(display).to.have.displayed(checkedData);
|
||||
});
|
||||
|
||||
it('should support drawing images via #imageRect', function (done) {
|
||||
display.imageRect(0, 0, 4, 4, "image/png", make_image_png(checked_data));
|
||||
display.imageRect(0, 0, 4, 4, "image/png", makeImagePng(checkedData));
|
||||
display.flip();
|
||||
display.onflush = () => {
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
expect(display).to.have.displayed(checkedData);
|
||||
done();
|
||||
};
|
||||
display.flush();
|
||||
@@ -315,12 +315,12 @@ describe('Display/Canvas Helper', function () {
|
||||
display.subTile(2, 2, 2, 2, [0xff, 0, 0]);
|
||||
display.finishTile();
|
||||
display.flip();
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
expect(display).to.have.displayed(checkedData);
|
||||
});
|
||||
|
||||
// We have a special cache for 16x16 tiles that we need to test
|
||||
it('should support drawing a 16x16 tile', function () {
|
||||
const large_checked_data = new Uint8Array(16*16*4);
|
||||
const largeCheckedData = new Uint8Array(16*16*4);
|
||||
display.resize(16, 16);
|
||||
|
||||
for (let y = 0;y < 16;y++) {
|
||||
@@ -328,11 +328,11 @@ describe('Display/Canvas Helper', function () {
|
||||
let pixel;
|
||||
if ((x < 4) && (y < 4)) {
|
||||
// NB: of course IE11 doesn't support #slice on ArrayBufferViews...
|
||||
pixel = Array.prototype.slice.call(checked_data, (y*4+x)*4, (y*4+x+1)*4);
|
||||
pixel = Array.prototype.slice.call(checkedData, (y*4+x)*4, (y*4+x+1)*4);
|
||||
} else {
|
||||
pixel = [0, 0xff, 0, 255];
|
||||
}
|
||||
large_checked_data.set(pixel, (y*16+x)*4);
|
||||
largeCheckedData.set(pixel, (y*16+x)*4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,39 +341,39 @@ describe('Display/Canvas Helper', function () {
|
||||
display.subTile(2, 2, 2, 2, [0xff, 0, 0]);
|
||||
display.finishTile();
|
||||
display.flip();
|
||||
expect(display).to.have.displayed(large_checked_data);
|
||||
expect(display).to.have.displayed(largeCheckedData);
|
||||
});
|
||||
|
||||
it('should support drawing BGRX blit images with true color via #blitImage', function () {
|
||||
const data = [];
|
||||
for (let i = 0; i < 16; i++) {
|
||||
data[i * 4] = checked_data[i * 4 + 2];
|
||||
data[i * 4 + 1] = checked_data[i * 4 + 1];
|
||||
data[i * 4 + 2] = checked_data[i * 4];
|
||||
data[i * 4 + 3] = checked_data[i * 4 + 3];
|
||||
data[i * 4] = checkedData[i * 4 + 2];
|
||||
data[i * 4 + 1] = checkedData[i * 4 + 1];
|
||||
data[i * 4 + 2] = checkedData[i * 4];
|
||||
data[i * 4 + 3] = checkedData[i * 4 + 3];
|
||||
}
|
||||
display.blitImage(0, 0, 4, 4, data, 0);
|
||||
display.flip();
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
expect(display).to.have.displayed(checkedData);
|
||||
});
|
||||
|
||||
it('should support drawing RGB blit images with true color via #blitRgbImage', function () {
|
||||
const data = [];
|
||||
for (let i = 0; i < 16; i++) {
|
||||
data[i * 3] = checked_data[i * 4];
|
||||
data[i * 3 + 1] = checked_data[i * 4 + 1];
|
||||
data[i * 3 + 2] = checked_data[i * 4 + 2];
|
||||
data[i * 3] = checkedData[i * 4];
|
||||
data[i * 3 + 1] = checkedData[i * 4 + 1];
|
||||
data[i * 3 + 2] = checkedData[i * 4 + 2];
|
||||
}
|
||||
display.blitRgbImage(0, 0, 4, 4, data, 0);
|
||||
display.flip();
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
expect(display).to.have.displayed(checkedData);
|
||||
});
|
||||
|
||||
it('should support drawing an image object via #drawImage', function () {
|
||||
const img = make_image_canvas(checked_data);
|
||||
const img = makeImageCanvas(checkedData);
|
||||
display.drawImage(img, 0, 0);
|
||||
display.flip();
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
expect(display).to.have.displayed(checkedData);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -382,22 +382,18 @@ describe('Display/Canvas Helper', function () {
|
||||
beforeEach(function () {
|
||||
display = new Display(document.createElement('canvas'));
|
||||
display.resize(4, 4);
|
||||
sinon.spy(display, '_scan_renderQ');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
window.requestAnimationFrame = this.old_requestAnimationFrame;
|
||||
sinon.spy(display, '_scanRenderQ');
|
||||
});
|
||||
|
||||
it('should try to process an item when it is pushed on, if nothing else is on the queue', function () {
|
||||
display._renderQ_push({ type: 'noop' }); // does nothing
|
||||
expect(display._scan_renderQ).to.have.been.calledOnce;
|
||||
display._renderQPush({ type: 'noop' }); // does nothing
|
||||
expect(display._scanRenderQ).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('should not try to process an item when it is pushed on if we are waiting for other items', function () {
|
||||
display._renderQ.length = 2;
|
||||
display._renderQ_push({ type: 'noop' });
|
||||
expect(display._scan_renderQ).to.not.have.been.called;
|
||||
display._renderQPush({ type: 'noop' });
|
||||
expect(display._scanRenderQ).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should wait until an image is loaded to attempt to draw it and the rest of the queue', function () {
|
||||
@@ -407,13 +403,13 @@ describe('Display/Canvas Helper', function () {
|
||||
display.drawImage = sinon.spy();
|
||||
display.fillRect = sinon.spy();
|
||||
|
||||
display._scan_renderQ();
|
||||
display._scanRenderQ();
|
||||
expect(display.drawImage).to.not.have.been.called;
|
||||
expect(display.fillRect).to.not.have.been.called;
|
||||
expect(img.addEventListener).to.have.been.calledOnce;
|
||||
|
||||
display._renderQ[0].img.complete = true;
|
||||
display._scan_renderQ();
|
||||
display._scanRenderQ();
|
||||
expect(display.drawImage).to.have.been.calledOnce;
|
||||
expect(display.fillRect).to.have.been.calledOnce;
|
||||
expect(img.addEventListener).to.have.been.calledOnce;
|
||||
@@ -426,7 +422,7 @@ describe('Display/Canvas Helper', function () {
|
||||
display.drawImage = sinon.spy();
|
||||
display.fillRect = sinon.spy();
|
||||
|
||||
display._scan_renderQ();
|
||||
display._scanRenderQ();
|
||||
expect(display.drawImage).to.not.have.been.called;
|
||||
expect(display.fillRect).to.not.have.been.called;
|
||||
expect(img.addEventListener).to.have.been.calledOnce;
|
||||
@@ -434,7 +430,7 @@ describe('Display/Canvas Helper', function () {
|
||||
display._renderQ[0].img.complete = true;
|
||||
display._renderQ[0].img.width = 4;
|
||||
display._renderQ[0].img.height = 4;
|
||||
display._scan_renderQ();
|
||||
display._scanRenderQ();
|
||||
expect(display.drawImage).to.have.been.calledOnce;
|
||||
expect(display.fillRect).to.have.been.calledOnce;
|
||||
expect(img.addEventListener).to.have.been.calledOnce;
|
||||
@@ -450,35 +446,35 @@ describe('Display/Canvas Helper', function () {
|
||||
|
||||
it('should draw a blit image on type "blit"', function () {
|
||||
display.blitImage = sinon.spy();
|
||||
display._renderQ_push({ type: 'blit', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] });
|
||||
display._renderQPush({ type: 'blit', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] });
|
||||
expect(display.blitImage).to.have.been.calledOnce;
|
||||
expect(display.blitImage).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9], 0);
|
||||
});
|
||||
|
||||
it('should draw a blit RGB image on type "blitRgb"', function () {
|
||||
display.blitRgbImage = sinon.spy();
|
||||
display._renderQ_push({ type: 'blitRgb', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] });
|
||||
display._renderQPush({ type: 'blitRgb', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] });
|
||||
expect(display.blitRgbImage).to.have.been.calledOnce;
|
||||
expect(display.blitRgbImage).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9], 0);
|
||||
});
|
||||
|
||||
it('should copy a region on type "copy"', function () {
|
||||
display.copyImage = sinon.spy();
|
||||
display._renderQ_push({ type: 'copy', x: 3, y: 4, width: 5, height: 6, old_x: 7, old_y: 8 });
|
||||
display._renderQPush({ type: 'copy', x: 3, y: 4, width: 5, height: 6, oldX: 7, oldY: 8 });
|
||||
expect(display.copyImage).to.have.been.calledOnce;
|
||||
expect(display.copyImage).to.have.been.calledWith(7, 8, 3, 4, 5, 6);
|
||||
});
|
||||
|
||||
it('should fill a rect with a given color on type "fill"', function () {
|
||||
display.fillRect = sinon.spy();
|
||||
display._renderQ_push({ type: 'fill', x: 3, y: 4, width: 5, height: 6, color: [7, 8, 9]});
|
||||
display._renderQPush({ type: 'fill', x: 3, y: 4, width: 5, height: 6, color: [7, 8, 9]});
|
||||
expect(display.fillRect).to.have.been.calledOnce;
|
||||
expect(display.fillRect).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9]);
|
||||
});
|
||||
|
||||
it('should draw an image from an image object on type "img" (if complete)', function () {
|
||||
display.drawImage = sinon.spy();
|
||||
display._renderQ_push({ type: 'img', x: 3, y: 4, img: { complete: true } });
|
||||
display._renderQPush({ type: 'img', x: 3, y: 4, img: { complete: true } });
|
||||
expect(display.drawImage).to.have.been.calledOnce;
|
||||
expect(display.drawImage).to.have.been.calledWith({ complete: true }, 3, 4);
|
||||
});
|
||||
|
||||
+80
-78
@@ -70,11 +70,13 @@ function deflateWithSize(data) {
|
||||
strm.output = new Uint8Array(chunkSize);
|
||||
deflateInit(strm, 5);
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
strm.input = unCompData;
|
||||
strm.avail_in = strm.input.length;
|
||||
strm.next_in = 0;
|
||||
strm.next_out = 0;
|
||||
strm.avail_out = chunkSize;
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
deflate(strm, 3);
|
||||
|
||||
@@ -99,8 +101,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||
const _sQ = new Uint8Array(sock._sQbufferSize);
|
||||
const rQ = new Uint8Array(sock._rQbufferSize);
|
||||
|
||||
Websock.prototype._old_allocate_buffers = Websock.prototype._allocate_buffers;
|
||||
Websock.prototype._allocate_buffers = function () {
|
||||
Websock.prototype._oldAllocateBuffers = Websock.prototype._allocateBuffers;
|
||||
Websock.prototype._allocateBuffers = function () {
|
||||
this._sQ = _sQ;
|
||||
this._rQ = rQ;
|
||||
};
|
||||
@@ -108,7 +110,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||
});
|
||||
|
||||
after(function () {
|
||||
Websock.prototype._allocate_buffers = Websock.prototype._old_allocate_buffers;
|
||||
Websock.prototype._allocateBuffers = Websock.prototype._oldAllocateBuffers;
|
||||
this.clock.restore();
|
||||
window.requestAnimationFrame = raf;
|
||||
});
|
||||
@@ -352,7 +354,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 +452,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 +649,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 +704,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 +713,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 +796,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 +1014,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 +1092,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 +1115,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 +1130,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 +1139,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 +1147,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 +1158,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 +1170,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 +1184,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 +1221,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 +1231,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 +1247,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 +1310,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 +1327,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 +1353,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 +1399,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 +1407,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 +1415,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 +1423,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 +1434,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 +1444,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 +1453,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 +1464,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 +1472,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 +1480,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]));
|
||||
});
|
||||
});
|
||||
@@ -1489,8 +1491,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||
});
|
||||
|
||||
function sendServerInit(opts, client) {
|
||||
const fullOpts = { width: 10, height: 12, bpp: 24, depth: 24, big_endian: 0,
|
||||
true_color: 1, redMax: 255, greenMax: 255, blueMax: 255,
|
||||
const fullOpts = { width: 10, height: 12, bpp: 24, depth: 24, bigEndian: 0,
|
||||
trueColor: 1, redMax: 255, greenMax: 255, blueMax: 255,
|
||||
redShift: 16, greenShift: 8, blueShift: 0, name: 'a name' };
|
||||
for (let opt in opts) {
|
||||
fullOpts[opt] = opts[opt];
|
||||
@@ -1502,8 +1504,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||
|
||||
data.push(fullOpts.bpp);
|
||||
data.push(fullOpts.depth);
|
||||
data.push(fullOpts.big_endian);
|
||||
data.push(fullOpts.true_color);
|
||||
data.push(fullOpts.bigEndian);
|
||||
data.push(fullOpts.trueColor);
|
||||
|
||||
push16(data, fullOpts.redMax);
|
||||
push16(data, fullOpts.greenMax);
|
||||
@@ -1517,15 +1519,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 +1562,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 +1686,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 +1694,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 +1709,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 +2390,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 +2399,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 +2413,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 +2439,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 +2465,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 +2489,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 +2516,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 +2548,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 +2572,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 +2595,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 +2613,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 +2639,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 +2652,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 +2666,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 +2676,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 +2688,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 +2698,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 +2709,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 +2720,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;
|
||||
});
|
||||
});
|
||||
@@ -2763,7 +2765,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||
});
|
||||
|
||||
it('should send a mask of 0 on mouseup', function () {
|
||||
client._mouse_buttonMask = 0x001;
|
||||
client._mouseButtonMask = 0x001;
|
||||
client._handleMouseButton(105, 120, 0, 0x001);
|
||||
expect(RFB.messages.pointerEvent).to.have.been.calledWith(
|
||||
client._sock, 105, 120, 0x000);
|
||||
@@ -2892,13 +2894,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 +2908,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;
|
||||
});
|
||||
|
||||
|
||||
+6
-6
@@ -22,37 +22,37 @@ describe('Utils', function () {
|
||||
console.warn.restore();
|
||||
console.error.restore();
|
||||
console.info.restore();
|
||||
Log.init_logging();
|
||||
Log.initLogging();
|
||||
});
|
||||
|
||||
it('should use noop for levels lower than the min level', function () {
|
||||
Log.init_logging('warn');
|
||||
Log.initLogging('warn');
|
||||
Log.Debug('hi');
|
||||
Log.Info('hello');
|
||||
expect(console.log).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should use console.debug for Debug', function () {
|
||||
Log.init_logging('debug');
|
||||
Log.initLogging('debug');
|
||||
Log.Debug('dbg');
|
||||
expect(console.debug).to.have.been.calledWith('dbg');
|
||||
});
|
||||
|
||||
it('should use console.info for Info', function () {
|
||||
Log.init_logging('debug');
|
||||
Log.initLogging('debug');
|
||||
Log.Info('inf');
|
||||
expect(console.info).to.have.been.calledWith('inf');
|
||||
});
|
||||
|
||||
it('should use console.warn for Warn', function () {
|
||||
Log.init_logging('warn');
|
||||
Log.initLogging('warn');
|
||||
Log.Warn('wrn');
|
||||
expect(console.warn).to.have.been.called;
|
||||
expect(console.warn).to.have.been.calledWith('wrn');
|
||||
});
|
||||
|
||||
it('should use console.error for Error', function () {
|
||||
Log.init_logging('error');
|
||||
Log.initLogging('error');
|
||||
Log.Error('err');
|
||||
expect(console.error).to.have.been.called;
|
||||
expect(console.error).to.have.been.calledWith('err');
|
||||
|
||||
+46
-46
@@ -13,7 +13,7 @@ describe('Websock', function () {
|
||||
beforeEach(function () {
|
||||
sock = new Websock();
|
||||
// skip init
|
||||
sock._allocate_buffers();
|
||||
sock._allocateBuffers();
|
||||
sock._rQ.set(RQ_TEMPLATE);
|
||||
sock._rQlen = RQ_TEMPLATE.length;
|
||||
});
|
||||
@@ -33,51 +33,51 @@ describe('Websock', function () {
|
||||
|
||||
describe('rQpeek8', function () {
|
||||
it('should peek at the next byte without poping it off the queue', function () {
|
||||
const bef_len = sock.rQlen;
|
||||
const befLen = sock.rQlen;
|
||||
const peek = sock.rQpeek8();
|
||||
expect(sock.rQpeek8()).to.equal(peek);
|
||||
expect(sock.rQlen).to.equal(bef_len);
|
||||
expect(sock.rQlen).to.equal(befLen);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rQshift8()', function () {
|
||||
it('should pop a single byte from the receive queue', function () {
|
||||
const peek = sock.rQpeek8();
|
||||
const bef_len = sock.rQlen;
|
||||
const befLen = sock.rQlen;
|
||||
expect(sock.rQshift8()).to.equal(peek);
|
||||
expect(sock.rQlen).to.equal(bef_len - 1);
|
||||
expect(sock.rQlen).to.equal(befLen - 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rQshift16()', function () {
|
||||
it('should pop two bytes from the receive queue and return a single number', function () {
|
||||
const bef_len = sock.rQlen;
|
||||
const befLen = sock.rQlen;
|
||||
const expected = (RQ_TEMPLATE[0] << 8) + RQ_TEMPLATE[1];
|
||||
expect(sock.rQshift16()).to.equal(expected);
|
||||
expect(sock.rQlen).to.equal(bef_len - 2);
|
||||
expect(sock.rQlen).to.equal(befLen - 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rQshift32()', function () {
|
||||
it('should pop four bytes from the receive queue and return a single number', function () {
|
||||
const bef_len = sock.rQlen;
|
||||
const befLen = sock.rQlen;
|
||||
const expected = (RQ_TEMPLATE[0] << 24) +
|
||||
(RQ_TEMPLATE[1] << 16) +
|
||||
(RQ_TEMPLATE[2] << 8) +
|
||||
RQ_TEMPLATE[3];
|
||||
expect(sock.rQshift32()).to.equal(expected);
|
||||
expect(sock.rQlen).to.equal(bef_len - 4);
|
||||
expect(sock.rQlen).to.equal(befLen - 4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rQshiftStr', function () {
|
||||
it('should shift the given number of bytes off of the receive queue and return a string', function () {
|
||||
const bef_len = sock.rQlen;
|
||||
const bef_rQi = sock.rQi;
|
||||
const befLen = sock.rQlen;
|
||||
const befRQi = sock.rQi;
|
||||
const shifted = sock.rQshiftStr(3);
|
||||
expect(shifted).to.be.a('string');
|
||||
expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3))));
|
||||
expect(sock.rQlen).to.equal(bef_len - 3);
|
||||
expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, befRQi, 3))));
|
||||
expect(sock.rQlen).to.equal(befLen - 3);
|
||||
});
|
||||
|
||||
it('should shift the entire rest of the queue off if no length is given', function () {
|
||||
@@ -112,12 +112,12 @@ describe('Websock', function () {
|
||||
|
||||
describe('rQshiftBytes', function () {
|
||||
it('should shift the given number of bytes of the receive queue and return an array', function () {
|
||||
const bef_len = sock.rQlen;
|
||||
const bef_rQi = sock.rQi;
|
||||
const befLen = sock.rQlen;
|
||||
const befRQi = sock.rQi;
|
||||
const shifted = sock.rQshiftBytes(3);
|
||||
expect(shifted).to.be.an.instanceof(Uint8Array);
|
||||
expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3));
|
||||
expect(sock.rQlen).to.equal(bef_len - 3);
|
||||
expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, befRQi, 3));
|
||||
expect(sock.rQlen).to.equal(befLen - 3);
|
||||
});
|
||||
|
||||
it('should shift the entire rest of the queue off if no length is given', function () {
|
||||
@@ -132,9 +132,9 @@ describe('Websock', function () {
|
||||
});
|
||||
|
||||
it('should not modify the receive queue', function () {
|
||||
const bef_len = sock.rQlen;
|
||||
const befLen = sock.rQlen;
|
||||
sock.rQslice(0, 2);
|
||||
expect(sock.rQlen).to.equal(bef_len);
|
||||
expect(sock.rQlen).to.equal(befLen);
|
||||
});
|
||||
|
||||
it('should return an array containing the given slice of the receive queue', function () {
|
||||
@@ -198,7 +198,7 @@ describe('Websock', function () {
|
||||
sock._websocket.readyState = WebSocket.OPEN;
|
||||
sock._sQ = new Uint8Array([1, 2, 3]);
|
||||
sock._sQlen = 3;
|
||||
const encoded = sock._encode_message();
|
||||
const encoded = sock._encodeMessage();
|
||||
|
||||
sock.flush();
|
||||
expect(sock._websocket.send).to.have.been.calledOnce;
|
||||
@@ -232,22 +232,22 @@ describe('Websock', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('send_string', function () {
|
||||
describe('sendString', function () {
|
||||
beforeEach(function () {
|
||||
sock.send = sinon.spy();
|
||||
});
|
||||
|
||||
it('should call send after converting the string to an array', function () {
|
||||
sock.send_string("\x01\x02\x03");
|
||||
sock.sendString("\x01\x02\x03");
|
||||
expect(sock.send).to.have.been.calledWith([1, 2, 3]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('lifecycle methods', function () {
|
||||
let old_WS;
|
||||
let oldWS;
|
||||
before(function () {
|
||||
old_WS = WebSocket;
|
||||
oldWS = WebSocket;
|
||||
});
|
||||
|
||||
let sock;
|
||||
@@ -255,10 +255,10 @@ describe('Websock', function () {
|
||||
sock = new Websock();
|
||||
// eslint-disable-next-line no-global-assign
|
||||
WebSocket = sinon.spy();
|
||||
WebSocket.OPEN = old_WS.OPEN;
|
||||
WebSocket.CONNECTING = old_WS.CONNECTING;
|
||||
WebSocket.CLOSING = old_WS.CLOSING;
|
||||
WebSocket.CLOSED = old_WS.CLOSED;
|
||||
WebSocket.OPEN = oldWS.OPEN;
|
||||
WebSocket.CONNECTING = oldWS.CONNECTING;
|
||||
WebSocket.CLOSING = oldWS.CLOSING;
|
||||
WebSocket.CLOSED = oldWS.CLOSED;
|
||||
|
||||
WebSocket.prototype.binaryType = 'arraybuffer';
|
||||
});
|
||||
@@ -306,30 +306,30 @@ describe('Websock', function () {
|
||||
expect(sock._websocket.close).not.to.have.been.called;
|
||||
});
|
||||
|
||||
it('should reset onmessage to not call _recv_message', function () {
|
||||
sinon.spy(sock, '_recv_message');
|
||||
it('should reset onmessage to not call _recvMessage', function () {
|
||||
sinon.spy(sock, '_recvMessage');
|
||||
sock.close();
|
||||
sock._websocket.onmessage(null);
|
||||
try {
|
||||
expect(sock._recv_message).not.to.have.been.called;
|
||||
expect(sock._recvMessage).not.to.have.been.called;
|
||||
} finally {
|
||||
sock._recv_message.restore();
|
||||
sock._recvMessage.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('event handlers', function () {
|
||||
beforeEach(function () {
|
||||
sock._recv_message = sinon.spy();
|
||||
sock._recvMessage = sinon.spy();
|
||||
sock.on('open', sinon.spy());
|
||||
sock.on('close', sinon.spy());
|
||||
sock.on('error', sinon.spy());
|
||||
sock.open('ws://');
|
||||
});
|
||||
|
||||
it('should call _recv_message on a message', function () {
|
||||
it('should call _recvMessage on a message', function () {
|
||||
sock._websocket.onmessage(null);
|
||||
expect(sock._recv_message).to.have.been.calledOnce;
|
||||
expect(sock._recvMessage).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('should call the open event handler on opening', function () {
|
||||
@@ -350,7 +350,7 @@ describe('Websock', function () {
|
||||
|
||||
after(function () {
|
||||
// eslint-disable-next-line no-global-assign
|
||||
WebSocket = old_WS;
|
||||
WebSocket = oldWS;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -358,13 +358,13 @@ describe('Websock', function () {
|
||||
let sock;
|
||||
beforeEach(function () {
|
||||
sock = new Websock();
|
||||
sock._allocate_buffers();
|
||||
sock._allocateBuffers();
|
||||
});
|
||||
|
||||
it('should support adding binary Uint8Array data to the receive queue', function () {
|
||||
const msg = { data: new Uint8Array([1, 2, 3]) };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
sock._recvMessage(msg);
|
||||
expect(sock.rQshiftStr(3)).to.equal('\x01\x02\x03');
|
||||
});
|
||||
|
||||
@@ -372,7 +372,7 @@ describe('Websock', function () {
|
||||
sock._eventHandlers.message = sinon.spy();
|
||||
const msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
sock._recvMessage(msg);
|
||||
expect(sock._eventHandlers.message).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
@@ -380,7 +380,7 @@ describe('Websock', function () {
|
||||
sock._eventHandlers.message = sinon.spy();
|
||||
const msg = { data: new Uint8Array([]).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
sock._recvMessage(msg);
|
||||
expect(sock._eventHandlers.message).not.to.have.been.called;
|
||||
});
|
||||
|
||||
@@ -391,7 +391,7 @@ describe('Websock', function () {
|
||||
sock.rQi = 6;
|
||||
const msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
sock._recvMessage(msg);
|
||||
expect(sock._rQlen).to.equal(0);
|
||||
expect(sock.rQi).to.equal(0);
|
||||
});
|
||||
@@ -403,7 +403,7 @@ describe('Websock', function () {
|
||||
sock.rQi = 10;
|
||||
const msg = { data: new Uint8Array([1, 2]).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
sock._recvMessage(msg);
|
||||
expect(sock._rQlen).to.equal(12);
|
||||
expect(sock.rQi).to.equal(0);
|
||||
});
|
||||
@@ -415,7 +415,7 @@ describe('Websock', function () {
|
||||
sock._rQbufferSize = 20;
|
||||
const msg = { data: new Uint8Array(30).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
sock._recvMessage(msg);
|
||||
expect(sock._rQlen).to.equal(30);
|
||||
expect(sock.rQi).to.equal(0);
|
||||
expect(sock._rQ.length).to.equal(240); // keep the invariant that rQbufferSize / 8 >= rQlen
|
||||
@@ -428,7 +428,7 @@ describe('Websock', function () {
|
||||
sock._rQbufferSize = 20;
|
||||
const msg = { data: new Uint8Array(6).buffer };
|
||||
sock._mode = 'binary';
|
||||
sock._recv_message(msg);
|
||||
sock._recvMessage(msg);
|
||||
expect(sock._rQlen).to.equal(6);
|
||||
expect(sock.rQi).to.equal(0);
|
||||
expect(sock._rQ.length).to.equal(48);
|
||||
@@ -450,13 +450,13 @@ describe('Websock', function () {
|
||||
it('should only send the send queue up to the send queue length', function () {
|
||||
sock._sQ = new Uint8Array([1, 2, 3, 4, 5]);
|
||||
sock._sQlen = 3;
|
||||
const res = sock._encode_message();
|
||||
const res = sock._encodeMessage();
|
||||
expect(res).to.array.equal(new Uint8Array([1, 2, 3]));
|
||||
});
|
||||
|
||||
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]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user