| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/ash/session_state_delegate_chromeos.h" | 5 #include "chrome/browser/ui/ash/session_state_delegate_chromeos.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 11 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 12 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 12 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
| 13 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 13 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 14 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | 14 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 15 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | 15 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
| 16 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" | 16 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
| 20 #include "chrome/test/base/testing_profile_manager.h" | 20 #include "chrome/test/base/testing_profile_manager.h" |
| 21 #include "components/user_manager/user_manager.h" | 21 #include "components/user_manager/user_manager.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 class SessionStateDelegateChromeOSTest : public testing::Test { | 45 class SessionStateDelegateChromeOSTest : public testing::Test { |
| 46 protected: | 46 protected: |
| 47 SessionStateDelegateChromeOSTest() : user_manager_(NULL) { | 47 SessionStateDelegateChromeOSTest() : user_manager_(NULL) { |
| 48 } | 48 } |
| 49 | 49 |
| 50 ~SessionStateDelegateChromeOSTest() override {} | 50 ~SessionStateDelegateChromeOSTest() override {} |
| 51 | 51 |
| 52 void SetUp() override { | 52 void SetUp() override { |
| 53 // Initialize the UserManager singleton to a fresh FakeUserManager instance. | 53 // Initialize the UserManager singleton to a fresh FakeChromeUserManager |
| 54 user_manager_ = new chromeos::FakeUserManager; | 54 // instance. |
| 55 user_manager_ = new FakeChromeUserManager; |
| 55 user_manager_enabler_.reset( | 56 user_manager_enabler_.reset( |
| 56 new chromeos::ScopedUserManagerEnabler(user_manager_)); | 57 new chromeos::ScopedUserManagerEnabler(user_manager_)); |
| 57 | 58 |
| 58 // Create our SessionStateDelegate to experiment with. | 59 // Create our SessionStateDelegate to experiment with. |
| 59 session_state_delegate_.reset(new SessionStateDelegateChromeos()); | 60 session_state_delegate_.reset(new SessionStateDelegateChromeos()); |
| 60 testing::Test::SetUp(); | 61 testing::Test::SetUp(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void TearDown() override { | 64 void TearDown() override { |
| 64 testing::Test::TearDown(); | 65 testing::Test::TearDown(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 82 void UserAddedToSession(std::string user) { | 83 void UserAddedToSession(std::string user) { |
| 83 user_manager()->AddUser(user); | 84 user_manager()->AddUser(user); |
| 84 user_manager()->LoginUser(user); | 85 user_manager()->LoginUser(user); |
| 85 } | 86 } |
| 86 | 87 |
| 87 // Get the active user. | 88 // Get the active user. |
| 88 const std::string& GetActiveUser() { | 89 const std::string& GetActiveUser() { |
| 89 return user_manager::UserManager::Get()->GetActiveUser()->email(); | 90 return user_manager::UserManager::Get()->GetActiveUser()->email(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 chromeos::FakeUserManager* user_manager() { return user_manager_; } | 93 FakeChromeUserManager* user_manager() { return user_manager_; } |
| 93 SessionStateDelegateChromeos* session_state_delegate() { | 94 SessionStateDelegateChromeos* session_state_delegate() { |
| 94 return session_state_delegate_.get(); | 95 return session_state_delegate_.get(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void InitForMultiProfile() { | 98 void InitForMultiProfile() { |
| 98 profile_manager_.reset( | 99 profile_manager_.reset( |
| 99 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 100 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 100 ASSERT_TRUE(profile_manager_->SetUp()); | 101 ASSERT_TRUE(profile_manager_->SetUp()); |
| 101 | 102 |
| 102 const std::string user_email(kUser); | 103 const std::string user_email(kUser); |
| 103 const user_manager::User* user = user_manager()->AddUser(user_email); | 104 const user_manager::User* user = user_manager()->AddUser(user_email); |
| 104 | 105 |
| 105 // Note that user profiles are created after user login in reality. | 106 // Note that user profiles are created after user login in reality. |
| 106 user_profile_ = profile_manager_->CreateTestingProfile(user_email); | 107 user_profile_ = profile_manager_->CreateTestingProfile(user_email); |
| 107 user_profile_->set_profile_name(user_email); | 108 user_profile_->set_profile_name(user_email); |
| 108 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( | 109 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( |
| 109 user, user_profile_); | 110 user, user_profile_); |
| 110 } | 111 } |
| 111 | 112 |
| 112 content::TestBrowserThreadBundle threads_; | 113 content::TestBrowserThreadBundle threads_; |
| 113 scoped_ptr<policy::PolicyCertVerifier> cert_verifier_; | 114 scoped_ptr<policy::PolicyCertVerifier> cert_verifier_; |
| 114 scoped_ptr<TestingProfileManager> profile_manager_; | 115 scoped_ptr<TestingProfileManager> profile_manager_; |
| 115 TestingProfile* user_profile_; | 116 TestingProfile* user_profile_; |
| 116 | 117 |
| 117 private: | 118 private: |
| 118 scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 119 scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 119 scoped_ptr<SessionStateDelegateChromeos> session_state_delegate_; | 120 scoped_ptr<SessionStateDelegateChromeos> session_state_delegate_; |
| 120 | 121 |
| 121 // Not owned. | 122 // Not owned. |
| 122 chromeos::FakeUserManager* user_manager_; | 123 FakeChromeUserManager* user_manager_; |
| 123 | 124 |
| 124 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateChromeOSTest); | 125 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateChromeOSTest); |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 // Make sure that cycling one user does not cause any harm. | 128 // Make sure that cycling one user does not cause any harm. |
| 128 TEST_F(SessionStateDelegateChromeOSTest, CyclingOneUser) { | 129 TEST_F(SessionStateDelegateChromeOSTest, CyclingOneUser) { |
| 129 UserAddedToSession("firstuser@test.com"); | 130 UserAddedToSession("firstuser@test.com"); |
| 130 | 131 |
| 131 EXPECT_EQ("firstuser@test.com", GetActiveUser()); | 132 EXPECT_EQ("firstuser@test.com", GetActiveUser()); |
| 132 session_state_delegate()->CycleActiveUser( | 133 session_state_delegate()->CycleActiveUser( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 prefs::kMultiProfileUserBehavior, | 282 prefs::kMultiProfileUserBehavior, |
| 282 chromeos::MultiProfileUserController::kBehaviorNotAllowed); | 283 chromeos::MultiProfileUserController::kBehaviorNotAllowed); |
| 283 user_manager()->AddUser("bb@b.b"); | 284 user_manager()->AddUser("bb@b.b"); |
| 284 EXPECT_FALSE( | 285 EXPECT_FALSE( |
| 285 session_state_delegate()->CanAddUserToMultiProfile(&add_user_error)); | 286 session_state_delegate()->CanAddUserToMultiProfile(&add_user_error)); |
| 286 EXPECT_EQ(ash::SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER, | 287 EXPECT_EQ(ash::SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER, |
| 287 add_user_error); | 288 add_user_error); |
| 288 } | 289 } |
| 289 | 290 |
| 290 } // namespace chromeos | 291 } // namespace chromeos |
| OLD | NEW |