Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: remoting/webapp/crd/js/mock_host_list_api.js

Issue 1217643002: Added HostListApl implementation to connect to legacy directory and GCD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcd-e2e
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 remoting.HostList 7 * Mock implementation of remoting.HostList
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 14 matching lines...) Expand all
25 this.authCodeFromRegister = null; 25 this.authCodeFromRegister = null;
26 26
27 /** 27 /**
28 * The email value for the |register| method to return, or null if 28 * The email value for the |register| method to return, or null if
29 * it should fail. 29 * it should fail.
30 * @type {?string} 30 * @type {?string}
31 */ 31 */
32 this.emailFromRegister = null; 32 this.emailFromRegister = null;
33 33
34 /** 34 /**
35 * This host ID to return from register(), or null if it should fail. 35 * The host ID to return from register(), or null if it should fail.
36 * @type {?string} 36 * @type {?string}
37 */ 37 */
38 this.hostIdFromRegister = null; 38 this.hostIdFromRegister = null;
39 39
40 /** @type {Array<remoting.Host>} */ 40 /**
41 this.hosts = [ 41 * The host ID to return from getHostIdFromConfig(), or null if it
42 { 42 * should fail.
43 'hostName': 'Online host', 43 * @type {?string}
44 'hostId': 'online-host-id', 44 */
45 'status': 'ONLINE', 45 this.hostIdFromConfig = null;
46 'jabberId': 'online-jid', 46
47 'publicKey': 'online-public-key', 47 /** @type {!Array<!remoting.Host>} */
48 'tokenUrlPatterns': [], 48 this.hosts = [];
49 'updatedTime': new Date().toISOString() 49 };
50 }, 50
51 { 51 /**
52 'hostName': 'Offline host', 52 * Creates and adds a new mock host.
53 'hostId': 'offline-host-id', 53 *
54 'status': 'OFFLINE', 54 * @param {string} hostId The ID of the new host to add.
55 'jabberId': 'offline-jid', 55 * @return {!remoting.Host} the new mock host
56 'publicKey': 'offline-public-key', 56 */
57 'tokenUrlPatterns': [], 57 remoting.MockHostListApi.prototype.addMockHost = function(hostId) {
58 'updatedTime': new Date(1970, 1, 1).toISOString() 58 var newHost = new remoting.Host(hostId);
59 } 59 this.hosts.push(newHost);
60 ]; 60 return newHost;
61 }; 61 };
62 62
63 /** @override */ 63 /** @override */
64 remoting.MockHostListApi.prototype.register = function( 64 remoting.MockHostListApi.prototype.register = function(
65 hostName, publicKey, hostClientId) { 65 hostName, publicKey, hostClientId) {
66 if (this.authCodeFromRegister === null || this.emailFromRegister === null) { 66 if (this.authCodeFromRegister === null || this.emailFromRegister === null) {
67 return Promise.reject( 67 return Promise.reject(
68 new remoting.Error( 68 new remoting.Error(
69 remoting.Error.Tag.REGISTRATION_FAILED, 69 remoting.Error.Tag.REGISTRATION_FAILED,
70 'MockHostListApi.register')); 70 'MockHostListApi.register'));
71 } else { 71 } else {
72 return Promise.resolve({ 72 return Promise.resolve({
73 authCode: this.authCodeFromRegister, 73 authCode: this.authCodeFromRegister,
74 email: this.emailFromRegister, 74 email: this.emailFromRegister,
75 hostId: this.hostIdFromRegister 75 hostId: this.hostIdFromRegister
76 }); 76 });
77 } 77 }
78 }; 78 };
79 79
80 /** @override */ 80 /** @override */
81 remoting.MockHostListApi.prototype.get = function() { 81 remoting.MockHostListApi.prototype.get = function() {
82 var that = this; 82 return Promise.resolve(this.hosts);
83 return new Promise(function(resolve, reject) {
84 remoting.mockIdentity.validateTokenAndCall(
85 resolve, remoting.Error.handler(reject), [that.hosts]);
John Williams 2015/06/29 19:45:06 Many of the changes in this file involve removing
86 });
87 }; 83 };
88 84
89 /** 85 /**
90 * @override 86 * @override
91 * @param {string} hostId 87 * @param {string} hostId
92 * @param {string} hostName 88 * @param {string} hostName
93 * @param {string} hostPublicKey 89 * @param {string} hostPublicKey
94 */ 90 */
95 remoting.MockHostListApi.prototype.put = 91 remoting.MockHostListApi.prototype.put =
96 function(hostId, hostName, hostPublicKey) { 92 function(hostId, hostName, hostPublicKey) {
97 /** @type {remoting.MockHostListApi} */ 93 /** @type {remoting.MockHostListApi} */
98 var that = this; 94 var that = this;
99 return new Promise(function(resolve, reject) { 95 return new Promise(function(resolve, reject) {
100 var onTokenValid = function() { 96 for (var i = 0; i < that.hosts.length; ++i) {
101 for (var i = 0; i < that.hosts.length; ++i) { 97 /** type {remoting.Host} */
102 /** type {remoting.Host} */ 98 var host = that.hosts[i];
103 var host = that.hosts[i]; 99 if (host.hostId == hostId) {
104 if (host.hostId == hostId) { 100 host.hostName = hostName;
105 host.hostName = hostName; 101 host.hostPublicKey = hostPublicKey;
106 host.hostPublicKey = hostPublicKey; 102 resolve(undefined);
107 resolve(undefined); 103 return;
108 return;
109 }
110 } 104 }
111 console.error('PUT request for unknown host: ' + hostId + 105 }
112 ' (' + hostName + ')'); 106 console.error('PUT request for unknown host: ' + hostId +
113 reject(remoting.Error.unexpected()); 107 ' (' + hostName + ')');
114 }; 108 reject(remoting.Error.unexpected());
115 remoting.mockIdentity.validateTokenAndCall(onTokenValid, reject, []);
116 }); 109 });
117 }; 110 };
118 111
119 /** 112 /**
120 * @override 113 * @override
121 * @param {string} hostId 114 * @param {string} hostId
122 */ 115 */
123 remoting.MockHostListApi.prototype.remove = function(hostId) { 116 remoting.MockHostListApi.prototype.remove = function(hostId) {
124 /** @type {remoting.MockHostListApi} */ 117 /** @type {remoting.MockHostListApi} */
125 var that = this; 118 var that = this;
126 return new Promise(function(resolve, reject) { 119 return new Promise(function(resolve, reject) {
127 var onTokenValid = function() { 120 for (var i = 0; i < that.hosts.length; ++i) {
128 for (var i = 0; i < that.hosts.length; ++i) { 121 var host = that.hosts[i];
129 var host = that.hosts[i]; 122 if (host.hostId == hostId) {
130 if (host.hostId == hostId) { 123 that.hosts.splice(i, 1);
131 that.hosts.splice(i, 1); 124 resolve(undefined);
132 resolve(undefined); 125 return;
133 return;
134 }
135 } 126 }
136 console.error('DELETE request for unknown host: ' + hostId); 127 }
137 reject(remoting.Error.unexpected()); 128 console.error('DELETE request for unknown host: ' + hostId);
138 }; 129 reject(remoting.Error.unexpected());
139 remoting.mockIdentity.validateTokenAndCall(onTokenValid, reject, []);
140 }); 130 });
141 }; 131 };
142 132
143 /** @override */ 133 /** @override */
144 remoting.MockHostListApi.prototype.getSupportHost = function(supportId) { 134 remoting.MockHostListApi.prototype.getSupportHost = function(supportId) {
145 var that = this; 135 return Promise.resolve(this.hosts[0]);
146 return new Promise(function(resolve, reject) { 136 };
147 remoting.mockIdentity.validateTokenAndCall(
148 resolve, remoting.Error.handler(reject), [that.hosts[0]]);
149 });
150 137
138 /** @override */
139 remoting.MockHostListApi.prototype.getHostIdFromConfig = function(config) {
140 if (this.hostIdFromConfig == null) {
141 throw new Error('Must set hostIdFromConfig');
142 }
143 return this.hostIdFromConfig;
151 }; 144 };
152 145
153 /** 146 /**
154 * @param {boolean} active 147 * @param {boolean} active
155 */ 148 */
156 remoting.MockHostListApi.setActive = function(active) { 149 remoting.MockHostListApi.setActive = function(active) {
157 remoting.HostListApi.setInstance( 150 remoting.HostListApi.setInstance(
158 active ? new remoting.MockHostListApi() : null); 151 active ? new remoting.MockHostListApi() : null);
159 }; 152 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698