OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Mock implementation of ClientPlugin for testing. | 7 * Mock implementation of ClientPlugin for testing. |
8 * @suppress {checkTypes} | 8 * @suppress {checkTypes} |
9 */ | 9 */ |
10 | 10 |
11 'use strict'; | 11 'use strict'; |
12 | 12 |
13 /** @suppress {duplicate} */ | 13 /** @suppress {duplicate} */ |
14 var remoting = remoting || {}; | 14 var remoting = remoting || {}; |
15 | 15 |
16 /** | 16 /** |
17 * @param {Element} container | 17 * @param {Element} container |
18 * @constructor | 18 * @constructor |
19 * @implements {remoting.ClientPlugin} | 19 * @implements {remoting.ClientPlugin} |
20 */ | 20 */ |
21 remoting.MockClientPlugin = function(container) { | 21 remoting.MockClientPlugin = function(container) { |
22 this.container_ = container; | 22 this.container_ = container; |
23 this.element_ = document.createElement('div'); | 23 this.element_ = document.createElement('div'); |
24 this.element_.style.backgroundImage = 'linear-gradient(45deg, blue, red)'; | 24 this.element_.style.backgroundImage = 'linear-gradient(45deg, blue, red)'; |
25 this.width_ = 640; | |
26 this.height_ = 480; | |
27 this.connectionStatusUpdateHandler_ = null; | 25 this.connectionStatusUpdateHandler_ = null; |
28 this.desktopSizeUpdateHandler_ = null; | 26 this.desktopSizeUpdateHandler_ = null; |
29 this.container_.appendChild(this.element_); | 27 this.container_.appendChild(this.element_); |
28 this.hostDesktop_ = new remoting.MockClientPlugin.HostDesktop(); | |
30 }; | 29 }; |
31 | 30 |
32 remoting.MockClientPlugin.prototype.dispose = function() { | 31 remoting.MockClientPlugin.prototype.dispose = function() { |
33 this.container_.removeChild(this.element_); | 32 this.container_.removeChild(this.element_); |
34 this.element_ = null; | 33 this.element_ = null; |
35 this.connectionStatusUpdateHandler_ = null; | 34 this.connectionStatusUpdateHandler_ = null; |
36 }; | 35 }; |
37 | 36 |
38 remoting.MockClientPlugin.prototype.getDesktopWidth = function() { | 37 remoting.MockClientPlugin.prototype.hostDesktop = function() { |
39 return this.width_; | 38 return this.hostDesktop_; |
40 }; | |
41 | |
42 remoting.MockClientPlugin.prototype.getDesktopHeight = function() { | |
43 return this.height_; | |
44 }; | |
45 | |
46 remoting.MockClientPlugin.prototype.getDesktopXDpi = function() { | |
47 return 96; | |
48 }; | |
49 | |
50 remoting.MockClientPlugin.prototype.getDesktopYDpi = function() { | |
51 return 96; | |
52 }; | 39 }; |
53 | 40 |
54 remoting.MockClientPlugin.prototype.element = function() { | 41 remoting.MockClientPlugin.prototype.element = function() { |
55 return this.element_; | 42 return this.element_; |
56 }; | 43 }; |
57 | 44 |
58 remoting.MockClientPlugin.prototype.initialize = function(onDone) { | 45 remoting.MockClientPlugin.prototype.initialize = function(onDone) { |
59 window.setTimeout(onDone.bind(null, true), 0); | 46 window.setTimeout(onDone.bind(null, true), 0); |
60 }; | 47 }; |
61 | 48 |
(...skipping 10 matching lines...) Expand all Loading... | |
72 0); | 59 0); |
73 }; | 60 }; |
74 | 61 |
75 remoting.MockClientPlugin.prototype.injectKeyEvent = | 62 remoting.MockClientPlugin.prototype.injectKeyEvent = |
76 function(key, down) {}; | 63 function(key, down) {}; |
77 | 64 |
78 remoting.MockClientPlugin.prototype.remapKey = function(from, to) {}; | 65 remoting.MockClientPlugin.prototype.remapKey = function(from, to) {}; |
79 | 66 |
80 remoting.MockClientPlugin.prototype.releaseAllKeys = function() {}; | 67 remoting.MockClientPlugin.prototype.releaseAllKeys = function() {}; |
81 | 68 |
82 remoting.MockClientPlugin.prototype.notifyClientResolution = | |
83 function(width, height, dpi) { | |
84 this.width_ = width; | |
85 this.height_ = height; | |
86 if (this.desktopSizeUpdateHandler_) { | |
87 window.setTimeout(this.desktopSizeUpdateHandler_, 0); | |
88 } | |
89 }; | |
90 | |
91 remoting.MockClientPlugin.prototype.onIncomingIq = function(iq) {}; | 69 remoting.MockClientPlugin.prototype.onIncomingIq = function(iq) {}; |
92 | 70 |
93 remoting.MockClientPlugin.prototype.isSupportedVersion = function() { | 71 remoting.MockClientPlugin.prototype.isSupportedVersion = function() { |
94 return true; | 72 return true; |
95 }; | 73 }; |
96 | 74 |
97 remoting.MockClientPlugin.prototype.hasFeature = function(feature) { | 75 remoting.MockClientPlugin.prototype.hasFeature = function(feature) { |
98 return false; | 76 return false; |
99 }; | 77 }; |
100 | 78 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 /** @type {function(number, number):void} */ | 123 /** @type {function(number, number):void} */ |
146 this.connectionStatusUpdateHandler_ = handler; | 124 this.connectionStatusUpdateHandler_ = handler; |
147 }; | 125 }; |
148 | 126 |
149 remoting.MockClientPlugin.prototype.setRouteChangedHandler = | 127 remoting.MockClientPlugin.prototype.setRouteChangedHandler = |
150 function(handler) {}; | 128 function(handler) {}; |
151 | 129 |
152 remoting.MockClientPlugin.prototype.setConnectionReadyHandler = | 130 remoting.MockClientPlugin.prototype.setConnectionReadyHandler = |
153 function(handler) {}; | 131 function(handler) {}; |
154 | 132 |
155 remoting.MockClientPlugin.prototype.setDesktopSizeUpdateHandler = | |
156 function(handler) { | |
157 this.desktopSizeUpdateHandler_ = handler; | |
158 }; | |
159 | |
160 remoting.MockClientPlugin.prototype.setCapabilitiesHandler = | 133 remoting.MockClientPlugin.prototype.setCapabilitiesHandler = |
161 function(handler) {}; | 134 function(handler) {}; |
162 | 135 |
163 remoting.MockClientPlugin.prototype.setGnubbyAuthHandler = | 136 remoting.MockClientPlugin.prototype.setGnubbyAuthHandler = |
164 function(handler) {}; | 137 function(handler) {}; |
165 | 138 |
166 remoting.MockClientPlugin.prototype.setCastExtensionHandler = | 139 remoting.MockClientPlugin.prototype.setCastExtensionHandler = |
167 function(handler) {}; | 140 function(handler) {}; |
168 | 141 |
169 remoting.MockClientPlugin.prototype.setMouseCursorHandler = | 142 remoting.MockClientPlugin.prototype.setMouseCursorHandler = |
170 function(handler) {}; | 143 function(handler) {}; |
171 | 144 |
172 remoting.MockClientPlugin.prototype.setFetchThirdPartyTokenHandler = | 145 remoting.MockClientPlugin.prototype.setFetchThirdPartyTokenHandler = |
173 function(handler) {}; | 146 function(handler) {}; |
174 | 147 |
175 remoting.MockClientPlugin.prototype.setFetchPinHandler = | 148 remoting.MockClientPlugin.prototype.setFetchPinHandler = |
176 function(handler) {}; | 149 function(handler) {}; |
177 | 150 |
151 /** | |
152 * @constructor | |
153 * @implements {remoting.HostDesktop} | |
154 * @extends {base.EventSourceImpl} | |
155 */ | |
156 remoting.MockClientPlugin.HostDesktop = function() { | |
157 /** @private */ | |
158 this.width_ = 0; | |
159 /** @private */ | |
160 this.height_ = 0; | |
161 /** @private */ | |
162 this.xDpi_ = 96; | |
163 /** @private */ | |
164 this.yDpi_ = 96; | |
165 /** @private */ | |
166 this.resizable_ = true; | |
167 this.defineEvents(base.values(remoting.HostDesktop.Events)); | |
168 }; | |
169 base.extend(remoting.MockClientPlugin.HostDesktop, base.EventSourceImpl); | |
170 | |
171 /** | |
172 * @return {{width:number, height:number, xDpi:number, yDpi:number}} | |
173 * @override | |
174 */ | |
175 remoting.MockClientPlugin.HostDesktop.prototype.getDimensions = function() { | |
176 return { | |
177 width: this.width_, | |
178 height: this.height_, | |
179 xDpi: this.xDpi_, | |
180 yDpi: this.yDpi_ | |
181 }; | |
182 }; | |
183 | |
184 /** | |
185 * @return {boolean} | |
186 * @override | |
187 */ | |
188 remoting.MockClientPlugin.HostDesktop.prototype.isResizable = function() { | |
189 return this.resizable_; | |
190 }; | |
191 | |
192 /** | |
193 * @param {number} width | |
194 * @param {number} height | |
195 * @param {number} deviceScale | |
196 * @override | |
197 */ | |
198 remoting.MockClientPlugin.HostDesktop.prototype.resize = function(width, | |
199 height, | |
200 deviceScale) { | |
Jamie
2015/02/19 22:44:04
Nit: When the method name is so long that you can
kelvinp
2015/02/19 23:36:20
Done.
| |
201 this.width_ = width; | |
202 this.height_ = height; | |
203 this.xDpi_ = this.yDpi_ = Math.floor(deviceScale * 96); | |
204 this.raiseEvent(remoting.HostDesktop.Events.sizeChanged, | |
205 this.getDimensions()); | |
206 }; | |
178 | 207 |
179 /** | 208 /** |
180 * @constructor | 209 * @constructor |
181 * @extends {remoting.ClientPluginFactory} | 210 * @extends {remoting.ClientPluginFactory} |
182 */ | 211 */ |
183 remoting.MockClientPluginFactory = function() {}; | 212 remoting.MockClientPluginFactory = function() {}; |
184 | 213 |
185 remoting.MockClientPluginFactory.prototype.createPlugin = | 214 remoting.MockClientPluginFactory.prototype.createPlugin = |
186 function(container, onExtensionMessage) { | 215 function(container, onExtensionMessage) { |
187 return new remoting.MockClientPlugin(container); | 216 return new remoting.MockClientPlugin(container); |
188 }; | 217 }; |
189 | 218 |
190 remoting.MockClientPluginFactory.prototype.preloadPlugin = function() {}; | 219 remoting.MockClientPluginFactory.prototype.preloadPlugin = function() {}; |
OLD | NEW |