Chromium Code Reviews| Index: remoting/webapp/crd/js/mock_host_list_api.js |
| diff --git a/remoting/webapp/crd/js/mock_host_list_api.js b/remoting/webapp/crd/js/mock_host_list_api.js |
| index 3cead52c60e328123182855d86fd0e03f74ba8ea..afc4ba2a222d9819dca01af192e2adb6f282240d 100644 |
| --- a/remoting/webapp/crd/js/mock_host_list_api.js |
| +++ b/remoting/webapp/crd/js/mock_host_list_api.js |
| @@ -32,32 +32,32 @@ remoting.MockHostListApi = function() { |
| this.emailFromRegister = null; |
| /** |
| - * This host ID to return from register(), or null if it should fail. |
| + * The host ID to return from register(), or null if it should fail. |
| * @type {?string} |
| */ |
| this.hostIdFromRegister = null; |
| - /** @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() |
| - } |
| - ]; |
| + /** |
| + * The host ID to return from getHostIdFromConfig(), or null if it |
| + * should fail. |
| + * @type {?string} |
| + */ |
| + this.hostIdFromConfig = null; |
| + |
| + /** @type {!Array<!remoting.Host>} */ |
| + this.hosts = []; |
| +}; |
| + |
| +/** |
| + * Creates and adds a new mock host. |
| + * |
| + * @param {string} hostId The ID of the new host to add. |
| + * @return {!remoting.Host} the new mock host |
| + */ |
| +remoting.MockHostListApi.prototype.addMockHost = function(hostId) { |
| + var newHost = new remoting.Host(hostId); |
| + this.hosts.push(newHost); |
| + return newHost; |
| }; |
| /** @override */ |
| @@ -79,11 +79,7 @@ remoting.MockHostListApi.prototype.register = function( |
| /** @override */ |
| remoting.MockHostListApi.prototype.get = function() { |
| - var that = this; |
| - return new Promise(function(resolve, reject) { |
| - remoting.mockIdentity.validateTokenAndCall( |
| - resolve, remoting.Error.handler(reject), [that.hosts]); |
|
John Williams
2015/06/29 19:45:06
Many of the changes in this file involve removing
|
| - }); |
| + return Promise.resolve(this.hosts); |
| }; |
| /** |
| @@ -97,22 +93,19 @@ remoting.MockHostListApi.prototype.put = |
| /** @type {remoting.MockHostListApi} */ |
| var that = this; |
| return new Promise(function(resolve, reject) { |
| - var onTokenValid = function() { |
| - for (var i = 0; i < that.hosts.length; ++i) { |
| - /** type {remoting.Host} */ |
| - var host = that.hosts[i]; |
| - if (host.hostId == hostId) { |
| - host.hostName = hostName; |
| - host.hostPublicKey = hostPublicKey; |
| - resolve(undefined); |
| - return; |
| - } |
| + for (var i = 0; i < that.hosts.length; ++i) { |
| + /** type {remoting.Host} */ |
| + var host = that.hosts[i]; |
| + if (host.hostId == hostId) { |
| + host.hostName = hostName; |
| + host.hostPublicKey = hostPublicKey; |
| + resolve(undefined); |
| + return; |
| } |
| - console.error('PUT request for unknown host: ' + hostId + |
| - ' (' + hostName + ')'); |
| - reject(remoting.Error.unexpected()); |
| - }; |
| - remoting.mockIdentity.validateTokenAndCall(onTokenValid, reject, []); |
| + } |
| + console.error('PUT request for unknown host: ' + hostId + |
| + ' (' + hostName + ')'); |
| + reject(remoting.Error.unexpected()); |
| }); |
| }; |
| @@ -124,30 +117,30 @@ remoting.MockHostListApi.prototype.remove = function(hostId) { |
| /** @type {remoting.MockHostListApi} */ |
| var that = this; |
| return new Promise(function(resolve, reject) { |
| - 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); |
| - resolve(undefined); |
| - return; |
| - } |
| + for (var i = 0; i < that.hosts.length; ++i) { |
| + var host = that.hosts[i]; |
| + if (host.hostId == hostId) { |
| + that.hosts.splice(i, 1); |
| + resolve(undefined); |
| + return; |
| } |
| - console.error('DELETE request for unknown host: ' + hostId); |
| - reject(remoting.Error.unexpected()); |
| - }; |
| - remoting.mockIdentity.validateTokenAndCall(onTokenValid, reject, []); |
| + } |
| + console.error('DELETE request for unknown host: ' + hostId); |
| + reject(remoting.Error.unexpected()); |
| }); |
| }; |
| /** @override */ |
| remoting.MockHostListApi.prototype.getSupportHost = function(supportId) { |
| - var that = this; |
| - return new Promise(function(resolve, reject) { |
| - remoting.mockIdentity.validateTokenAndCall( |
| - resolve, remoting.Error.handler(reject), [that.hosts[0]]); |
| - }); |
| + return Promise.resolve(this.hosts[0]); |
| +}; |
| +/** @override */ |
| +remoting.MockHostListApi.prototype.getHostIdFromConfig = function(config) { |
| + if (this.hostIdFromConfig == null) { |
| + throw new Error('Must set hostIdFromConfig'); |
| + } |
| + return this.hostIdFromConfig; |
| }; |
| /** |