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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/signin/OAuth2TokenServiceIntegrationTest.java

Issue 1256283002: GAIA ID migration for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase & solve tests Created 5 years, 3 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.chrome.browser.signin; 5 package org.chromium.chrome.browser.signin;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.app.Activity;
9 import android.content.Context;
8 import android.test.UiThreadTest; 10 import android.test.UiThreadTest;
9 import android.test.suitebuilder.annotation.MediumTest; 11 import android.test.suitebuilder.annotation.MediumTest;
10 12
11 import org.chromium.base.ThreadUtils; 13 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.test.util.AdvancedMockContext; 14 import org.chromium.base.test.util.AdvancedMockContext;
13 import org.chromium.base.test.util.Feature; 15 import org.chromium.base.test.util.Feature;
14 import org.chromium.chrome.browser.profiles.Profile; 16 import org.chromium.chrome.browser.profiles.Profile;
15 import org.chromium.chrome.test.util.ApplicationData; 17 import org.chromium.chrome.test.util.ApplicationData;
16 import org.chromium.content.browser.test.NativeLibraryTestBase; 18 import org.chromium.content.browser.test.NativeLibraryTestBase;
17 import org.chromium.sync.signin.AccountManagerHelper; 19 import org.chromium.sync.signin.AccountManagerHelper;
(...skipping 20 matching lines...) Expand all
38 AccountHolder.create().account(TEST_ACCOUNT2).alwaysAccept(true).bui ld(); 40 AccountHolder.create().account(TEST_ACCOUNT2).alwaysAccept(true).bui ld();
39 41
40 private AdvancedMockContext mContext; 42 private AdvancedMockContext mContext;
41 private OAuth2TokenService mOAuth2TokenService; 43 private OAuth2TokenService mOAuth2TokenService;
42 private MockAccountManager mAccountManager; 44 private MockAccountManager mAccountManager;
43 private TestObserver mObserver; 45 private TestObserver mObserver;
44 private ChromeSigninController mChromeSigninController; 46 private ChromeSigninController mChromeSigninController;
45 47
46 @Override 48 @Override
47 protected void setUp() throws Exception { 49 protected void setUp() throws Exception {
50 mapAccountNamesToIds();
48 super.setUp(); 51 super.setUp();
49 ApplicationData.clearAppData(getInstrumentation().getTargetContext()); 52 ApplicationData.clearAppData(getInstrumentation().getTargetContext());
50 loadNativeLibraryAndInitBrowserProcess(); 53 loadNativeLibraryAndInitBrowserProcess();
51 54
52 // Set up AccountManager. 55 // Set up AccountManager.
53 mContext = new AdvancedMockContext(getInstrumentation().getTargetContext ()); 56 mContext = new AdvancedMockContext(getInstrumentation().getTargetContext ());
54 mAccountManager = new MockAccountManager(mContext, getInstrumentation(). getContext()); 57 mAccountManager = new MockAccountManager(mContext, getInstrumentation(). getContext());
55 AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAcc ountManager); 58 AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAcc ountManager);
56 59
57 // Make sure there is no account signed in yet. 60 // Make sure there is no account signed in yet.
58 mChromeSigninController = ChromeSigninController.get(mContext); 61 mChromeSigninController = ChromeSigninController.get(mContext);
59 mChromeSigninController.setSignedInAccountName(null); 62 mChromeSigninController.setSignedInAccountName(null);
60 63
64 // Seed test accounts to AccountTrackerService.
65 seedAccountTrackerService(mContext);
66
61 // Get a reference to the service. 67 // Get a reference to the service.
62 mOAuth2TokenService = getOAuth2TokenServiceOnUiThread(); 68 mOAuth2TokenService = getOAuth2TokenServiceOnUiThread();
63 69
64 // Set up observer. 70 // Set up observer.
65 mObserver = new TestObserver(); 71 mObserver = new TestObserver();
66 addObserver(mObserver); 72 addObserver(mObserver);
67 } 73 }
68 74
75 @Override
76 protected void tearDown() throws Exception {
77 mChromeSigninController.setSignedInAccountName(null);
78 super.tearDown();
79 }
80
81 private void mapAccountNamesToIds() {
82 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
83 @Override
84 public void run() {
85 AccountIdProvider.setInstanceForTest(new AccountIdProvider() {
86 @Override
87 public String getAccountId(Context ctx, String accountName) {
88 return "gaia-id-" + accountName;
89 }
90
91 @Override
92 public boolean canBeUsed(Context ctx, Activity activity) {
93 return true;
94 }
95 });
96 }
97 });
98 }
99
100 private void seedAccountTrackerService(Context context) {
nyquist 2015/09/11 00:42:52 Add final to this argument
101 final Context mContext = context;
nyquist 2015/09/11 00:42:52 remove this since it's not necessary. Also, for fu
102 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
103 @Override
104 public void run() {
105 AccountIdProvider provider = AccountIdProvider.getInstance();
106 String[] accountNames = {TEST_ACCOUNT1.name, TEST_ACCOUNT2.name} ;
107 String[] accountIds = {provider.getAccountId(mContext, accountNa mes[0]),
108 provider.getAccountId(mContext, accountNames[1])};
109 AccountTrackerService.get(mContext).syncForceRefreshForTest(
110 accountIds, accountNames);
111 }
112 });
113 }
114
69 /** 115 /**
70 * The {@link OAuth2TokenService} and the {@link Profile} can only be access ed from the UI 116 * The {@link OAuth2TokenService} and the {@link Profile} can only be access ed from the UI
71 * thread, so this helper method is a convenience method to retrieve it. 117 * thread, so this helper method is a convenience method to retrieve it.
72 * 118 *
73 * @return the OAuth2TokenService. 119 * @return the OAuth2TokenService.
74 */ 120 */
75 private static OAuth2TokenService getOAuth2TokenServiceOnUiThread() { 121 private static OAuth2TokenService getOAuth2TokenServiceOnUiThread() {
76 final AtomicReference<OAuth2TokenService> service = 122 final AtomicReference<OAuth2TokenService> service =
77 new AtomicReference<OAuth2TokenService>(); 123 new AtomicReference<OAuth2TokenService>();
78 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 124 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Adding an observer should not lead to a callback. 168 // Adding an observer should not lead to a callback.
123 assertEquals(0, mObserver.getRevokedCallCount()); 169 assertEquals(0, mObserver.getRevokedCallCount());
124 170
125 // An observer should be called with the correct account. 171 // An observer should be called with the correct account.
126 mOAuth2TokenService.fireRefreshTokenRevoked(TEST_ACCOUNT1); 172 mOAuth2TokenService.fireRefreshTokenRevoked(TEST_ACCOUNT1);
127 assertEquals(1, mObserver.getRevokedCallCount()); 173 assertEquals(1, mObserver.getRevokedCallCount());
128 assertEquals(TEST_ACCOUNT1, mObserver.getLastAccount()); 174 assertEquals(TEST_ACCOUNT1, mObserver.getLastAccount());
129 175
130 // When removed, an observer should not be called. 176 // When removed, an observer should not be called.
131 mOAuth2TokenService.removeObserver(mObserver); 177 mOAuth2TokenService.removeObserver(mObserver);
132 mOAuth2TokenService.fireRefreshTokenRevoked(TEST_ACCOUNT1); 178 mOAuth2TokenService.fireRefreshTokenRevoked(TEST_ACCOUNT2);
133 assertEquals(1, mObserver.getRevokedCallCount()); 179 assertEquals(1, mObserver.getRevokedCallCount());
134 180
135 // No other observer interface method should ever have been called. 181 // No other observer interface method should ever have been called.
136 assertEquals(0, mObserver.getAvailableCallCount()); 182 assertEquals(0, mObserver.getAvailableCallCount());
137 assertEquals(0, mObserver.getLoadedCallCount()); 183 assertEquals(0, mObserver.getLoadedCallCount());
138 } 184 }
139 185
140 @MediumTest 186 @MediumTest
141 @UiThreadTest 187 @UiThreadTest
142 @Feature({"Sync"}) 188 @Feature({"Sync"})
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 462
417 public int getLoadedCallCount() { 463 public int getLoadedCallCount() {
418 return mLoadedCallCount; 464 return mLoadedCallCount;
419 } 465 }
420 466
421 public Account getLastAccount() { 467 public Account getLastAccount() {
422 return mLastAccount; 468 return mLastAccount;
423 } 469 }
424 } 470 }
425 } 471 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698