Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / remoting / webapp / browser_test / mock_host_list_api.js
blob2fca22060590987f9d501c88be255891823b639c
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
3 // found in the LICENSE file.
5 /**
6 * @fileoverview
7 * Mock implementation of remoting.HostList
8 */
10 'use strict';
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
15 /**
16 * @constructor
17 * @implements {remoting.HostListApi}
19 remoting.MockHostListApi = function() {
20 /** @type {Array<remoting.Host>} */
21 this.hosts = [
23 'hostName': 'Online host',
24 'hostId': 'online-host-id',
25 'status': 'ONLINE',
26 'jabberId': 'online-jid',
27 'publicKey': 'online-public-key',
28 'tokenUrlPatterns': [],
29 'updatedTime': new Date().toISOString()
32 'hostName': 'Offline host',
33 'hostId': 'offline-host-id',
34 'status': 'OFFLINE',
35 'jabberId': 'offline-jid',
36 'publicKey': 'offline-public-key',
37 'tokenUrlPatterns': [],
38 'updatedTime': new Date(1970, 1, 1).toISOString()
43 /**
44 * @param {function(Array<remoting.Host>):void} onDone
45 * @param {function(remoting.Error):void} onError
47 remoting.MockHostListApi.prototype.get = function(onDone, onError) {
48 remoting.mockIdentity.validateTokenAndCall(onDone, onError, [this.hosts]);
51 /**
52 * @param {string} hostId
53 * @param {string} hostName
54 * @param {string} hostPublicKey
55 * @param {function():void} onDone
56 * @param {function(remoting.Error):void} onError
58 remoting.MockHostListApi.prototype.put =
59 function(hostId, hostName, hostPublicKey, onDone, onError) {
60 /** @type {remoting.MockHostListApi} */
61 var that = this;
62 var onTokenValid = function() {
63 for (var i = 0; i < that.hosts.length; ++i) {
64 var host = that.hosts[i];
65 if (host.hostId == hostId) {
66 host.hostName = hostName;
67 host.hostPublicKey = hostPublicKey;
68 onDone();
69 return;
72 console.error('PUT request for unknown host: ' + hostId +
73 ' (' + hostName + ')');
74 onError(remoting.Error.UNEXPECTED);
76 remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []);
79 /**
80 * @param {string} hostId
81 * @param {function():void} onDone
82 * @param {function(remoting.Error):void} onError
84 remoting.MockHostListApi.prototype.remove =
85 function(hostId, onDone, onError) {
86 /** @type {remoting.MockHostListApi} */
87 var that = this;
88 var onTokenValid = function() {
89 for (var i = 0; i < that.hosts.length; ++i) {
90 var host = that.hosts[i];
91 if (host.hostId == hostId) {
92 that.hosts.splice(i, 1);
93 onDone();
94 return;
97 console.error('DELETE request for unknown host: ' + hostId);
98 onError(remoting.Error.UNEXPECTED);
100 remoting.mockIdentity.validateTokenAndCall(onTokenValid, onError, []);
104 * @param {boolean} active
106 remoting.MockHostListApi.setActive = function(active) {
107 remoting.hostListApi = active ? new remoting.MockHostListApi()
108 : new remoting.HostListApiImpl();