OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function() { | 5 (function() { |
6 | 6 |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 /** @type {remoting.MockConnection} */ | 9 /** @type {remoting.MockConnection} */ |
10 var mockConnection; | 10 var mockConnection; |
11 /** @type {remoting.ClientSession} */ | 11 /** @type {remoting.ClientSession} */ |
12 var session; | 12 var session; |
13 /** @type {remoting.ClientSession.EventHandler} */ | 13 /** @type {remoting.ClientSession.EventHandler} */ |
14 var listener; | 14 var listener; |
15 /** @type {sinon.TestStub} */ | 15 /** @type {sinon.TestStub} */ |
16 var logToServerStub; | 16 var logToServerStub; |
17 /** | 17 /** |
18 * @constructor | 18 * @constructor |
19 * @implements {remoting.ClientSession.EventHandler} | 19 * @implements {remoting.ClientSession.EventHandler} |
20 */ | 20 */ |
21 var SessionListener = function() {}; | 21 var SessionListener = function() {}; |
22 SessionListener.prototype.onConnectionFailed = function(error) {}; | 22 SessionListener.prototype.onConnectionFailed = function(error) {}; |
23 SessionListener.prototype.onConnected = function(connectionInfo) {}; | 23 SessionListener.prototype.onConnected = function(connectionInfo) {}; |
24 SessionListener.prototype.onDisconnected = function() {}; | 24 SessionListener.prototype.onDisconnected = function(error) {}; |
25 SessionListener.prototype.onError = function(error) {}; | |
26 | 25 |
27 /** @return {Promise} */ | 26 /** @return {Promise} */ |
28 function connect() { | 27 function connect() { |
29 var deferred = new base.Deferred(); | 28 var deferred = new base.Deferred(); |
30 var host = new remoting.Host('hostId'); | 29 var host = new remoting.Host('hostId'); |
31 host.jabberId = 'jid'; | 30 host.jabberId = 'jid'; |
32 | 31 |
33 session.connect(host, new remoting.CredentialsProvider({ | 32 session.connect(host, new remoting.CredentialsProvider({ |
34 pairingInfo: { clientId: 'clientId', sharedSecret: 'secret' } | 33 pairingInfo: { clientId: 'clientId', sharedSecret: 'secret' } |
35 })); | 34 })); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 var onDisconnected = sinon.stub(listener, 'onDisconnected'); | 120 var onDisconnected = sinon.stub(listener, 'onDisconnected'); |
122 session.disconnect(remoting.Error.none()); | 121 session.disconnect(remoting.Error.none()); |
123 assert.equal(onDisconnected.callCount, 1); | 122 assert.equal(onDisconnected.callCount, 1); |
124 }); | 123 }); |
125 }); | 124 }); |
126 | 125 |
127 QUnit.test( | 126 QUnit.test( |
128 'Connection error after CONNECTED should raise the CONNECTION_DROPPED event', | 127 'Connection error after CONNECTED should raise the CONNECTION_DROPPED event', |
129 function(assert) { | 128 function(assert) { |
130 return connect().then(function() { | 129 return connect().then(function() { |
131 var onError = sinon.stub(listener, 'onError'); | 130 var onDisconnected = sinon.stub(listener, 'onDisconnected'); |
132 session.disconnect(new remoting.Error(remoting.Error.Tag.P2P_FAILURE)); | 131 session.disconnect(new remoting.Error(remoting.Error.Tag.P2P_FAILURE)); |
133 assert.equal(onError.callCount, 1); | 132 assert.equal(onDisconnected.callCount, 1); |
134 assert.equal(logToServerStub.args[2][0], | 133 assert.equal(logToServerStub.args[2][0], |
135 remoting.ClientSession.State.CONNECTION_DROPPED); | 134 remoting.ClientSession.State.CONNECTION_DROPPED); |
136 }); | 135 }); |
137 }); | 136 }); |
138 | 137 |
139 QUnit.test( | 138 QUnit.test( |
140 'Connection error before CONNECTED should raise the CONNECTION_FAILED event', | 139 'Connection error before CONNECTED should raise the CONNECTION_FAILED event', |
141 function(assert) { | 140 function(assert) { |
142 | 141 |
143 session.logHostOfflineErrors(true); | 142 session.logHostOfflineErrors(true); |
(...skipping 14 matching lines...) Expand all Loading... |
158 }); | 157 }); |
159 }); | 158 }); |
160 | 159 |
161 QUnit.test('dispose() should dispose the plugin', function(assert) { | 160 QUnit.test('dispose() should dispose the plugin', function(assert) { |
162 var pluginDispose = sinon.stub(mockConnection.plugin(), 'dispose'); | 161 var pluginDispose = sinon.stub(mockConnection.plugin(), 'dispose'); |
163 session.dispose(); | 162 session.dispose(); |
164 assert.equal(pluginDispose.callCount, 1); | 163 assert.equal(pluginDispose.callCount, 1); |
165 }); | 164 }); |
166 | 165 |
167 })(); | 166 })(); |
OLD | NEW |