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 "components/user_manager/fake_user_manager.h"
7 #include "base/callback.h"
8 #include "base/task_runner.h"
9 #include "components/user_manager/user_type.h"
10 #include "ui/base/resource/resource_bundle.h"
14 class FakeTaskRunner
: public base::TaskRunner
{
16 bool PostDelayedTask(const tracked_objects::Location
& from_here
,
17 const base::Closure
& task
,
18 base::TimeDelta delay
) override
{
22 bool RunsTasksOnCurrentThread() const override
{ return true; }
25 ~FakeTaskRunner() override
{}
30 namespace user_manager
{
32 FakeUserManager::FakeUserManager()
33 : UserManagerBase(new FakeTaskRunner(), new FakeTaskRunner()),
35 owner_email_(std::string()) {
38 FakeUserManager::~FakeUserManager() {
41 const user_manager::User
* FakeUserManager::AddUser(const std::string
& email
) {
42 user_manager::User
* user
= user_manager::User::CreateRegularUser(email
);
43 users_
.push_back(user
);
47 void FakeUserManager::RemoveUserFromList(const std::string
& email
) {
48 user_manager::UserList::iterator it
= users_
.begin();
49 while (it
!= users_
.end() && (*it
)->email() != email
)
51 if (it
!= users_
.end()) {
57 const user_manager::UserList
& FakeUserManager::GetUsers() const {
61 user_manager::UserList
FakeUserManager::GetUsersAllowedForMultiProfile() const {
62 user_manager::UserList result
;
63 for (user_manager::UserList::const_iterator it
= users_
.begin();
64 it
!= users_
.end(); ++it
) {
65 if ((*it
)->GetType() == user_manager::USER_TYPE_REGULAR
&&
66 !(*it
)->is_logged_in())
67 result
.push_back(*it
);
72 const user_manager::UserList
& FakeUserManager::GetLoggedInUsers() const {
73 return logged_in_users_
;
76 void FakeUserManager::UserLoggedIn(const std::string
& email
,
77 const std::string
& username_hash
,
78 bool browser_restart
) {
79 for (user_manager::UserList::const_iterator it
= users_
.begin();
80 it
!= users_
.end(); ++it
) {
81 if ((*it
)->username_hash() == username_hash
) {
82 (*it
)->set_is_logged_in(true);
83 (*it
)->set_profile_is_created();
84 logged_in_users_
.push_back(*it
);
93 user_manager::User
* FakeUserManager::GetActiveUserInternal() const {
95 if (!active_user_id_
.empty()) {
96 for (user_manager::UserList::const_iterator it
= users_
.begin();
97 it
!= users_
.end(); ++it
) {
98 if ((*it
)->email() == active_user_id_
)
107 const user_manager::User
* FakeUserManager::GetActiveUser() const {
108 return GetActiveUserInternal();
111 user_manager::User
* FakeUserManager::GetActiveUser() {
112 return GetActiveUserInternal();
115 void FakeUserManager::SwitchActiveUser(const std::string
& email
) {
118 void FakeUserManager::SaveUserDisplayName(const std::string
& username
,
119 const base::string16
& display_name
) {
120 for (user_manager::UserList::iterator it
= users_
.begin(); it
!= users_
.end();
122 if ((*it
)->email() == username
) {
123 (*it
)->set_display_name(display_name
);
129 const user_manager::UserList
& FakeUserManager::GetLRULoggedInUsers() const {
133 user_manager::UserList
FakeUserManager::GetUnlockUsers() const {
137 const std::string
& FakeUserManager::GetOwnerEmail() const {
141 bool FakeUserManager::IsKnownUser(const std::string
& email
) const {
145 const user_manager::User
* FakeUserManager::FindUser(
146 const std::string
& email
) const {
147 const user_manager::UserList
& users
= GetUsers();
148 for (user_manager::UserList::const_iterator it
= users
.begin();
149 it
!= users
.end(); ++it
) {
150 if ((*it
)->email() == email
)
156 user_manager::User
* FakeUserManager::FindUserAndModify(
157 const std::string
& email
) {
161 const user_manager::User
* FakeUserManager::GetLoggedInUser() const {
165 user_manager::User
* FakeUserManager::GetLoggedInUser() {
169 const user_manager::User
* FakeUserManager::GetPrimaryUser() const {
170 return primary_user_
;
173 base::string16
FakeUserManager::GetUserDisplayName(
174 const std::string
& username
) const {
175 return base::string16();
178 std::string
FakeUserManager::GetUserDisplayEmail(
179 const std::string
& username
) const {
180 return std::string();
183 bool FakeUserManager::IsCurrentUserOwner() const {
187 bool FakeUserManager::IsCurrentUserNew() const {
191 bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
195 bool FakeUserManager::CanCurrentUserLock() const {
199 bool FakeUserManager::IsUserLoggedIn() const {
200 return logged_in_users_
.size() > 0;
203 bool FakeUserManager::IsLoggedInAsUserWithGaiaAccount() const {
207 bool FakeUserManager::IsLoggedInAsPublicAccount() const {
211 bool FakeUserManager::IsLoggedInAsGuest() const {
215 bool FakeUserManager::IsLoggedInAsSupervisedUser() const {
219 bool FakeUserManager::IsLoggedInAsKioskApp() const {
220 const user_manager::User
* active_user
= GetActiveUser();
222 ? active_user
->GetType() == user_manager::USER_TYPE_KIOSK_APP
226 bool FakeUserManager::IsLoggedInAsStub() const {
230 bool FakeUserManager::IsSessionStarted() const {
234 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
235 const std::string
& email
) const {
239 bool FakeUserManager::AreSupervisedUsersAllowed() const {
243 bool FakeUserManager::AreEphemeralUsersEnabled() const {
247 const std::string
& FakeUserManager::GetApplicationLocale() const {
248 static const std::string
default_locale("en-US");
249 return default_locale
;
252 PrefService
* FakeUserManager::GetLocalState() const {
256 bool FakeUserManager::IsEnterpriseManaged() const {
260 bool FakeUserManager::IsDemoApp(const std::string
& user_id
) const {
264 bool FakeUserManager::IsKioskApp(const std::string
& user_id
) const {
268 bool FakeUserManager::IsPublicAccountMarkedForRemoval(
269 const std::string
& user_id
) const {
273 } // namespace user_manager