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 "chrome/browser/chromeos/login/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 | 521 |
522 private: | 522 private: |
523 base::ScopedTempDir scoped_temp_dir_; | 523 base::ScopedTempDir scoped_temp_dir_; |
524 | 524 |
525 std::string device_policy_; | 525 std::string device_policy_; |
526 std::string user_policy_; | 526 std::string user_policy_; |
527 | 527 |
528 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); | 528 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); |
529 }; | 529 }; |
530 | 530 |
531 struct LoginUtilsBlockingLoginTestParam { | |
532 const int steps; | |
533 const char* username; | |
534 const bool enroll_device; | |
535 }; | |
536 | |
537 class LoginUtilsBlockingLoginTest | 531 class LoginUtilsBlockingLoginTest |
538 : public LoginUtilsTest, | 532 : public LoginUtilsTest, |
539 public testing::WithParamInterface<LoginUtilsBlockingLoginTestParam> {}; | 533 public testing::WithParamInterface<int> {}; |
| 534 |
| 535 TEST_F(LoginUtilsTest, NormalLoginDoesntBlock) { |
| 536 UserManager* user_manager = UserManager::Get(); |
| 537 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
| 538 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
| 539 EXPECT_FALSE(prepared_profile_); |
| 540 EXPECT_EQ(policy::USER_AFFILIATION_NONE, |
| 541 connector_->GetUserAffiliation(kUsername)); |
| 542 |
| 543 // The profile will be created without waiting for a policy response. |
| 544 PrepareProfile(kUsername); |
| 545 |
| 546 EXPECT_TRUE(prepared_profile_); |
| 547 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
| 548 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser()->email()); |
| 549 } |
| 550 |
| 551 TEST_F(LoginUtilsTest, EnterpriseLoginDoesntBlockForNormalUser) { |
| 552 UserManager* user_manager = UserManager::Get(); |
| 553 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
| 554 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
| 555 EXPECT_FALSE(prepared_profile_); |
| 556 |
| 557 // Enroll the device. |
| 558 EnrollDevice(kUsername); |
| 559 |
| 560 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
| 561 EXPECT_TRUE(connector_->IsEnterpriseManaged()); |
| 562 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); |
| 563 EXPECT_FALSE(prepared_profile_); |
| 564 EXPECT_EQ(policy::USER_AFFILIATION_NONE, |
| 565 connector_->GetUserAffiliation(kUsernameOtherDomain)); |
| 566 |
| 567 // Login with a non-enterprise user shouldn't block. |
| 568 PrepareProfile(kUsernameOtherDomain); |
| 569 |
| 570 EXPECT_TRUE(prepared_profile_); |
| 571 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
| 572 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser()->email()); |
| 573 } |
540 | 574 |
541 #if defined(ENABLE_RLZ) | 575 #if defined(ENABLE_RLZ) |
542 TEST_F(LoginUtilsTest, RlzInitialized) { | 576 TEST_F(LoginUtilsTest, RlzInitialized) { |
543 // No RLZ brand code set initially. | 577 // No RLZ brand code set initially. |
544 EXPECT_FALSE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); | 578 EXPECT_FALSE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); |
545 | 579 |
546 base::RunLoop wait_for_rlz_init; | 580 base::RunLoop wait_for_rlz_init; |
547 rlz_initialized_cb_ = wait_for_rlz_init.QuitClosure(); | 581 rlz_initialized_cb_ = wait_for_rlz_init.QuitClosure(); |
548 | 582 |
549 PrepareProfile(kUsername); | 583 PrepareProfile(kUsername); |
550 | 584 |
551 wait_for_rlz_init.Run(); | 585 wait_for_rlz_init.Run(); |
552 // Wait for blocking RLZ tasks to complete. | 586 // Wait for blocking RLZ tasks to complete. |
553 RunUntilIdle(); | 587 RunUntilIdle(); |
554 | 588 |
555 // RLZ brand code has been set to empty string. | 589 // RLZ brand code has been set to empty string. |
556 EXPECT_TRUE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); | 590 EXPECT_TRUE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); |
557 EXPECT_EQ(std::string(), local_state_.Get()->GetString(prefs::kRLZBrand)); | 591 EXPECT_EQ(std::string(), local_state_.Get()->GetString(prefs::kRLZBrand)); |
558 | 592 |
559 // RLZ value for homepage access point should have been initialized. | 593 // RLZ value for homepage access point should have been initialized. |
560 base::string16 rlz_string; | 594 base::string16 rlz_string; |
561 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( | 595 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( |
562 RLZTracker::ChromeHomePage(), &rlz_string)); | 596 RLZTracker::ChromeHomePage(), &rlz_string)); |
563 EXPECT_EQ(base::string16(), rlz_string); | 597 EXPECT_EQ(base::string16(), rlz_string); |
564 } | 598 } |
565 #endif | 599 #endif |
566 | 600 |
567 TEST_P(LoginUtilsBlockingLoginTest, LoginBlocksForUser) { | 601 TEST_P(LoginUtilsBlockingLoginTest, EnterpriseLoginBlocksForEnterpriseUser) { |
568 UserManager* user_manager = UserManager::Get(); | 602 UserManager* user_manager = UserManager::Get(); |
569 EXPECT_FALSE(user_manager->IsUserLoggedIn()); | 603 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
570 EXPECT_FALSE(connector_->IsEnterpriseManaged()); | 604 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
571 EXPECT_FALSE(prepared_profile_); | 605 EXPECT_FALSE(prepared_profile_); |
572 | 606 |
573 if (GetParam().enroll_device) { | 607 // Enroll the device. |
574 // Enroll the device. | 608 EnrollDevice(kUsername); |
575 EnrollDevice(kUsername); | |
576 | 609 |
577 EXPECT_FALSE(user_manager->IsUserLoggedIn()); | 610 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
578 EXPECT_TRUE(connector_->IsEnterpriseManaged()); | 611 EXPECT_TRUE(connector_->IsEnterpriseManaged()); |
579 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); | 612 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); |
580 EXPECT_FALSE(prepared_profile_); | 613 EXPECT_FALSE(prepared_profile_); |
581 EXPECT_EQ(policy::USER_AFFILIATION_MANAGED, | 614 EXPECT_EQ(policy::USER_AFFILIATION_MANAGED, |
582 connector_->GetUserAffiliation(kUsername)); | 615 connector_->GetUserAffiliation(kUsername)); |
583 EXPECT_FALSE(user_manager->IsKnownUser(kUsername)); | 616 EXPECT_FALSE(user_manager->IsKnownUser(kUsername)); |
584 } | |
585 | 617 |
586 PrepareProfile(GetParam().username); | 618 // Login with a user of the enterprise domain waits for policy. |
| 619 PrepareProfile(kUsername); |
587 | 620 |
588 EXPECT_FALSE(prepared_profile_); | 621 EXPECT_FALSE(prepared_profile_); |
589 ASSERT_TRUE(user_manager->IsUserLoggedIn()); | 622 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
590 EXPECT_TRUE(user_manager->IsCurrentUserNew()); | 623 EXPECT_TRUE(user_manager->IsCurrentUserNew()); |
591 | 624 |
592 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 625 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
593 net::TestURLFetcher* fetcher; | 626 net::TestURLFetcher* fetcher; |
594 | 627 |
595 // |steps| is the test parameter, and is the number of successful fetches. | 628 // |steps| is the test parameter, and is the number of successful fetches. |
596 // The first incomplete fetch will fail. In any case, the profile creation | 629 // The first incomplete fetch will fail. In any case, the profile creation |
597 // should resume. | 630 // should resume. |
598 int steps = GetParam().steps; | 631 int steps = GetParam(); |
599 | 632 |
600 // The next expected fetcher ID. This is used to make it fail. | 633 // The next expected fetcher ID. This is used to make it fail. |
601 int next_expected_fetcher_id = 0; | 634 int next_expected_fetcher_id = 0; |
602 | 635 |
603 do { | 636 do { |
604 if (steps < 1) break; | 637 if (steps < 1) break; |
605 | 638 |
606 // Fake refresh token retrieval: | 639 // Fake refresh token retrieval: |
607 fetcher = PrepareOAuthFetcher(gaia_urls->client_login_to_oauth2_url()); | 640 fetcher = PrepareOAuthFetcher(gaia_urls->client_login_to_oauth2_url()); |
608 ASSERT_TRUE(fetcher); | 641 ASSERT_TRUE(fetcher); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 // fetchers then it will make them fail too. | 696 // fetchers then it will make them fail too. |
664 fetcher->SetResponseString(kGaiaAccountDisabledResponse); | 697 fetcher->SetResponseString(kGaiaAccountDisabledResponse); |
665 fetcher->delegate()->OnURLFetchComplete(fetcher); | 698 fetcher->delegate()->OnURLFetchComplete(fetcher); |
666 RunUntilIdle(); | 699 RunUntilIdle(); |
667 } | 700 } |
668 | 701 |
669 // The profile is finally ready: | 702 // The profile is finally ready: |
670 EXPECT_TRUE(prepared_profile_); | 703 EXPECT_TRUE(prepared_profile_); |
671 } | 704 } |
672 | 705 |
673 const LoginUtilsBlockingLoginTestParam kBlockinLoginTestCases[] = { | 706 INSTANTIATE_TEST_CASE_P( |
674 {0, kUsername, true}, | 707 LoginUtilsBlockingLoginTestInstance, |
675 {1, kUsername, true}, | 708 LoginUtilsBlockingLoginTest, |
676 {2, kUsername, true}, | 709 testing::Values(0, 1, 2, 3, 4, 5)); |
677 {3, kUsername, true}, | |
678 {4, kUsername, true}, | |
679 {5, kUsername, true}, | |
680 {0, kUsername, false}, | |
681 {1, kUsername, false}, | |
682 {2, kUsername, false}, | |
683 {3, kUsername, false}, | |
684 {4, kUsername, false}, | |
685 {5, kUsername, false}, | |
686 {0, kUsernameOtherDomain, true}, | |
687 {1, kUsernameOtherDomain, true}, | |
688 {2, kUsernameOtherDomain, true}, | |
689 {3, kUsernameOtherDomain, true}, | |
690 {4, kUsernameOtherDomain, true}, | |
691 {5, kUsernameOtherDomain, true}}; | |
692 | |
693 INSTANTIATE_TEST_CASE_P(LoginUtilsBlockingLoginTestInstance, | |
694 LoginUtilsBlockingLoginTest, | |
695 testing::ValuesIn(kBlockinLoginTestCases)); | |
696 | 710 |
697 } // namespace | 711 } // namespace |
698 | 712 |
699 } // namespace chromeos | 713 } // namespace chromeos |
OLD | NEW |