Chromium Code Reviews| Index: remoting/webapp/browser_test/mock_host_list_api.js |
| diff --git a/remoting/webapp/browser_test/mock_host_list_api.js b/remoting/webapp/browser_test/mock_host_list_api.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..144c20fb397ad6a8190ae9a92b86557224b7d1c6 |
| --- /dev/null |
| +++ b/remoting/webapp/browser_test/mock_host_list_api.js |
| @@ -0,0 +1,109 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview |
| + * Mock implementation of remoting.HostList |
| + */ |
| + |
| +'use strict'; |
| + |
| +/** @suppress {duplicate} */ |
| +var remoting = remoting || {}; |
| + |
| +/** |
| + * @constructor |
| + * @implements {remoting.HostListApi} |
| + */ |
| +remoting.MockHostListApi = function() { |
|
kelvinp
2015/01/08 22:54:40
I would imagine some test would like to supply a c
Jamie
2015/01/08 23:43:08
I would prefer to wait until we have such a test a
|
| + /** @type {Array.<remoting.Host>} */ |
| + this.hosts = [ |
| + { |
| + 'hostName': 'Online host', |
| + 'hostId': 'online-host-id', |
| + 'status': 'ONLINE', |
| + 'jabberId': 'online-jid', |
| + 'publicKey': 'online-public-key', |
| + 'tokenUrlPatterns': [], |
| + 'updatedTime': new Date().toISOString() |
| + }, |
| + { |
| + 'hostName': 'Offline host', |
| + 'hostId': 'offline-host-id', |
| + 'status': 'OFFLINE', |
| + 'jabberId': 'offline-jid', |
| + 'publicKey': 'offline-public-key', |
| + 'tokenUrlPatterns': [], |
| + 'updatedTime': new Date(1970, 1, 1).toISOString() |
| + } |
| + ]; |
| +}; |
| + |
| +/** |
| + * @param {function(Array.<remoting.Host>):void} onDone |
| + * @param {function(remoting.Error):void} onError |
| + */ |
| +remoting.MockHostListApi.prototype.get = function(onDone, onError) { |
| + remoting.mockIdentity.validateTokenAndCall(onDone, onError, [this.hosts]); |
| +}; |
| + |
| +/** |
| + * @param {function():void} onDone |
| + * @param {function(remoting.Error):void} onError |
| + * @param {string} hostId |
| + * @param {string} hostName |
| + * @param {string} hostPublicKey |
| + */ |
| +remoting.MockHostListApi.prototype.put = |
| + function(hostId, hostName, hostPublicKey, onDone, onError) { |
| + /** @type {remoting.MockHostListApi} */ |
| + var that = this; |
| + var onTokenValid = function() { |
| + for (var i = 0; i < that.hosts.length; ++i) { |
| + var host = that.hosts[i]; |
| + if (host.hostId == hostId) { |
| + host.hostName = hostName; |
| + host.hostPublicKey = hostPublicKey; |
| + onDone(); |
| + return; |
| + } |
| + } |
| + console.error('PUT request for unknown host: ' + hostId + |
| + ' (' + hostName + ')'); |
| + onError(remoting.Error.UNEXPECTED); |
| + }; |
| + remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []); |
| +}; |
| + |
| +/** |
| + * @param {function():void} onDone |
| + * @param {function(remoting.Error):void} onError |
| + * @param {string} hostId |
| + */ |
| +remoting.MockHostListApi.prototype.remove = |
| + function(hostId, onDone, onError) { |
| + /** @type {remoting.MockHostListApi} */ |
| + var that = this; |
| + var onTokenValid = function() { |
| + for (var i = 0; i < that.hosts.length; ++i) { |
| + var host = that.hosts[i]; |
| + if (host.hostId == hostId) { |
| + that.hosts.splice(i, 1); |
| + onDone(); |
| + return; |
| + } |
| + } |
| + console.error('DELETE request for unknown host: ' + hostId); |
| + onError(remoting.Error.UNEXPECTED); |
| + }; |
| + remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []); |
| +}; |
| + |
| +/** |
| + * @param {boolean} active |
| + */ |
| +remoting.MockHostListApi.setActive = function(active) { |
| + remoting.hostListApi = active ? new remoting.MockHostListApi() |
|
kelvinp
2015/01/08 22:54:40
Should we cache the old HostListApiImpl instead of
Jamie
2015/01/08 23:43:08
We could, but I think a similar argument could be
|
| + : new remoting.HostListApiImpl(); |
| +}; |