summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2021-04-18 11:07:43 +0200
committerPierre Ossman <ossman@cendio.se>2021-04-18 14:25:59 +0200
commit42100e82333e32fffbae8b1b0027b2a95a4897c9 (patch)
tree2d47804313ae0e3b98dc7aaea7cb580fbd783b0f
parentae3c01f782ca998456fef994504e58ec81a8ebc1 (diff)
downloadnovnc-42100e82333e32fffbae8b1b0027b2a95a4897c9.tar.gz
Add unit tests for connect/attach errors
-rw-r--r--tests/test.rfb.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/test.rfb.js b/tests/test.rfb.js
index c50379d..5a1b713 100644
--- a/tests/test.rfb.js
+++ b/tests/test.rfb.js
@@ -163,6 +163,18 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(open).to.have.been.calledOnceWithExactly('ws://HOST:8675/PATH', []);
});
+ it('should report connection problems via event', function () {
+ open.restore();
+ open = sinon.stub(Websock.prototype, 'open');
+ open.throws(Error('Failure'));
+ const client = new RFB(document.createElement('div'), 'ws://HOST:8675/PATH');
+ let callback = sinon.spy();
+ client.addEventListener('disconnect', callback);
+ this.clock.tick();
+ expect(callback).to.have.been.calledOnce;
+ expect(callback.args[0][0].detail.clean).to.be.false;
+ });
+
it('should handle WebSocket/RTCDataChannel objects', function () {
let sock = new FakeWebSocket('ws://HOST:8675/PATH', []);
new RFB(document.createElement('div'), sock);
@@ -170,6 +182,19 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(open).to.not.have.been.called;
expect(attach).to.have.been.calledOnceWithExactly(sock);
});
+
+ it('should report attach problems via event', function () {
+ attach.restore();
+ attach = sinon.stub(Websock.prototype, 'attach');
+ attach.throws(Error('Failure'));
+ let sock = new FakeWebSocket('ws://HOST:8675/PATH', []);
+ const client = new RFB(document.createElement('div'), sock);
+ let callback = sinon.spy();
+ client.addEventListener('disconnect', callback);
+ this.clock.tick();
+ expect(callback).to.have.been.calledOnce;
+ expect(callback.args[0][0].detail.clean).to.be.false;
+ });
});
describe('#disconnect', function () {