Chromium Code Reviews| 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 * @constructor | 17 * @constructor |
| 18 * @implements {remoting.ClientPlugin} | 18 * @implements {remoting.ClientPlugin} |
| 19 */ | 19 */ |
| 20 remoting.MockClientPlugin = function(container) { | 20 remoting.MockClientPlugin = function(container) { |
| 21 this.container_ = container; | 21 this.container_ = container; |
| 22 this.element_ = document.createElement('div'); | 22 this.element_ = document.createElement('div'); |
| 23 this.element_.style.backgroundImage = 'linear-gradient(45deg, blue, red)'; | 23 this.element_.style.backgroundImage = 'linear-gradient(45deg, blue, red)'; |
| 24 this.width_ = 640; | |
| 25 this.height_ = 480; | |
| 26 this.connectionStatusUpdateHandler_ = null; | 24 this.connectionStatusUpdateHandler_ = null; |
| 27 this.desktopSizeUpdateHandler_ = null; | 25 this.desktopSizeUpdateHandler_ = null; |
| 28 this.container_.appendChild(this.element_); | 26 this.container_.appendChild(this.element_); |
| 27 this.hostDesktop_ = new remoting.MockClientPlugin.HostDesktop(); | |
| 29 }; | 28 }; |
| 30 | 29 |
| 31 remoting.MockClientPlugin.prototype.dispose = function() { | 30 remoting.MockClientPlugin.prototype.dispose = function() { |
| 32 this.container_.removeChild(this.element_); | 31 this.container_.removeChild(this.element_); |
| 33 this.element_ = null; | 32 this.element_ = null; |
| 34 this.connectionStatusUpdateHandler_ = null; | 33 this.connectionStatusUpdateHandler_ = null; |
| 35 }; | 34 }; |
| 36 | 35 |
| 36 // TODO(kelvinp): Fix all call sites to use ClientPlugin.HostDesktop and remove | |
| 37 // the four methods below. | |
| 37 remoting.MockClientPlugin.prototype.getDesktopWidth = function() { | 38 remoting.MockClientPlugin.prototype.getDesktopWidth = function() { |
| 38 return this.width_; | 39 return this.hostDesktop_.getDimensions().width; |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 remoting.MockClientPlugin.prototype.getDesktopHeight = function() { | 42 remoting.MockClientPlugin.prototype.getDesktopHeight = function() { |
| 42 return this.height_; | 43 return this.hostDesktop_.getDimensions().height; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 remoting.MockClientPlugin.prototype.getDesktopXDpi = function() { | 46 remoting.MockClientPlugin.prototype.getDesktopXDpi = function() { |
| 46 return 96; | 47 return this.hostDesktop_.getDimensions().xDpi; |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 remoting.MockClientPlugin.prototype.getDesktopYDpi = function() { | 50 remoting.MockClientPlugin.prototype.getDesktopYDpi = function() { |
| 50 return 96; | 51 return this.hostDesktop_.getDimensions().yDpi; |
| 52 }; | |
| 53 | |
| 54 remoting.MockClientPlugin.prototype.hostDesktop = function() { | |
| 55 return this.hostDesktop_; | |
| 51 }; | 56 }; |
| 52 | 57 |
| 53 remoting.MockClientPlugin.prototype.element = function() { | 58 remoting.MockClientPlugin.prototype.element = function() { |
| 54 return this.element_; | 59 return this.element_; |
| 55 }; | 60 }; |
| 56 | 61 |
| 57 remoting.MockClientPlugin.prototype.initialize = function(onDone) { | 62 remoting.MockClientPlugin.prototype.initialize = function(onDone) { |
| 58 window.setTimeout(onDone.bind(null, true), 0); | 63 window.setTimeout(onDone.bind(null, true), 0); |
| 59 }; | 64 }; |
| 60 | 65 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 73 | 78 |
| 74 remoting.MockClientPlugin.prototype.injectKeyEvent = | 79 remoting.MockClientPlugin.prototype.injectKeyEvent = |
| 75 function(key, down) {}; | 80 function(key, down) {}; |
| 76 | 81 |
| 77 remoting.MockClientPlugin.prototype.remapKey = function(from, to) {}; | 82 remoting.MockClientPlugin.prototype.remapKey = function(from, to) {}; |
| 78 | 83 |
| 79 remoting.MockClientPlugin.prototype.releaseAllKeys = function() {}; | 84 remoting.MockClientPlugin.prototype.releaseAllKeys = function() {}; |
| 80 | 85 |
| 81 remoting.MockClientPlugin.prototype.notifyClientResolution = | 86 remoting.MockClientPlugin.prototype.notifyClientResolution = |
| 82 function(width, height, dpi) { | 87 function(width, height, dpi) { |
| 83 this.width_ = width; | 88 this.hostDesktop_.resize(width, height, dpi); |
| 84 this.height_ = height; | |
| 85 if (this.desktopSizeUpdateHandler_) { | 89 if (this.desktopSizeUpdateHandler_) { |
| 86 window.setTimeout(this.desktopSizeUpdateHandler_, 0); | 90 window.setTimeout(this.desktopSizeUpdateHandler_, 0); |
| 87 } | 91 } |
| 88 }; | 92 }; |
| 89 | 93 |
| 90 remoting.MockClientPlugin.prototype.onIncomingIq = function(iq) {}; | 94 remoting.MockClientPlugin.prototype.onIncomingIq = function(iq) {}; |
| 91 | 95 |
| 92 remoting.MockClientPlugin.prototype.isSupportedVersion = function() { | 96 remoting.MockClientPlugin.prototype.isSupportedVersion = function() { |
| 93 return true; | 97 return true; |
| 94 }; | 98 }; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 166 |
| 163 remoting.MockClientPlugin.prototype.setMouseCursorHandler = | 167 remoting.MockClientPlugin.prototype.setMouseCursorHandler = |
| 164 function(handler) {}; | 168 function(handler) {}; |
| 165 | 169 |
| 166 remoting.MockClientPlugin.prototype.setFetchThirdPartyTokenHandler = | 170 remoting.MockClientPlugin.prototype.setFetchThirdPartyTokenHandler = |
| 167 function(handler) {}; | 171 function(handler) {}; |
| 168 | 172 |
| 169 remoting.MockClientPlugin.prototype.setFetchPinHandler = | 173 remoting.MockClientPlugin.prototype.setFetchPinHandler = |
| 170 function(handler) {}; | 174 function(handler) {}; |
| 171 | 175 |
| 176 remoting.MockClientPlugin.HostDesktop = function() { | |
|
Jamie
2015/02/12 21:07:29
As with HostDesktopImpl, I don't think this needs
| |
| 177 this.width_ = 0; | |
| 178 this.height_ = 0; | |
| 179 this.xDpi_ = 96; | |
| 180 this.yDpi_ = 96; | |
| 181 this.resizable_ = true; | |
| 182 this.defineEvents(Object.keys(remoting.ClientPlugin.HostDesktop.Events)); | |
| 183 }; | |
| 184 base.extend(remoting.MockClientPlugin.HostDesktop, base.EventSourceImpl); | |
| 185 | |
| 186 remoting.MockClientPlugin.HostDesktop.prototype.getDimensions = function() { | |
| 187 return { | |
| 188 width: this.width_, | |
| 189 height: this.height_, | |
| 190 xDpi: this.xDpi_, | |
| 191 yDpi: this.yDpi_ | |
| 192 }; | |
| 193 }; | |
| 194 | |
| 195 remoting.MockClientPlugin.HostDesktop.prototype.isResizable = function() { | |
| 196 return this.resizable_; | |
| 197 }; | |
| 198 | |
| 199 remoting.MockClientPlugin.HostDesktop.prototype.hasResizeRateLimit = | |
| 200 function() { | |
| 201 return false; | |
| 202 }; | |
| 203 | |
| 204 remoting.MockClientPlugin.HostDesktop.prototype.resize = function( | |
| 205 width, height, device_scale) { | |
| 206 this.width_ = width; | |
| 207 this.height_ = height; | |
| 208 this.xDpi_ = this.yDpi_ = device_scale; | |
| 209 this.raiseEvent(remoting.ClientPlugin.HostDesktop.Events.sizeChanged); | |
| 210 }; | |
| 172 | 211 |
| 173 /** | 212 /** |
| 174 * @constructor | 213 * @constructor |
| 175 * @extends {remoting.ClientPluginFactory} | 214 * @extends {remoting.ClientPluginFactory} |
| 176 */ | 215 */ |
| 177 remoting.MockClientPluginFactory = function() {}; | 216 remoting.MockClientPluginFactory = function() {}; |
| 178 | 217 |
| 179 remoting.MockClientPluginFactory.prototype.createPlugin = | 218 remoting.MockClientPluginFactory.prototype.createPlugin = |
| 180 function(container, onExtensionMessage) { | 219 function(container, onExtensionMessage) { |
| 181 return new remoting.MockClientPlugin(container); | 220 return new remoting.MockClientPlugin(container); |
| 182 }; | 221 }; |
| 183 | 222 |
| 184 remoting.MockClientPluginFactory.prototype.preloadPlugin = function() {}; | 223 remoting.MockClientPluginFactory.prototype.preloadPlugin = function() {}; |
| OLD | NEW |