This commit is contained in:
Jussi Saurio 2018-04-12 22:09:44 +00:00 committed by GitHub
commit 6ec924878b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -312,6 +312,9 @@ RFB.prototype = {
}
},
get connectionState() { return this._rfb_connection_state; },
set connectionState(val) { Log.Error("Cannot assign value " + val + " to get-only property connectionState"); },
// ===== PUBLIC METHODS =====
disconnect: function () {
@ -646,6 +649,8 @@ RFB.prototype = {
switch (state) {
case 'connecting':
var event = new CustomEvent("connecting", { detail: {} });
this.dispatchEvent(event);
this._connect();
break;

View File

@ -823,6 +823,23 @@ describe('Remote Frame Buffer Protocol Client', function() {
this.clock.tick();
expect(client._sock.open).to.have.been.calledOnce;
});
it('should result in a connecting event if state is updated to connecting through the correct function', function () {
var client = make_rfb();
var spy = sinon.spy();
client.addEventListener("connecting", spy);
client._rfb_connection_state = '';
client._updateConnectionState('connecting');
expect(spy).to.have.been.calledOnce;
});
it('should not result in a connecting event if state is updated to connecting via direct assignment', function () {
var client = make_rfb();
var spy = sinon.spy();
client.addEventListener("connecting", spy);
client._rfb_connection_state = 'connecting';
expect(spy).to.not.have.been.called;
});
});
describe('connected', function () {
@ -912,6 +929,27 @@ describe('Remote Frame Buffer Protocol Client', function() {
expect(spy.args[0].length).to.equal(1);
});
});
describe('connectionState getter', function () {
var client;
beforeEach(function () {
client = new RFB(document.createElement('div'), 'ws://HOST:8675/PATH');
});
it('should get the internal connection state', function () {
client._rfb_connection_state = 'connecting';
client._updateConnectionState('connected');
var state = client.connectionState;
expect(state).to.equal('connected');
});
it('should disallow manually changing the state', function () {
client._rfb_connection_state = 'connecting';
client.connectionState = 'connected';
var state = client.connectionState;
expect(state).to.equal('connecting');
});
});
});
describe('Protocol Initialization States', function () {