| OLD | NEW |
| 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.components.signin.test.util; | 5 package org.chromium.components.signin.test.util; |
| 6 | 6 |
| 7 import android.accounts.Account; | 7 import android.accounts.Account; |
| 8 import android.accounts.AuthenticatorDescription; | 8 import android.accounts.AuthenticatorDescription; |
| 9 import android.app.Activity; | 9 import android.app.Activity; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 * | 32 * |
| 33 * If you want to auto-approve a given authtokentype, use addAccountHolderExplic
itly(...) with | 33 * If you want to auto-approve a given authtokentype, use addAccountHolderExplic
itly(...) with |
| 34 * an AccountHolder you have built with hasBeenAccepted("yourAuthTokenType", tru
e). | 34 * an AccountHolder you have built with hasBeenAccepted("yourAuthTokenType", tru
e). |
| 35 * | 35 * |
| 36 * If you want to auto-approve all auth token types for a given account, use the
{@link | 36 * If you want to auto-approve all auth token types for a given account, use the
{@link |
| 37 * AccountHolder} builder method alwaysAccept(true). | 37 * AccountHolder} builder method alwaysAccept(true). |
| 38 */ | 38 */ |
| 39 public class FakeAccountManagerDelegate implements AccountManagerDelegate { | 39 public class FakeAccountManagerDelegate implements AccountManagerDelegate { |
| 40 private static final String TAG = "FakeAccountManager"; | 40 private static final String TAG = "FakeAccountManager"; |
| 41 | 41 |
| 42 private final Context mContext; | |
| 43 private final Set<AccountHolder> mAccounts = new HashSet<>(); | 42 private final Set<AccountHolder> mAccounts = new HashSet<>(); |
| 44 | 43 |
| 45 @VisibleForTesting | 44 @VisibleForTesting |
| 46 public FakeAccountManagerDelegate(Context context, Account... accounts) { | 45 public FakeAccountManagerDelegate(Context context, Account... accounts) { |
| 47 mContext = context; | 46 this(accounts); |
| 47 } |
| 48 |
| 49 @VisibleForTesting |
| 50 public FakeAccountManagerDelegate(Account... accounts) { |
| 48 if (accounts != null) { | 51 if (accounts != null) { |
| 49 for (Account account : accounts) { | 52 for (Account account : accounts) { |
| 50 mAccounts.add(AccountHolder.builder(account).alwaysAccept(true).
build()); | 53 mAccounts.add(AccountHolder.builder(account).alwaysAccept(true).
build()); |
| 51 } | 54 } |
| 52 } | 55 } |
| 53 } | 56 } |
| 54 | 57 |
| 55 @Override | 58 @Override |
| 56 public Account[] getAccountsByType(String type) { | 59 public Account[] getAccountsByType(String type) { |
| 57 if (!AccountManagerHelper.GOOGLE_ACCOUNT_TYPE.equals(type)) { | 60 if (!AccountManagerHelper.GOOGLE_ACCOUNT_TYPE.equals(type)) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 throw new IllegalArgumentException("Account can not be null"); | 164 throw new IllegalArgumentException("Account can not be null"); |
| 162 } | 165 } |
| 163 for (AccountHolder accountHolder : mAccounts) { | 166 for (AccountHolder accountHolder : mAccounts) { |
| 164 if (account.equals(accountHolder.getAccount())) { | 167 if (account.equals(accountHolder.getAccount())) { |
| 165 return accountHolder; | 168 return accountHolder; |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 throw new IllegalArgumentException("Can not find AccountHolder for accou
nt " + account); | 171 throw new IllegalArgumentException("Can not find AccountHolder for accou
nt " + account); |
| 169 } | 172 } |
| 170 } | 173 } |
| OLD | NEW |