| OLD | NEW |
| 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/message_loop/message_loop_proxy.h" | 6 #include "base/message_loop/message_loop_proxy.h" |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 void OnRegisterCompleted(scoped_ptr<CloudPolicyClient> client) { | 102 void OnRegisterCompleted(scoped_ptr<CloudPolicyClient> client) { |
| 103 register_completed_ = true; | 103 register_completed_ = true; |
| 104 created_client_.swap(client); | 104 created_client_.swap(client); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) { | 107 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) { |
| 108 // Policy client registration on Android depends on Token Service having | 108 // Policy client registration on Android depends on Token Service having |
| 109 // a valid login token, while on other platforms, the login refresh token | 109 // a valid login token, while on other platforms, the login refresh token |
| 110 // is specified directly. | 110 // is specified directly. |
| 111 #if defined(OS_ANDROID) | 111 #if defined(OS_ANDROID) |
| 112 GetTokenService()->IssueRefreshToken("oauth2_login_refresh_token"); | 112 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 113 "oauth2_login_refresh_token"); |
| 113 #endif | 114 #endif |
| 114 service->RegisterPolicyClient( | 115 service->RegisterPolicyClient( |
| 115 kTestUser, | 116 kTestUser, |
| 116 #if !defined(OS_ANDROID) | 117 #if !defined(OS_ANDROID) |
| 117 "mock_oauth_token", | 118 "mock_oauth_token", |
| 118 #endif | 119 #endif |
| 119 base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted, | 120 base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted, |
| 120 base::Unretained(this))); | 121 base::Unretained(this))); |
| 121 ASSERT_TRUE(IsRequestActive()); | 122 ASSERT_TRUE(IsRequestActive()); |
| 122 } | 123 } |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // UserCloudPolicyManager should be initialized. | 353 // UserCloudPolicyManager should be initialized. |
| 353 ASSERT_TRUE(manager_->core()->service()); | 354 ASSERT_TRUE(manager_->core()->service()); |
| 354 | 355 |
| 355 // Complete initialization of the store. | 356 // Complete initialization of the store. |
| 356 mock_store_->NotifyStoreLoaded(); | 357 mock_store_->NotifyStoreLoaded(); |
| 357 | 358 |
| 358 // No oauth access token yet, so client registration should be deferred. | 359 // No oauth access token yet, so client registration should be deferred. |
| 359 ASSERT_FALSE(IsRequestActive()); | 360 ASSERT_FALSE(IsRequestActive()); |
| 360 | 361 |
| 361 // Make oauth token available. | 362 // Make oauth token available. |
| 362 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); | 363 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 364 "oauth_login_refresh_token"); |
| 363 | 365 |
| 364 // Client registration should be in progress since we now have an oauth token. | 366 // Client registration should be in progress since we now have an oauth token. |
| 365 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 367 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
| 366 ASSERT_TRUE(IsRequestActive()); | 368 ASSERT_TRUE(IsRequestActive()); |
| 367 } | 369 } |
| 368 | 370 |
| 369 TEST_F(UserPolicySigninServiceTest, InitWhileSignedInOAuthError) { | 371 TEST_F(UserPolicySigninServiceTest, InitWhileSignedInOAuthError) { |
| 370 // Set the user as signed in. | 372 // Set the user as signed in. |
| 371 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 373 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 372 kTestUser); | 374 kTestUser); |
| 373 | 375 |
| 374 // Let the SigninService know that the profile has been created. | 376 // Let the SigninService know that the profile has been created. |
| 375 content::NotificationService::current()->Notify( | 377 content::NotificationService::current()->Notify( |
| 376 chrome::NOTIFICATION_PROFILE_ADDED, | 378 chrome::NOTIFICATION_PROFILE_ADDED, |
| 377 content::Source<Profile>(profile_.get()), | 379 content::Source<Profile>(profile_.get()), |
| 378 content::NotificationService::NoDetails()); | 380 content::NotificationService::NoDetails()); |
| 379 | 381 |
| 380 // UserCloudPolicyManager should be initialized. | 382 // UserCloudPolicyManager should be initialized. |
| 381 ASSERT_TRUE(manager_->core()->service()); | 383 ASSERT_TRUE(manager_->core()->service()); |
| 382 | 384 |
| 383 // Complete initialization of the store. | 385 // Complete initialization of the store. |
| 384 mock_store_->NotifyStoreLoaded(); | 386 mock_store_->NotifyStoreLoaded(); |
| 385 | 387 |
| 386 // No oauth access token yet, so client registration should be deferred. | 388 // No oauth access token yet, so client registration should be deferred. |
| 387 ASSERT_FALSE(IsRequestActive()); | 389 ASSERT_FALSE(IsRequestActive()); |
| 388 | 390 |
| 389 // Make oauth token available. | 391 // Make oauth token available. |
| 390 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); | 392 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 393 "oauth_login_refresh_token"); |
| 391 | 394 |
| 392 // Client registration should be in progress since we now have an oauth token. | 395 // Client registration should be in progress since we now have an oauth token. |
| 393 ASSERT_TRUE(IsRequestActive()); | 396 ASSERT_TRUE(IsRequestActive()); |
| 394 | 397 |
| 395 // Now fail the access token fetch. | 398 // Now fail the access token fetch. |
| 396 GoogleServiceAuthError error( | 399 GoogleServiceAuthError error( |
| 397 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 400 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 398 GetTokenService()->IssueErrorForAllPendingRequests(error); | 401 GetTokenService()->IssueErrorForAllPendingRequests(error); |
| 399 ASSERT_FALSE(IsRequestActive()); | 402 ASSERT_FALSE(IsRequestActive()); |
| 400 } | 403 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 412 ASSERT_FALSE(manager_->core()->service()); | 415 ASSERT_FALSE(manager_->core()->service()); |
| 413 | 416 |
| 414 // Now sign in the user. | 417 // Now sign in the user. |
| 415 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 418 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 416 kTestUser); | 419 kTestUser); |
| 417 | 420 |
| 418 // Complete initialization of the store. | 421 // Complete initialization of the store. |
| 419 mock_store_->NotifyStoreLoaded(); | 422 mock_store_->NotifyStoreLoaded(); |
| 420 | 423 |
| 421 // Make oauth token available. | 424 // Make oauth token available. |
| 422 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); | 425 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 426 "oauth_login_refresh_token"); |
| 423 | 427 |
| 424 // UserCloudPolicyManager should be initialized. | 428 // UserCloudPolicyManager should be initialized. |
| 425 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 429 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
| 426 ASSERT_TRUE(manager_->core()->service()); | 430 ASSERT_TRUE(manager_->core()->service()); |
| 427 | 431 |
| 428 // Client registration should be in progress since we have an oauth token. | 432 // Client registration should be in progress since we have an oauth token. |
| 429 ASSERT_TRUE(IsRequestActive()); | 433 ASSERT_TRUE(IsRequestActive()); |
| 430 } | 434 } |
| 431 | 435 |
| 432 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { | 436 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { |
| 433 EXPECT_CALL(*mock_store_, Clear()); | 437 EXPECT_CALL(*mock_store_, Clear()); |
| 434 // Let the SigninService know that the profile has been created. | 438 // Let the SigninService know that the profile has been created. |
| 435 content::NotificationService::current()->Notify( | 439 content::NotificationService::current()->Notify( |
| 436 chrome::NOTIFICATION_PROFILE_ADDED, | 440 chrome::NOTIFICATION_PROFILE_ADDED, |
| 437 content::Source<Profile>(profile_.get()), | 441 content::Source<Profile>(profile_.get()), |
| 438 content::NotificationService::NoDetails()); | 442 content::NotificationService::NoDetails()); |
| 439 | 443 |
| 440 // UserCloudPolicyManager should not be initialized since there is no | 444 // UserCloudPolicyManager should not be initialized since there is no |
| 441 // signed-in user. | 445 // signed-in user. |
| 442 ASSERT_FALSE(manager_->core()->service()); | 446 ASSERT_FALSE(manager_->core()->service()); |
| 443 | 447 |
| 444 // Now sign in a non-enterprise user (blacklisted gmail.com domain). | 448 // Now sign in a non-enterprise user (blacklisted gmail.com domain). |
| 445 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 449 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 446 "non_enterprise_user@gmail.com"); | 450 "non_enterprise_user@gmail.com"); |
| 447 | 451 |
| 448 // Complete initialization of the store. | 452 // Complete initialization of the store. |
| 449 mock_store_->NotifyStoreLoaded(); | 453 mock_store_->NotifyStoreLoaded(); |
| 450 | 454 |
| 451 // Make oauth token available. | 455 // Make oauth token available. |
| 452 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); | 456 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 457 "oauth_login_refresh_token"); |
| 453 | 458 |
| 454 // UserCloudPolicyManager should not be initialized and there should be no | 459 // UserCloudPolicyManager should not be initialized and there should be no |
| 455 // DMToken request active. | 460 // DMToken request active. |
| 456 ASSERT_TRUE(!manager_->core()->service()); | 461 ASSERT_TRUE(!manager_->core()->service()); |
| 457 ASSERT_FALSE(IsRequestActive()); | 462 ASSERT_FALSE(IsRequestActive()); |
| 458 } | 463 } |
| 459 | 464 |
| 460 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { | 465 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { |
| 461 EXPECT_CALL(*mock_store_, Clear()); | 466 EXPECT_CALL(*mock_store_, Clear()); |
| 462 // Let the SigninService know that the profile has been created. | 467 // Let the SigninService know that the profile has been created. |
| 463 content::NotificationService::current()->Notify( | 468 content::NotificationService::current()->Notify( |
| 464 chrome::NOTIFICATION_PROFILE_ADDED, | 469 chrome::NOTIFICATION_PROFILE_ADDED, |
| 465 content::Source<Profile>(profile_.get()), | 470 content::Source<Profile>(profile_.get()), |
| 466 content::NotificationService::NoDetails()); | 471 content::NotificationService::NoDetails()); |
| 467 | 472 |
| 468 // UserCloudPolicyManager should not be initialized since there is no | 473 // UserCloudPolicyManager should not be initialized since there is no |
| 469 // signed-in user. | 474 // signed-in user. |
| 470 ASSERT_FALSE(manager_->core()->service()); | 475 ASSERT_FALSE(manager_->core()->service()); |
| 471 | 476 |
| 472 // Now sign in the user. | 477 // Now sign in the user. |
| 473 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 478 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 474 kTestUser); | 479 kTestUser); |
| 475 | 480 |
| 476 // Make oauth token available. | 481 // Make oauth token available. |
| 477 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); | 482 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 483 "oauth_login_refresh_token"); |
| 478 | 484 |
| 479 // UserCloudPolicyManager should be initialized. | 485 // UserCloudPolicyManager should be initialized. |
| 480 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 486 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
| 481 ASSERT_TRUE(manager_->core()->service()); | 487 ASSERT_TRUE(manager_->core()->service()); |
| 482 | 488 |
| 483 // Client registration should not be in progress since the store is not | 489 // Client registration should not be in progress since the store is not |
| 484 // yet initialized. | 490 // yet initialized. |
| 485 ASSERT_FALSE(IsRequestActive()); | 491 ASSERT_FALSE(IsRequestActive()); |
| 486 | 492 |
| 487 // Complete initialization of the store with no policy (unregistered client). | 493 // Complete initialization of the store with no policy (unregistered client). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 501 | 507 |
| 502 // UserCloudPolicyManager should not be initialized since there is no | 508 // UserCloudPolicyManager should not be initialized since there is no |
| 503 // signed-in user. | 509 // signed-in user. |
| 504 ASSERT_FALSE(manager_->core()->service()); | 510 ASSERT_FALSE(manager_->core()->service()); |
| 505 | 511 |
| 506 // Now sign in the user. | 512 // Now sign in the user. |
| 507 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 513 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 508 kTestUser); | 514 kTestUser); |
| 509 | 515 |
| 510 // Make oauth token available. | 516 // Make oauth token available. |
| 511 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); | 517 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 518 "oauth_login_refresh_token"); |
| 512 | 519 |
| 513 // UserCloudPolicyManager should be initialized. | 520 // UserCloudPolicyManager should be initialized. |
| 514 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 521 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
| 515 ASSERT_TRUE(manager_->core()->service()); | 522 ASSERT_TRUE(manager_->core()->service()); |
| 516 | 523 |
| 517 // Client registration should not be in progress since the store is not | 524 // Client registration should not be in progress since the store is not |
| 518 // yet initialized. | 525 // yet initialized. |
| 519 ASSERT_FALSE(manager_->IsClientRegistered()); | 526 ASSERT_FALSE(manager_->IsClientRegistered()); |
| 520 ASSERT_FALSE(IsRequestActive()); | 527 ASSERT_FALSE(IsRequestActive()); |
| 521 | 528 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 base::RunLoop().RunUntilIdle(); | 797 base::RunLoop().RunUntilIdle(); |
| 791 EXPECT_FALSE(manager_->IsClientRegistered()); | 798 EXPECT_FALSE(manager_->IsClientRegistered()); |
| 792 #if !defined(OS_ANDROID) | 799 #if !defined(OS_ANDROID) |
| 793 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); | 800 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); |
| 794 #endif | 801 #endif |
| 795 } | 802 } |
| 796 | 803 |
| 797 } // namespace | 804 } // namespace |
| 798 | 805 |
| 799 } // namespace policy | 806 } // namespace policy |
| OLD | NEW |