Avoid code duplication in RFB test preparation

This commit is contained in:
Pierre Ossman 2017-10-14 12:00:19 +02:00
parent c7d08d721f
commit 3a0010a3d0
1 changed files with 1 additions and 39 deletions

View File

@ -1242,18 +1242,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
}); });
describe('Framebuffer Update Handling', function () { describe('Framebuffer Update Handling', function () {
var client;
beforeEach(function () {
client = make_rfb();
client.connect('host', 8675);
client._sock._websocket._open();
client._rfb_connection_state = 'connected';
client._fb_name = 'some device';
client._fb_width = 640;
client._fb_height = 20;
});
var target_data_arr = [ var target_data_arr = [
0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0xff, 0x00, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
@ -1619,14 +1607,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
}); });
describe('the ExtendedDesktopSize pseudo-encoding handler', function () { describe('the ExtendedDesktopSize pseudo-encoding handler', function () {
var client;
beforeEach(function () { beforeEach(function () {
client = make_rfb();
client.connect('host', 8675);
client._sock._websocket._open();
client._rfb_connection_state = 'connected';
client._fb_name = 'some device';
client._supportsSetDesktopSize = false; client._supportsSetDesktopSize = false;
// a really small frame // a really small frame
client._fb_width = 4; client._fb_width = 4;
@ -1758,16 +1739,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
}); });
describe('XVP Message Handling', function () { describe('XVP Message Handling', function () {
beforeEach(function () {
client = make_rfb();
client.connect('host', 8675);
client._sock._websocket._open();
client._rfb_connection_state = 'connected';
client._fb_name = 'some device';
client._fb_width = 27;
client._fb_height = 32;
});
it('should send a notification on XVP_FAIL', function () { it('should send a notification on XVP_FAIL', function () {
client.set_onNotification(sinon.spy()); client.set_onNotification(sinon.spy());
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 0])); client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 0]));
@ -2026,6 +1997,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
var client; var client;
beforeEach(function () { beforeEach(function () {
client = make_rfb(); client = make_rfb();
client.connect('host', 8675);
this.clock = sinon.useFakeTimers(); this.clock = sinon.useFakeTimers();
}); });
@ -2033,7 +2005,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
// message events // message events
it ('should do nothing if we receive an empty message and have nothing in the queue', function () { it ('should do nothing if we receive an empty message and have nothing in the queue', function () {
client.connect('host', 8675);
client._rfb_connection_state = 'connected'; client._rfb_connection_state = 'connected';
client._normal_msg = sinon.spy(); client._normal_msg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([])); client._sock._websocket._receive_data(new Uint8Array([]));
@ -2041,7 +2012,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
}); });
it('should handle a message in the connected state as a normal message', function () { it('should handle a message in the connected state as a normal message', function () {
client.connect('host', 8675);
client._rfb_connection_state = 'connected'; client._rfb_connection_state = 'connected';
client._normal_msg = sinon.spy(); client._normal_msg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3])); client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
@ -2049,7 +2019,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
}); });
it('should handle a message in any non-disconnected/failed state like an init message', function () { it('should handle a message in any non-disconnected/failed state like an init message', function () {
client.connect('host', 8675);
client._rfb_init_state = 'ProtocolVersion'; client._rfb_init_state = 'ProtocolVersion';
client._init_msg = sinon.spy(); client._init_msg = sinon.spy();
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3])); client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
@ -2057,7 +2026,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
}); });
it('should process all normal messages directly', function () { it('should process all normal messages directly', function () {
client.connect('host', 8675);
client._sock._websocket._open(); client._sock._websocket._open();
client._rfb_connection_state = 'connected'; client._rfb_connection_state = 'connected';
client.set_onBell(sinon.spy()); client.set_onBell(sinon.spy());
@ -2067,14 +2035,12 @@ describe('Remote Frame Buffer Protocol Client', function() {
// open events // open events
it('should update the state to ProtocolVersion on open (if the state is "connecting")', function () { it('should update the state to ProtocolVersion on open (if the state is "connecting")', function () {
client.connect('host', 8675);
client._sock._websocket._open(); client._sock._websocket._open();
expect(client._rfb_init_state).to.equal('ProtocolVersion'); expect(client._rfb_init_state).to.equal('ProtocolVersion');
}); });
it('should fail if we are not currently ready to connect and we get an "open" event', function () { it('should fail if we are not currently ready to connect and we get an "open" event', function () {
sinon.spy(client, "_fail"); sinon.spy(client, "_fail");
client.connect('host', 8675);
client._rfb_connection_state = 'some_other_state'; client._rfb_connection_state = 'some_other_state';
client._sock._websocket._open(); client._sock._websocket._open();
expect(client._fail).to.have.been.calledOnce; expect(client._fail).to.have.been.calledOnce;
@ -2082,7 +2048,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
// close events // close events
it('should transition to "disconnected" from "disconnecting" on a close event', function () { it('should transition to "disconnected" from "disconnecting" on a close event', function () {
client.connect('host', 8675);
client._rfb_connection_state = 'disconnecting'; client._rfb_connection_state = 'disconnecting';
client._sock._websocket.close(); client._sock._websocket.close();
expect(client._rfb_connection_state).to.equal('disconnected'); expect(client._rfb_connection_state).to.equal('disconnected');
@ -2090,7 +2055,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
it('should fail if we get a close event while connecting', function () { it('should fail if we get a close event while connecting', function () {
sinon.spy(client, "_fail"); sinon.spy(client, "_fail");
client.connect('host', 8675);
client._rfb_connection_state = 'connecting'; client._rfb_connection_state = 'connecting';
client._sock._websocket.close(); client._sock._websocket.close();
expect(client._fail).to.have.been.calledOnce; expect(client._fail).to.have.been.calledOnce;
@ -2098,7 +2062,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
it('should fail if we get a close event while disconnected', function () { it('should fail if we get a close event while disconnected', function () {
sinon.spy(client, "_fail"); sinon.spy(client, "_fail");
client.connect('host', 8675);
client._rfb_connection_state = 'disconnected'; client._rfb_connection_state = 'disconnected';
client._sock._websocket.close(); client._sock._websocket.close();
expect(client._fail).to.have.been.calledOnce; expect(client._fail).to.have.been.calledOnce;
@ -2106,7 +2069,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
it('should unregister close event handler', function () { it('should unregister close event handler', function () {
sinon.spy(client._sock, 'off'); sinon.spy(client._sock, 'off');
client.connect('host', 8675);
client._rfb_connection_state = 'disconnecting'; client._rfb_connection_state = 'disconnecting';
client._sock._websocket.close(); client._sock._websocket.close();
expect(client._sock.off).to.have.been.calledWith('close'); expect(client._sock.off).to.have.been.calledWith('close');