| 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..8d5452a7f0282045ff1d5a3842c456c14006e7b3 100644
|
| --- a/remoting/webapp/crd/js/mock_host_list_api.js
|
| +++ b/remoting/webapp/crd/js/mock_host_list_api.js
|
| @@ -32,32 +32,25 @@ 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()
|
| - }
|
| - ];
|
| + /** @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 +72,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]);
|
| - });
|
| + return Promise.resolve(this.hosts);
|
| };
|
|
|
| /**
|
| @@ -97,22 +86,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 +110,22 @@ 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]);
|
| };
|
|
|
| /**
|
|
|