]> git.proxmox.com Git - mirror_novnc.git/blobdiff - tests/test.websock.js
Move localization.js to app
[mirror_novnc.git] / tests / test.websock.js
index f708e04b0ade63f130462853e61cdcf224424965..211ab60172d441d1632a1e01bbd31d8436412025 100644 (file)
@@ -1,9 +1,12 @@
-// requires local modules: websock, util
-// requires test modules: fake.websocket, assertions
 /* jshint expr: true */
 var assert = chai.assert;
 var expect = chai.expect;
 
+import Websock from '../core/websock.js';
+import FakeWebSocket from './fake.websocket.js';
+
+import sinon from '../vendor/sinon.js';
+
 describe('Websock', function() {
     "use strict";
 
@@ -170,8 +173,7 @@ describe('Websock', function() {
                 };
             });
 
-            it('should actually send on the websocket if the websocket does not have too much buffered', function () {
-                sock.maxBufferedAmount = 10;
+            it('should actually send on the websocket', function () {
                 sock._websocket.bufferedAmount = 8;
                 sock._websocket.readyState = WebSocket.OPEN
                 sock._sQ = new Uint8Array([1, 2, 3]);
@@ -183,30 +185,14 @@ describe('Websock', function() {
                 expect(sock._websocket.send).to.have.been.calledWith(encoded);
             });
 
-            it('should return true if the websocket did not have too much buffered', function () {
-                sock.maxBufferedAmount = 10;
-                sock._websocket.bufferedAmount = 8;
-
-                expect(sock.flush()).to.be.true;
-            });
-
             it('should not call send if we do not have anything queued up', function () {
                 sock._sQlen = 0;
-                sock.maxBufferedAmount = 10;
                 sock._websocket.bufferedAmount = 8;
 
                 sock.flush();
 
                 expect(sock._websocket.send).not.to.have.been.called;
             });
-
-            it('should not send and return false if the websocket has too much buffered', function () {
-                sock.maxBufferedAmount = 10;
-                sock._websocket.bufferedAmount = 12;
-
-                expect(sock.flush()).to.be.false;
-                expect(sock._websocket.send).to.not.have.been.called;
-            });
         });
 
         describe('send', function () {
@@ -266,10 +252,6 @@ describe('Websock', function() {
                 expect(WebSocket).to.have.been.calledWith('ws://localhost:8675', 'binary');
             });
 
-            it('should fail if we specify a protocol besides binary', function () {
-                expect(function () { sock.open('ws:///', 'base64'); }).to.throw(Error);
-            });
-
             // it('should initialize the event handlers')?
         });
 
@@ -329,17 +311,6 @@ describe('Websock', function() {
                 expect(sock._recv_message).to.have.been.calledOnce;
             });
 
-            it('should fail if a protocol besides binary is requested', function () {
-                sock._websocket.protocol = 'base64';
-                expect(sock._websocket.onopen).to.throw(Error);
-            });
-
-            it('should assume binary if no protocol was available on opening', function () {
-                sock._websocket.protocol = null;
-                sock._websocket.onopen();
-                expect(sock._mode).to.equal('binary');
-            });
-
             it('should call the open event handler on opening', function () {
                 sock._websocket.onopen();
                 expect(sock._eventHandlers.open).to.have.been.calledOnce;
@@ -418,15 +389,6 @@ describe('Websock', function() {
             expect(sock.get_rQi()).to.equal(0);
             expect(sock._rQ.length).to.equal(240);  // keep the invariant that rQbufferSize / 8 >= rQlen
         });
-
-        it('should call the error event handler on an exception', function () {
-            sock._eventHandlers.error = sinon.spy();
-            sock._eventHandlers.message = sinon.stub().throws();
-            var msg = { data: new Uint8Array([1, 2, 3]).buffer };
-            sock._mode = 'binary';
-            sock._recv_message(msg);
-            expect(sock._eventHandlers.error).to.have.been.calledOnce;
-        });
     });
 
     describe('Data encoding', function () {