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 MultiProfileUserController
* MockUserManager::GetMultiProfileUserController() {
79 UserImageManager
* MockUserManager::GetUserImageManager(
80 const std::string
& user_id
) {
84 SupervisedUserManager
* MockUserManager::GetSupervisedUserManager() {
85 return supervised_user_manager_
.get();
88 // Creates a new User instance.
89 void MockUserManager::SetActiveUser(const std::string
& email
) {
94 UserFlow
* MockUserManager::GetCurrentUserFlow() const {
95 return user_flow_
.get();
98 UserFlow
* MockUserManager::GetUserFlow(const std::string
&) const {
99 return user_flow_
.get();
102 user_manager::User
* MockUserManager::CreatePublicAccountUser(
103 const std::string
& email
) {
105 user_manager::User
* user
= user_manager::User::CreatePublicAccountUser(email
);
106 user_list_
.push_back(user
);
107 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user
);
108 return user_list_
.back();
111 user_manager::User
* MockUserManager::CreateKioskAppUser(
112 const std::string
& email
) {
114 user_list_
.push_back(user_manager::User::CreateKioskAppUser(email
));
115 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_
.back());
116 return user_list_
.back();
119 void MockUserManager::AddUser(const std::string
& email
) {
120 user_manager::User
* user
= user_manager::User::CreateRegularUser(email
);
121 user_list_
.push_back(user
);
122 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user
);
125 void MockUserManager::ClearUserList() {
126 // Can't use STLDeleteElements because of the protected destructor of User.
127 user_manager::UserList::iterator user
;
128 for (user
= user_list_
.begin(); user
!= user_list_
.end(); ++user
)
133 } // namespace chromeos