| 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 22 matching lines...) Expand all Loading... |
| 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 virtual ~SessionStateDelegateChromeOSTest() { | 50 virtual ~SessionStateDelegateChromeOSTest() { |
| 51 } | 51 } |
| 52 | 52 |
| 53 virtual void SetUp() override { | 53 virtual void SetUp() override { |
| 54 // Initialize the UserManager singleton to a fresh FakeUserManager instance. | 54 // Initialize the UserManager singleton to a fresh FakeChromeUserManager |
| 55 user_manager_ = new chromeos::FakeUserManager; | 55 // instance. |
| 56 user_manager_ = new FakeChromeUserManager; |
| 56 user_manager_enabler_.reset( | 57 user_manager_enabler_.reset( |
| 57 new chromeos::ScopedUserManagerEnabler(user_manager_)); | 58 new chromeos::ScopedUserManagerEnabler(user_manager_)); |
| 58 | 59 |
| 59 // Create our SessionStateDelegate to experiment with. | 60 // Create our SessionStateDelegate to experiment with. |
| 60 session_state_delegate_.reset(new SessionStateDelegateChromeos()); | 61 session_state_delegate_.reset(new SessionStateDelegateChromeos()); |
| 61 testing::Test::SetUp(); | 62 testing::Test::SetUp(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 virtual void TearDown() override { | 65 virtual void TearDown() override { |
| 65 testing::Test::TearDown(); | 66 testing::Test::TearDown(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 83 void UserAddedToSession(std::string user) { | 84 void UserAddedToSession(std::string user) { |
| 84 user_manager()->AddUser(user); | 85 user_manager()->AddUser(user); |
| 85 user_manager()->LoginUser(user); | 86 user_manager()->LoginUser(user); |
| 86 } | 87 } |
| 87 | 88 |
| 88 // Get the active user. | 89 // Get the active user. |
| 89 const std::string& GetActiveUser() { | 90 const std::string& GetActiveUser() { |
| 90 return user_manager::UserManager::Get()->GetActiveUser()->email(); | 91 return user_manager::UserManager::Get()->GetActiveUser()->email(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 chromeos::FakeUserManager* user_manager() { return user_manager_; } | 94 FakeChromeUserManager* user_manager() { return user_manager_; } |
| 94 SessionStateDelegateChromeos* session_state_delegate() { | 95 SessionStateDelegateChromeos* session_state_delegate() { |
| 95 return session_state_delegate_.get(); | 96 return session_state_delegate_.get(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void InitForMultiProfile() { | 99 void InitForMultiProfile() { |
| 99 profile_manager_.reset( | 100 profile_manager_.reset( |
| 100 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 101 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 101 ASSERT_TRUE(profile_manager_->SetUp()); | 102 ASSERT_TRUE(profile_manager_->SetUp()); |
| 102 | 103 |
| 103 const std::string user_email(kUser); | 104 const std::string user_email(kUser); |
| 104 const user_manager::User* user = user_manager()->AddUser(user_email); | 105 const user_manager::User* user = user_manager()->AddUser(user_email); |
| 105 | 106 |
| 106 // Note that user profiles are created after user login in reality. | 107 // Note that user profiles are created after user login in reality. |
| 107 user_profile_ = profile_manager_->CreateTestingProfile(user_email); | 108 user_profile_ = profile_manager_->CreateTestingProfile(user_email); |
| 108 user_profile_->set_profile_name(user_email); | 109 user_profile_->set_profile_name(user_email); |
| 109 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( | 110 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( |
| 110 user, user_profile_); | 111 user, user_profile_); |
| 111 } | 112 } |
| 112 | 113 |
| 113 content::TestBrowserThreadBundle threads_; | 114 content::TestBrowserThreadBundle threads_; |
| 114 scoped_ptr<policy::PolicyCertVerifier> cert_verifier_; | 115 scoped_ptr<policy::PolicyCertVerifier> cert_verifier_; |
| 115 scoped_ptr<TestingProfileManager> profile_manager_; | 116 scoped_ptr<TestingProfileManager> profile_manager_; |
| 116 TestingProfile* user_profile_; | 117 TestingProfile* user_profile_; |
| 117 | 118 |
| 118 private: | 119 private: |
| 119 scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 120 scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 120 scoped_ptr<SessionStateDelegateChromeos> session_state_delegate_; | 121 scoped_ptr<SessionStateDelegateChromeos> session_state_delegate_; |
| 121 | 122 |
| 122 // Not owned. | 123 // Not owned. |
| 123 chromeos::FakeUserManager* user_manager_; | 124 FakeChromeUserManager* user_manager_; |
| 124 | 125 |
| 125 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateChromeOSTest); | 126 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateChromeOSTest); |
| 126 }; | 127 }; |
| 127 | 128 |
| 128 // Make sure that cycling one user does not cause any harm. | 129 // Make sure that cycling one user does not cause any harm. |
| 129 TEST_F(SessionStateDelegateChromeOSTest, CyclingOneUser) { | 130 TEST_F(SessionStateDelegateChromeOSTest, CyclingOneUser) { |
| 130 UserAddedToSession("firstuser@test.com"); | 131 UserAddedToSession("firstuser@test.com"); |
| 131 | 132 |
| 132 EXPECT_EQ("firstuser@test.com", GetActiveUser()); | 133 EXPECT_EQ("firstuser@test.com", GetActiveUser()); |
| 133 session_state_delegate()->CycleActiveUser( | 134 session_state_delegate()->CycleActiveUser( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 prefs::kMultiProfileUserBehavior, | 283 prefs::kMultiProfileUserBehavior, |
| 283 chromeos::MultiProfileUserController::kBehaviorNotAllowed); | 284 chromeos::MultiProfileUserController::kBehaviorNotAllowed); |
| 284 user_manager()->AddUser("bb@b.b"); | 285 user_manager()->AddUser("bb@b.b"); |
| 285 EXPECT_FALSE( | 286 EXPECT_FALSE( |
| 286 session_state_delegate()->CanAddUserToMultiProfile(&add_user_error)); | 287 session_state_delegate()->CanAddUserToMultiProfile(&add_user_error)); |
| 287 EXPECT_EQ(ash::SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER, | 288 EXPECT_EQ(ash::SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER, |
| 288 add_user_error); | 289 add_user_error); |
| 289 } | 290 } |
| 290 | 291 |
| 291 } // namespace chromeos | 292 } // namespace chromeos |
| OLD | NEW |