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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(onDone, onError, [this.hosts]); |
49 }; | 49 }; |
50 | 50 |
51 /** | 51 /** |
52 * @param {function():void} onDone | |
53 * @param {function(remoting.Error):void} onError | |
54 * @param {string} hostId | 52 * @param {string} hostId |
55 * @param {string} hostName | 53 * @param {string} hostName |
56 * @param {string} hostPublicKey | 54 * @param {string} hostPublicKey |
| 55 * @param {function():void} onDone |
| 56 * @param {function(remoting.Error):void} onError |
57 */ | 57 */ |
58 remoting.MockHostListApi.prototype.put = | 58 remoting.MockHostListApi.prototype.put = |
59 function(hostId, hostName, hostPublicKey, onDone, onError) { | 59 function(hostId, hostName, hostPublicKey, onDone, onError) { |
60 /** @type {remoting.MockHostListApi} */ | 60 /** @type {remoting.MockHostListApi} */ |
61 var that = this; | 61 var that = this; |
62 var onTokenValid = function() { | 62 var onTokenValid = function() { |
63 for (var i = 0; i < that.hosts.length; ++i) { | 63 for (var i = 0; i < that.hosts.length; ++i) { |
64 var host = that.hosts[i]; | 64 var host = that.hosts[i]; |
65 if (host.hostId == hostId) { | 65 if (host.hostId == hostId) { |
66 host.hostName = hostName; | 66 host.hostName = hostName; |
67 host.hostPublicKey = hostPublicKey; | 67 host.hostPublicKey = hostPublicKey; |
68 onDone(); | 68 onDone(); |
69 return; | 69 return; |
70 } | 70 } |
71 } | 71 } |
72 console.error('PUT request for unknown host: ' + hostId + | 72 console.error('PUT request for unknown host: ' + hostId + |
73 ' (' + hostName + ')'); | 73 ' (' + hostName + ')'); |
74 onError(remoting.Error.UNEXPECTED); | 74 onError(remoting.Error.UNEXPECTED); |
75 }; | 75 }; |
76 remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []); | 76 remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []); |
77 }; | 77 }; |
78 | 78 |
79 /** | 79 /** |
| 80 * @param {string} hostId |
80 * @param {function():void} onDone | 81 * @param {function():void} onDone |
81 * @param {function(remoting.Error):void} onError | 82 * @param {function(remoting.Error):void} onError |
82 * @param {string} hostId | |
83 */ | 83 */ |
84 remoting.MockHostListApi.prototype.remove = | 84 remoting.MockHostListApi.prototype.remove = |
85 function(hostId, onDone, onError) { | 85 function(hostId, onDone, onError) { |
86 /** @type {remoting.MockHostListApi} */ | 86 /** @type {remoting.MockHostListApi} */ |
87 var that = this; | 87 var that = this; |
88 var onTokenValid = function() { | 88 var onTokenValid = function() { |
89 for (var i = 0; i < that.hosts.length; ++i) { | 89 for (var i = 0; i < that.hosts.length; ++i) { |
90 var host = that.hosts[i]; | 90 var host = that.hosts[i]; |
91 if (host.hostId == hostId) { | 91 if (host.hostId == hostId) { |
92 that.hosts.splice(i, 1); | 92 that.hosts.splice(i, 1); |
93 onDone(); | 93 onDone(); |
94 return; | 94 return; |
95 } | 95 } |
96 } | 96 } |
97 console.error('DELETE request for unknown host: ' + hostId); | 97 console.error('DELETE request for unknown host: ' + hostId); |
98 onError(remoting.Error.UNEXPECTED); | 98 onError(remoting.Error.UNEXPECTED); |
99 }; | 99 }; |
100 remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []); | 100 remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []); |
101 }; | 101 }; |
102 | 102 |
103 /** | 103 /** |
104 * @param {boolean} active | 104 * @param {boolean} active |
105 */ | 105 */ |
106 remoting.MockHostListApi.setActive = function(active) { | 106 remoting.MockHostListApi.setActive = function(active) { |
107 remoting.hostListApi = active ? new remoting.MockHostListApi() | 107 remoting.hostListApi = active ? new remoting.MockHostListApi() |
108 : new remoting.HostListApiImpl(); | 108 : new remoting.HostListApiImpl(); |
109 }; | 109 }; |
OLD | NEW |