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

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

Issue 1111603002: Added ability to register new hosts using GCD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host-list-delete
Patch Set: unit test fix Created 5 years, 7 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
« no previous file with comments | « remoting/webapp/crd/js/host_list_api_impl_unittest.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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';
11 11
12 /** @suppress {duplicate} */ 12 /** @suppress {duplicate} */
13 var remoting = remoting || {}; 13 var remoting = remoting || {};
14 14
15 /** 15 /**
16 * @constructor 16 * @constructor
17 * @implements {remoting.HostListApi} 17 * @implements {remoting.HostListApi}
18 */ 18 */
19 remoting.MockHostListApi = function() { 19 remoting.MockHostListApi = function() {
20 /** 20 /**
21 * The auth code for the |register| method to return, or null if it 21 * The auth code value for the |register| method to return, or null
22 * should fail. 22 * if it should fail.
23 * @type {?string} 23 * @type {?string}
24 */ 24 */
25 this.registerResult = null; 25 this.authCodeFromRegister = null;
26
27 /**
28 * The email value for the |register| method to return, or null if
29 * it should fail.
30 * @type {?string}
31 */
32 this.emailFromRegister = null;
26 33
27 /** @type {Array<remoting.Host>} */ 34 /** @type {Array<remoting.Host>} */
28 this.hosts = [ 35 this.hosts = [
29 { 36 {
30 'hostName': 'Online host', 37 'hostName': 'Online host',
31 'hostId': 'online-host-id', 38 'hostId': 'online-host-id',
32 'status': 'ONLINE', 39 'status': 'ONLINE',
33 'jabberId': 'online-jid', 40 'jabberId': 'online-jid',
34 'publicKey': 'online-public-key', 41 'publicKey': 'online-public-key',
35 'tokenUrlPatterns': [], 42 'tokenUrlPatterns': [],
36 'updatedTime': new Date().toISOString() 43 'updatedTime': new Date().toISOString()
37 }, 44 },
38 { 45 {
39 'hostName': 'Offline host', 46 'hostName': 'Offline host',
40 'hostId': 'offline-host-id', 47 'hostId': 'offline-host-id',
41 'status': 'OFFLINE', 48 'status': 'OFFLINE',
42 'jabberId': 'offline-jid', 49 'jabberId': 'offline-jid',
43 'publicKey': 'offline-public-key', 50 'publicKey': 'offline-public-key',
44 'tokenUrlPatterns': [], 51 'tokenUrlPatterns': [],
45 'updatedTime': new Date(1970, 1, 1).toISOString() 52 'updatedTime': new Date(1970, 1, 1).toISOString()
46 } 53 }
47 ]; 54 ];
48 }; 55 };
49 56
50 /** @override */ 57 /** @override */
51 remoting.MockHostListApi.prototype.register = function( 58 remoting.MockHostListApi.prototype.register = function(
52 newHostId, hostName, publicKey, hostClientId) { 59 newHostId, hostName, publicKey, hostClientId) {
53 if (this.registerResult === null) { 60 if (this.authCodeFromRegister === null || this.emailFromRegister === null) {
54 return Promise.reject( 61 return Promise.reject(
55 new remoting.Error( 62 new remoting.Error(
56 remoting.Error.Tag.REGISTRATION_FAILED, 63 remoting.Error.Tag.REGISTRATION_FAILED,
57 'MockHostListApi.register')); 64 'MockHostListApi.register'));
58 } else { 65 } else {
59 return Promise.resolve(this.registerResult); 66 return Promise.resolve({
67 authCode: this.authCodeFromRegister,
68 email: this.emailFromRegister
69 });
60 } 70 }
61 }; 71 };
62 72
63 /** @override */ 73 /** @override */
64 remoting.MockHostListApi.prototype.get = function() { 74 remoting.MockHostListApi.prototype.get = function() {
65 var that = this; 75 var that = this;
66 return new Promise(function(resolve, reject) { 76 return new Promise(function(resolve, reject) {
67 remoting.mockIdentity.validateTokenAndCall( 77 remoting.mockIdentity.validateTokenAndCall(
68 resolve, remoting.Error.handler(reject), [that.hosts]); 78 resolve, remoting.Error.handler(reject), [that.hosts]);
69 }); 79 });
70 }; 80 };
71 81
72 /** 82 /**
73 * @override 83 * @override
74 * @param {string} hostId 84 * @param {string} hostId
75 * @param {string} hostName 85 * @param {string} hostName
76 * @param {string} hostPublicKey 86 * @param {string} hostPublicKey
77 */ 87 */
78 remoting.MockHostListApi.prototype.put = 88 remoting.MockHostListApi.prototype.put =
79 function(hostId, hostName, hostPublicKey) { 89 function(hostId, hostName, hostPublicKey) {
80 /** @type {remoting.MockHostListApi} */ 90 /** @type {remoting.MockHostListApi} */
81 var that = this; 91 var that = this;
82 return new Promise(function(resolve, reject) { 92 return new Promise(function(resolve, reject) {
83 var onTokenValid = function() { 93 var onTokenValid = function() {
84 for (var i = 0; i < that.hosts.length; ++i) { 94 for (var i = 0; i < that.hosts.length; ++i) {
95 /** type {remoting.Host} */
85 var host = that.hosts[i]; 96 var host = that.hosts[i];
86 if (host.hostId == hostId) { 97 if (host.hostId == hostId) {
87 host.hostName = hostName; 98 host.hostName = hostName;
88 host.hostPublicKey = hostPublicKey; 99 host.hostPublicKey = hostPublicKey;
89 resolve(undefined); 100 resolve(undefined);
90 return; 101 return;
91 } 102 }
92 } 103 }
93 console.error('PUT request for unknown host: ' + hostId + 104 console.error('PUT request for unknown host: ' + hostId +
94 ' (' + hostName + ')'); 105 ' (' + hostName + ')');
(...skipping 27 matching lines...) Expand all
122 }); 133 });
123 }; 134 };
124 135
125 /** 136 /**
126 * @param {boolean} active 137 * @param {boolean} active
127 */ 138 */
128 remoting.MockHostListApi.setActive = function(active) { 139 remoting.MockHostListApi.setActive = function(active) {
129 remoting.HostListApi.setInstance( 140 remoting.HostListApi.setInstance(
130 active ? new remoting.MockHostListApi() : null); 141 active ? new remoting.MockHostListApi() : null);
131 }; 142 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/host_list_api_impl_unittest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698