Modify unit tests to work with ResizeObserver
This commit is contained in:
parent
a9c2ff30b6
commit
375f36c575
|
@ -71,6 +71,18 @@ function deflateWithSize(data) {
|
||||||
describe('Remote Frame Buffer Protocol Client', function () {
|
describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
let clock;
|
let clock;
|
||||||
let raf;
|
let raf;
|
||||||
|
let fakeResizeObserver = null;
|
||||||
|
const realObserver = window.ResizeObserver;
|
||||||
|
|
||||||
|
class FakeResizeObserver {
|
||||||
|
constructor(handler) {
|
||||||
|
this.fire = handler;
|
||||||
|
fakeResizeObserver = this;
|
||||||
|
}
|
||||||
|
disconnect() {}
|
||||||
|
observe(target, options) {}
|
||||||
|
unobserve(target) {}
|
||||||
|
}
|
||||||
|
|
||||||
before(FakeWebSocket.replace);
|
before(FakeWebSocket.replace);
|
||||||
after(FakeWebSocket.restore);
|
after(FakeWebSocket.restore);
|
||||||
|
@ -80,6 +92,9 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
// sinon doesn't support this yet
|
// sinon doesn't support this yet
|
||||||
raf = window.requestAnimationFrame;
|
raf = window.requestAnimationFrame;
|
||||||
window.requestAnimationFrame = setTimeout;
|
window.requestAnimationFrame = setTimeout;
|
||||||
|
// We must do this in a 'before' since it needs to be set before
|
||||||
|
// the RFB constructor, which runs in beforeEach further down
|
||||||
|
window.ResizeObserver = FakeResizeObserver;
|
||||||
// Use a single set of buffers instead of reallocating to
|
// Use a single set of buffers instead of reallocating to
|
||||||
// speed up tests
|
// speed up tests
|
||||||
const sock = new Websock();
|
const sock = new Websock();
|
||||||
|
@ -100,6 +115,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
delete Websock.prototype.toString;
|
delete Websock.prototype.toString;
|
||||||
this.clock.restore();
|
this.clock.restore();
|
||||||
window.requestAnimationFrame = raf;
|
window.requestAnimationFrame = raf;
|
||||||
|
window.ResizeObserver = realObserver;
|
||||||
});
|
});
|
||||||
|
|
||||||
let container;
|
let container;
|
||||||
|
@ -470,6 +486,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
describe('Clipping', function () {
|
describe('Clipping', function () {
|
||||||
let client;
|
let client;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
client = makeRFB();
|
client = makeRFB();
|
||||||
container.style.width = '70px';
|
container.style.width = '70px';
|
||||||
|
@ -495,8 +512,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
container.style.width = '40px';
|
container.style.width = '40px';
|
||||||
container.style.height = '50px';
|
container.style.height = '50px';
|
||||||
const event = new UIEvent('resize');
|
fakeResizeObserver.fire();
|
||||||
window.dispatchEvent(event);
|
|
||||||
clock.tick();
|
clock.tick();
|
||||||
|
|
||||||
expect(client._display.viewportChangeSize).to.have.been.calledOnce;
|
expect(client._display.viewportChangeSize).to.have.been.calledOnce;
|
||||||
|
@ -692,8 +708,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
container.style.width = '40px';
|
container.style.width = '40px';
|
||||||
container.style.height = '50px';
|
container.style.height = '50px';
|
||||||
const event = new UIEvent('resize');
|
fakeResizeObserver.fire();
|
||||||
window.dispatchEvent(event);
|
|
||||||
clock.tick();
|
clock.tick();
|
||||||
|
|
||||||
expect(client._display.autoscale).to.have.been.calledOnce;
|
expect(client._display.autoscale).to.have.been.calledOnce;
|
||||||
|
@ -782,8 +797,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should request a resize when the container resizes', function () {
|
it('should request a resize when the container resizes', function () {
|
||||||
container.style.width = '40px';
|
container.style.width = '40px';
|
||||||
container.style.height = '50px';
|
container.style.height = '50px';
|
||||||
const event = new UIEvent('resize');
|
fakeResizeObserver.fire();
|
||||||
window.dispatchEvent(event);
|
|
||||||
clock.tick(1000);
|
clock.tick(1000);
|
||||||
|
|
||||||
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
|
expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
|
||||||
|
@ -793,16 +807,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
it('should not resize until the container size is stable', function () {
|
it('should not resize until the container size is stable', function () {
|
||||||
container.style.width = '20px';
|
container.style.width = '20px';
|
||||||
container.style.height = '30px';
|
container.style.height = '30px';
|
||||||
const event1 = new UIEvent('resize');
|
fakeResizeObserver.fire();
|
||||||
window.dispatchEvent(event1);
|
|
||||||
clock.tick(400);
|
clock.tick(400);
|
||||||
|
|
||||||
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
|
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
|
||||||
|
|
||||||
container.style.width = '40px';
|
container.style.width = '40px';
|
||||||
container.style.height = '50px';
|
container.style.height = '50px';
|
||||||
const event2 = new UIEvent('resize');
|
fakeResizeObserver.fire();
|
||||||
window.dispatchEvent(event2);
|
|
||||||
clock.tick(400);
|
clock.tick(400);
|
||||||
|
|
||||||
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
|
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
|
||||||
|
|
Loading…
Reference in New Issue