OLD | NEW |
---|---|
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 27 matching lines...) Expand all Loading... | |
38 'updatedTime': new Date(1970, 1, 1).toISOString() | 38 'updatedTime': new Date(1970, 1, 1).toISOString() |
39 } | 39 } |
40 ]; | 40 ]; |
41 }; | 41 }; |
42 | 42 |
43 /** | 43 /** |
44 * @param {function(Array.<remoting.Host>):void} onDone | 44 * @param {function(Array.<remoting.Host>):void} onDone |
45 * @param {function(remoting.Error):void} onError | 45 * @param {function(remoting.Error):void} onError |
46 */ | 46 */ |
47 remoting.MockHostListApi.prototype.get = function(onDone, onError) { | 47 remoting.MockHostListApi.prototype.get = function(onDone, onError) { |
48 remoting.mockIdentity.validateTokenAndCall(onDone, onError, [this.hosts]); | 48 remoting.mockIdentity.validateTokenAndCall( |
49 /** @type {function():void} */ (onDone), | |
Jamie
2015/02/18 00:51:33
This doesn't look right. Is the issue simply that
garykac
2015/02/18 02:06:49
Using @type {Function} on validateTokenAndCall mak
| |
50 /** @type {function():void} */ (onError), | |
Jamie
2015/02/18 00:51:33
IIRC, the error callback always has the same signa
garykac
2015/02/18 02:06:49
Done.
| |
51 [this.hosts]); | |
49 }; | 52 }; |
50 | 53 |
51 /** | 54 /** |
52 * @param {function():void} onDone | |
53 * @param {function(remoting.Error):void} onError | |
54 * @param {string} hostId | 55 * @param {string} hostId |
55 * @param {string} hostName | 56 * @param {string} hostName |
56 * @param {string} hostPublicKey | 57 * @param {string} hostPublicKey |
58 * @param {function():void} onDone | |
59 * @param {function(remoting.Error):void} onError | |
57 */ | 60 */ |
58 remoting.MockHostListApi.prototype.put = | 61 remoting.MockHostListApi.prototype.put = |
59 function(hostId, hostName, hostPublicKey, onDone, onError) { | 62 function(hostId, hostName, hostPublicKey, onDone, onError) { |
60 /** @type {remoting.MockHostListApi} */ | 63 /** @type {remoting.MockHostListApi} */ |
61 var that = this; | 64 var that = this; |
62 var onTokenValid = function() { | 65 var onTokenValid = function() { |
63 for (var i = 0; i < that.hosts.length; ++i) { | 66 for (var i = 0; i < that.hosts.length; ++i) { |
64 var host = that.hosts[i]; | 67 var host = that.hosts[i]; |
65 if (host.hostId == hostId) { | 68 if (host.hostId == hostId) { |
66 host.hostName = hostName; | 69 host.hostName = hostName; |
67 host.hostPublicKey = hostPublicKey; | 70 host.hostPublicKey = hostPublicKey; |
68 onDone(); | 71 onDone(); |
69 return; | 72 return; |
70 } | 73 } |
71 } | 74 } |
72 console.error('PUT request for unknown host: ' + hostId + | 75 console.error('PUT request for unknown host: ' + hostId + |
73 ' (' + hostName + ')'); | 76 ' (' + hostName + ')'); |
74 onError(remoting.Error.UNEXPECTED); | 77 onError(remoting.Error.UNEXPECTED); |
75 }; | 78 }; |
76 remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []); | 79 remoting.mockIdentity.validateTokenAndCall( |
80 onTokenValid, | |
81 /** @type {function():void} */ (onError), | |
82 []); | |
77 }; | 83 }; |
78 | 84 |
79 /** | 85 /** |
86 * @param {string} hostId | |
80 * @param {function():void} onDone | 87 * @param {function():void} onDone |
81 * @param {function(remoting.Error):void} onError | 88 * @param {function(remoting.Error):void} onError |
82 * @param {string} hostId | |
83 */ | 89 */ |
84 remoting.MockHostListApi.prototype.remove = | 90 remoting.MockHostListApi.prototype.remove = |
85 function(hostId, onDone, onError) { | 91 function(hostId, onDone, onError) { |
86 /** @type {remoting.MockHostListApi} */ | 92 /** @type {remoting.MockHostListApi} */ |
87 var that = this; | 93 var that = this; |
88 var onTokenValid = function() { | 94 var onTokenValid = function() { |
89 for (var i = 0; i < that.hosts.length; ++i) { | 95 for (var i = 0; i < that.hosts.length; ++i) { |
90 var host = that.hosts[i]; | 96 var host = that.hosts[i]; |
91 if (host.hostId == hostId) { | 97 if (host.hostId == hostId) { |
92 that.hosts.splice(i, 1); | 98 that.hosts.splice(i, 1); |
93 onDone(); | 99 onDone(); |
94 return; | 100 return; |
95 } | 101 } |
96 } | 102 } |
97 console.error('DELETE request for unknown host: ' + hostId); | 103 console.error('DELETE request for unknown host: ' + hostId); |
98 onError(remoting.Error.UNEXPECTED); | 104 onError(remoting.Error.UNEXPECTED); |
99 }; | 105 }; |
100 remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []); | 106 remoting.mockIdentity.validateTokenAndCall( |
107 onTokenValid, | |
108 /** @type {function():void} */ (onError), | |
109 []); | |
101 }; | 110 }; |
102 | 111 |
103 /** | 112 /** |
104 * @param {boolean} active | 113 * @param {boolean} active |
105 */ | 114 */ |
106 remoting.MockHostListApi.setActive = function(active) { | 115 remoting.MockHostListApi.setActive = function(active) { |
107 remoting.hostListApi = active ? new remoting.MockHostListApi() | 116 remoting.hostListApi = active ? new remoting.MockHostListApi() |
108 : new remoting.HostListApiImpl(); | 117 : new remoting.HostListApiImpl(); |
109 }; | 118 }; |
OLD | NEW |