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

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

Issue 2800833003: Revert of Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Created 3 years, 8 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.content.Context; 8 import android.content.Context;
9 import android.support.test.InstrumentationRegistry; 9 import android.support.test.InstrumentationRegistry;
10 import android.support.test.filters.MediumTest; 10 import android.support.test.filters.MediumTest;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 mActivityTestRule.loadNativeLibraryAndInitBrowserProcess(); 68 mActivityTestRule.loadNativeLibraryAndInitBrowserProcess();
69 69
70 // Set up AccountManager. 70 // Set up AccountManager.
71 mContext = new AdvancedMockContext( 71 mContext = new AdvancedMockContext(
72 InstrumentationRegistry.getInstrumentation().getTargetContext()) ; 72 InstrumentationRegistry.getInstrumentation().getTargetContext()) ;
73 mAccountManager = new MockAccountManager( 73 mAccountManager = new MockAccountManager(
74 mContext, InstrumentationRegistry.getInstrumentation().getContex t()); 74 mContext, InstrumentationRegistry.getInstrumentation().getContex t());
75 AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAcc ountManager); 75 AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAcc ountManager);
76 76
77 // Make sure there is no account signed in yet. 77 // Make sure there is no account signed in yet.
78 mChromeSigninController = ChromeSigninController.get(); 78 mChromeSigninController = ChromeSigninController.get(mContext);
79 mChromeSigninController.setSignedInAccountName(null); 79 mChromeSigninController.setSignedInAccountName(null);
80 80
81 // Seed test accounts to AccountTrackerService. 81 // Seed test accounts to AccountTrackerService.
82 seedAccountTrackerService(mContext); 82 seedAccountTrackerService(mContext);
83 83
84 // Get a reference to the service. 84 // Get a reference to the service.
85 mOAuth2TokenService = getOAuth2TokenServiceOnUiThread(); 85 mOAuth2TokenService = getOAuth2TokenServiceOnUiThread();
86 86
87 // Set up observer. 87 // Set up observer.
88 mObserver = new TestObserver(); 88 mObserver = new TestObserver();
89 addObserver(mObserver); 89 addObserver(mObserver);
90 } 90 }
91 91
92 @After 92 @After
93 public void tearDown() throws Exception { 93 public void tearDown() throws Exception {
94 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 94 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
95 @Override 95 @Override
96 public void run() { 96 public void run() {
97 mChromeSigninController.setSignedInAccountName(null); 97 mChromeSigninController.setSignedInAccountName(null);
98 mOAuth2TokenService.validateAccounts(false); 98 mOAuth2TokenService.validateAccounts(mContext, false);
99 } 99 }
100 }); 100 });
101 } 101 }
102 102
103 private void mapAccountNamesToIds() { 103 private void mapAccountNamesToIds() {
104 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 104 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
105 @Override 105 @Override
106 public void run() { 106 public void run() {
107 AccountIdProvider.setInstanceForTest(new AccountIdProvider() { 107 AccountIdProvider.setInstanceForTest(new AccountIdProvider() {
108 @Override 108 @Override
109 public String getAccountId(String accountName) { 109 public String getAccountId(Context ctx, String accountName) {
110 return "gaia-id-" + accountName; 110 return "gaia-id-" + accountName;
111 } 111 }
112 112
113 @Override 113 @Override
114 public boolean canBeUsed() { 114 public boolean canBeUsed(Context ctx) {
115 return true; 115 return true;
116 } 116 }
117 }); 117 });
118 } 118 }
119 }); 119 });
120 } 120 }
121 121
122 private void seedAccountTrackerService(final Context context) { 122 private void seedAccountTrackerService(final Context context) {
123 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 123 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
124 @Override 124 @Override
125 public void run() { 125 public void run() {
126 AccountIdProvider provider = AccountIdProvider.getInstance(); 126 AccountIdProvider provider = AccountIdProvider.getInstance();
127 String[] accountNames = {TEST_ACCOUNT1.name, TEST_ACCOUNT2.name} ; 127 String[] accountNames = {TEST_ACCOUNT1.name, TEST_ACCOUNT2.name} ;
128 String[] accountIds = {provider.getAccountId(accountNames[0]), 128 String[] accountIds = {provider.getAccountId(context, accountNam es[0]),
129 provider.getAccountId(accountNames[1])}; 129 provider.getAccountId(context, accountNames[1])};
130 AccountTrackerService.get().syncForceRefreshForTest(accountIds, accountNames); 130 AccountTrackerService.get(context).syncForceRefreshForTest(
131 accountIds, accountNames);
131 } 132 }
132 }); 133 });
133 } 134 }
134 135
135 /** 136 /**
136 * The {@link OAuth2TokenService} and the {@link Profile} can only be access ed from the UI 137 * The {@link OAuth2TokenService} and the {@link Profile} can only be access ed from the UI
137 * thread, so this helper method is a convenience method to retrieve it. 138 * thread, so this helper method is a convenience method to retrieve it.
138 * 139 *
139 * @return the OAuth2TokenService. 140 * @return the OAuth2TokenService.
140 */ 141 */
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 }); 237 });
237 } 238 }
238 239
239 @Test 240 @Test
240 @MediumTest 241 @MediumTest
241 public void testValidateAccountsNoAccountsRegisteredAndNoSignedInUser() thro ws Throwable { 242 public void testValidateAccountsNoAccountsRegisteredAndNoSignedInUser() thro ws Throwable {
242 mUiThreadTestRule.runOnUiThread(new Runnable() { 243 mUiThreadTestRule.runOnUiThread(new Runnable() {
243 @Override 244 @Override
244 public void run() { 245 public void run() {
245 // Run test. 246 // Run test.
246 mOAuth2TokenService.validateAccounts(false); 247 mOAuth2TokenService.validateAccounts(mContext, false);
247 248
248 // Ensure no calls have been made to the observer. 249 // Ensure no calls have been made to the observer.
249 Assert.assertEquals(0, mObserver.getAvailableCallCount()); 250 Assert.assertEquals(0, mObserver.getAvailableCallCount());
250 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 251 Assert.assertEquals(0, mObserver.getRevokedCallCount());
251 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 252 Assert.assertEquals(0, mObserver.getLoadedCallCount());
252 } 253 }
253 }); 254 });
254 } 255 }
255 256
256 @Test 257 @Test
257 @MediumTest 258 @MediumTest
258 public void testValidateAccountsOneAccountsRegisteredAndNoSignedInUser() thr ows Throwable { 259 public void testValidateAccountsOneAccountsRegisteredAndNoSignedInUser() thr ows Throwable {
259 mUiThreadTestRule.runOnUiThread(new Runnable() { 260 mUiThreadTestRule.runOnUiThread(new Runnable() {
260 @Override 261 @Override
261 public void run() { 262 public void run() {
262 // Add account. 263 // Add account.
263 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 ); 264 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 );
264 265
265 // Run test. 266 // Run test.
266 mOAuth2TokenService.validateAccounts(false); 267 mOAuth2TokenService.validateAccounts(mContext, false);
267 268
268 // Ensure no calls have been made to the observer. 269 // Ensure no calls have been made to the observer.
269 Assert.assertEquals(0, mObserver.getAvailableCallCount()); 270 Assert.assertEquals(0, mObserver.getAvailableCallCount());
270 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 271 Assert.assertEquals(0, mObserver.getRevokedCallCount());
271 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 272 Assert.assertEquals(0, mObserver.getLoadedCallCount());
272 } 273 }
273 }); 274 });
274 } 275 }
275 276
276 @Test 277 @Test
277 @MediumTest 278 @MediumTest
278 public void testValidateAccountsOneAccountsRegisteredSignedIn() throws Throw able { 279 public void testValidateAccountsOneAccountsRegisteredSignedIn() throws Throw able {
279 mUiThreadTestRule.runOnUiThread(new Runnable() { 280 mUiThreadTestRule.runOnUiThread(new Runnable() {
280 @Override 281 @Override
281 public void run() { 282 public void run() {
282 // Add account. 283 // Add account.
283 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 ); 284 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 );
284 285
285 // Mark user as signed in. 286 // Mark user as signed in.
286 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 287 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
287 288
288 // Run test. 289 // Run test.
289 mOAuth2TokenService.validateAccounts(false); 290 mOAuth2TokenService.validateAccounts(mContext, false);
290 291
291 // Ensure one call for the signed in account. 292 // Ensure one call for the signed in account.
292 Assert.assertEquals(1, mObserver.getAvailableCallCount()); 293 Assert.assertEquals(1, mObserver.getAvailableCallCount());
293 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 294 Assert.assertEquals(0, mObserver.getRevokedCallCount());
294 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 295 Assert.assertEquals(0, mObserver.getLoadedCallCount());
295 296
296 // Validate again and make sure no new calls are made. 297 // Validate again and make sure no new calls are made.
297 mOAuth2TokenService.validateAccounts(false); 298 mOAuth2TokenService.validateAccounts(mContext, false);
298 Assert.assertEquals(1, mObserver.getAvailableCallCount()); 299 Assert.assertEquals(1, mObserver.getAvailableCallCount());
299 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 300 Assert.assertEquals(0, mObserver.getRevokedCallCount());
300 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 301 Assert.assertEquals(0, mObserver.getLoadedCallCount());
301 302
302 // Validate again with force notifications and make sure one new calls is made. 303 // Validate again with force notifications and make sure one new calls is made.
303 mOAuth2TokenService.validateAccounts(true); 304 mOAuth2TokenService.validateAccounts(mContext, true);
304 Assert.assertEquals(2, mObserver.getAvailableCallCount()); 305 Assert.assertEquals(2, mObserver.getAvailableCallCount());
305 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 306 Assert.assertEquals(0, mObserver.getRevokedCallCount());
306 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 307 Assert.assertEquals(0, mObserver.getLoadedCallCount());
307 } 308 }
308 }); 309 });
309 } 310 }
310 311
311 @Test 312 @Test
312 @MediumTest 313 @MediumTest
313 public void testValidateAccountsSingleAccountWithoutChanges() throws Throwab le { 314 public void testValidateAccountsSingleAccountWithoutChanges() throws Throwab le {
314 mUiThreadTestRule.runOnUiThread(new Runnable() { 315 mUiThreadTestRule.runOnUiThread(new Runnable() {
315 @Override 316 @Override
316 public void run() { 317 public void run() {
317 // Add account. 318 // Add account.
318 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 ); 319 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 );
319 320
320 // Mark user as signed in. 321 // Mark user as signed in.
321 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 322 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
322 323
323 // Run one validation. 324 // Run one validation.
324 mOAuth2TokenService.validateAccounts(false); 325 mOAuth2TokenService.validateAccounts(mContext, false);
325 Assert.assertEquals(1, mObserver.getAvailableCallCount()); 326 Assert.assertEquals(1, mObserver.getAvailableCallCount());
326 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 327 Assert.assertEquals(0, mObserver.getRevokedCallCount());
327 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 328 Assert.assertEquals(0, mObserver.getLoadedCallCount());
328 329
329 // Re-run validation. 330 // Re-run validation.
330 mOAuth2TokenService.validateAccounts(false); 331 mOAuth2TokenService.validateAccounts(mContext, false);
331 Assert.assertEquals(1, mObserver.getAvailableCallCount()); 332 Assert.assertEquals(1, mObserver.getAvailableCallCount());
332 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 333 Assert.assertEquals(0, mObserver.getRevokedCallCount());
333 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 334 Assert.assertEquals(0, mObserver.getLoadedCallCount());
334 } 335 }
335 }); 336 });
336 } 337 }
337 338
338 @Test 339 @Test
339 @MediumTest 340 @MediumTest
340 public void testValidateAccountsSingleAccountThenAddOne() throws Throwable { 341 public void testValidateAccountsSingleAccountThenAddOne() throws Throwable {
341 mUiThreadTestRule.runOnUiThread(new Runnable() { 342 mUiThreadTestRule.runOnUiThread(new Runnable() {
342 @Override 343 @Override
343 public void run() { 344 public void run() {
344 // Add account. 345 // Add account.
345 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 ); 346 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 );
346 347
347 // Mark user as signed in. 348 // Mark user as signed in.
348 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 349 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
349 350
350 // Run one validation. 351 // Run one validation.
351 mOAuth2TokenService.validateAccounts(false); 352 mOAuth2TokenService.validateAccounts(mContext, false);
352 Assert.assertEquals(1, mObserver.getAvailableCallCount()); 353 Assert.assertEquals(1, mObserver.getAvailableCallCount());
353 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 354 Assert.assertEquals(0, mObserver.getRevokedCallCount());
354 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 355 Assert.assertEquals(0, mObserver.getLoadedCallCount());
355 356
356 // Add another account. 357 // Add another account.
357 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 ); 358 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 );
358 359
359 // Seed AccountTrackerService again since accounts changed after last validation. 360 // Seed AccountTrackerService again since accounts changed after last validation.
360 seedAccountTrackerService(mContext); 361 seedAccountTrackerService(mContext);
361 362
362 // Re-run validation. 363 // Re-run validation.
363 mOAuth2TokenService.validateAccounts(false); 364 mOAuth2TokenService.validateAccounts(mContext, false);
364 Assert.assertEquals(2, mObserver.getAvailableCallCount()); 365 Assert.assertEquals(2, mObserver.getAvailableCallCount());
365 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 366 Assert.assertEquals(0, mObserver.getRevokedCallCount());
366 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 367 Assert.assertEquals(0, mObserver.getLoadedCallCount());
367 } 368 }
368 }); 369 });
369 } 370 }
370 371
371 @Test 372 @Test
372 @MediumTest 373 @MediumTest
373 public void testValidateAccountsTwoAccountsThenRemoveOne() throws Throwable { 374 public void testValidateAccountsTwoAccountsThenRemoveOne() throws Throwable {
374 mUiThreadTestRule.runOnUiThread(new Runnable() { 375 mUiThreadTestRule.runOnUiThread(new Runnable() {
375 @Override 376 @Override
376 public void run() { 377 public void run() {
377 // Add accounts. 378 // Add accounts.
378 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 ); 379 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 );
379 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 ); 380 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 );
380 381
381 // Mark user as signed in. 382 // Mark user as signed in.
382 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 383 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
383 384
384 // Run one validation. 385 // Run one validation.
385 mOAuth2TokenService.validateAccounts(false); 386 mOAuth2TokenService.validateAccounts(mContext, false);
386 Assert.assertEquals(2, mObserver.getAvailableCallCount()); 387 Assert.assertEquals(2, mObserver.getAvailableCallCount());
387 388
388 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_2); 389 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_2);
389 mOAuth2TokenService.validateAccounts(false); 390 mOAuth2TokenService.validateAccounts(mContext, false);
390 391
391 Assert.assertEquals(2, mObserver.getAvailableCallCount()); 392 Assert.assertEquals(2, mObserver.getAvailableCallCount());
392 Assert.assertEquals(1, mObserver.getRevokedCallCount()); 393 Assert.assertEquals(1, mObserver.getRevokedCallCount());
393 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 394 Assert.assertEquals(0, mObserver.getLoadedCallCount());
394 } 395 }
395 }); 396 });
396 } 397 }
397 398
398 @Test 399 @Test
399 @MediumTest 400 @MediumTest
400 public void testValidateAccountsTwoAccountsThenRemoveAll() throws Throwable { 401 public void testValidateAccountsTwoAccountsThenRemoveAll() throws Throwable {
401 mUiThreadTestRule.runOnUiThread(new Runnable() { 402 mUiThreadTestRule.runOnUiThread(new Runnable() {
402 @Override 403 @Override
403 public void run() { 404 public void run() {
404 // Add accounts. 405 // Add accounts.
405 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 ); 406 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 );
406 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 ); 407 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 );
407 408
408 // Mark user as signed in. 409 // Mark user as signed in.
409 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 410 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
410 411
411 mOAuth2TokenService.validateAccounts(false); 412 mOAuth2TokenService.validateAccounts(mContext, false);
412 Assert.assertEquals(2, mObserver.getAvailableCallCount()); 413 Assert.assertEquals(2, mObserver.getAvailableCallCount());
413 414
414 // Remove all. 415 // Remove all.
415 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_1); 416 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_1);
416 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_2); 417 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_2);
417 418
418 // Re-validate and run checks. 419 // Re-validate and run checks.
419 mOAuth2TokenService.validateAccounts(false); 420 mOAuth2TokenService.validateAccounts(mContext, false);
420 Assert.assertEquals(2, mObserver.getRevokedCallCount()); 421 Assert.assertEquals(2, mObserver.getRevokedCallCount());
421 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 422 Assert.assertEquals(0, mObserver.getLoadedCallCount());
422 } 423 }
423 }); 424 });
424 } 425 }
425 426
426 @Test 427 @Test
427 @MediumTest 428 @MediumTest
428 @RetryOnFailure 429 @RetryOnFailure
429 public void testValidateAccountsTwoAccountsThenRemoveAllSignOut() throws Thr owable { 430 public void testValidateAccountsTwoAccountsThenRemoveAllSignOut() throws Thr owable {
430 mUiThreadTestRule.runOnUiThread(new Runnable() { 431 mUiThreadTestRule.runOnUiThread(new Runnable() {
431 @Override 432 @Override
432 public void run() { 433 public void run() {
433 // Add accounts. 434 // Add accounts.
434 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 ); 435 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 );
435 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 ); 436 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 );
436 437
437 // Mark user as signed in. 438 // Mark user as signed in.
438 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 439 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
439 440
440 mOAuth2TokenService.validateAccounts(false); 441 mOAuth2TokenService.validateAccounts(mContext, false);
441 Assert.assertEquals(2, mObserver.getAvailableCallCount()); 442 Assert.assertEquals(2, mObserver.getAvailableCallCount());
442 443
443 // Remove all. 444 // Remove all.
444 mChromeSigninController.setSignedInAccountName(null); 445 mChromeSigninController.setSignedInAccountName(null);
445 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_1); 446 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_1);
446 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_2); 447 mAccountManager.removeAccountHolderExplicitly(TEST_ACCOUNT_HOLDE R_2);
447 448
448 // Re-validate and run checks. 449 // Re-validate and run checks.
449 mOAuth2TokenService.validateAccounts(false); 450 mOAuth2TokenService.validateAccounts(mContext, false);
450 Assert.assertEquals(2, mObserver.getRevokedCallCount()); 451 Assert.assertEquals(2, mObserver.getRevokedCallCount());
451 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 452 Assert.assertEquals(0, mObserver.getLoadedCallCount());
452 } 453 }
453 }); 454 });
454 } 455 }
455 456
456 @Test 457 @Test
457 @MediumTest 458 @MediumTest
458 public void testValidateAccountsTwoAccountsRegisteredAndOneSignedIn() throws Throwable { 459 public void testValidateAccountsTwoAccountsRegisteredAndOneSignedIn() throws Throwable {
459 mUiThreadTestRule.runOnUiThread(new Runnable() { 460 mUiThreadTestRule.runOnUiThread(new Runnable() {
460 @Override 461 @Override
461 public void run() { 462 public void run() {
462 // Add accounts. 463 // Add accounts.
463 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 ); 464 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_1 );
464 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 ); 465 mAccountManager.addAccountHolderExplicitly(TEST_ACCOUNT_HOLDER_2 );
465 466
466 // Mark user as signed in. 467 // Mark user as signed in.
467 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 468 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
468 469
469 // Run test. 470 // Run test.
470 mOAuth2TokenService.validateAccounts(false); 471 mOAuth2TokenService.validateAccounts(mContext, false);
471 472
472 // All accounts will be notified. It is up to the observer 473 // All accounts will be notified. It is up to the observer
473 // to design if any action is needed. 474 // to design if any action is needed.
474 Assert.assertEquals(2, mObserver.getAvailableCallCount()); 475 Assert.assertEquals(2, mObserver.getAvailableCallCount());
475 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 476 Assert.assertEquals(0, mObserver.getRevokedCallCount());
476 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 477 Assert.assertEquals(0, mObserver.getLoadedCallCount());
477 } 478 }
478 }); 479 });
479 } 480 }
480 481
481 @Test 482 @Test
482 @MediumTest 483 @MediumTest
483 public void testValidateAccountsNoAccountsRegisteredButSignedIn() throws Thr owable { 484 public void testValidateAccountsNoAccountsRegisteredButSignedIn() throws Thr owable {
484 mUiThreadTestRule.runOnUiThread(new Runnable() { 485 mUiThreadTestRule.runOnUiThread(new Runnable() {
485 @Override 486 @Override
486 public void run() { 487 public void run() {
487 // Mark user as signed in without setting up the account. 488 // Mark user as signed in without setting up the account.
488 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 489 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
489 490
490 // Run test. 491 // Run test.
491 mOAuth2TokenService.validateAccounts(false); 492 mOAuth2TokenService.validateAccounts(mContext, false);
492 493
493 // Ensure no calls have been made to the observer. 494 // Ensure no calls have been made to the observer.
494 Assert.assertEquals(0, mObserver.getAvailableCallCount()); 495 Assert.assertEquals(0, mObserver.getAvailableCallCount());
495 Assert.assertEquals(0, mObserver.getRevokedCallCount()); 496 Assert.assertEquals(0, mObserver.getRevokedCallCount());
496 Assert.assertEquals(0, mObserver.getLoadedCallCount()); 497 Assert.assertEquals(0, mObserver.getLoadedCallCount());
497 } 498 }
498 }); 499 });
499 } 500 }
500 501
501 @Test 502 @Test
502 @MediumTest 503 @MediumTest
503 public void testValidateAccountsFiresEventAtTheEnd() throws Throwable { 504 public void testValidateAccountsFiresEventAtTheEnd() throws Throwable {
504 mUiThreadTestRule.runOnUiThread(new Runnable() { 505 mUiThreadTestRule.runOnUiThread(new Runnable() {
505 @Override 506 @Override
506 public void run() { 507 public void run() {
507 // Mark user as signed in without setting up the account. 508 // Mark user as signed in without setting up the account.
508 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e); 509 mChromeSigninController.setSignedInAccountName(TEST_ACCOUNT1.nam e);
509 TestObserver ob = new TestObserver() { 510 TestObserver ob = new TestObserver() {
510 @Override 511 @Override
511 public void onRefreshTokenAvailable(Account account) { 512 public void onRefreshTokenAvailable(Account account) {
512 super.onRefreshTokenAvailable(account); 513 super.onRefreshTokenAvailable(account);
513 Assert.assertEquals(1, OAuth2TokenService.getAccounts(). length); 514 Assert.assertEquals(1, OAuth2TokenService.getAccounts(mC ontext).length);
514 } 515 }
515 }; 516 };
516 517
517 addObserver(ob); 518 addObserver(ob);
518 mOAuth2TokenService.validateAccounts(false); 519 mOAuth2TokenService.validateAccounts(mContext, false);
519 } 520 }
520 }); 521 });
521 } 522 }
522 523
523 private static class TestObserver implements OAuth2TokenService.OAuth2TokenS erviceObserver { 524 private static class TestObserver implements OAuth2TokenService.OAuth2TokenS erviceObserver {
524 private int mAvailableCallCount; 525 private int mAvailableCallCount;
525 private int mRevokedCallCount; 526 private int mRevokedCallCount;
526 private int mLoadedCallCount; 527 private int mLoadedCallCount;
527 private Account mLastAccount; 528 private Account mLastAccount;
528 529
(...skipping 24 matching lines...) Expand all
553 554
554 public int getLoadedCallCount() { 555 public int getLoadedCallCount() {
555 return mLoadedCallCount; 556 return mLoadedCallCount;
556 } 557 }
557 558
558 public Account getLastAccount() { 559 public Account getLastAccount() {
559 return mLastAccount; 560 return mLastAccount;
560 } 561 }
561 } 562 }
562 } 563 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698