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 remoting.MockSignalStrategy.prototype.sendConnectionSetupResults = function() {
53 * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback
54 * Callback to call on state change.
56 remoting.MockSignalStrategy.prototype.setStateChangedCallback = function(
57 onStateChangedCallback) {
58 this.onStateChangedCallback_ = onStateChangedCallback;
62 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on
65 remoting.MockSignalStrategy.prototype.setIncomingStanzaCallback =
66 function(onIncomingStanzaCallback) {
67 this.onIncomingStanzaCallback_ =
68 onIncomingStanzaCallback ? onIncomingStanzaCallback
72 /** @param {Element} stanza */
73 remoting.MockSignalStrategy.prototype.mock$onIncomingStanza = function(stanza) {
74 this.onIncomingStanzaCallback_(stanza);
77 /** @return {remoting.SignalStrategy.State} */
78 remoting.MockSignalStrategy.prototype.getState = function() {
82 /** @return {!remoting.Error} */
83 remoting.MockSignalStrategy.prototype.getError = function() {
87 /** @return {string} */
88 remoting.MockSignalStrategy.prototype.getJid = function() {
92 /** @return {remoting.SignalStrategy.Type} */
93 remoting.MockSignalStrategy.prototype.getType = function() {
98 * @param {remoting.SignalStrategy.State} state
100 remoting.MockSignalStrategy.prototype.setStateForTesting = function(state) {
102 if (state == remoting.SignalStrategy.State.FAILED) {
103 this.error_ = remoting.Error.unexpected('setStateForTesting');
105 this.error_ = remoting.Error.none();
107 this.onStateChangedCallback_(state);