summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2021-04-16 16:47:56 +0200
committerPierre Ossman <ossman@cendio.se>2021-04-18 14:25:03 +0200
commitae3c01f782ca998456fef994504e58ec81a8ebc1 (patch)
treea248b629d86997ee41d6e7acd77977b9c1d5f580
parentf0e4908dec36659212b376e5898e0e5811fd0628 (diff)
downloadnovnc-ae3c01f782ca998456fef994504e58ec81a8ebc1.tar.gz
Add unit tests for passing WebSocket objects
-rw-r--r--tests/test.rfb.js12
-rw-r--r--tests/test.websock.js21
2 files changed, 32 insertions, 1 deletions
diff --git a/tests/test.rfb.js b/tests/test.rfb.js
index 21f2f7a..c50379d 100644
--- a/tests/test.rfb.js
+++ b/tests/test.rfb.js
@@ -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 () {
diff --git a/tests/test.websock.js b/tests/test.websock.js
index 6f35ec3..196a300 100644
--- a/tests/test.websock.js
+++ b/tests/test.websock.js
@@ -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');