]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Add unit tests for passing WebSocket objects
authorPierre Ossman <ossman@cendio.se>
Fri, 16 Apr 2021 14:47:56 +0000 (16:47 +0200)
committerPierre Ossman <ossman@cendio.se>
Sun, 18 Apr 2021 12:25:03 +0000 (14:25 +0200)
tests/test.rfb.js
tests/test.websock.js

index 21f2f7a4b7bed4c695a11372dfc6ef07e5f402f6..c50379d85ae04a8cbe595d0952b92fc2c9676e67 100644 (file)
@@ -141,12 +141,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
 
     describe('Connecting/Disconnecting', function () {
         describe('#RFB (constructor)', function () {
-            let open;
+            let open, attach;
             beforeEach(function () {
                 open = sinon.spy(Websock.prototype, 'open');
+                attach = sinon.spy(Websock.prototype, 'attach');
             });
             afterEach(function () {
                 open.restore();
+                attach.restore();
             });
 
             it('should not connect from constructor', function () {
@@ -160,6 +162,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
                 this.clock.tick();
                 expect(open).to.have.been.calledOnceWithExactly('ws://HOST:8675/PATH', []);
             });
+
+            it('should handle WebSocket/RTCDataChannel objects', function () {
+                let sock = new FakeWebSocket('ws://HOST:8675/PATH', []);
+                new RFB(document.createElement('div'), sock);
+                this.clock.tick();
+                expect(open).to.not.have.been.called;
+                expect(attach).to.have.been.calledOnceWithExactly(sock);
+            });
         });
 
         describe('#disconnect', function () {
index 6f35ec35ec46ebe386045862f24bdff092bc6475..196a3003d8543df1422cffb68fdae096cb122e0b 100644 (file)
@@ -270,6 +270,27 @@ describe('Websock', function () {
             // it('should initialize the event handlers')?
         });
 
+        describe('attaching', function () {
+            it('should attach to an existing open websocket', function () {
+                let ws = new FakeWebSocket('ws://localhost:8675');
+                ws._open();
+                let callback = sinon.spy();
+                sock.on('open', callback);
+                sock.attach(ws);
+                expect(WebSocket).to.not.have.been.called;
+                expect(callback).to.have.been.calledOnce;
+            });
+
+            it('should attach to an existing connecting websocket', function () {
+                let ws = new FakeWebSocket('ws://localhost:8675');
+                let callback = sinon.spy();
+                sock.on('open', callback);
+                sock.attach(ws);
+                expect(WebSocket).to.not.have.been.called;
+                expect(callback).to.not.have.been.called;
+            });
+        });
+
         describe('closing', function () {
             beforeEach(function () {
                 sock.open('ws://localhost');