Make ExtendedDesktopSize tests more realistic

Send real messages and avoid poking around in internals, as we weren't
testing things correctly that way.
This commit is contained in:
Pierre Ossman 2023-06-04 14:56:48 +02:00
parent 45cedea78f
commit 2a7db6f647
1 changed files with 44 additions and 16 deletions

View File

@ -814,10 +814,32 @@ describe('Remote Frame Buffer Protocol Client', function () {
let client; let client;
beforeEach(function () { beforeEach(function () {
client = makeRFB(); client = makeRFB();
client._supportsSetDesktopSize = true;
client.resizeSession = true; client.resizeSession = true;
container.style.width = '70px'; container.style.width = '70px';
container.style.height = '80px'; container.style.height = '80px';
const incoming = [ 0x00, // msg-type=FBU
0x00, // padding
0x00, 0x01, // number of rects = 1
0x00, 0x00, // reason = server initialized
0x00, 0x00, // status = no error
0x00, 0x04, // new width = 4
0x00, 0x04, // new height = 4
0xff, 0xff,
0xfe, 0xcc, // enc = (-308) ExtendedDesktopSize
0x01, // number of screens = 1
0x00, 0x00,
0x00, // padding
0x78, 0x90,
0xab, 0xcd, // screen id = 0
0x00, 0x00, // screen x = 0
0x00, 0x00, // screen y = 0
0x00, 0x04, // screen width = 4
0x00, 0x04, // screen height = 4
0x12, 0x34,
0x56, 0x78]; // screen flags
client._sock._websocket._receiveData(new Uint8Array(incoming));
sinon.spy(RFB.messages, "setDesktopSize"); sinon.spy(RFB.messages, "setDesktopSize");
}); });
@ -833,6 +855,13 @@ describe('Remote Frame Buffer Protocol Client', function () {
}); });
it('should request a resize when initially connecting', function () { it('should request a resize when initially connecting', function () {
// Create a new object that hasn't yet seen a
// ExtendedDesktopSize rect
client = makeRFB();
client.resizeSession = true;
container.style.width = '70px';
container.style.height = '80px';
// Simple ExtendedDesktopSize FBU message // Simple ExtendedDesktopSize FBU message
const incoming = [ 0x00, // msg-type=FBU const incoming = [ 0x00, // msg-type=FBU
0x00, // padding 0x00, // padding
@ -846,17 +875,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
0x01, // number of screens = 1 0x01, // number of screens = 1
0x00, 0x00, 0x00, 0x00,
0x00, // padding 0x00, // padding
0x00, 0x00, 0x78, 0x90,
0x00, 0x00, // screen id = 0 0xab, 0xcd, // screen id = 0
0x00, 0x00, // screen x = 0 0x00, 0x00, // screen x = 0
0x00, 0x00, // screen y = 0 0x00, 0x00, // screen y = 0
0x00, 0x04, // screen width = 4 0x00, 0x04, // screen width = 4
0x00, 0x04, // screen height = 4 0x00, 0x04, // screen height = 4
0x00, 0x00, 0x12, 0x34,
0x00, 0x00]; // screen flags 0x56, 0x78]; // screen flags
// This property is indirectly used as a marker for the first update
client._supportsSetDesktopSize = false;
// First message should trigger a resize // First message should trigger a resize
@ -866,7 +892,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
// not the reported size from the server // not the reported size from the server
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce; expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
expect(RFB.messages.setDesktopSize).to.have.been.calledWith( expect(RFB.messages.setDesktopSize).to.have.been.calledWith(
sinon.match.object, 70, 80, 0, 0); sinon.match.object, 70, 80, 0x7890abcd, 0x12345678);
RFB.messages.setDesktopSize.resetHistory(); RFB.messages.setDesktopSize.resetHistory();
@ -884,7 +910,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
clock.tick(1000); clock.tick(1000);
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce; expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
expect(RFB.messages.setDesktopSize).to.have.been.calledWith(sinon.match.object, 40, 50, 0, 0); expect(RFB.messages.setDesktopSize).to.have.been.calledWith(
sinon.match.object, 40, 50, 0x7890abcd, 0x12345678);
}); });
it('should not request the same size twice', function () { it('should not request the same size twice', function () {
@ -895,7 +922,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce; expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
expect(RFB.messages.setDesktopSize).to.have.been.calledWith( expect(RFB.messages.setDesktopSize).to.have.been.calledWith(
sinon.match.object, 40, 50, 0, 0); sinon.match.object, 40, 50, 0x7890abcd, 0x12345678);
// Server responds with the requested size 40x50 // Server responds with the requested size 40x50
const incoming = [ 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, const incoming = [ 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
@ -934,7 +961,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
clock.tick(200); clock.tick(200);
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce; expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
expect(RFB.messages.setDesktopSize).to.have.been.calledWith(sinon.match.object, 40, 50, 0, 0); expect(RFB.messages.setDesktopSize).to.have.been.calledWith(
sinon.match.object, 40, 50, 0x7890abcd, 0x12345678);
}); });
it('should not resize when resize is disabled', function () { it('should not resize when resize is disabled', function () {
@ -974,9 +1002,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
// Simple ExtendedDesktopSize FBU message, new size: 100x100 // Simple ExtendedDesktopSize FBU message, new size: 100x100
const incoming = [ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, const incoming = [ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x64, 0x00, 0x64, 0xff, 0xff, 0xfe, 0xcc, 0x00, 0x64, 0x00, 0x64, 0xff, 0xff, 0xfe, 0xcc,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xab, 0xab, 0xab, 0xab,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00 ]; 0x11, 0x22, 0x33, 0x44 ];
// Note that this will cause the browser to display scrollbars // Note that this will cause the browser to display scrollbars
// since the framebuffer is 100x100 and the container is 70x80. // since the framebuffer is 100x100 and the container is 70x80.
@ -996,8 +1024,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
clock.tick(1000); clock.tick(1000);
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce; expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
expect(RFB.messages.setDesktopSize.firstCall.args[1]).to.equal(120); expect(RFB.messages.setDesktopSize).to.have.been.calledWith(
expect(RFB.messages.setDesktopSize.firstCall.args[2]).to.equal(130); sinon.match.object, 120, 130, 0xabababab, 0x11223344);
}); });
}); });