Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / remoting / webapp / crd / js / mock_signal_strategy.js
blob8fee7ad8deed4503d1784766501df7ccf08318a0
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.
5 'use strict';
7 /** @suppress {duplicate} */
8 var remoting = remoting || {};
11 /**
12  * @param {string=} jid
13  * @param {remoting.SignalStrategy.Type=} type
14  *
15  * @implements {remoting.SignalStrategy}
16  * @constructor
17  */
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() {};
32 /** @override */
33 remoting.MockSignalStrategy.prototype.dispose = function() {
36 /** @override */
37 remoting.MockSignalStrategy.prototype.connect = function() {
38   var that = this;
39   Promise.resolve().then(function() {
40     that.setStateForTesting(remoting.SignalStrategy.State.CONNECTED);
41   });
44 /** @override */
45 remoting.MockSignalStrategy.prototype.sendMessage = function() {
48 /** @override */
49 remoting.MockSignalStrategy.prototype.sendConnectionSetupResults = function() {
52 /**
53  * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback
54  *   Callback to call on state change.
55  */
56 remoting.MockSignalStrategy.prototype.setStateChangedCallback = function(
57     onStateChangedCallback) {
58   this.onStateChangedCallback_ = onStateChangedCallback;
61 /**
62  * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on
63  *     incoming messages.
64  */
65 remoting.MockSignalStrategy.prototype.setIncomingStanzaCallback =
66     function(onIncomingStanzaCallback) {
67   this.onIncomingStanzaCallback_ =
68       onIncomingStanzaCallback ? onIncomingStanzaCallback
69                                : function() {};
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() {
79   return this.state_;
82 /** @return {!remoting.Error} */
83 remoting.MockSignalStrategy.prototype.getError = function() {
84   return this.error_;
87 /** @return {string} */
88 remoting.MockSignalStrategy.prototype.getJid = function() {
89   return this.jid_;
92 /** @return {remoting.SignalStrategy.Type} */
93 remoting.MockSignalStrategy.prototype.getType = function() {
94   return this.type_;
97 /**
98  * @param {remoting.SignalStrategy.State} state
99  */
100 remoting.MockSignalStrategy.prototype.setStateForTesting = function(state) {
101   this.state_ = state;
102   if (state == remoting.SignalStrategy.State.FAILED) {
103     this.error_ = remoting.Error.unexpected('setStateForTesting');
104   } else {
105     this.error_ = remoting.Error.none();
106   }
107   this.onStateChangedCallback_(state);