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