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

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address roger's comments Created 5 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/thread_task_runner_handle.h" 8 #include "base/thread_task_runner_handle.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 register_completed_ = true; 128 register_completed_ = true;
129 dm_token_ = dm_token; 129 dm_token_ = dm_token;
130 client_id_ = client_id; 130 client_id_ = client_id;
131 } 131 }
132 132
133 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) { 133 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) {
134 // Policy client registration on Android depends on Token Service having 134 // Policy client registration on Android depends on Token Service having
135 // a valid login token, while on other platforms, the login refresh token 135 // a valid login token, while on other platforms, the login refresh token
136 // is specified directly. 136 // is specified directly.
137 #if defined(OS_ANDROID) 137 #if defined(OS_ANDROID)
138 GetTokenService()->IssueRefreshTokenForUser( 138 GetTokenService()->UpdateCredentials(
139 AccountTrackerService::PickAccountIdForAccount( 139 AccountTrackerService::PickAccountIdForAccount(
140 profile_.get()->GetPrefs(), kTestGaiaId, kTestUser), 140 profile_.get()->GetPrefs(), kTestGaiaId, kTestUser),
141 "oauth2_login_refresh_token"); 141 "oauth2_login_refresh_token");
142 #endif 142 #endif
143 service->RegisterForPolicy( 143 service->RegisterForPolicy(
144 kTestUser, 144 kTestUser,
145 #if !defined(OS_ANDROID) 145 #if !defined(OS_ANDROID)
146 "mock_oauth_token", 146 "mock_oauth_token",
147 #endif 147 #endif
148 base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted, 148 base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted,
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // UserCloudPolicyManager should be initialized. 421 // UserCloudPolicyManager should be initialized.
422 ASSERT_TRUE(manager_->core()->service()); 422 ASSERT_TRUE(manager_->core()->service());
423 423
424 // Complete initialization of the store. 424 // Complete initialization of the store.
425 mock_store_->NotifyStoreLoaded(); 425 mock_store_->NotifyStoreLoaded();
426 426
427 // No oauth access token yet, so client registration should be deferred. 427 // No oauth access token yet, so client registration should be deferred.
428 ASSERT_FALSE(IsRequestActive()); 428 ASSERT_FALSE(IsRequestActive());
429 429
430 // Make oauth token available. 430 // Make oauth token available.
431 GetTokenService()->IssueRefreshTokenForUser( 431 GetTokenService()->UpdateCredentials(
432 SigninManagerFactory::GetForProfile(profile_.get()) 432 SigninManagerFactory::GetForProfile(profile_.get())
433 ->GetAuthenticatedAccountId(), 433 ->GetAuthenticatedAccountId(),
434 "oauth_login_refresh_token"); 434 "oauth_login_refresh_token");
435 435
436 // Client registration should be in progress since we now have an oauth token. 436 // Client registration should be in progress since we now have an oauth token.
437 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 437 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
438 ASSERT_TRUE(IsRequestActive()); 438 ASSERT_TRUE(IsRequestActive());
439 } 439 }
440 440
441 TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) { 441 TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) {
442 // UserCloudPolicyManager should be initialized. 442 // UserCloudPolicyManager should be initialized.
443 ASSERT_TRUE(manager_->core()->service()); 443 ASSERT_TRUE(manager_->core()->service());
444 444
445 // Complete initialization of the store. 445 // Complete initialization of the store.
446 mock_store_->NotifyStoreLoaded(); 446 mock_store_->NotifyStoreLoaded();
447 447
448 // No oauth access token yet, so client registration should be deferred. 448 // No oauth access token yet, so client registration should be deferred.
449 ASSERT_FALSE(IsRequestActive()); 449 ASSERT_FALSE(IsRequestActive());
450 450
451 // Make oauth token available. 451 // Make oauth token available.
452 GetTokenService()->IssueRefreshTokenForUser( 452 GetTokenService()->UpdateCredentials(
453 SigninManagerFactory::GetForProfile(profile_.get()) 453 SigninManagerFactory::GetForProfile(profile_.get())
454 ->GetAuthenticatedAccountId(), 454 ->GetAuthenticatedAccountId(),
455 "oauth_login_refresh_token"); 455 "oauth_login_refresh_token");
456 456
457 // Client registration should be in progress since we now have an oauth token. 457 // Client registration should be in progress since we now have an oauth token.
458 ASSERT_TRUE(IsRequestActive()); 458 ASSERT_TRUE(IsRequestActive());
459 459
460 // Now fail the access token fetch. 460 // Now fail the access token fetch.
461 GoogleServiceAuthError error( 461 GoogleServiceAuthError error(
462 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 462 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
463 GetTokenService()->IssueErrorForAllPendingRequests(error); 463 GetTokenService()->IssueErrorForAllPendingRequests(error);
464 ASSERT_FALSE(IsRequestActive()); 464 ASSERT_FALSE(IsRequestActive());
465 } 465 }
466 466
467 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { 467 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) {
468 // UserCloudPolicyManager should not be initialized since there is no 468 // UserCloudPolicyManager should not be initialized since there is no
469 // signed-in user. 469 // signed-in user.
470 ASSERT_FALSE(manager_->core()->service()); 470 ASSERT_FALSE(manager_->core()->service());
471 471
472 // Now sign in the user. 472 // Now sign in the user.
473 SigninManagerFactory::GetForProfile(profile_.get()) 473 SigninManagerFactory::GetForProfile(profile_.get())
474 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 474 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
475 475
476 // Complete initialization of the store. 476 // Complete initialization of the store.
477 mock_store_->NotifyStoreLoaded(); 477 mock_store_->NotifyStoreLoaded();
478 478
479 // Make oauth token available. 479 // Make oauth token available.
480 GetTokenService()->IssueRefreshTokenForUser( 480 GetTokenService()->UpdateCredentials(
481 SigninManagerFactory::GetForProfile(profile_.get()) 481 SigninManagerFactory::GetForProfile(profile_.get())
482 ->GetAuthenticatedAccountId(), 482 ->GetAuthenticatedAccountId(),
483 "oauth_login_refresh_token"); 483 "oauth_login_refresh_token");
484 484
485 // UserCloudPolicyManager should be initialized. 485 // UserCloudPolicyManager should be initialized.
486 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 486 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
487 ASSERT_TRUE(manager_->core()->service()); 487 ASSERT_TRUE(manager_->core()->service());
488 488
489 // Client registration should be in progress since we have an oauth token. 489 // Client registration should be in progress since we have an oauth token.
490 ASSERT_TRUE(IsRequestActive()); 490 ASSERT_TRUE(IsRequestActive());
491 } 491 }
492 492
493 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { 493 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) {
494 // UserCloudPolicyManager should not be initialized since there is no 494 // UserCloudPolicyManager should not be initialized since there is no
495 // signed-in user. 495 // signed-in user.
496 ASSERT_FALSE(manager_->core()->service()); 496 ASSERT_FALSE(manager_->core()->service());
497 497
498 // Now sign in a non-enterprise user (blacklisted gmail.com domain). 498 // Now sign in a non-enterprise user (blacklisted gmail.com domain).
499 SigninManagerFactory::GetForProfile(profile_.get()) 499 SigninManagerFactory::GetForProfile(profile_.get())
500 ->SetAuthenticatedAccountInfo("gaia-id-non_enterprise_user@gmail.com", 500 ->SetAuthenticatedAccountInfo("gaia-id-non_enterprise_user@gmail.com",
501 "non_enterprise_user@gmail.com"); 501 "non_enterprise_user@gmail.com");
502 502
503 // Complete initialization of the store. 503 // Complete initialization of the store.
504 mock_store_->NotifyStoreLoaded(); 504 mock_store_->NotifyStoreLoaded();
505 505
506 // Make oauth token available. 506 // Make oauth token available.
507 GetTokenService()->IssueRefreshTokenForUser( 507 GetTokenService()->UpdateCredentials(
508 SigninManagerFactory::GetForProfile(profile_.get()) 508 SigninManagerFactory::GetForProfile(profile_.get())
509 ->GetAuthenticatedAccountId(), 509 ->GetAuthenticatedAccountId(),
510 "oauth_login_refresh_token"); 510 "oauth_login_refresh_token");
511 511
512 // UserCloudPolicyManager should not be initialized and there should be no 512 // UserCloudPolicyManager should not be initialized and there should be no
513 // DMToken request active. 513 // DMToken request active.
514 ASSERT_TRUE(!manager_->core()->service()); 514 ASSERT_TRUE(!manager_->core()->service());
515 ASSERT_FALSE(IsRequestActive()); 515 ASSERT_FALSE(IsRequestActive());
516 } 516 }
517 517
518 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { 518 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) {
519 // UserCloudPolicyManager should not be initialized since there is no 519 // UserCloudPolicyManager should not be initialized since there is no
520 // signed-in user. 520 // signed-in user.
521 ASSERT_FALSE(manager_->core()->service()); 521 ASSERT_FALSE(manager_->core()->service());
522 522
523 // Now sign in the user. 523 // Now sign in the user.
524 SigninManagerFactory::GetForProfile(profile_.get()) 524 SigninManagerFactory::GetForProfile(profile_.get())
525 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 525 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
526 526
527 // Make oauth token available. 527 // Make oauth token available.
528 GetTokenService()->IssueRefreshTokenForUser( 528 GetTokenService()->UpdateCredentials(
529 SigninManagerFactory::GetForProfile(profile_.get()) 529 SigninManagerFactory::GetForProfile(profile_.get())
530 ->GetAuthenticatedAccountId(), 530 ->GetAuthenticatedAccountId(),
531 "oauth_login_refresh_token"); 531 "oauth_login_refresh_token");
532 532
533 // UserCloudPolicyManager should be initialized. 533 // UserCloudPolicyManager should be initialized.
534 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 534 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
535 ASSERT_TRUE(manager_->core()->service()); 535 ASSERT_TRUE(manager_->core()->service());
536 536
537 // Client registration should not be in progress since the store is not 537 // Client registration should not be in progress since the store is not
538 // yet initialized. 538 // yet initialized.
539 ASSERT_FALSE(IsRequestActive()); 539 ASSERT_FALSE(IsRequestActive());
540 540
541 // Complete initialization of the store with no policy (unregistered client). 541 // Complete initialization of the store with no policy (unregistered client).
542 mock_store_->NotifyStoreLoaded(); 542 mock_store_->NotifyStoreLoaded();
543 543
544 // Client registration should be in progress since we have an oauth token. 544 // Client registration should be in progress since we have an oauth token.
545 ASSERT_TRUE(IsRequestActive()); 545 ASSERT_TRUE(IsRequestActive());
546 } 546 }
547 547
548 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { 548 TEST_F(UserPolicySigninServiceTest, RegisteredClient) {
549 // UserCloudPolicyManager should not be initialized since there is no 549 // UserCloudPolicyManager should not be initialized since there is no
550 // signed-in user. 550 // signed-in user.
551 ASSERT_FALSE(manager_->core()->service()); 551 ASSERT_FALSE(manager_->core()->service());
552 552
553 // Now sign in the user. 553 // Now sign in the user.
554 SigninManagerFactory::GetForProfile(profile_.get()) 554 SigninManagerFactory::GetForProfile(profile_.get())
555 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 555 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
556 556
557 // Make oauth token available. 557 // Make oauth token available.
558 GetTokenService()->IssueRefreshTokenForUser( 558 GetTokenService()->UpdateCredentials(
559 SigninManagerFactory::GetForProfile(profile_.get()) 559 SigninManagerFactory::GetForProfile(profile_.get())
560 ->GetAuthenticatedAccountId(), 560 ->GetAuthenticatedAccountId(),
561 "oauth_login_refresh_token"); 561 "oauth_login_refresh_token");
562 562
563 // UserCloudPolicyManager should be initialized. 563 // UserCloudPolicyManager should be initialized.
564 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 564 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
565 ASSERT_TRUE(manager_->core()->service()); 565 ASSERT_TRUE(manager_->core()->service());
566 566
567 // Client registration should not be in progress since the store is not 567 // Client registration should not be in progress since the store is not
568 // yet initialized. 568 // yet initialized.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 base::RunLoop().RunUntilIdle(); 830 base::RunLoop().RunUntilIdle();
831 EXPECT_FALSE(manager_->IsClientRegistered()); 831 EXPECT_FALSE(manager_->IsClientRegistered());
832 #if !defined(OS_ANDROID) 832 #if !defined(OS_ANDROID)
833 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); 833 EXPECT_FALSE(signin_manager_->IsSignoutProhibited());
834 #endif 834 #endif
835 } 835 }
836 836
837 } // namespace 837 } // namespace
838 838
839 } // namespace policy 839 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698