Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / remoting / webapp / browser_test / mock_identity.js
blob4a1c61bc4dc9522d8371cc18e27303d84516ea93
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 chrome.identity.
8 */
10 'use strict';
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
15 /**
16 * @constructor
18 remoting.MockIdentity = function() {
19 /**
20 * @type {remoting.MockIdentity.AccessToken}
21 * @private
23 this.accessToken_ = remoting.MockIdentity.AccessToken.NONE;
26 /**
27 * @param {Object} details
28 * @param {function(string)} callback
30 remoting.MockIdentity.prototype.getAuthToken = function(details, callback) {
31 window.setTimeout(callback.bind(null, this.accessToken_), 0);
34 /**
35 * @param {Object} details
36 * @param {function()} callback
38 remoting.MockIdentity.prototype.removeCachedAuthToken =
39 function(details, callback) {
40 window.setTimeout(callback, 0);
43 /**
44 * @param {Object} details
45 * @param {function()} callback
47 remoting.MockIdentity.prototype.launchWebAuthFlow =
48 function(details, callback) {
49 // TODO(jamiewalch): Work out how to test third-party auth.
50 console.error('No mock implementation for launchWebAuthFlow.');
54 /** @enum {string} */
55 remoting.MockIdentity.AccessToken = {
56 VALID: 'valid-token',
57 INVALID: 'invalid-token',
58 NONE: ''
61 /**
62 * @param {remoting.MockIdentity.AccessToken} accessToken
64 remoting.MockIdentity.prototype.setAccessToken = function(accessToken) {
65 this.accessToken_ = accessToken;
68 /**
69 * @param {string} token
70 * @param {Function} onDone
71 * @param {function(remoting.Error)} onError
72 * @param {Array<*>} values
74 remoting.MockIdentity.validateTokenAndCall =
75 function(token, onDone, onError, values) {
76 if (token == remoting.MockIdentity.AccessToken.VALID) {
77 window.setTimeout(
78 onDone.apply.bind(onDone, null, values),
79 0);
80 } else {
81 window.setTimeout(
82 onError.bind(null, remoting.Error.AUTHENTICATION_FAILED),
83 0);
87 /**
88 * @param {Function} onDone
89 * @param {function(remoting.Error)} onError
90 * @param {Array<*>} values
92 remoting.MockIdentity.prototype.validateTokenAndCall =
93 function(onDone, onError, values) {
94 remoting.MockIdentity.validateTokenAndCall(
95 this.accessToken_, onDone, onError, values);
98 /**
99 * @param {boolean} active
101 remoting.MockIdentity.setActive = function(active) {
102 chrome.identity = active ? remoting.mockIdentity
103 : remoting.savedIdentityApi;
106 /** @type {Object} */
107 remoting.savedIdentityApi = chrome.identity;
109 /** @type {remoting.MockIdentity} */
110 remoting.mockIdentity = new remoting.MockIdentity();