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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/util/FeatureUtilitiesTest.java

Issue 2872743003: Change AccountManagerHelper initialization
Patch Set: Created 3 years, 7 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 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 package org.chromium.chrome.browser.util; 5 package org.chromium.chrome.browser.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.content.Context; 9 import android.content.Context;
10 import android.content.Intent; 10 import android.content.Intent;
11 import android.content.pm.ResolveInfo; 11 import android.content.pm.ResolveInfo;
12 import android.speech.RecognizerIntent; 12 import android.speech.RecognizerIntent;
13 import android.support.test.InstrumentationRegistry; 13 import android.support.test.InstrumentationRegistry;
14 import android.support.test.filters.SmallTest; 14 import android.support.test.filters.SmallTest;
15 import android.test.mock.MockContext; 15 import android.test.mock.MockContext;
16 import android.test.mock.MockPackageManager; 16 import android.test.mock.MockPackageManager;
17 17
18 import org.junit.After;
19 import org.junit.Assert; 18 import org.junit.Assert;
20 import org.junit.Before; 19 import org.junit.Before;
21 import org.junit.Test; 20 import org.junit.Test;
22 import org.junit.runner.RunWith; 21 import org.junit.runner.RunWith;
23 22
24 import org.chromium.base.ThreadUtils; 23 import org.chromium.base.ThreadUtils;
25 import org.chromium.base.test.util.AdvancedMockContext; 24 import org.chromium.base.test.util.AdvancedMockContext;
26 import org.chromium.base.test.util.Feature; 25 import org.chromium.base.test.util.Feature;
27 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; 26 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
28 import org.chromium.components.signin.AccountManagerHelper; 27 import org.chromium.components.signin.AccountManagerHelper;
(...skipping 25 matching lines...) Expand all
54 } 53 }
55 54
56 @Before 55 @Before
57 public void setUp() { 56 public void setUp() {
58 // GetInstrumentation().getTargetContext() cannot be called in 57 // GetInstrumentation().getTargetContext() cannot be called in
59 // constructor due to external dependencies. 58 // constructor due to external dependencies.
60 mAccountTestingContext = new AdvancedMockContext( 59 mAccountTestingContext = new AdvancedMockContext(
61 InstrumentationRegistry.getInstrumentation().getTargetContext()) ; 60 InstrumentationRegistry.getInstrumentation().getTargetContext()) ;
62 } 61 }
63 62
64 @After
65 public void tearDown() {
66 AccountManagerHelper.resetAccountManagerHelperForTests();
67 }
68
69 private static class IntentTestPackageManager extends MockPackageManager { 63 private static class IntentTestPackageManager extends MockPackageManager {
70 64
71 private final String mAction; 65 private final String mAction;
72 66
73 public IntentTestPackageManager(String recognizesAction) { 67 public IntentTestPackageManager(String recognizesAction) {
74 super(); 68 super();
75 mAction = recognizesAction; 69 mAction = recognizesAction;
76 } 70 }
77 71
78 @Override 72 @Override
(...skipping 24 matching lines...) Expand all
103 public IntentTestPackageManager getPackageManager() { 97 public IntentTestPackageManager getPackageManager() {
104 return new IntentTestPackageManager(mAction); 98 return new IntentTestPackageManager(mAction);
105 } 99 }
106 } 100 }
107 101
108 private static class FakeAuthenticationAccountManager extends FakeAccountMan agerDelegate { 102 private static class FakeAuthenticationAccountManager extends FakeAccountMan agerDelegate {
109 private final String mAccountType; 103 private final String mAccountType;
110 104
111 public FakeAuthenticationAccountManager( 105 public FakeAuthenticationAccountManager(
112 Context localContext, String accountType, Account... accounts) { 106 Context localContext, String accountType, Account... accounts) {
113 super(localContext, accounts); 107 super(accounts);
114 mAccountType = accountType; 108 mAccountType = accountType;
115 } 109 }
116 110
117 @Override 111 @Override
118 public Account[] getAccountsByType(String accountType) { 112 public Account[] getAccountsByType(String accountType) {
119 if (accountType.equals(mAccountType)) { 113 if (accountType.equals(mAccountType)) {
120 // Calling function uses length of array to determine if 114 // Calling function uses length of array to determine if
121 // accounts of the requested type are available, so return 115 // accounts of the requested type are available, so return
122 // a non-empty array to indicate the account type is correct. 116 // a non-empty array to indicate the account type is correct.
123 return new Account[] { AccountManagerHelper.createAccountFromNam e("Dummy") }; 117 return new Account[] { AccountManagerHelper.createAccountFromNam e("Dummy") };
(...skipping 22 matching lines...) Expand all
146 context, 140 context,
147 useCachedResult); 141 useCachedResult);
148 } 142 }
149 }); 143 });
150 } 144 }
151 145
152 private void setUpAccount(final String accountType) { 146 private void setUpAccount(final String accountType) {
153 mAccountManager = new FakeAuthenticationAccountManager( 147 mAccountManager = new FakeAuthenticationAccountManager(
154 mAccountTestingContext, accountType, mTestAccount); 148 mAccountTestingContext, accountType, mTestAccount);
155 149
156 AccountManagerHelper.overrideAccountManagerHelperForTests( 150 AccountManagerHelper.overrideAccountManagerHelperForTests(mAccountManage r);
157 mAccountTestingContext, mAccountManager);
158 } 151 }
159 152
160 @Test 153 @Test
161 @SmallTest 154 @SmallTest
162 @Feature({"FeatureUtilities", "Speech"}) 155 @Feature({"FeatureUtilities", "Speech"})
163 public void testSpeechFeatureAvailable() { 156 public void testSpeechFeatureAvailable() {
164 final boolean doNotUseCachedResult = false; 157 final boolean doNotUseCachedResult = false;
165 final boolean recognizesSpeech = isRecognitionIntentPresent( 158 final boolean recognizesSpeech = isRecognitionIntentPresent(
166 mContextWithSpeech, 159 mContextWithSpeech,
167 doNotUseCachedResult); 160 doNotUseCachedResult);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 mAccountTestingContext); 243 mAccountTestingContext);
251 244
252 Assert.assertFalse(hasAccounts); 245 Assert.assertFalse(hasAccounts);
253 246
254 boolean hasAuthenticator = FeatureUtilities.hasGoogleAccountAuthenticato r( 247 boolean hasAuthenticator = FeatureUtilities.hasGoogleAccountAuthenticato r(
255 mAccountTestingContext); 248 mAccountTestingContext);
256 249
257 Assert.assertFalse(hasAuthenticator); 250 Assert.assertFalse(hasAuthenticator);
258 } 251 }
259 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698