]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Add unit tests for connect/attach errors
authorPierre Ossman <ossman@cendio.se>
Sun, 18 Apr 2021 09:07:43 +0000 (11:07 +0200)
committerPierre Ossman <ossman@cendio.se>
Sun, 18 Apr 2021 12:25:59 +0000 (14:25 +0200)
tests/test.rfb.js

index c50379d85ae04a8cbe595d0952b92fc2c9676e67..5a1b7131fdcb513814438f06aa75e1c995bb6b22 100644 (file)
@@ -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 () {