Use standard JavaScript properties
Use normal properties with JavaScript setters and getters instead of our homegrown stuff. This also changes the properties to follow normal naming conventions.
This commit is contained in:
+10
-10
@@ -77,10 +77,10 @@ export default function RecordingPlayer (frames, encoding, disconnected, notific
|
||||
RecordingPlayer.prototype = {
|
||||
run: function (realtime, trafficManagement) {
|
||||
// initialize a new RFB
|
||||
this._rfb = new RFB(document.getElementById('VNC_canvas'),
|
||||
{'view_only': true,
|
||||
'onDisconnected': this._handleDisconnect.bind(this),
|
||||
'onNotification': this._notification});
|
||||
this._rfb = new RFB(document.getElementById('VNC_canvas'));
|
||||
this._rfb.viewOnly = true;
|
||||
this._rfb.ondisconnected = this._handleDisconnect.bind(this);
|
||||
this._rfb.onnotification = this._notification;
|
||||
this._enablePlaybackMode();
|
||||
|
||||
// reset the frame index and timer
|
||||
@@ -152,12 +152,12 @@ RecordingPlayer.prototype = {
|
||||
// Avoid having excessive queue buildup in non-realtime mode
|
||||
if (this._trafficManagement && this._rfb._flushing) {
|
||||
let player = this;
|
||||
let orig = this._rfb._display.get_onFlush();
|
||||
this._rfb._display.set_onFlush(function () {
|
||||
player._rfb._display.set_onFlush(orig);
|
||||
let orig = this._rfb._display.onflush;
|
||||
this._rfb._display.onflush = function () {
|
||||
player._rfb._display.onflush = orig;
|
||||
player._rfb._onFlush();
|
||||
player._doPacket();
|
||||
});
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -182,12 +182,12 @@ RecordingPlayer.prototype = {
|
||||
_finish() {
|
||||
if (this._rfb._display.pending()) {
|
||||
var player = this;
|
||||
this._rfb._display.set_onFlush(function () {
|
||||
this._rfb._display.onflush = function () {
|
||||
if (player._rfb._flushing) {
|
||||
player._rfb._onFlush();
|
||||
}
|
||||
player._finish();
|
||||
});
|
||||
};
|
||||
this._rfb._display.flush();
|
||||
} else {
|
||||
this._running = false;
|
||||
|
||||
+24
-20
@@ -39,7 +39,8 @@ describe('Display/Canvas Helper', function () {
|
||||
describe('viewport handling', function () {
|
||||
var display;
|
||||
beforeEach(function () {
|
||||
display = new Display(document.createElement('canvas'), { viewport: true });
|
||||
display = new Display(document.createElement('canvas'));
|
||||
display.viewport = true;
|
||||
display.resize(5, 5);
|
||||
display.viewportChangeSize(3, 3);
|
||||
display.viewportChangePos(1, 1);
|
||||
@@ -102,7 +103,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should show the entire framebuffer when disabling the viewport', function() {
|
||||
display.set_viewport(false);
|
||||
display.viewport = false;
|
||||
expect(display.absX(0)).to.equal(0);
|
||||
expect(display.absY(0)).to.equal(0);
|
||||
expect(display._target.width).to.equal(5);
|
||||
@@ -110,7 +111,7 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should ignore viewport changes when the viewport is disabled', function() {
|
||||
display.set_viewport(false);
|
||||
display.viewport = false;
|
||||
display.viewportChangeSize(2, 2);
|
||||
display.viewportChangePos(1, 1);
|
||||
expect(display.absX(0)).to.equal(0);
|
||||
@@ -120,8 +121,8 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should show the entire framebuffer just after enabling the viewport', function() {
|
||||
display.set_viewport(false);
|
||||
display.set_viewport(true);
|
||||
display.viewport = false;
|
||||
display.viewport = true;
|
||||
expect(display.absX(0)).to.equal(0);
|
||||
expect(display.absY(0)).to.equal(0);
|
||||
expect(display._target.width).to.equal(5);
|
||||
@@ -132,7 +133,8 @@ describe('Display/Canvas Helper', function () {
|
||||
describe('resizing', function () {
|
||||
var display;
|
||||
beforeEach(function () {
|
||||
display = new Display(document.createElement('canvas'), { viewport: false });
|
||||
display = new Display(document.createElement('canvas'));
|
||||
display.viewport = false;
|
||||
display.resize(4, 4);
|
||||
});
|
||||
|
||||
@@ -157,7 +159,7 @@ describe('Display/Canvas Helper', function () {
|
||||
|
||||
describe('viewport', function () {
|
||||
beforeEach(function () {
|
||||
display.set_viewport(true);
|
||||
display.viewport = true;
|
||||
display.viewportChangeSize(3, 3);
|
||||
display.viewportChangePos(1, 1);
|
||||
});
|
||||
@@ -194,7 +196,8 @@ describe('Display/Canvas Helper', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
canvas = document.createElement('canvas');
|
||||
display = new Display(canvas, { viewport: true });
|
||||
display = new Display(canvas);
|
||||
display.viewport = true;
|
||||
display.resize(4, 4);
|
||||
display.viewportChangeSize(3, 3);
|
||||
display.viewportChangePos(1, 1);
|
||||
@@ -206,21 +209,21 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should not change the bitmap size of the canvas', function () {
|
||||
display.set_scale(2.0);
|
||||
display.scale = 2.0;
|
||||
expect(canvas.width).to.equal(3);
|
||||
expect(canvas.height).to.equal(3);
|
||||
});
|
||||
|
||||
it('should change the effective rendered size of the canvas', function () {
|
||||
display.set_scale(2.0);
|
||||
display.scale = 2.0;
|
||||
expect(canvas.clientWidth).to.equal(6);
|
||||
expect(canvas.clientHeight).to.equal(6);
|
||||
});
|
||||
|
||||
it('should not change when resizing', function () {
|
||||
display.set_scale(2.0);
|
||||
display.scale = 2.0;
|
||||
display.resize(5, 5);
|
||||
expect(display.get_scale()).to.equal(2.0);
|
||||
expect(display.scale).to.equal(2.0);
|
||||
expect(canvas.width).to.equal(3);
|
||||
expect(canvas.height).to.equal(3);
|
||||
expect(canvas.clientWidth).to.equal(6);
|
||||
@@ -234,7 +237,8 @@ describe('Display/Canvas Helper', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
canvas = document.createElement('canvas');
|
||||
display = new Display(canvas, { viewport: true });
|
||||
display = new Display(canvas);
|
||||
display.viewport = true;
|
||||
display.resize(4, 3);
|
||||
document.body.appendChild(canvas);
|
||||
});
|
||||
@@ -309,12 +313,12 @@ describe('Display/Canvas Helper', function () {
|
||||
it('should draw the logo on #clear with a logo set', function (done) {
|
||||
display._logo = { width: 4, height: 4, type: "image/png", data: make_image_png(checked_data) };
|
||||
display.clear();
|
||||
display.set_onFlush(function () {
|
||||
display.onflush = function () {
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
expect(display._fb_width).to.equal(4);
|
||||
expect(display._fb_height).to.equal(4);
|
||||
done();
|
||||
});
|
||||
};
|
||||
display.flush();
|
||||
});
|
||||
|
||||
@@ -350,10 +354,10 @@ describe('Display/Canvas Helper', function () {
|
||||
it('should support drawing images via #imageRect', function (done) {
|
||||
display.imageRect(0, 0, "image/png", make_image_png(checked_data));
|
||||
display.flip();
|
||||
display.set_onFlush(function () {
|
||||
display.onflush = function () {
|
||||
expect(display).to.have.displayed(checked_data);
|
||||
done();
|
||||
});
|
||||
};
|
||||
display.flush();
|
||||
});
|
||||
|
||||
@@ -442,11 +446,11 @@ describe('Display/Canvas Helper', function () {
|
||||
});
|
||||
|
||||
it('should call callback when queue is flushed', function () {
|
||||
display.set_onFlush(sinon.spy());
|
||||
display.onflush = sinon.spy();
|
||||
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
||||
expect(display.get_onFlush()).to.not.have.been.called;
|
||||
expect(display.onflush).to.not.have.been.called;
|
||||
display.flush();
|
||||
expect(display.get_onFlush()).to.have.been.calledOnce;
|
||||
expect(display.onflush).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('should draw a blit image on type "blit"', function () {
|
||||
|
||||
+72
-72
@@ -31,105 +31,105 @@ describe('Key Event Handling', function() {
|
||||
describe('Decode Keyboard Events', function() {
|
||||
it('should decode keydown events', function(done) {
|
||||
if (isIE() || isEdge()) this.skip();
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
expect(down).to.be.equal(true);
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
|
||||
});
|
||||
it('should decode keyup events', function(done) {
|
||||
if (isIE() || isEdge()) this.skip();
|
||||
var calls = 0;
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
if (calls++ === 1) {
|
||||
expect(down).to.be.equal(false);
|
||||
done();
|
||||
}
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
|
||||
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
|
||||
});
|
||||
|
||||
describe('Legacy keypress Events', function() {
|
||||
it('should wait for keypress when needed', function() {
|
||||
var callback = sinon.spy();
|
||||
var kbd = new Keyboard(document, {onKeyEvent: callback});
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
||||
expect(callback).to.not.have.been.called;
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
});
|
||||
it('should decode keypress events', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
expect(down).to.be.equal(true);
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
||||
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyA', charCode: 0x61}));
|
||||
});
|
||||
it('should ignore keypress with different code', function() {
|
||||
var callback = sinon.spy();
|
||||
var kbd = new Keyboard(document, {onKeyEvent: callback});
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
||||
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyB', charCode: 0x61}));
|
||||
expect(callback).to.not.have.been.called;
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
});
|
||||
it('should handle keypress with missing code', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
expect(down).to.be.equal(true);
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
||||
kbd._handleKeyPress(keyevent('keypress', {charCode: 0x61}));
|
||||
});
|
||||
it('should guess key if no keypress and numeric key', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x32);
|
||||
expect(code).to.be.equal('Digit2');
|
||||
expect(down).to.be.equal(true);
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'Digit2', keyCode: 0x32}));
|
||||
});
|
||||
it('should guess key if no keypress and alpha key', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
expect(down).to.be.equal(true);
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: false}));
|
||||
});
|
||||
it('should guess key if no keypress and alpha key (with shift)', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x41);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
expect(down).to.be.equal(true);
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: true}));
|
||||
});
|
||||
it('should not guess key if no keypress and unknown key', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
expect(down).to.be.equal(true);
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x09}));
|
||||
});
|
||||
});
|
||||
@@ -168,8 +168,8 @@ describe('Key Event Handling', function() {
|
||||
it('should fake keyup events for virtual keyboards', function(done) {
|
||||
if (isIE() || isEdge()) this.skip();
|
||||
var count = 0;
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
@@ -182,7 +182,7 @@ describe('Key Event Handling', function() {
|
||||
expect(down).to.be.equal(false);
|
||||
done();
|
||||
}
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'Unidentified', key: 'a'}));
|
||||
});
|
||||
|
||||
@@ -215,8 +215,8 @@ describe('Key Event Handling', function() {
|
||||
it('should fake keyup events on iOS', function(done) {
|
||||
if (isIE() || isEdge()) this.skip();
|
||||
var count = 0;
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
@@ -229,7 +229,7 @@ describe('Key Event Handling', function() {
|
||||
expect(down).to.be.equal(false);
|
||||
done();
|
||||
}
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
|
||||
});
|
||||
});
|
||||
@@ -240,67 +240,67 @@ describe('Key Event Handling', function() {
|
||||
if (isIE() || isEdge()) this.skip();
|
||||
});
|
||||
it('should send release using the same keysym as the press', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
if (!down) {
|
||||
done();
|
||||
}
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
|
||||
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'b'}));
|
||||
});
|
||||
it('should send the same keysym for multiple presses', function() {
|
||||
var count = 0;
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('KeyA');
|
||||
expect(down).to.be.equal(true);
|
||||
count++;
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'b'}));
|
||||
expect(count).to.be.equal(2);
|
||||
});
|
||||
it('should do nothing on keyup events if no keys are down', function() {
|
||||
var callback = sinon.spy();
|
||||
var kbd = new Keyboard(document, {onKeyEvent: callback});
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = sinon.spy();
|
||||
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
|
||||
expect(callback).to.not.have.been.called;
|
||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||
});
|
||||
|
||||
describe('Legacy Events', function() {
|
||||
it('should track keys using keyCode if no code', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('Platform65');
|
||||
if (!down) {
|
||||
done();
|
||||
}
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {keyCode: 65, key: 'a'}));
|
||||
kbd._handleKeyUp(keyevent('keyup', {keyCode: 65, key: 'b'}));
|
||||
});
|
||||
it('should ignore compositing code', function() {
|
||||
var kbd = new Keyboard({
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('Unidentified');
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {keyCode: 229, key: 'a'}));
|
||||
});
|
||||
it('should track keys using keyIdentifier if no code', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
expect(code).to.be.equal('Platform65');
|
||||
if (!down) {
|
||||
done();
|
||||
}
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {keyIdentifier: 'U+0041', key: 'a'}));
|
||||
kbd._handleKeyUp(keyevent('keyup', {keyIdentifier: 'U+0041', key: 'b'}));
|
||||
});
|
||||
@@ -335,8 +335,8 @@ describe('Key Event Handling', function() {
|
||||
|
||||
it('should change Alt to AltGraph', function() {
|
||||
var count = 0;
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
expect(keysym).to.be.equal(0xFF7E);
|
||||
@@ -347,27 +347,27 @@ describe('Key Event Handling', function() {
|
||||
expect(code).to.be.equal('AltRight');
|
||||
break;
|
||||
}
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'AltLeft', key: 'Alt', location: 1}));
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'Alt', location: 2}));
|
||||
expect(count).to.be.equal(2);
|
||||
});
|
||||
it('should change left Super to Alt', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0xFFE9);
|
||||
expect(code).to.be.equal('MetaLeft');
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'MetaLeft', key: 'Meta', location: 1}));
|
||||
});
|
||||
it('should change right Super to left Super', function(done) {
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
expect(keysym).to.be.equal(0xFFEB);
|
||||
expect(code).to.be.equal('MetaRight');
|
||||
done();
|
||||
}});
|
||||
};
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'MetaRight', key: 'Meta', location: 2}));
|
||||
});
|
||||
});
|
||||
@@ -400,8 +400,8 @@ describe('Key Event Handling', function() {
|
||||
|
||||
it('should generate fake undo/redo events on press when AltGraph is down', function() {
|
||||
var times_called = 0;
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch(times_called++) {
|
||||
case 0:
|
||||
expect(keysym).to.be.equal(0xFFE3);
|
||||
@@ -439,7 +439,7 @@ describe('Key Event Handling', function() {
|
||||
expect(down).to.be.equal(true);
|
||||
break;
|
||||
}
|
||||
}});
|
||||
};
|
||||
// First the modifier combo
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'Alt', location: 2}));
|
||||
@@ -449,8 +449,8 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
it('should no do anything on key release', function() {
|
||||
var times_called = 0;
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch(times_called++) {
|
||||
case 7:
|
||||
expect(keysym).to.be.equal(0x61);
|
||||
@@ -458,7 +458,7 @@ describe('Key Event Handling', function() {
|
||||
expect(down).to.be.equal(false);
|
||||
break;
|
||||
}
|
||||
}});
|
||||
};
|
||||
// First the modifier combo
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'Alt', location: 2}));
|
||||
@@ -469,8 +469,8 @@ describe('Key Event Handling', function() {
|
||||
});
|
||||
it('should not consider a char modifier to be down on the modifier key itself', function() {
|
||||
var times_called = 0;
|
||||
var kbd = new Keyboard(document, {
|
||||
onKeyEvent: function(keysym, code, down) {
|
||||
var kbd = new Keyboard(document);
|
||||
kbd.onkeyevent = function(keysym, code, down) {
|
||||
switch(times_called++) {
|
||||
case 0:
|
||||
expect(keysym).to.be.equal(0xFFE3);
|
||||
@@ -488,7 +488,7 @@ describe('Key Event Handling', function() {
|
||||
expect(down).to.be.equal(true);
|
||||
break;
|
||||
}
|
||||
}});
|
||||
};
|
||||
// First the modifier combo
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
|
||||
kbd._handleKeyDown(keyevent('keydown', {code: 'AltLeft', key: 'Alt', location: 1}));
|
||||
|
||||
+95
-103
@@ -33,55 +33,51 @@ describe('Mouse Event Handling', function() {
|
||||
|
||||
describe('Decode Mouse Events', function() {
|
||||
it('should decode mousedown events', function(done) {
|
||||
var mouse = new Mouse(target, {
|
||||
onMouseButton: function(x, y, down, bmask) {
|
||||
expect(bmask).to.be.equal(0x01);
|
||||
expect(down).to.be.equal(1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
expect(bmask).to.be.equal(0x01);
|
||||
expect(down).to.be.equal(1);
|
||||
done();
|
||||
};
|
||||
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
|
||||
});
|
||||
it('should decode mouseup events', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target, {
|
||||
onMouseButton: function(x, y, down, bmask) {
|
||||
expect(bmask).to.be.equal(0x01);
|
||||
if (calls++ === 1) {
|
||||
expect(down).to.not.be.equal(1);
|
||||
done();
|
||||
}
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
expect(bmask).to.be.equal(0x01);
|
||||
if (calls++ === 1) {
|
||||
expect(down).to.not.be.equal(1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
|
||||
mouse._handleMouseUp(mouseevent('mouseup', { button: '0x01' }));
|
||||
});
|
||||
it('should decode mousemove events', function(done) {
|
||||
var mouse = new Mouse(target, {
|
||||
onMouseMove: function(x, y) {
|
||||
// Note that target relative coordinates are sent
|
||||
expect(x).to.be.equal(40);
|
||||
expect(y).to.be.equal(10);
|
||||
done();
|
||||
}
|
||||
});
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousemove = function(x, y) {
|
||||
// Note that target relative coordinates are sent
|
||||
expect(x).to.be.equal(40);
|
||||
expect(y).to.be.equal(10);
|
||||
done();
|
||||
};
|
||||
mouse._handleMouseMove(mouseevent('mousemove',
|
||||
{ clientX: 50, clientY: 20 }));
|
||||
});
|
||||
it('should decode mousewheel events', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target, {
|
||||
onMouseButton: function(x, y, down, bmask) {
|
||||
calls++;
|
||||
expect(bmask).to.be.equal(1<<6);
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
} else if (calls === 2) {
|
||||
expect(down).to.not.be.equal(1);
|
||||
done();
|
||||
}
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
expect(bmask).to.be.equal(1<<6);
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
} else if (calls === 2) {
|
||||
expect(down).to.not.be.equal(1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
mouse._handleMouseWheel(mouseevent('mousewheel',
|
||||
{ deltaX: 50, deltaY: 0,
|
||||
deltaMode: 0}));
|
||||
@@ -95,21 +91,20 @@ describe('Mouse Event Handling', function() {
|
||||
|
||||
it('should use same pos for 2nd tap if close enough', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target, {
|
||||
onMouseButton: function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
} else if (calls === 3) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
done();
|
||||
}
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
} else if (calls === 3) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
// touch events are sent in an array of events
|
||||
// with one item for each touch point
|
||||
mouse._handleMouseDown(touchevent(
|
||||
@@ -127,21 +122,20 @@ describe('Mouse Event Handling', function() {
|
||||
|
||||
it('should not modify 2nd tap pos if far apart', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target, {
|
||||
onMouseButton: function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
} else if (calls === 3) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.not.be.equal(68);
|
||||
expect(y).to.not.be.equal(36);
|
||||
done();
|
||||
}
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
} else if (calls === 3) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.not.be.equal(68);
|
||||
expect(y).to.not.be.equal(36);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
mouse._handleMouseDown(touchevent(
|
||||
'touchstart', { touches: [{ clientX: 78, clientY: 46 }]}));
|
||||
this.clock.tick(10);
|
||||
@@ -157,21 +151,20 @@ describe('Mouse Event Handling', function() {
|
||||
|
||||
it('should not modify 2nd tap pos if not soon enough', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target, {
|
||||
onMouseButton: function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
} else if (calls === 3) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.not.be.equal(68);
|
||||
expect(y).to.not.be.equal(36);
|
||||
done();
|
||||
}
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
} else if (calls === 3) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.not.be.equal(68);
|
||||
expect(y).to.not.be.equal(36);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
mouse._handleMouseDown(touchevent(
|
||||
'touchstart', { touches: [{ clientX: 78, clientY: 46 }]}));
|
||||
this.clock.tick(10);
|
||||
@@ -187,21 +180,20 @@ describe('Mouse Event Handling', function() {
|
||||
|
||||
it('should not modify 2nd tap pos if not touch', function(done) {
|
||||
var calls = 0;
|
||||
var mouse = new Mouse(target, {
|
||||
onMouseButton: function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
} else if (calls === 3) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.not.be.equal(68);
|
||||
expect(y).to.not.be.equal(36);
|
||||
done();
|
||||
}
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
||||
calls++;
|
||||
if (calls === 1) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.be.equal(68);
|
||||
expect(y).to.be.equal(36);
|
||||
} else if (calls === 3) {
|
||||
expect(down).to.be.equal(1);
|
||||
expect(x).to.not.be.equal(68);
|
||||
expect(y).to.not.be.equal(36);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
mouse._handleMouseDown(mouseevent(
|
||||
'mousedown', { button: '0x01', clientX: 78, clientY: 46 }));
|
||||
this.clock.tick(10);
|
||||
@@ -223,8 +215,8 @@ describe('Mouse Event Handling', function() {
|
||||
afterEach(function () { this.clock.restore(); });
|
||||
|
||||
it('should accumulate wheel events if small enough', function () {
|
||||
var callback = sinon.spy();
|
||||
var mouse = new Mouse(target, { onMouseButton: callback });
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = sinon.spy();
|
||||
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
'mousewheel', { clientX: 18, clientY: 40,
|
||||
@@ -242,7 +234,7 @@ describe('Mouse Event Handling', function() {
|
||||
'mousewheel', { clientX: 18, clientY: 40,
|
||||
deltaX: 4, deltaY: 0, deltaMode: 0 }));
|
||||
|
||||
expect(callback).to.have.callCount(2); // mouse down and up
|
||||
expect(mouse.onmousebutton).to.have.callCount(2); // mouse down and up
|
||||
|
||||
this.clock.tick(10);
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
@@ -252,12 +244,12 @@ describe('Mouse Event Handling', function() {
|
||||
expect(mouse._accumulatedWheelDeltaX).to.be.equal(4);
|
||||
expect(mouse._accumulatedWheelDeltaY).to.be.equal(9);
|
||||
|
||||
expect(callback).to.have.callCount(2); // still
|
||||
expect(mouse.onmousebutton).to.have.callCount(2); // still
|
||||
});
|
||||
|
||||
it('should not accumulate large wheel events', function () {
|
||||
var callback = sinon.spy();
|
||||
var mouse = new Mouse(target, { onMouseButton: callback });
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = sinon.spy();
|
||||
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
'mousewheel', { clientX: 18, clientY: 40,
|
||||
@@ -271,24 +263,24 @@ describe('Mouse Event Handling', function() {
|
||||
'mousewheel', { clientX: 18, clientY: 40,
|
||||
deltaX: 400, deltaY: 400, deltaMode: 0 }));
|
||||
|
||||
expect(callback).to.have.callCount(8); // mouse down and up
|
||||
expect(mouse.onmousebutton).to.have.callCount(8); // mouse down and up
|
||||
});
|
||||
|
||||
it('should send even small wheel events after a timeout', function () {
|
||||
var callback = sinon.spy();
|
||||
var mouse = new Mouse(target, { onMouseButton: callback });
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = sinon.spy();
|
||||
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
'mousewheel', { clientX: 18, clientY: 40,
|
||||
deltaX: 1, deltaY: 0, deltaMode: 0 }));
|
||||
this.clock.tick(51); // timeout on 50 ms
|
||||
|
||||
expect(callback).to.have.callCount(2); // mouse down and up
|
||||
expect(mouse.onmousebutton).to.have.callCount(2); // mouse down and up
|
||||
});
|
||||
|
||||
it('should account for non-zero deltaMode', function () {
|
||||
var callback = sinon.spy();
|
||||
var mouse = new Mouse(target, { onMouseButton: callback });
|
||||
var mouse = new Mouse(target);
|
||||
mouse.onmousebutton = sinon.spy();
|
||||
|
||||
mouse._handleMouseWheel(mouseevent(
|
||||
'mousewheel', { clientX: 18, clientY: 40,
|
||||
@@ -300,7 +292,7 @@ describe('Mouse Event Handling', function() {
|
||||
'mousewheel', { clientX: 18, clientY: 40,
|
||||
deltaX: 1, deltaY: 0, deltaMode: 2 }));
|
||||
|
||||
expect(callback).to.have.callCount(4); // mouse down and up
|
||||
expect(mouse.onmousebutton).to.have.callCount(4); // mouse down and up
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+87
-88
@@ -9,9 +9,8 @@ import { encodings } from '../core/encodings.js';
|
||||
import FakeWebSocket from './fake.websocket.js';
|
||||
import sinon from '../vendor/sinon.js';
|
||||
|
||||
function make_rfb (extra_opts) {
|
||||
extra_opts = extra_opts || {};
|
||||
return new RFB(document.createElement('canvas'), extra_opts);
|
||||
function make_rfb () {
|
||||
return new RFB(document.createElement('canvas'));
|
||||
}
|
||||
|
||||
var push8 = function (arr, num) {
|
||||
@@ -136,7 +135,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._sock._websocket._open();
|
||||
sinon.spy(client._sock, 'flush');
|
||||
client._rfb_connection_state = 'connected';
|
||||
client._view_only = false;
|
||||
client._viewOnly = false;
|
||||
});
|
||||
|
||||
it('should sent ctrl[down]-alt[down]-del[down] then del[up]-alt[up]-ctrl[up]', function () {
|
||||
@@ -159,7 +158,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should not send the keys if we are set as view_only', function () {
|
||||
client._view_only = true;
|
||||
client._viewOnly = true;
|
||||
client.sendCtrlAltDel();
|
||||
expect(client._sock.flush).to.not.have.been.called;
|
||||
});
|
||||
@@ -172,7 +171,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._sock._websocket._open();
|
||||
sinon.spy(client._sock, 'flush');
|
||||
client._rfb_connection_state = 'connected';
|
||||
client._view_only = false;
|
||||
client._viewOnly = false;
|
||||
});
|
||||
|
||||
it('should send a single key with the given code and state (down = true)', function () {
|
||||
@@ -197,7 +196,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should not send the key if we are set as view_only', function () {
|
||||
client._view_only = true;
|
||||
client._viewOnly = true;
|
||||
client.sendKey(123, 'Key123');
|
||||
expect(client._sock.flush).to.not.have.been.called;
|
||||
});
|
||||
@@ -226,7 +225,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._sock._websocket._open();
|
||||
sinon.spy(client._sock, 'flush');
|
||||
client._rfb_connection_state = 'connected';
|
||||
client._view_only = false;
|
||||
client._viewOnly = false;
|
||||
});
|
||||
|
||||
it('should send the given text in a paste event', function () {
|
||||
@@ -250,7 +249,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._sock._websocket._open();
|
||||
sinon.spy(client._sock, 'flush');
|
||||
client._rfb_connection_state = 'connected';
|
||||
client._view_only = false;
|
||||
client._viewOnly = false;
|
||||
client._supportsSetDesktopSize = true;
|
||||
});
|
||||
|
||||
@@ -292,7 +291,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._sock._websocket._open();
|
||||
sinon.spy(client._sock, 'flush');
|
||||
client._rfb_connection_state = 'connected';
|
||||
client._view_only = false;
|
||||
client._viewOnly = false;
|
||||
client._rfb_xvp_ver = 1;
|
||||
});
|
||||
|
||||
@@ -340,9 +339,9 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should call the updateState callback', function () {
|
||||
client.set_onUpdateState(sinon.spy());
|
||||
client.onupdatestate = sinon.spy();
|
||||
client._updateConnectionState('connecting');
|
||||
var spy = client.get_onUpdateState();
|
||||
var spy = client.onupdatestate;
|
||||
expect(spy.args[0][1]).to.equal('connecting');
|
||||
});
|
||||
|
||||
@@ -359,19 +358,19 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should ignore state changes to the same state', function () {
|
||||
client.set_onUpdateState(sinon.spy());
|
||||
client.onupdatestate = sinon.spy();
|
||||
client._rfb_connection_state = 'connecting';
|
||||
client._updateConnectionState('connecting');
|
||||
var spy = client.get_onUpdateState();
|
||||
var spy = client.onupdatestate;
|
||||
expect(spy).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should ignore illegal state changes', function () {
|
||||
client.set_onUpdateState(sinon.spy());
|
||||
client.onupdatestate = sinon.spy();
|
||||
client._rfb_connection_state = 'connected';
|
||||
client._updateConnectionState('disconnected');
|
||||
expect(client._rfb_connection_state).to.not.equal('disconnected');
|
||||
var spy = client.get_onUpdateState();
|
||||
var spy = client.onupdatestate;
|
||||
expect(spy).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
@@ -416,9 +415,9 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
it('should result in disconnect callback with message when reason given', function () {
|
||||
client._rfb_connection_state = 'connected';
|
||||
client.set_onDisconnected(sinon.spy());
|
||||
client.ondisconnected = sinon.spy();
|
||||
client._fail('a reason');
|
||||
var spy = client.get_onDisconnected();
|
||||
var spy = client.ondisconnected;
|
||||
this.clock.tick(2000);
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0].length).to.equal(2);
|
||||
@@ -432,18 +431,18 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
beforeEach(function () { client = make_rfb(); });
|
||||
|
||||
it('should call the notification callback', function () {
|
||||
client.set_onNotification(sinon.spy());
|
||||
client.onnotification = sinon.spy();
|
||||
client._notification('notify!', 'warn');
|
||||
var spy = client.get_onNotification();
|
||||
var spy = client.onnotification;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0][1]).to.equal('notify!');
|
||||
expect(spy.args[0][2]).to.equal('warn');
|
||||
});
|
||||
|
||||
it('should not call the notification callback when level is invalid', function () {
|
||||
client.set_onNotification(sinon.spy());
|
||||
client.onnotification = sinon.spy();
|
||||
client._notification('notify!', 'invalid');
|
||||
var spy = client.get_onNotification();
|
||||
var spy = client.onnotification;
|
||||
expect(spy).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
@@ -484,7 +483,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
sinon.spy(client, '_updateConnectionState');
|
||||
client._sock._websocket.close = function () {}; // explicitly don't call onclose
|
||||
client._updateConnectionState('disconnecting');
|
||||
this.clock.tick(client.get_disconnectTimeout() * 1000);
|
||||
this.clock.tick(client.disconnectTimeout * 1000);
|
||||
expect(client._updateConnectionState).to.have.been.calledTwice;
|
||||
expect(client._rfb_disconnect_reason).to.not.equal("");
|
||||
expect(client._rfb_connection_state).to.equal("disconnected");
|
||||
@@ -492,9 +491,9 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
it('should not fail if Websock.onclose gets called within the disconnection timeout', function () {
|
||||
client._updateConnectionState('disconnecting');
|
||||
this.clock.tick(client.get_disconnectTimeout() * 500);
|
||||
this.clock.tick(client.disconnectTimeout * 500);
|
||||
client._sock._websocket.close();
|
||||
this.clock.tick(client.get_disconnectTimeout() * 500 + 1);
|
||||
this.clock.tick(client.disconnectTimeout * 500 + 1);
|
||||
expect(client._rfb_connection_state).to.equal('disconnected');
|
||||
});
|
||||
|
||||
@@ -510,39 +509,39 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
beforeEach(function () { client = make_rfb(); });
|
||||
|
||||
it('should call the disconnect callback if the state is "disconnected"', function () {
|
||||
client.set_onDisconnected(sinon.spy());
|
||||
client.ondisconnected = sinon.spy();
|
||||
client._rfb_connection_state = 'disconnecting';
|
||||
client._rfb_disconnect_reason = "error";
|
||||
client._updateConnectionState('disconnected');
|
||||
var spy = client.get_onDisconnected();
|
||||
var spy = client.ondisconnected;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0][1]).to.equal("error");
|
||||
});
|
||||
|
||||
it('should not call the disconnect callback if the state is not "disconnected"', function () {
|
||||
client.set_onDisconnected(sinon.spy());
|
||||
client.ondisconnected = sinon.spy();
|
||||
client._updateConnectionState('disconnecting');
|
||||
var spy = client.get_onDisconnected();
|
||||
var spy = client.ondisconnected;
|
||||
expect(spy).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should call the disconnect callback without msg when no reason given', function () {
|
||||
client.set_onDisconnected(sinon.spy());
|
||||
client.ondisconnected = sinon.spy();
|
||||
client._rfb_connection_state = 'disconnecting';
|
||||
client._rfb_disconnect_reason = "";
|
||||
client._updateConnectionState('disconnected');
|
||||
var spy = client.get_onDisconnected();
|
||||
var spy = client.ondisconnected;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0].length).to.equal(1);
|
||||
});
|
||||
|
||||
it('should call the updateState callback before the disconnect callback', function () {
|
||||
client.set_onDisconnected(sinon.spy());
|
||||
client.set_onUpdateState(sinon.spy());
|
||||
client.ondisconnected = sinon.spy();
|
||||
client.onupdatestate = sinon.spy();
|
||||
client._rfb_connection_state = 'disconnecting';
|
||||
client._updateConnectionState('disconnected');
|
||||
var updateStateSpy = client.get_onUpdateState();
|
||||
var disconnectSpy = client.get_onDisconnected();
|
||||
var updateStateSpy = client.onupdatestate;
|
||||
var disconnectSpy = client.ondisconnected;
|
||||
expect(updateStateSpy.calledBefore(disconnectSpy)).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -790,14 +789,14 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should call the onCredentialsRequired callback if missing a password', function () {
|
||||
client.set_onCredentialsRequired(sinon.spy());
|
||||
client.oncredentialsrequired = sinon.spy();
|
||||
send_security(2, client);
|
||||
|
||||
var challenge = [];
|
||||
for (var i = 0; i < 16; i++) { challenge[i] = i; }
|
||||
client._sock._websocket._receive_data(new Uint8Array(challenge));
|
||||
|
||||
var spy = client.get_onCredentialsRequired();
|
||||
var spy = client.oncredentialsrequired;
|
||||
expect(client._rfb_credentials).to.be.empty;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0][1]).to.have.members(["password"]);
|
||||
@@ -849,23 +848,23 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should call the onCredentialsRequired callback if all credentials are missing', function() {
|
||||
client.set_onCredentialsRequired(sinon.spy());
|
||||
client.oncredentialsrequired = sinon.spy();
|
||||
client._rfb_credentials = {};
|
||||
send_security(22, client);
|
||||
|
||||
var spy = client.get_onCredentialsRequired();
|
||||
var spy = client.oncredentialsrequired;
|
||||
expect(client._rfb_credentials).to.be.empty;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0][1]).to.have.members(["username", "password", "target"]);
|
||||
});
|
||||
|
||||
it('should call the onCredentialsRequired callback if some credentials are missing', function() {
|
||||
client.set_onCredentialsRequired(sinon.spy());
|
||||
client.oncredentialsrequired = sinon.spy();
|
||||
client._rfb_credentials = { username: 'user',
|
||||
target: 'target' };
|
||||
send_security(22, client);
|
||||
|
||||
var spy = client.get_onCredentialsRequired();
|
||||
var spy = client.oncredentialsrequired;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0][1]).to.have.members(["username", "password", "target"]);
|
||||
});
|
||||
@@ -1098,10 +1097,10 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
// NB(sross): we just warn, not fail, for endian-ness and shifts, so we don't test them
|
||||
|
||||
it('should set the framebuffer name and call the callback', function () {
|
||||
client.set_onDesktopName(sinon.spy());
|
||||
client.ondesktopname = sinon.spy();
|
||||
send_server_init({ name: 'some name' }, client);
|
||||
|
||||
var spy = client.get_onDesktopName();
|
||||
var spy = client.ondesktopname;
|
||||
expect(client._fb_name).to.equal('some name');
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0][1]).to.equal('some name');
|
||||
@@ -1127,11 +1126,11 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should call the resize callback and resize the display', function () {
|
||||
client.set_onFBResize(sinon.spy());
|
||||
client.onfbresize = sinon.spy();
|
||||
sinon.spy(client._display, 'resize');
|
||||
send_server_init({ width: 27, height: 32 }, client);
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
var spy = client.onfbresize;
|
||||
expect(client._display.resize).to.have.been.calledOnce;
|
||||
expect(client._display.resize).to.have.been.calledWith(27, 32);
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
@@ -1559,11 +1558,11 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should handle the DesktopSize pseduo-encoding', function () {
|
||||
client.set_onFBResize(sinon.spy());
|
||||
client.onfbresize = sinon.spy();
|
||||
sinon.spy(client._display, 'resize');
|
||||
send_fbu_msg([{ x: 0, y: 0, width: 20, height: 50, encoding: -223 }], [[]], client);
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
var spy = client.onfbresize;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy).to.have.been.calledWith(sinon.match.any, 20, 50);
|
||||
|
||||
@@ -1582,7 +1581,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._fb_height = 4;
|
||||
client._display.resize(4, 4);
|
||||
sinon.spy(client._display, 'resize');
|
||||
client.set_onFBResize(sinon.spy());
|
||||
client.onfbresize = sinon.spy();
|
||||
});
|
||||
|
||||
function make_screen_data (nr_of_screens) {
|
||||
@@ -1602,10 +1601,10 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
}
|
||||
|
||||
it('should call callback when resize is supported', function () {
|
||||
client.set_onCapabilities(sinon.spy());
|
||||
client.oncapabilities = sinon.spy();
|
||||
|
||||
expect(client._supportsSetDesktopSize).to.be.false;
|
||||
expect(client.get_capabilities().resize).to.be.false;
|
||||
expect(client.capabilities.resize).to.be.false;
|
||||
|
||||
var reason_for_change = 0; // server initiated
|
||||
var status_code = 0; // No error
|
||||
@@ -1615,9 +1614,9 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
make_screen_data(1), client);
|
||||
|
||||
expect(client._supportsSetDesktopSize).to.be.true;
|
||||
expect(client.get_onCapabilities()).to.have.been.calledOnce;
|
||||
expect(client.get_onCapabilities().args[0][1].resize).to.be.true;
|
||||
expect(client.get_capabilities().resize).to.be.true;
|
||||
expect(client.oncapabilities).to.have.been.calledOnce;
|
||||
expect(client.oncapabilities.args[0][1].resize).to.be.true;
|
||||
expect(client.capabilities.resize).to.be.true;
|
||||
}),
|
||||
|
||||
it('should handle a resize requested by this client', function () {
|
||||
@@ -1634,7 +1633,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
expect(client._display.resize).to.have.been.calledOnce;
|
||||
expect(client._display.resize).to.have.been.calledWith(20, 50);
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
var spy = client.onfbresize;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy).to.have.been.calledWith(sinon.match.any, 20, 50);
|
||||
});
|
||||
@@ -1653,7 +1652,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
expect(client._display.resize).to.have.been.calledOnce;
|
||||
expect(client._display.resize).to.have.been.calledWith(20, 50);
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
var spy = client.onfbresize;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy).to.have.been.calledWith(sinon.match.any, 20, 50);
|
||||
});
|
||||
@@ -1672,7 +1671,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
expect(client._display.resize).to.have.been.calledOnce;
|
||||
expect(client._display.resize).to.have.been.calledWith(60, 50);
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
var spy = client.onfbresize;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy).to.have.been.calledWith(sinon.match.any, 60, 50);
|
||||
});
|
||||
@@ -1690,7 +1689,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
expect(client._display.resize).to.not.have.been.called;
|
||||
|
||||
var spy = client.get_onFBResize();
|
||||
var spy = client.onfbresize;
|
||||
expect(spy).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
@@ -1708,20 +1707,20 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
describe('XVP Message Handling', function () {
|
||||
it('should send a notification on XVP_FAIL', function () {
|
||||
client.set_onNotification(sinon.spy());
|
||||
client.onnotification = sinon.spy();
|
||||
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 0]));
|
||||
var spy = client.get_onNotification();
|
||||
var spy = client.onnotification;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0][1]).to.equal('XVP Operation Failed');
|
||||
});
|
||||
|
||||
it('should set the XVP version and fire the callback with the version on XVP_INIT', function () {
|
||||
client.set_onCapabilities(sinon.spy());
|
||||
client.oncapabilities = sinon.spy();
|
||||
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 1]));
|
||||
expect(client._rfb_xvp_ver).to.equal(10);
|
||||
expect(client.get_onCapabilities()).to.have.been.calledOnce;
|
||||
expect(client.get_onCapabilities().args[0][1].power).to.be.true;
|
||||
expect(client.get_capabilities().power).to.be.true;
|
||||
expect(client.oncapabilities).to.have.been.calledOnce;
|
||||
expect(client.oncapabilities.args[0][1].power).to.be.true;
|
||||
expect(client.capabilities.power).to.be.true;
|
||||
});
|
||||
|
||||
it('should fail on unknown XVP message types', function () {
|
||||
@@ -1736,18 +1735,18 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
var data = [3, 0, 0, 0];
|
||||
push32(data, expected_str.length);
|
||||
for (var i = 0; i < expected_str.length; i++) { data.push(expected_str.charCodeAt(i)); }
|
||||
client.set_onClipboard(sinon.spy());
|
||||
client.onclipboard = sinon.spy();
|
||||
|
||||
client._sock._websocket._receive_data(new Uint8Array(data));
|
||||
var spy = client.get_onClipboard();
|
||||
var spy = client.onclipboard;
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy.args[0][1]).to.equal(expected_str);
|
||||
});
|
||||
|
||||
it('should fire the bell callback on Bell', function () {
|
||||
client.set_onBell(sinon.spy());
|
||||
client.onbell = sinon.spy();
|
||||
client._sock._websocket._receive_data(new Uint8Array([2]));
|
||||
expect(client.get_onBell()).to.have.been.calledOnce;
|
||||
expect(client.onbell).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('should respond correctly to ServerFence', function () {
|
||||
@@ -1832,26 +1831,26 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
});
|
||||
|
||||
it('should not send button messages in view-only mode', function () {
|
||||
client._view_only = true;
|
||||
client._mouse._onMouseButton(0, 0, 1, 0x001);
|
||||
client._viewOnly = true;
|
||||
client._handleMouseButton(0, 0, 1, 0x001);
|
||||
expect(client._sock.flush).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should not send movement messages in view-only mode', function () {
|
||||
client._view_only = true;
|
||||
client._mouse._onMouseMove(0, 0);
|
||||
client._viewOnly = true;
|
||||
client._handleMouseMove(0, 0);
|
||||
expect(client._sock.flush).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should send a pointer event on mouse button presses', function () {
|
||||
client._mouse._onMouseButton(10, 12, 1, 0x001);
|
||||
client._handleMouseButton(10, 12, 1, 0x001);
|
||||
var pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: function () {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x001);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
});
|
||||
|
||||
it('should send a mask of 1 on mousedown', function () {
|
||||
client._mouse._onMouseButton(10, 12, 1, 0x001);
|
||||
client._handleMouseButton(10, 12, 1, 0x001);
|
||||
var pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: function () {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x001);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
@@ -1859,22 +1858,22 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
|
||||
it('should send a mask of 0 on mouseup', function () {
|
||||
client._mouse_buttonMask = 0x001;
|
||||
client._mouse._onMouseButton(10, 12, 0, 0x001);
|
||||
client._handleMouseButton(10, 12, 0, 0x001);
|
||||
var pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: function () {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x000);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
});
|
||||
|
||||
it('should send a pointer event on mouse movement', function () {
|
||||
client._mouse._onMouseMove(10, 12);
|
||||
client._handleMouseMove(10, 12);
|
||||
var pointer_msg = {_sQ: new Uint8Array(6), _sQlen: 0, flush: function () {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x000);
|
||||
expect(client._sock).to.have.sent(pointer_msg._sQ);
|
||||
});
|
||||
|
||||
it('should set the button mask so that future mouse movements use it', function () {
|
||||
client._mouse._onMouseButton(10, 12, 1, 0x010);
|
||||
client._mouse._onMouseMove(13, 9);
|
||||
client._handleMouseButton(10, 12, 1, 0x010);
|
||||
client._handleMouseMove(13, 9);
|
||||
var pointer_msg = {_sQ: new Uint8Array(12), _sQlen: 0, flush: function () {}};
|
||||
RFB.messages.pointerEvent(pointer_msg, 10, 12, 0x010);
|
||||
RFB.messages.pointerEvent(pointer_msg, 13, 9, 0x010);
|
||||
@@ -1888,19 +1887,19 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
it('should not send movement messages when viewport dragging', function () {
|
||||
client._viewportDragging = true;
|
||||
client._display.viewportChangePos = sinon.spy();
|
||||
client._mouse._onMouseMove(13, 9);
|
||||
client._handleMouseMove(13, 9);
|
||||
expect(client._sock.flush).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should not send button messages when initiating viewport dragging', function () {
|
||||
client._viewportDrag = true;
|
||||
client._mouse._onMouseButton(13, 9, 0x001);
|
||||
client._handleMouseButton(13, 9, 0x001);
|
||||
expect(client._sock.flush).to.not.have.been.called;
|
||||
});
|
||||
|
||||
it('should be initiate viewport dragging on a button down event, if enabled', function () {
|
||||
client._viewportDrag = true;
|
||||
client._mouse._onMouseButton(13, 9, 0x001);
|
||||
client._handleMouseButton(13, 9, 0x001);
|
||||
expect(client._viewportDragging).to.be.true;
|
||||
expect(client._viewportDragPos).to.deep.equal({ x: 13, y: 9 });
|
||||
});
|
||||
@@ -1908,7 +1907,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
it('should terminate viewport dragging on a button up event, if enabled', function () {
|
||||
client._viewportDrag = true;
|
||||
client._viewportDragging = true;
|
||||
client._mouse._onMouseButton(13, 9, 0x000);
|
||||
client._handleMouseButton(13, 9, 0x000);
|
||||
expect(client._viewportDragging).to.be.false;
|
||||
});
|
||||
|
||||
@@ -1924,7 +1923,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._viewportDragPos = { x: oldX, y: oldY };
|
||||
client._display.viewportChangePos = sinon.spy();
|
||||
|
||||
client._mouse._onMouseMove(newX, newY);
|
||||
client._handleMouseMove(newX, newY);
|
||||
|
||||
expect(client._viewportDragging).to.be.true;
|
||||
expect(client._viewportHasMoved).to.be.true;
|
||||
@@ -1943,20 +1942,20 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
client._sock._websocket._open();
|
||||
sinon.spy(client._sock, 'flush');
|
||||
client._rfb_connection_state = 'connected';
|
||||
client._view_only = false;
|
||||
client._viewOnly = false;
|
||||
});
|
||||
|
||||
it('should send a key message on a key press', function () {
|
||||
var keyevent = {};
|
||||
client._keyboard._onKeyEvent(0x41, 'KeyA', true);
|
||||
client._handleKeyEvent(0x41, 'KeyA', true);
|
||||
var key_msg = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
|
||||
RFB.messages.keyEvent(key_msg, 0x41, 1);
|
||||
expect(client._sock).to.have.sent(key_msg._sQ);
|
||||
});
|
||||
|
||||
it('should not send messages in view-only mode', function () {
|
||||
client._view_only = true;
|
||||
client._keyboard._onKeyEvent('a', 'KeyA', true);
|
||||
client._viewOnly = true;
|
||||
client._handleKeyEvent('a', 'KeyA', true);
|
||||
expect(client._sock.flush).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
@@ -1996,9 +1995,9 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||
it('should process all normal messages directly', function () {
|
||||
client._sock._websocket._open();
|
||||
client._rfb_connection_state = 'connected';
|
||||
client.set_onBell(sinon.spy());
|
||||
client.onbell = sinon.spy();
|
||||
client._sock._websocket._receive_data(new Uint8Array([0x02, 0x02]));
|
||||
expect(client.get_onBell()).to.have.been.calledTwice;
|
||||
expect(client.onbell).to.have.been.calledTwice;
|
||||
});
|
||||
|
||||
// open events
|
||||
|
||||
Reference in New Issue
Block a user