| 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 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 27 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 29 #include "chrome/browser/chromeos/settings/cros_settings.h" | 29 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 30 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 30 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 31 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 31 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 32 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" | 32 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" |
| 33 #include "chrome/browser/io_thread.h" | 33 #include "chrome/browser/io_thread.h" |
| 34 #include "chrome/browser/net/predictor.h" | 34 #include "chrome/browser/net/predictor.h" |
| 35 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" | 35 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
| 36 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
| 37 #include "chrome/browser/profiles/profiles_state.h" |
| 37 #include "chrome/browser/rlz/rlz.h" | 38 #include "chrome/browser/rlz/rlz.h" |
| 38 #include "chrome/common/chrome_content_client.h" | 39 #include "chrome/common/chrome_content_client.h" |
| 39 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
| 40 #include "chrome/common/chrome_switches.h" | |
| 41 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 42 #include "chrome/test/base/chrome_unit_test_suite.h" | 42 #include "chrome/test/base/chrome_unit_test_suite.h" |
| 43 #include "chrome/test/base/scoped_testing_local_state.h" | 43 #include "chrome/test/base/scoped_testing_local_state.h" |
| 44 #include "chrome/test/base/testing_browser_process.h" | 44 #include "chrome/test/base/testing_browser_process.h" |
| 45 #include "chromeos/chromeos_switches.h" | 45 #include "chromeos/chromeos_switches.h" |
| 46 #include "chromeos/cryptohome/mock_async_method_caller.h" | 46 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 47 #include "chromeos/cryptohome/system_salt_getter.h" | 47 #include "chromeos/cryptohome/system_salt_getter.h" |
| 48 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 48 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 49 #include "chromeos/disks/disk_mount_manager.h" | 49 #include "chromeos/disks/disk_mount_manager.h" |
| 50 #include "chromeos/disks/mock_disk_mount_manager.h" | 50 #include "chromeos/disks/mock_disk_mount_manager.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // will be executed. | 200 // will be executed. |
| 201 io_thread_.reset( | 201 io_thread_.reset( |
| 202 new content::TestBrowserThread(BrowserThread::IO, fake_io_loop)); | 202 new content::TestBrowserThread(BrowserThread::IO, fake_io_loop)); |
| 203 | 203 |
| 204 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 204 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
| 205 | 205 |
| 206 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 206 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 207 command_line->AppendSwitchASCII( | 207 command_line->AppendSwitchASCII( |
| 208 policy::switches::kDeviceManagementUrl, kDMServer); | 208 policy::switches::kDeviceManagementUrl, kDMServer); |
| 209 | 209 |
| 210 if (!command_line->HasSwitch(::switches::kMultiProfiles)) | |
| 211 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | |
| 212 | |
| 213 // DBusThreadManager should be initialized before io_thread_state_, as | 210 // DBusThreadManager should be initialized before io_thread_state_, as |
| 214 // DBusThreadManager is used from chromeos::ProxyConfigServiceImpl, | 211 // DBusThreadManager is used from chromeos::ProxyConfigServiceImpl, |
| 215 // which is part of io_thread_state_. | 212 // which is part of io_thread_state_. |
| 216 DBusThreadManager::InitializeWithStub(); | 213 DBusThreadManager::InitializeWithStub(); |
| 217 | 214 |
| 218 SystemSaltGetter::Initialize(); | 215 SystemSaltGetter::Initialize(); |
| 219 LoginState::Initialize(); | 216 LoginState::Initialize(); |
| 220 | 217 |
| 221 EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, _)) | 218 EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, _)) |
| 222 .WillRepeatedly(Return(false)); | 219 .WillRepeatedly(Return(false)); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 516 |
| 520 private: | 517 private: |
| 521 base::ScopedTempDir scoped_temp_dir_; | 518 base::ScopedTempDir scoped_temp_dir_; |
| 522 | 519 |
| 523 std::string device_policy_; | 520 std::string device_policy_; |
| 524 std::string user_policy_; | 521 std::string user_policy_; |
| 525 | 522 |
| 526 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); | 523 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); |
| 527 }; | 524 }; |
| 528 | 525 |
| 529 class LoginUtilsParamTest | |
| 530 : public LoginUtilsTest, | |
| 531 public testing::WithParamInterface<bool> { | |
| 532 public: | |
| 533 LoginUtilsParamTest() {} | |
| 534 | |
| 535 virtual void SetUp() OVERRIDE { | |
| 536 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 537 if (GetParam()) | |
| 538 command_line->AppendSwitch(::switches::kMultiProfiles); | |
| 539 LoginUtilsTest::SetUp(); | |
| 540 } | |
| 541 | |
| 542 private: | |
| 543 DISALLOW_COPY_AND_ASSIGN(LoginUtilsParamTest); | |
| 544 }; | |
| 545 | |
| 546 class LoginUtilsBlockingLoginTest | 526 class LoginUtilsBlockingLoginTest |
| 547 : public LoginUtilsTest, | 527 : public LoginUtilsTest, |
| 548 public testing::WithParamInterface<int> {}; | 528 public testing::WithParamInterface<int> {}; |
| 549 | 529 |
| 550 TEST_P(LoginUtilsParamTest, NormalLoginDoesntBlock) { | 530 TEST_F(LoginUtilsTest, NormalLoginDoesntBlock) { |
| 551 UserManager* user_manager = UserManager::Get(); | 531 UserManager* user_manager = UserManager::Get(); |
| 552 EXPECT_FALSE(user_manager->IsUserLoggedIn()); | 532 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
| 553 EXPECT_FALSE(connector_->IsEnterpriseManaged()); | 533 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
| 554 EXPECT_FALSE(prepared_profile_); | 534 EXPECT_FALSE(prepared_profile_); |
| 555 EXPECT_EQ(policy::USER_AFFILIATION_NONE, | 535 EXPECT_EQ(policy::USER_AFFILIATION_NONE, |
| 556 connector_->GetUserAffiliation(kUsername)); | 536 connector_->GetUserAffiliation(kUsername)); |
| 557 | 537 |
| 558 // The profile will be created without waiting for a policy response. | 538 // The profile will be created without waiting for a policy response. |
| 559 PrepareProfile(kUsername); | 539 PrepareProfile(kUsername); |
| 560 | 540 |
| 561 EXPECT_TRUE(prepared_profile_); | 541 EXPECT_TRUE(prepared_profile_); |
| 562 ASSERT_TRUE(user_manager->IsUserLoggedIn()); | 542 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
| 563 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser()->email()); | 543 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser()->email()); |
| 564 } | 544 } |
| 565 | 545 |
| 566 TEST_P(LoginUtilsParamTest, EnterpriseLoginDoesntBlockForNormalUser) { | 546 TEST_F(LoginUtilsTest, EnterpriseLoginDoesntBlockForNormalUser) { |
| 567 UserManager* user_manager = UserManager::Get(); | 547 UserManager* user_manager = UserManager::Get(); |
| 568 EXPECT_FALSE(user_manager->IsUserLoggedIn()); | 548 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
| 569 EXPECT_FALSE(connector_->IsEnterpriseManaged()); | 549 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
| 570 EXPECT_FALSE(prepared_profile_); | 550 EXPECT_FALSE(prepared_profile_); |
| 571 | 551 |
| 572 // Enroll the device. | 552 // Enroll the device. |
| 573 EnrollDevice(kUsername); | 553 EnrollDevice(kUsername); |
| 574 | 554 |
| 575 EXPECT_FALSE(user_manager->IsUserLoggedIn()); | 555 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
| 576 EXPECT_TRUE(connector_->IsEnterpriseManaged()); | 556 EXPECT_TRUE(connector_->IsEnterpriseManaged()); |
| 577 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); | 557 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); |
| 578 EXPECT_FALSE(prepared_profile_); | 558 EXPECT_FALSE(prepared_profile_); |
| 579 EXPECT_EQ(policy::USER_AFFILIATION_NONE, | 559 EXPECT_EQ(policy::USER_AFFILIATION_NONE, |
| 580 connector_->GetUserAffiliation(kUsernameOtherDomain)); | 560 connector_->GetUserAffiliation(kUsernameOtherDomain)); |
| 581 | 561 |
| 582 // Login with a non-enterprise user shouldn't block. | 562 // Login with a non-enterprise user shouldn't block. |
| 583 PrepareProfile(kUsernameOtherDomain); | 563 PrepareProfile(kUsernameOtherDomain); |
| 584 | 564 |
| 585 EXPECT_TRUE(prepared_profile_); | 565 EXPECT_TRUE(prepared_profile_); |
| 586 ASSERT_TRUE(user_manager->IsUserLoggedIn()); | 566 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
| 587 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser()->email()); | 567 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser()->email()); |
| 588 } | 568 } |
| 589 | 569 |
| 590 #if defined(ENABLE_RLZ) | 570 #if defined(ENABLE_RLZ) |
| 591 TEST_P(LoginUtilsParamTest, RlzInitialized) { | 571 TEST_F(LoginUtilsTest, RlzInitialized) { |
| 592 // No RLZ brand code set initially. | 572 // No RLZ brand code set initially. |
| 593 EXPECT_FALSE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); | 573 EXPECT_FALSE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); |
| 594 | 574 |
| 595 base::RunLoop wait_for_rlz_init; | 575 base::RunLoop wait_for_rlz_init; |
| 596 rlz_initialized_cb_ = wait_for_rlz_init.QuitClosure(); | 576 rlz_initialized_cb_ = wait_for_rlz_init.QuitClosure(); |
| 597 | 577 |
| 598 PrepareProfile(kUsername); | 578 PrepareProfile(kUsername); |
| 599 | 579 |
| 600 wait_for_rlz_init.Run(); | 580 wait_for_rlz_init.Run(); |
| 601 // Wait for blocking RLZ tasks to complete. | 581 // Wait for blocking RLZ tasks to complete. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 | 696 |
| 717 // The profile is finally ready: | 697 // The profile is finally ready: |
| 718 EXPECT_TRUE(prepared_profile_); | 698 EXPECT_TRUE(prepared_profile_); |
| 719 } | 699 } |
| 720 | 700 |
| 721 INSTANTIATE_TEST_CASE_P( | 701 INSTANTIATE_TEST_CASE_P( |
| 722 LoginUtilsBlockingLoginTestInstance, | 702 LoginUtilsBlockingLoginTestInstance, |
| 723 LoginUtilsBlockingLoginTest, | 703 LoginUtilsBlockingLoginTest, |
| 724 testing::Values(0, 1, 2, 3, 4, 5)); | 704 testing::Values(0, 1, 2, 3, 4, 5)); |
| 725 | 705 |
| 726 INSTANTIATE_TEST_CASE_P(LoginUtilsParamTestInstantiation, | |
| 727 LoginUtilsParamTest, | |
| 728 testing::Bool()); | |
| 729 | |
| 730 } // namespace | 706 } // namespace |
| 731 | 707 |
| 732 } // namespace chromeos | 708 } // namespace chromeos |
| OLD | NEW |