Send keyboard events from single place

This makes it easier to handle any needed variations, like different
types of messages.
This commit is contained in:
Pierre Ossman
2017-01-26 17:59:25 +01:00
parent f714f7deae
commit 94f5cf05f3
3 changed files with 51 additions and 36 deletions
+14 -4
View File
@@ -193,7 +193,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
it('should send a single key with the given code and state (down = true)', function () {
var expected = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
RFB.messages.keyEvent(expected, 123, 1);
client.sendKey(123, true);
client.sendKey(123, 'Key123', true);
expect(client._sock).to.have.sent(expected._sQ);
});
@@ -201,21 +201,29 @@ describe('Remote Frame Buffer Protocol Client', function() {
var expected = {_sQ: new Uint8Array(16), _sQlen: 0, flush: function () {}};
RFB.messages.keyEvent(expected, 123, 1);
RFB.messages.keyEvent(expected, 123, 0);
client.sendKey(123);
client.sendKey(123, 'Key123');
expect(client._sock).to.have.sent(expected._sQ);
});
it('should not send the key if we are not in a normal state', function () {
client._rfb_connection_state = "broken";
client.sendKey(123);
client.sendKey(123, 'Key123');
expect(client._sock.flush).to.not.have.been.called;
});
it('should not send the key if we are set as view_only', function () {
client._view_only = true;
client.sendKey(123);
client.sendKey(123, 'Key123');
expect(client._sock.flush).to.not.have.been.called;
});
it('should send QEMU extended events if supported', function () {
client._qemuExtKeyEventSupported = true;
var expected = {_sQ: new Uint8Array(12), _sQlen: 0, flush: function () {}};
RFB.messages.QEMUExtendedKeyEvent(expected, 0x20, true, 0x0039);
client.sendKey(0x20, 'Space', true);
expect(client._sock).to.have.sent(expected._sQ);
});
});
describe('#clipboardPasteFrom', function () {
@@ -2012,6 +2020,8 @@ describe('Remote Frame Buffer Protocol Client', function() {
client._sock.open('ws://', 'binary');
client._sock._websocket._open();
sinon.spy(client._sock, 'flush');
client._rfb_connection_state = 'connected';
client._view_only = false;
});
it('should send a key message on a key press', function () {