From 4dec490aae2a8ab82f287ee2f7adc4ff6dec3447 Mon Sep 17 00:00:00 2001 From: samhed Date: Tue, 10 Feb 2015 17:06:55 +0100 Subject: [PATCH] Support automatic resize [Part 4/4]: unit tests * Added new tests for the setDesktopSize encoding * Added new tests for the ExtendedDesktopSize encoding --- tests/test.rfb.js | 158 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 2ac8a1290..444e42c46 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -195,6 +195,48 @@ describe('Remote Frame Buffer Protocol Client', function() { }); }); + describe("#setDesktopSize", function () { + beforeEach(function() { + client._sock = new Websock(); + client._sock.open('ws://', 'binary'); + client._sock._websocket._open(); + sinon.spy(client._sock, 'send'); + client._rfb_state = "normal"; + client._view_only = false; + client._supportsSetDesktopSize = true; + }); + + it('should send the request with the given width and height', function () { + var expected = [251]; + expected.push8(0); // padding + expected.push16(1); // width + expected.push16(2); // height + expected.push8(1); // number-of-screens + expected.push8(0); // padding before screen array + expected.push32(0); // id + expected.push16(0); // x-position + expected.push16(0); // y-position + expected.push16(1); // width + expected.push16(2); // height + expected.push32(0); // flags + + client.setDesktopSize(1, 2); + expect(client._sock).to.have.sent(expected); + }); + + it('should not send the request if the client has not recieved a ExtendedDesktopSize rectangle', function () { + client._supportsSetDesktopSize = false; + client.setDesktopSize(1,2); + expect(client._sock.send).to.not.have.been.called; + }); + + it('should not send the request if we are not in a normal state', function () { + client._rfb_state = "broken"; + client.setDesktopSize(1,2); + expect(client._sock.send).to.not.have.been.called; + }); + }); + describe("XVP operations", function () { beforeEach(function () { client._sock = new Websock(); @@ -1443,6 +1485,122 @@ describe('Remote Frame Buffer Protocol Client', function() { expect(client._display.resize).to.have.been.calledWith(20, 50); }); + describe('the ExtendedDesktopSize pseudo-encoding handler', function () { + var client; + + beforeEach(function () { + client = make_rfb(); + client.connect('host', 8675); + client._sock._websocket._open(); + client._rfb_state = 'normal'; + client._fb_name = 'some device'; + client._supportsSetDesktopSize = false; + // a really small frame + client._fb_width = 4; + client._fb_height = 4; + client._display._fb_width = 4; + client._display._fb_height = 4; + client._display._viewportLoc.w = 4; + client._display._viewportLoc.h = 4; + client._fb_Bpp = 4; + sinon.spy(client._display, 'resize'); + client.set_onFBResize(sinon.spy()); + }); + + function make_screen_data (nr_of_screens) { + var data = []; + data.push8(nr_of_screens); // number-of-screens + data.push8(0); // padding + data.push16(0); // padding + for (var i=0; i