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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
7 #include "base/task_runner.h"
8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 class FakeTaskRunner
: public base::TaskRunner
{
15 bool PostDelayedTask(const tracked_objects::Location
& from_here
,
16 const base::Closure
& task
,
17 base::TimeDelta delay
) override
{
21 bool RunsTasksOnCurrentThread() const override
{ return true; }
24 ~FakeTaskRunner() override
{}
31 MockUserManager::MockUserManager()
32 : ChromeUserManager(new FakeTaskRunner(), new FakeTaskRunner()),
33 user_flow_(new DefaultUserFlow()),
34 supervised_user_manager_(new FakeSupervisedUserManager()) {
35 ProfileHelper::SetProfileToUserForTestingEnabled(true);
38 MockUserManager::~MockUserManager() {
39 ProfileHelper::SetProfileToUserForTestingEnabled(false);
43 const user_manager::UserList
& MockUserManager::GetUsers() const {
47 const user_manager::User
* MockUserManager::GetLoggedInUser() const {
48 return user_list_
.empty() ? NULL
: user_list_
.front();
51 user_manager::User
* MockUserManager::GetLoggedInUser() {
52 return user_list_
.empty() ? NULL
: user_list_
.front();
55 user_manager::UserList
MockUserManager::GetUnlockUsers() const {
59 const std::string
& MockUserManager::GetOwnerEmail() const {
60 return GetLoggedInUser()->email();
63 const user_manager::User
* MockUserManager::GetActiveUser() const {
64 return GetLoggedInUser();
67 user_manager::User
* MockUserManager::GetActiveUser() {
68 return GetLoggedInUser();
71 const user_manager::User
* MockUserManager::GetPrimaryUser() const {
72 return GetLoggedInUser();
75 BootstrapManager
* MockUserManager::GetBootstrapManager() {
79 MultiProfileUserController
* MockUserManager::GetMultiProfileUserController() {
83 UserImageManager
* MockUserManager::GetUserImageManager(
84 const std::string
& user_id
) {
88 SupervisedUserManager
* MockUserManager::GetSupervisedUserManager() {
89 return supervised_user_manager_
.get();
92 // Creates a new User instance.
93 void MockUserManager::SetActiveUser(const std::string
& email
) {
98 UserFlow
* MockUserManager::GetCurrentUserFlow() const {
99 return user_flow_
.get();
102 UserFlow
* MockUserManager::GetUserFlow(const std::string
&) const {
103 return user_flow_
.get();
106 user_manager::User
* MockUserManager::CreatePublicAccountUser(
107 const std::string
& email
) {
109 user_manager::User
* user
= user_manager::User::CreatePublicAccountUser(email
);
110 user_list_
.push_back(user
);
111 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user
);
112 return user_list_
.back();
115 user_manager::User
* MockUserManager::CreateKioskAppUser(
116 const std::string
& email
) {
118 user_list_
.push_back(user_manager::User::CreateKioskAppUser(email
));
119 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_
.back());
120 return user_list_
.back();
123 void MockUserManager::AddUser(const std::string
& email
) {
124 AddUserWithAffiliation(email
, false);
127 void MockUserManager::AddUserWithAffiliation(const std::string
& email
,
128 bool is_affiliated
) {
129 user_manager::User
* user
= user_manager::User::CreateRegularUser(email
);
130 user
->set_affiliation(is_affiliated
);
131 user_list_
.push_back(user
);
132 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user
);
135 void MockUserManager::ClearUserList() {
136 // Can't use STLDeleteElements because of the protected destructor of User.
137 user_manager::UserList::iterator user
;
138 for (user
= user_list_
.begin(); user
!= user_list_
.end(); ++user
)
143 bool MockUserManager::ShouldReportUser(const std::string
& user_id
) const {
144 for (const auto& user
: user_list_
) {
145 if (user
->GetUserID() == user_id
) {
146 return user
->is_affiliated();
153 } // namespace chromeos