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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
| 10 |
| 11 /** |
| 12 * @param {string} jid |
| 13 * @param {remoting.SignalStrategy.Type} type |
| 14 * |
| 15 * @implements {remoting.SignalStrategy} |
| 16 * @constructor |
| 17 */ |
10 remoting.MockSignalStrategy = function(jid, type) { | 18 remoting.MockSignalStrategy = function(jid, type) { |
11 this.jid_ = (jid != undefined) ? jid : "jid@example.com"; | 19 this.jid_ = (jid != undefined) ? jid : "jid@example.com"; |
12 this.type_ = (type != undefined) ? type : remoting.SignalStrategy.Type.XMPP; | 20 this.type_ = (type != undefined) ? type : remoting.SignalStrategy.Type.XMPP; |
13 this.onStateChangedCallback_ = null; | 21 this.onStateChangedCallback_ = null; |
14 this.state_ = null; | 22 |
| 23 /** @type {remoting.SignalStrategy.State} */ |
| 24 this.state_ = remoting.SignalStrategy.State.NOT_CONNECTED; |
| 25 |
15 this.onIncomingStanzaCallback_ = function() {}; | 26 this.onIncomingStanzaCallback_ = function() {}; |
16 this.dispose = sinon.spy(); | 27 this.dispose = sinon.spy(); |
17 this.connect = sinon.spy(); | 28 this.connect = sinon.spy(); |
18 this.sendMessage = sinon.spy(); | 29 this.sendMessage = sinon.spy(); |
19 this.sendConnectionSetupResults = sinon.spy(); | 30 this.sendConnectionSetupResults = sinon.spy(); |
20 }; | 31 }; |
21 | 32 |
| 33 /** |
| 34 * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback |
| 35 * Callback to call on state change. |
| 36 */ |
22 remoting.MockSignalStrategy.prototype.setStateChangedCallback = function( | 37 remoting.MockSignalStrategy.prototype.setStateChangedCallback = function( |
23 onStateChangedCallback) { | 38 onStateChangedCallback) { |
24 this.onStateChangedCallback_ = onStateChangedCallback; | 39 this.onStateChangedCallback_ = onStateChangedCallback; |
25 }; | 40 }; |
26 | 41 |
| 42 /** |
| 43 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on |
| 44 * incoming messages. |
| 45 */ |
27 remoting.MockSignalStrategy.prototype.setIncomingStanzaCallback = | 46 remoting.MockSignalStrategy.prototype.setIncomingStanzaCallback = |
28 function(onIncomingStanzaCallback) { | 47 function(onIncomingStanzaCallback) { |
29 this.onIncomingStanzaCallback_ = | 48 this.onIncomingStanzaCallback_ = |
30 onIncomingStanzaCallback ? onIncomingStanzaCallback | 49 onIncomingStanzaCallback ? onIncomingStanzaCallback |
31 : function() {}; | 50 : function() {}; |
32 }; | 51 }; |
33 | 52 |
34 remoting.MockSignalStrategy.prototype.getState = function(message) { | 53 /** @return {remoting.SignalStrategy.State} */ |
| 54 remoting.MockSignalStrategy.prototype.getState = function() { |
35 return this.state_; | 55 return this.state_; |
36 }; | 56 }; |
37 | 57 |
38 remoting.MockSignalStrategy.prototype.getError = function(message) { | 58 /** @return {remoting.Error} */ |
39 return remoting.Error.UNKNOWN; | 59 remoting.MockSignalStrategy.prototype.getError = function() { |
| 60 return remoting.Error.NONE; |
40 }; | 61 }; |
41 | 62 |
42 remoting.MockSignalStrategy.prototype.getJid = function(message) { | 63 /** @return {string} */ |
| 64 remoting.MockSignalStrategy.prototype.getJid = function() { |
43 return this.jid_; | 65 return this.jid_; |
44 }; | 66 }; |
45 | 67 |
46 remoting.MockSignalStrategy.prototype.getType = function(message) { | 68 /** @return {remoting.SignalStrategy.Type} */ |
| 69 remoting.MockSignalStrategy.prototype.getType = function() { |
47 return this.type_; | 70 return this.type_; |
48 }; | 71 }; |
49 | 72 |
| 73 /** |
| 74 * @param {remoting.SignalStrategy.State} state |
| 75 */ |
50 remoting.MockSignalStrategy.prototype.setStateForTesting = function(state) { | 76 remoting.MockSignalStrategy.prototype.setStateForTesting = function(state) { |
51 this.state_ = state; | 77 this.state_ = state; |
52 this.onStateChangedCallback_(state); | 78 this.onStateChangedCallback_(state); |
53 }; | 79 }; |
54 | |
55 remoting.MockSignalStrategy.prototype.dispose = function() { | |
56 this.state_ = remoting.SignalStrategy.State.CLOSED; | |
57 this.onStateChangedCallback_(this.state_); | |
58 }; | |
OLD | NEW |