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
3 // found in the LICENSE file.
7 /** @suppress {duplicate} */
8 var remoting
= remoting
|| {};
12 * @param {string=} jid
13 * @param {remoting.SignalStrategy.Type=} type
15 * @implements {remoting.SignalStrategy}
18 remoting
.MockSignalStrategy = function(jid
, type
) {
19 this.jid_
= (jid
!= undefined) ? jid
: "jid@example.com";
20 this.type_
= (type
!= undefined) ? type
: remoting
.SignalStrategy
.Type
.XMPP
;
21 this.onStateChangedCallback_
= null;
23 /** @type {remoting.SignalStrategy.State} */
24 this.state_
= remoting
.SignalStrategy
.State
.NOT_CONNECTED
;
26 /** @type {!remoting.Error} */
27 this.error_
= remoting
.Error
.none();
29 this.onIncomingStanzaCallback_ = function() {};
33 remoting
.MockSignalStrategy
.prototype.dispose = function() {
37 remoting
.MockSignalStrategy
.prototype.connect = function() {
39 Promise
.resolve().then(function() {
40 that
.setStateForTesting(remoting
.SignalStrategy
.State
.CONNECTED
);
45 remoting
.MockSignalStrategy
.prototype.sendMessage = function() {
49 * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback
50 * Callback to call on state change.
52 remoting
.MockSignalStrategy
.prototype.setStateChangedCallback = function(
53 onStateChangedCallback
) {
54 this.onStateChangedCallback_
= onStateChangedCallback
;
58 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on
61 remoting
.MockSignalStrategy
.prototype.setIncomingStanzaCallback
=
62 function(onIncomingStanzaCallback
) {
63 this.onIncomingStanzaCallback_
=
64 onIncomingStanzaCallback
? onIncomingStanzaCallback
68 /** @param {Element} stanza */
69 remoting
.MockSignalStrategy
.prototype.mock
$onIncomingStanza = function(stanza
) {
70 this.onIncomingStanzaCallback_(stanza
);
73 /** @return {remoting.SignalStrategy.State} */
74 remoting
.MockSignalStrategy
.prototype.getState = function() {
78 /** @return {!remoting.Error} */
79 remoting
.MockSignalStrategy
.prototype.getError = function() {
83 /** @return {string} */
84 remoting
.MockSignalStrategy
.prototype.getJid = function() {
88 /** @return {remoting.SignalStrategy.Type} */
89 remoting
.MockSignalStrategy
.prototype.getType = function() {
94 * @param {remoting.SignalStrategy.State} state
96 remoting
.MockSignalStrategy
.prototype.setStateForTesting = function(state
) {
98 if (state
== remoting
.SignalStrategy
.State
.FAILED
) {
99 this.error_
= remoting
.Error
.unexpected('setStateForTesting');
101 this.error_
= remoting
.Error
.none();
103 this.onStateChangedCallback_(state
);