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