Update failing WebChannel tests, 6 RFB tests still failing
This commit is contained in:
parent
fc8518c057
commit
5837888fca
|
|
@ -1,7 +1,7 @@
|
||||||
import Base64 from '../core/base64.js';
|
import Base64 from '../core/base64.js';
|
||||||
|
|
||||||
// PhantomJS can't create Event objects directly, so we need to use this
|
// PhantomJS can't create Event objects directly, so we need to use this
|
||||||
function make_event(name, props) {
|
export function make_event(name, props) {
|
||||||
const evt = document.createEvent('Event');
|
const evt = document.createEvent('Event');
|
||||||
evt.initEvent(name, true, true);
|
evt.initEvent(name, true, true);
|
||||||
if (props) {
|
if (props) {
|
||||||
|
|
@ -30,6 +30,7 @@ export default class FakeWebSocket {
|
||||||
this.bufferedAmount = 0;
|
this.bufferedAmount = 0;
|
||||||
|
|
||||||
this.__is_fake = true;
|
this.__is_fake = true;
|
||||||
|
this.__listeners = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
close(code, reason) {
|
close(code, reason) {
|
||||||
|
|
@ -49,6 +50,19 @@ export default class FakeWebSocket {
|
||||||
this.bufferedAmount += data.length;
|
this.bufferedAmount += data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addEventListener(type, listener, options) {
|
||||||
|
this.__listeners.push({type, handler: listener, options});
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatchEvent(evt) {
|
||||||
|
for (let i = 0; i < this.__listeners.length; i++) {
|
||||||
|
let listener = this.__listeners[i];
|
||||||
|
if (evt.type === listener.type) {
|
||||||
|
listener.handler(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_get_sent_data() {
|
_get_sent_data() {
|
||||||
const res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
|
const res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
|
||||||
this.bufferedAmount = 0;
|
this.bufferedAmount = 0;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
|
|
||||||
import WebChannel from '../core/websock.js';
|
import WebChannel from '../core/websock.js';
|
||||||
import FakeWebSocket from './fake.websocket.js';
|
import FakeWebSocket, { make_event } from './fake.websocket.js';
|
||||||
|
|
||||||
describe('WebChannel', function () {
|
describe('WebChannel', function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
@ -259,6 +259,19 @@ describe('WebChannel', function () {
|
||||||
WebSocket.CONNECTING = old_WS.CONNECTING;
|
WebSocket.CONNECTING = old_WS.CONNECTING;
|
||||||
WebSocket.CLOSING = old_WS.CLOSING;
|
WebSocket.CLOSING = old_WS.CLOSING;
|
||||||
WebSocket.CLOSED = old_WS.CLOSED;
|
WebSocket.CLOSED = old_WS.CLOSED;
|
||||||
|
WebSocket.__listeners = [];
|
||||||
|
WebSocket.prototype.addEventListener = (type, listener, options) => {
|
||||||
|
WebSocket.__listeners.push({type, handler: listener, options});
|
||||||
|
};
|
||||||
|
|
||||||
|
WebSocket.prototype.dispatchEvent = (evt) => {
|
||||||
|
for (let i = 0; i < WebSocket.__listeners.length; i++) {
|
||||||
|
let listener = WebSocket.__listeners[i];
|
||||||
|
if (evt.type === listener.type) {
|
||||||
|
listener.handler(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
WebSocket.prototype.binaryType = 'arraybuffer';
|
WebSocket.prototype.binaryType = 'arraybuffer';
|
||||||
});
|
});
|
||||||
|
|
@ -338,7 +351,7 @@ describe('WebChannel', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the close event handler on closing', function () {
|
it('should call the close event handler on closing', function () {
|
||||||
sock._rawChannel.onclose();
|
sock._rawChannel.dispatchEvent(make_event('close'));
|
||||||
expect(sock._eventHandlers.close).to.have.been.calledOnce;
|
expect(sock._eventHandlers.close).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue