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

Side by Side Diff: components/sync/test/android/javatests/src/org/chromium/components/sync/test/util/AccountHolder.java

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 package org.chromium.sync.test.util; 5 package org.chromium.components.sync.test.util;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.os.Handler; 8 import android.os.Handler;
9 9
10 import java.util.ArrayList; 10 import java.util.ArrayList;
11 import java.util.HashMap; 11 import java.util.HashMap;
12 import java.util.HashSet; 12 import java.util.HashSet;
13 import java.util.List; 13 import java.util.List;
14 import java.util.Map; 14 import java.util.Map;
15 import java.util.Set; 15 import java.util.Set;
16 16
17 import javax.annotation.Nullable; 17 import javax.annotation.Nullable;
18 18
19 /** 19 /**
20 * This class is used by the {@link MockAccountManager} to hold information abou t a given 20 * This class is used by the {@link MockAccountManager} to hold information abou t a given
21 * account, such as its password and set of granted auth tokens. 21 * account, such as its password and set of granted auth tokens.
22 */ 22 */
23 public class AccountHolder { 23 public class AccountHolder {
24
25 private final Account mAccount; 24 private final Account mAccount;
26 25
27 private final String mPassword; 26 private final String mPassword;
28 27
29 private final Map<String, String> mAuthTokens; 28 private final Map<String, String> mAuthTokens;
30 29
31 private final Map<String, Boolean> mHasBeenAccepted; 30 private final Map<String, Boolean> mHasBeenAccepted;
32 31
33 private final boolean mAlwaysAccept; 32 private final boolean mAlwaysAccept;
34 33
35 private Set<String> mFeatures; 34 private Set<String> mFeatures;
36 35
37 private final List<Runnable> mFeatureCallbacks = new ArrayList<>(); 36 private final List<Runnable> mFeatureCallbacks = new ArrayList<>();
38 37
39 private AccountHolder(Account account, String password, Map<String, String> authTokens, 38 private AccountHolder(Account account, String password, Map<String, String> authTokens,
40 Map<String, Boolean> hasBeenAccepted, boolean alwaysAccept, 39 Map<String, Boolean> hasBeenAccepted, boolean alwaysAccept,
41 @Nullable Set<String> features) { 40 @Nullable Set<String> features) {
42 if (account == null) { 41 if (account == null) {
43 throw new IllegalArgumentException("Account can not be null"); 42 throw new IllegalArgumentException("Account can not be null");
44 } 43 }
45 mAccount = account; 44 mAccount = account;
46 mPassword = password; 45 mPassword = password;
47 mAuthTokens = authTokens == null ? new HashMap<String, String>() : authT okens; 46 mAuthTokens = authTokens == null ? new HashMap<String, String>() : authT okens;
48 mHasBeenAccepted = hasBeenAccepted == null 47 mHasBeenAccepted =
49 ? new HashMap<String, Boolean>() : hasBeenAccepted; 48 hasBeenAccepted == null ? new HashMap<String, Boolean>() : hasBe enAccepted;
50 mAlwaysAccept = alwaysAccept; 49 mAlwaysAccept = alwaysAccept;
51 mFeatures = features; 50 mFeatures = features;
52 } 51 }
53 52
54 public Account getAccount() { 53 public Account getAccount() {
55 return mAccount; 54 return mAccount;
56 } 55 }
57 56
58 public String getPassword() { 57 public String getPassword() {
59 return mPassword; 58 return mPassword;
60 } 59 }
61 60
62 public boolean hasAuthTokenRegistered(String authTokenType) { 61 public boolean hasAuthTokenRegistered(String authTokenType) {
63 return mAuthTokens.containsKey(authTokenType); 62 return mAuthTokens.containsKey(authTokenType);
64 } 63 }
65 64
66 public String getAuthToken(String authTokenType) { 65 public String getAuthToken(String authTokenType) {
67 return mAuthTokens.get(authTokenType); 66 return mAuthTokens.get(authTokenType);
68 } 67 }
69 68
70 public boolean hasBeenAccepted(String authTokenType) { 69 public boolean hasBeenAccepted(String authTokenType) {
71 return mAlwaysAccept || mHasBeenAccepted.containsKey(authTokenType) 70 return mAlwaysAccept
71 || mHasBeenAccepted.containsKey(authTokenType)
72 && mHasBeenAccepted.get(authTokenType); 72 && mHasBeenAccepted.get(authTokenType);
73 } 73 }
74 74
75 /** 75 /**
76 * Removes an auth token from the auth token map. 76 * Removes an auth token from the auth token map.
77 * 77 *
78 * @param authToken the auth token to remove 78 * @param authToken the auth token to remove
79 * @return true if the auth token was found 79 * @return true if the auth token was found
80 */ 80 */
81 public boolean removeAuthToken(String authToken) { 81 public boolean removeAuthToken(String authToken) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 public AccountHolder withHasBeenAccepted(String authTokenType, boolean hasBe enAccepted) { 164 public AccountHolder withHasBeenAccepted(String authTokenType, boolean hasBe enAccepted) {
165 return copy().hasBeenAccepted(authTokenType, hasBeenAccepted).build(); 165 return copy().hasBeenAccepted(authTokenType, hasBeenAccepted).build();
166 } 166 }
167 167
168 public AccountHolder withAlwaysAccept(boolean alwaysAccept) { 168 public AccountHolder withAlwaysAccept(boolean alwaysAccept) {
169 return copy().alwaysAccept(alwaysAccept).build(); 169 return copy().alwaysAccept(alwaysAccept).build();
170 } 170 }
171 171
172 private Builder copy() { 172 private Builder copy() {
173 return create().account(mAccount).password(mPassword).authTokens(mAuthTo kens) 173 return create()
174 .hasBeenAcceptedMap(mHasBeenAccepted).alwaysAccept(mAlwaysAccept ); 174 .account(mAccount)
175 .password(mPassword)
176 .authTokens(mAuthTokens)
177 .hasBeenAcceptedMap(mHasBeenAccepted)
178 .alwaysAccept(mAlwaysAccept);
175 } 179 }
176 180
177 /** 181 /**
178 * Used to construct AccountHolder instances. 182 * Used to construct AccountHolder instances.
179 */ 183 */
180 public static class Builder { 184 public static class Builder {
181
182 private Account mTempAccount; 185 private Account mTempAccount;
183 186
184 private String mTempPassword; 187 private String mTempPassword;
185 188
186 private Map<String, String> mTempAuthTokens; 189 private Map<String, String> mTempAuthTokens;
187 190
188 private Map<String, Boolean> mTempHasBeenAccepted; 191 private Map<String, Boolean> mTempHasBeenAccepted;
189 192
190 private boolean mTempAlwaysAccept; 193 private boolean mTempAlwaysAccept;
191 194
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 public Builder featureSet(Set<String> features) { 255 public Builder featureSet(Set<String> features) {
253 mFeatures = features; 256 mFeatures = features;
254 return this; 257 return this;
255 } 258 }
256 259
257 public AccountHolder build() { 260 public AccountHolder build() {
258 return new AccountHolder(mTempAccount, mTempPassword, mTempAuthToken s, 261 return new AccountHolder(mTempAccount, mTempPassword, mTempAuthToken s,
259 mTempHasBeenAccepted, mTempAlwaysAccept, mFeatures); 262 mTempHasBeenAccepted, mTempAlwaysAccept, mFeatures);
260 } 263 }
261 } 264 }
262
263 } 265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698