1// Copyright 2014 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.
4
5/**
6 * @fileoverview
7 * Mock implementation of ClientPlugin for testing.
8 * @suppress {checkTypes}
9 */
10
11'use strict';
12
13/** @suppress {duplicate} */
14var remoting = remoting || {};
15
16/**
17 * @constructor
18 * @implements {remoting.ClientPlugin}
19 */
20remoting.MockClientPlugin = function(container) {
21  this.container_ = container;
22  this.element_ = document.createElement('div');
23  this.element_.style.backgroundImage = 'linear-gradient(45deg, blue, red)';
24  this.width_ = 640;
25  this.height_ = 480;
26  this.connectionStatusUpdateHandler_ = null;
27  this.desktopSizeUpdateHandler_ = null;
28  this.container_.appendChild(this.element_);
29};
30
31remoting.MockClientPlugin.prototype.dispose = function() {
32  this.container_.removeChild(this.element_);
33  this.element_ = null;
34  this.connectionStatusUpdateHandler_ = null;
35};
36
37remoting.MockClientPlugin.prototype.getDesktopWidth = function() {
38  return this.width_;
39};
40
41remoting.MockClientPlugin.prototype.getDesktopHeight = function() {
42  return this.height_;
43};
44
45remoting.MockClientPlugin.prototype.getDesktopXDpi = function() {
46  return 96;
47};
48
49remoting.MockClientPlugin.prototype.getDesktopYDpi = function() {
50  return 96;
51};
52
53remoting.MockClientPlugin.prototype.element = function() {
54  return this.element_;
55};
56
57remoting.MockClientPlugin.prototype.initialize = function(onDone) {
58  window.setTimeout(onDone.bind(null, true), 0);
59};
60
61remoting.MockClientPlugin.prototype.connect = function(
62    hostJid, hostPublicKey, localJid, sharedSecret,
63    authenticationMethods, authenticationTag,
64    clientPairingId, clientPairedSecret) {
65  base.debug.assert(this.connectionStatusUpdateHandler_ != null);
66  window.setTimeout(
67      this.connectionStatusUpdateHandler_.bind(
68          this,
69          remoting.ClientSession.State.CONNECTED,
70          remoting.ClientSession.ConnectionError.NONE),
71      0);
72};
73
74remoting.MockClientPlugin.prototype.injectKeyEvent =
75    function(key, down) {};
76
77remoting.MockClientPlugin.prototype.remapKey = function(from, to) {};
78
79remoting.MockClientPlugin.prototype.releaseAllKeys = function() {};
80
81remoting.MockClientPlugin.prototype.notifyClientResolution =
82    function(width, height, dpi) {
83  this.width_ = width;
84  this.height_ = height;
85  if (this.desktopSizeUpdateHandler_) {
86    window.setTimeout(this.desktopSizeUpdateHandler_, 0);
87  }
88};
89
90remoting.MockClientPlugin.prototype.onIncomingIq = function(iq) {};
91
92remoting.MockClientPlugin.prototype.isSupportedVersion = function() {
93  return true;
94};
95
96remoting.MockClientPlugin.prototype.hasFeature = function(feature) {
97  return false;
98};
99
100remoting.MockClientPlugin.prototype.enableMediaSourceRendering =
101    function(mediaSourceRenderer) {};
102
103remoting.MockClientPlugin.prototype.sendClipboardItem =
104    function(mimeType, item) {};
105
106remoting.MockClientPlugin.prototype.useAsyncPinDialog = function() {};
107
108remoting.MockClientPlugin.prototype.requestPairing =
109    function(clientName, onDone) {};
110
111remoting.MockClientPlugin.prototype.onPinFetched = function(pin) {};
112
113remoting.MockClientPlugin.prototype.onThirdPartyTokenFetched =
114    function(token, sharedSecret) {};
115
116remoting.MockClientPlugin.prototype.pauseAudio = function(pause) {};
117
118remoting.MockClientPlugin.prototype.pauseVideo = function(pause) {};
119
120remoting.MockClientPlugin.prototype.getPerfStats = function() {
121  var result = new remoting.ClientSession.PerfStats;
122  result.videoBandwidth = 999;
123  result.videoFrameRate = 60;
124  result.captureLatency = 10;
125  result.encodeLatency = 10;
126  result.decodeLatency = 10;
127  result.renderLatency = 10;
128  result.roundtripLatency = 10;
129  return result;
130};
131
132remoting.MockClientPlugin.prototype.sendClientMessage =
133    function(name, data) {};
134
135remoting.MockClientPlugin.prototype.setOnOutgoingIqHandler =
136    function(handler) {};
137
138remoting.MockClientPlugin.prototype.setOnDebugMessageHandler =
139    function(handler) {};
140
141remoting.MockClientPlugin.prototype.setConnectionStatusUpdateHandler =
142    function(handler) {
143  this.connectionStatusUpdateHandler_ = handler;
144};
145
146remoting.MockClientPlugin.prototype.setConnectionReadyHandler =
147    function(handler) {};
148
149remoting.MockClientPlugin.prototype.setDesktopSizeUpdateHandler =
150    function(handler) {
151  this.desktopSizeUpdateHandler_ = handler;
152};
153
154remoting.MockClientPlugin.prototype.setCapabilitiesHandler =
155    function(handler) {};
156
157remoting.MockClientPlugin.prototype.setGnubbyAuthHandler =
158    function(handler) {};
159
160remoting.MockClientPlugin.prototype.setCastExtensionHandler =
161    function(handler) {};
162
163remoting.MockClientPlugin.prototype.setMouseCursorHandler =
164    function(handler) {};
165
166remoting.MockClientPlugin.prototype.setFetchThirdPartyTokenHandler =
167    function(handler) {};
168
169remoting.MockClientPlugin.prototype.setFetchPinHandler =
170    function(handler) {};
171
172
173/**
174 * @constructor
175 * @extends {remoting.ClientPluginFactory}
176 */
177remoting.MockClientPluginFactory = function() {};
178
179remoting.MockClientPluginFactory.prototype.createPlugin =
180    function(container, onExtensionMessage) {
181  return new remoting.MockClientPlugin(container);
182};
183
184remoting.MockClientPluginFactory.prototype.preloadPlugin = function() {};
185