| 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 namespace em = enterprise_management; | 58 namespace em = enterprise_management; |
| 59 | 59 |
| 60 using testing::AnyNumber; | 60 using testing::AnyNumber; |
| 61 using testing::Mock; | 61 using testing::Mock; |
| 62 using testing::_; | 62 using testing::_; |
| 63 | 63 |
| 64 namespace policy { | 64 namespace policy { |
| 65 | 65 |
| 66 namespace { | 66 namespace { |
| 67 | 67 |
| 68 const char kTestGaiaId[] = "12345"; |
| 68 const char kTestUser[] = "testuser@test.com"; | 69 const char kTestUser[] = "testuser@test.com"; |
| 69 | 70 |
| 70 #if !defined(OS_ANDROID) | 71 #if !defined(OS_ANDROID) |
| 71 const char kValidTokenResponse[] = | 72 const char kValidTokenResponse[] = |
| 72 "{" | 73 "{" |
| 73 " \"access_token\": \"at1\"," | 74 " \"access_token\": \"at1\"," |
| 74 " \"expires_in\": 3600," | 75 " \"expires_in\": 3600," |
| 75 " \"token_type\": \"Bearer\"" | 76 " \"token_type\": \"Bearer\"" |
| 76 "}"; | 77 "}"; |
| 77 #endif | 78 #endif |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 }; | 384 }; |
| 384 | 385 |
| 385 class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest { | 386 class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest { |
| 386 public: | 387 public: |
| 387 void AddProfile() override { | 388 void AddProfile() override { |
| 388 // UserCloudPolicyManager should not be initialized. | 389 // UserCloudPolicyManager should not be initialized. |
| 389 ASSERT_FALSE(manager_->core()->service()); | 390 ASSERT_FALSE(manager_->core()->service()); |
| 390 | 391 |
| 391 // Set the user as signed in. | 392 // Set the user as signed in. |
| 392 SigninManagerFactory::GetForProfile(profile_.get())-> | 393 SigninManagerFactory::GetForProfile(profile_.get())-> |
| 393 SetAuthenticatedUsername(kTestUser); | 394 SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
| 394 | 395 |
| 395 // Let the SigninService know that the profile has been created. | 396 // Let the SigninService know that the profile has been created. |
| 396 content::NotificationService::current()->Notify( | 397 content::NotificationService::current()->Notify( |
| 397 chrome::NOTIFICATION_PROFILE_ADDED, | 398 chrome::NOTIFICATION_PROFILE_ADDED, |
| 398 content::Source<Profile>(profile_.get()), | 399 content::Source<Profile>(profile_.get()), |
| 399 content::NotificationService::NoDetails()); | 400 content::NotificationService::NoDetails()); |
| 400 } | 401 } |
| 401 }; | 402 }; |
| 402 | 403 |
| 403 TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { | 404 TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 GetTokenService()->IssueErrorForAllPendingRequests(error); | 457 GetTokenService()->IssueErrorForAllPendingRequests(error); |
| 457 ASSERT_FALSE(IsRequestActive()); | 458 ASSERT_FALSE(IsRequestActive()); |
| 458 } | 459 } |
| 459 | 460 |
| 460 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { | 461 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { |
| 461 // UserCloudPolicyManager should not be initialized since there is no | 462 // UserCloudPolicyManager should not be initialized since there is no |
| 462 // signed-in user. | 463 // signed-in user. |
| 463 ASSERT_FALSE(manager_->core()->service()); | 464 ASSERT_FALSE(manager_->core()->service()); |
| 464 | 465 |
| 465 // Now sign in the user. | 466 // Now sign in the user. |
| 466 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 467 SigninManagerFactory::GetForProfile(profile_.get()) |
| 467 kTestUser); | 468 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
| 468 | 469 |
| 469 // Complete initialization of the store. | 470 // Complete initialization of the store. |
| 470 mock_store_->NotifyStoreLoaded(); | 471 mock_store_->NotifyStoreLoaded(); |
| 471 | 472 |
| 472 // Make oauth token available. | 473 // Make oauth token available. |
| 473 GetTokenService()->IssueRefreshTokenForUser(kTestUser, | 474 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 474 "oauth_login_refresh_token"); | 475 "oauth_login_refresh_token"); |
| 475 | 476 |
| 476 // UserCloudPolicyManager should be initialized. | 477 // UserCloudPolicyManager should be initialized. |
| 477 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 478 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
| 478 ASSERT_TRUE(manager_->core()->service()); | 479 ASSERT_TRUE(manager_->core()->service()); |
| 479 | 480 |
| 480 // Client registration should be in progress since we have an oauth token. | 481 // Client registration should be in progress since we have an oauth token. |
| 481 ASSERT_TRUE(IsRequestActive()); | 482 ASSERT_TRUE(IsRequestActive()); |
| 482 } | 483 } |
| 483 | 484 |
| 484 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { | 485 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { |
| 485 // UserCloudPolicyManager should not be initialized since there is no | 486 // UserCloudPolicyManager should not be initialized since there is no |
| 486 // signed-in user. | 487 // signed-in user. |
| 487 ASSERT_FALSE(manager_->core()->service()); | 488 ASSERT_FALSE(manager_->core()->service()); |
| 488 | 489 |
| 489 // Now sign in a non-enterprise user (blacklisted gmail.com domain). | 490 // Now sign in a non-enterprise user (blacklisted gmail.com domain). |
| 490 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 491 SigninManagerFactory::GetForProfile(profile_.get()) |
| 491 "non_enterprise_user@gmail.com"); | 492 ->SetAuthenticatedAccountInfo("12345", "non_enterprise_user@gmail.com"); |
| 492 | 493 |
| 493 // Complete initialization of the store. | 494 // Complete initialization of the store. |
| 494 mock_store_->NotifyStoreLoaded(); | 495 mock_store_->NotifyStoreLoaded(); |
| 495 | 496 |
| 496 // Make oauth token available. | 497 // Make oauth token available. |
| 497 GetTokenService()->IssueRefreshTokenForUser(kTestUser, | 498 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 498 "oauth_login_refresh_token"); | 499 "oauth_login_refresh_token"); |
| 499 | 500 |
| 500 // UserCloudPolicyManager should not be initialized and there should be no | 501 // UserCloudPolicyManager should not be initialized and there should be no |
| 501 // DMToken request active. | 502 // DMToken request active. |
| 502 ASSERT_TRUE(!manager_->core()->service()); | 503 ASSERT_TRUE(!manager_->core()->service()); |
| 503 ASSERT_FALSE(IsRequestActive()); | 504 ASSERT_FALSE(IsRequestActive()); |
| 504 } | 505 } |
| 505 | 506 |
| 506 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { | 507 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { |
| 507 // UserCloudPolicyManager should not be initialized since there is no | 508 // UserCloudPolicyManager should not be initialized since there is no |
| 508 // signed-in user. | 509 // signed-in user. |
| 509 ASSERT_FALSE(manager_->core()->service()); | 510 ASSERT_FALSE(manager_->core()->service()); |
| 510 | 511 |
| 511 // Now sign in the user. | 512 // Now sign in the user. |
| 512 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 513 SigninManagerFactory::GetForProfile(profile_.get()) |
| 513 kTestUser); | 514 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
| 514 | 515 |
| 515 // Make oauth token available. | 516 // Make oauth token available. |
| 516 GetTokenService()->IssueRefreshTokenForUser(kTestUser, | 517 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 517 "oauth_login_refresh_token"); | 518 "oauth_login_refresh_token"); |
| 518 | 519 |
| 519 // UserCloudPolicyManager should be initialized. | 520 // UserCloudPolicyManager should be initialized. |
| 520 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 521 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
| 521 ASSERT_TRUE(manager_->core()->service()); | 522 ASSERT_TRUE(manager_->core()->service()); |
| 522 | 523 |
| 523 // 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 |
| 524 // yet initialized. | 525 // yet initialized. |
| 525 ASSERT_FALSE(IsRequestActive()); | 526 ASSERT_FALSE(IsRequestActive()); |
| 526 | 527 |
| 527 // Complete initialization of the store with no policy (unregistered client). | 528 // Complete initialization of the store with no policy (unregistered client). |
| 528 mock_store_->NotifyStoreLoaded(); | 529 mock_store_->NotifyStoreLoaded(); |
| 529 | 530 |
| 530 // Client registration should be in progress since we have an oauth token. | 531 // Client registration should be in progress since we have an oauth token. |
| 531 ASSERT_TRUE(IsRequestActive()); | 532 ASSERT_TRUE(IsRequestActive()); |
| 532 } | 533 } |
| 533 | 534 |
| 534 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { | 535 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { |
| 535 // UserCloudPolicyManager should not be initialized since there is no | 536 // UserCloudPolicyManager should not be initialized since there is no |
| 536 // signed-in user. | 537 // signed-in user. |
| 537 ASSERT_FALSE(manager_->core()->service()); | 538 ASSERT_FALSE(manager_->core()->service()); |
| 538 | 539 |
| 539 // Now sign in the user. | 540 // Now sign in the user. |
| 540 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 541 SigninManagerFactory::GetForProfile(profile_.get()) |
| 541 kTestUser); | 542 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
| 542 | 543 |
| 543 // Make oauth token available. | 544 // Make oauth token available. |
| 544 GetTokenService()->IssueRefreshTokenForUser(kTestUser, | 545 GetTokenService()->IssueRefreshTokenForUser(kTestUser, |
| 545 "oauth_login_refresh_token"); | 546 "oauth_login_refresh_token"); |
| 546 | 547 |
| 547 // UserCloudPolicyManager should be initialized. | 548 // UserCloudPolicyManager should be initialized. |
| 548 EXPECT_EQ(mock_store_->signin_username_, kTestUser); | 549 EXPECT_EQ(mock_store_->signin_username_, kTestUser); |
| 549 ASSERT_TRUE(manager_->core()->service()); | 550 ASSERT_TRUE(manager_->core()->service()); |
| 550 | 551 |
| 551 // Client registration should not be in progress since the store is not | 552 // Client registration should not be in progress since the store is not |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 base::RunLoop().RunUntilIdle(); | 815 base::RunLoop().RunUntilIdle(); |
| 815 EXPECT_FALSE(manager_->IsClientRegistered()); | 816 EXPECT_FALSE(manager_->IsClientRegistered()); |
| 816 #if !defined(OS_ANDROID) | 817 #if !defined(OS_ANDROID) |
| 817 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); | 818 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); |
| 818 #endif | 819 #endif |
| 819 } | 820 } |
| 820 | 821 |
| 821 } // namespace | 822 } // namespace |
| 822 | 823 |
| 823 } // namespace policy | 824 } // namespace policy |
| OLD | NEW |