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

Side by Side Diff: chrome/browser/chromeos/login/login_utils_browsertest.cc

Issue 330843002: Make the policy fetch for first time login blocking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and modified existing leak suppression to account for symbol changes Created 6 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 PrepareProfile(GetParam().username);
619 PrepareProfile(kUsername);
620 587
621 EXPECT_FALSE(prepared_profile_); 588 EXPECT_FALSE(prepared_profile_);
622 ASSERT_TRUE(user_manager->IsUserLoggedIn()); 589 ASSERT_TRUE(user_manager->IsUserLoggedIn());
623 EXPECT_TRUE(user_manager->IsCurrentUserNew()); 590 EXPECT_TRUE(user_manager->IsCurrentUserNew());
624 591
625 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 592 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
626 net::TestURLFetcher* fetcher; 593 net::TestURLFetcher* fetcher;
627 594
628 // |steps| is the test parameter, and is the number of successful fetches. 595 // |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 596 // The first incomplete fetch will fail. In any case, the profile creation
630 // should resume. 597 // should resume.
631 int steps = GetParam(); 598 int steps = GetParam().steps;
632 599
633 // The next expected fetcher ID. This is used to make it fail. 600 // The next expected fetcher ID. This is used to make it fail.
634 int next_expected_fetcher_id = 0; 601 int next_expected_fetcher_id = 0;
635 602
636 do { 603 do {
637 if (steps < 1) break; 604 if (steps < 1) break;
638 605
639 // Fake refresh token retrieval: 606 // Fake refresh token retrieval:
640 fetcher = PrepareOAuthFetcher(gaia_urls->client_login_to_oauth2_url()); 607 fetcher = PrepareOAuthFetcher(gaia_urls->client_login_to_oauth2_url());
641 ASSERT_TRUE(fetcher); 608 ASSERT_TRUE(fetcher);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 // fetchers then it will make them fail too. 663 // fetchers then it will make them fail too.
697 fetcher->SetResponseString(kGaiaAccountDisabledResponse); 664 fetcher->SetResponseString(kGaiaAccountDisabledResponse);
698 fetcher->delegate()->OnURLFetchComplete(fetcher); 665 fetcher->delegate()->OnURLFetchComplete(fetcher);
699 RunUntilIdle(); 666 RunUntilIdle();
700 } 667 }
701 668
702 // The profile is finally ready: 669 // The profile is finally ready:
703 EXPECT_TRUE(prepared_profile_); 670 EXPECT_TRUE(prepared_profile_);
704 } 671 }
705 672
706 INSTANTIATE_TEST_CASE_P( 673 const LoginUtilsBlockingLoginTestParam kBlockinLoginTestCases[] = {
707 LoginUtilsBlockingLoginTestInstance, 674 {0, kUsername, true},
708 LoginUtilsBlockingLoginTest, 675 {1, kUsername, true},
709 testing::Values(0, 1, 2, 3, 4, 5)); 676 {2, kUsername, true},
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));
710 696
711 } // namespace 697 } // namespace
712 698
713 } // namespace chromeos 699 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698