| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/mock_user_manager.h" | 5 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 6 | 6 |
| 7 #include "base/task_runner.h" | 7 #include "base/task_runner.h" |
| 8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" | 8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" |
| 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 ~FakeTaskRunner() override {} | 24 ~FakeTaskRunner() override {} |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 namespace chromeos { | 29 namespace chromeos { |
| 30 | 30 |
| 31 MockUserManager::MockUserManager() | 31 MockUserManager::MockUserManager() |
| 32 : ChromeUserManager(new FakeTaskRunner(), new FakeTaskRunner()), | 32 : ChromeUserManager(new FakeTaskRunner(), new FakeTaskRunner()), |
| 33 user_flow_(new DefaultUserFlow()), | 33 user_flow_(new DefaultUserFlow()), |
| 34 supervised_user_manager_(new FakeSupervisedUserManager()) { | 34 supervised_user_manager_(new FakeSupervisedUserManager()), |
| 35 temporary_owner_id_(EmptyAccountId()) { |
| 35 ProfileHelper::SetProfileToUserForTestingEnabled(true); | 36 ProfileHelper::SetProfileToUserForTestingEnabled(true); |
| 36 } | 37 } |
| 37 | 38 |
| 38 MockUserManager::~MockUserManager() { | 39 MockUserManager::~MockUserManager() { |
| 39 ProfileHelper::SetProfileToUserForTestingEnabled(false); | 40 ProfileHelper::SetProfileToUserForTestingEnabled(false); |
| 40 ClearUserList(); | 41 ClearUserList(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 const user_manager::UserList& MockUserManager::GetUsers() const { | 44 const user_manager::UserList& MockUserManager::GetUsers() const { |
| 44 return user_list_; | 45 return user_list_; |
| 45 } | 46 } |
| 46 | 47 |
| 47 const user_manager::User* MockUserManager::GetLoggedInUser() const { | 48 const user_manager::User* MockUserManager::GetLoggedInUser() const { |
| 48 return user_list_.empty() ? NULL : user_list_.front(); | 49 return user_list_.empty() ? NULL : user_list_.front(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 user_manager::User* MockUserManager::GetLoggedInUser() { | 52 user_manager::User* MockUserManager::GetLoggedInUser() { |
| 52 return user_list_.empty() ? NULL : user_list_.front(); | 53 return user_list_.empty() ? NULL : user_list_.front(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 user_manager::UserList MockUserManager::GetUnlockUsers() const { | 56 user_manager::UserList MockUserManager::GetUnlockUsers() const { |
| 56 return user_list_; | 57 return user_list_; |
| 57 } | 58 } |
| 58 | 59 |
| 59 const std::string& MockUserManager::GetOwnerEmail() const { | 60 const AccountId& MockUserManager::GetOwnerId() const { |
| 60 return GetLoggedInUser()->email(); | 61 temporary_owner_id_ = GetLoggedInUser()->GetUserID(); |
| 62 return temporary_owner_id_; |
| 61 } | 63 } |
| 62 | 64 |
| 63 const user_manager::User* MockUserManager::GetActiveUser() const { | 65 const user_manager::User* MockUserManager::GetActiveUser() const { |
| 64 return GetLoggedInUser(); | 66 return GetLoggedInUser(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 user_manager::User* MockUserManager::GetActiveUser() { | 69 user_manager::User* MockUserManager::GetActiveUser() { |
| 68 return GetLoggedInUser(); | 70 return GetLoggedInUser(); |
| 69 } | 71 } |
| 70 | 72 |
| 71 const user_manager::User* MockUserManager::GetPrimaryUser() const { | 73 const user_manager::User* MockUserManager::GetPrimaryUser() const { |
| 72 return GetLoggedInUser(); | 74 return GetLoggedInUser(); |
| 73 } | 75 } |
| 74 | 76 |
| 75 BootstrapManager* MockUserManager::GetBootstrapManager() { | 77 BootstrapManager* MockUserManager::GetBootstrapManager() { |
| 76 return NULL; | 78 return NULL; |
| 77 } | 79 } |
| 78 | 80 |
| 79 MultiProfileUserController* MockUserManager::GetMultiProfileUserController() { | 81 MultiProfileUserController* MockUserManager::GetMultiProfileUserController() { |
| 80 return NULL; | 82 return NULL; |
| 81 } | 83 } |
| 82 | 84 |
| 83 UserImageManager* MockUserManager::GetUserImageManager( | 85 UserImageManager* MockUserManager::GetUserImageManager( |
| 84 const std::string& user_id) { | 86 const AccountId& user_id) { |
| 85 return NULL; | 87 return NULL; |
| 86 } | 88 } |
| 87 | 89 |
| 88 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() { | 90 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() { |
| 89 return supervised_user_manager_.get(); | 91 return supervised_user_manager_.get(); |
| 90 } | 92 } |
| 91 | 93 |
| 92 // Creates a new User instance. | 94 // Creates a new User instance. |
| 93 void MockUserManager::SetActiveUser(const std::string& email) { | 95 void MockUserManager::SetActiveUser(const AccountId& user_id) { |
| 94 ClearUserList(); | 96 ClearUserList(); |
| 95 AddUser(email); | 97 AddUser(user_id); |
| 96 } | 98 } |
| 97 | 99 |
| 98 UserFlow* MockUserManager::GetCurrentUserFlow() const { | 100 UserFlow* MockUserManager::GetCurrentUserFlow() const { |
| 99 return user_flow_.get(); | 101 return user_flow_.get(); |
| 100 } | 102 } |
| 101 | 103 |
| 102 UserFlow* MockUserManager::GetUserFlow(const std::string&) const { | 104 UserFlow* MockUserManager::GetUserFlow(const AccountId&) const { |
| 103 return user_flow_.get(); | 105 return user_flow_.get(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 user_manager::User* MockUserManager::CreatePublicAccountUser( | 108 user_manager::User* MockUserManager::CreatePublicAccountUser( |
| 107 const std::string& email) { | 109 const AccountId& user_id) { |
| 108 ClearUserList(); | 110 ClearUserList(); |
| 109 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); | 111 user_manager::User* user = |
| 112 user_manager::User::CreatePublicAccountUser(user_id); |
| 110 user_list_.push_back(user); | 113 user_list_.push_back(user); |
| 111 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 114 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
| 112 return user_list_.back(); | 115 return user_list_.back(); |
| 113 } | 116 } |
| 114 | 117 |
| 115 user_manager::User* MockUserManager::CreateKioskAppUser( | 118 user_manager::User* MockUserManager::CreateKioskAppUser( |
| 116 const std::string& email) { | 119 const AccountId& user_id) { |
| 117 ClearUserList(); | 120 ClearUserList(); |
| 118 user_list_.push_back(user_manager::User::CreateKioskAppUser(email)); | 121 user_list_.push_back(user_manager::User::CreateKioskAppUser(user_id)); |
| 119 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_.back()); | 122 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_.back()); |
| 120 return user_list_.back(); | 123 return user_list_.back(); |
| 121 } | 124 } |
| 122 | 125 |
| 123 void MockUserManager::AddUser(const std::string& email) { | 126 void MockUserManager::AddUser(const AccountId& user_id) { |
| 124 AddUserWithAffiliation(email, false); | 127 AddUserWithAffiliation(user_id, false); |
| 125 } | 128 } |
| 126 | 129 |
| 127 void MockUserManager::AddUserWithAffiliation(const std::string& email, | 130 void MockUserManager::AddUserWithAffiliation(const AccountId& user_id, |
| 128 bool is_affiliated) { | 131 bool is_affiliated) { |
| 129 user_manager::User* user = user_manager::User::CreateRegularUser(email); | 132 user_manager::User* user = user_manager::User::CreateRegularUser(user_id); |
| 130 user->set_affiliation(is_affiliated); | 133 user->set_affiliation(is_affiliated); |
| 131 user_list_.push_back(user); | 134 user_list_.push_back(user); |
| 132 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 135 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
| 133 } | 136 } |
| 134 | 137 |
| 135 void MockUserManager::ClearUserList() { | 138 void MockUserManager::ClearUserList() { |
| 136 // Can't use STLDeleteElements because of the protected destructor of User. | 139 // Can't use STLDeleteElements because of the protected destructor of User. |
| 137 user_manager::UserList::iterator user; | 140 user_manager::UserList::iterator user; |
| 138 for (user = user_list_.begin(); user != user_list_.end(); ++user) | 141 for (user = user_list_.begin(); user != user_list_.end(); ++user) |
| 139 delete *user; | 142 delete *user; |
| 140 user_list_.clear(); | 143 user_list_.clear(); |
| 141 } | 144 } |
| 142 | 145 |
| 143 bool MockUserManager::ShouldReportUser(const std::string& user_id) const { | 146 bool MockUserManager::ShouldReportUser(const std::string& user_id) const { |
| 144 for (const auto& user : user_list_) { | 147 for (const auto& user : user_list_) { |
| 145 if (user->GetUserID() == user_id) { | 148 if (user->email() == user_id) { |
| 146 return user->is_affiliated(); | 149 return user->is_affiliated(); |
| 147 } | 150 } |
| 148 } | 151 } |
| 149 NOTREACHED(); | 152 NOTREACHED(); |
| 150 return false; | 153 return false; |
| 151 } | 154 } |
| 152 | 155 |
| 153 } // namespace chromeos | 156 } // namespace chromeos |
| OLD | NEW |