cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / user_manager / fake_user_manager.cc
blob39f63f1eae4493c0525b1378d7ec5ffa204caa24
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"
12 namespace {
14 class FakeTaskRunner : public base::TaskRunner {
15 public:
16 bool PostDelayedTask(const tracked_objects::Location& from_here,
17 const base::Closure& task,
18 base::TimeDelta delay) override {
19 task.Run();
20 return true;
22 bool RunsTasksOnCurrentThread() const override { return true; }
24 protected:
25 ~FakeTaskRunner() override {}
28 } // namespace
30 namespace user_manager {
32 FakeUserManager::FakeUserManager()
33 : UserManagerBase(new FakeTaskRunner(), new FakeTaskRunner()),
34 primary_user_(NULL),
35 owner_email_(std::string()) {
38 FakeUserManager::~FakeUserManager() {
41 const user_manager::User* FakeUserManager::AddUser(const std::string& email) {
42 return AddUserWithAffiliation(email, false);
45 const user_manager::User* FakeUserManager::AddUserWithAffiliation(
46 const std::string& email, bool is_affiliated) {
47 user_manager::User* user = user_manager::User::CreateRegularUser(email);
48 user->set_affiliation(is_affiliated);
49 users_.push_back(user);
50 return user;
53 void FakeUserManager::RemoveUserFromList(const std::string& email) {
54 user_manager::UserList::iterator it = users_.begin();
55 while (it != users_.end() && (*it)->email() != email)
56 ++it;
57 if (it != users_.end()) {
58 delete *it;
59 users_.erase(it);
63 const user_manager::UserList& FakeUserManager::GetUsers() const {
64 return users_;
67 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const {
68 user_manager::UserList result;
69 for (user_manager::UserList::const_iterator it = users_.begin();
70 it != users_.end(); ++it) {
71 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR &&
72 !(*it)->is_logged_in())
73 result.push_back(*it);
75 return result;
78 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const {
79 return logged_in_users_;
82 void FakeUserManager::UserLoggedIn(const std::string& email,
83 const std::string& username_hash,
84 bool browser_restart) {
85 for (user_manager::UserList::const_iterator it = users_.begin();
86 it != users_.end(); ++it) {
87 if ((*it)->username_hash() == username_hash) {
88 (*it)->set_is_logged_in(true);
89 (*it)->set_profile_is_created();
90 logged_in_users_.push_back(*it);
92 if (!primary_user_)
93 primary_user_ = *it;
94 break;
99 user_manager::User* FakeUserManager::GetActiveUserInternal() const {
100 if (users_.size()) {
101 if (!active_user_id_.empty()) {
102 for (user_manager::UserList::const_iterator it = users_.begin();
103 it != users_.end(); ++it) {
104 if ((*it)->email() == active_user_id_)
105 return *it;
108 return users_[0];
110 return NULL;
113 const user_manager::User* FakeUserManager::GetActiveUser() const {
114 return GetActiveUserInternal();
117 user_manager::User* FakeUserManager::GetActiveUser() {
118 return GetActiveUserInternal();
121 void FakeUserManager::SwitchActiveUser(const std::string& email) {
124 void FakeUserManager::SaveUserDisplayName(const std::string& username,
125 const base::string16& display_name) {
126 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end();
127 ++it) {
128 if ((*it)->email() == username) {
129 (*it)->set_display_name(display_name);
130 return;
135 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const {
136 return users_;
139 user_manager::UserList FakeUserManager::GetUnlockUsers() const {
140 return users_;
143 const std::string& FakeUserManager::GetOwnerEmail() const {
144 return owner_email_;
147 bool FakeUserManager::IsKnownUser(const std::string& email) const {
148 return true;
151 const user_manager::User* FakeUserManager::FindUser(
152 const std::string& email) const {
153 const user_manager::UserList& users = GetUsers();
154 for (user_manager::UserList::const_iterator it = users.begin();
155 it != users.end(); ++it) {
156 if ((*it)->email() == email)
157 return *it;
159 return NULL;
162 user_manager::User* FakeUserManager::FindUserAndModify(
163 const std::string& email) {
164 return NULL;
167 const user_manager::User* FakeUserManager::GetLoggedInUser() const {
168 return NULL;
171 user_manager::User* FakeUserManager::GetLoggedInUser() {
172 return NULL;
175 const user_manager::User* FakeUserManager::GetPrimaryUser() const {
176 return primary_user_;
179 base::string16 FakeUserManager::GetUserDisplayName(
180 const std::string& username) const {
181 return base::string16();
184 std::string FakeUserManager::GetUserDisplayEmail(
185 const std::string& username) const {
186 return std::string();
189 bool FakeUserManager::IsCurrentUserOwner() const {
190 return false;
193 bool FakeUserManager::IsCurrentUserNew() const {
194 return false;
197 bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
198 return false;
201 bool FakeUserManager::CanCurrentUserLock() const {
202 return false;
205 bool FakeUserManager::IsUserLoggedIn() const {
206 return logged_in_users_.size() > 0;
209 bool FakeUserManager::IsLoggedInAsUserWithGaiaAccount() const {
210 return true;
213 bool FakeUserManager::IsLoggedInAsPublicAccount() const {
214 return false;
217 bool FakeUserManager::IsLoggedInAsGuest() const {
218 return false;
221 bool FakeUserManager::IsLoggedInAsSupervisedUser() const {
222 return false;
225 bool FakeUserManager::IsLoggedInAsKioskApp() const {
226 const user_manager::User* active_user = GetActiveUser();
227 return active_user
228 ? active_user->GetType() == user_manager::USER_TYPE_KIOSK_APP
229 : false;
232 bool FakeUserManager::IsLoggedInAsStub() const {
233 return false;
236 bool FakeUserManager::IsSessionStarted() const {
237 return false;
240 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
241 const std::string& email) const {
242 return false;
245 bool FakeUserManager::AreSupervisedUsersAllowed() const {
246 return true;
249 bool FakeUserManager::AreEphemeralUsersEnabled() const {
250 return false;
253 const std::string& FakeUserManager::GetApplicationLocale() const {
254 static const std::string default_locale("en-US");
255 return default_locale;
258 PrefService* FakeUserManager::GetLocalState() const {
259 return NULL;
262 bool FakeUserManager::IsEnterpriseManaged() const {
263 return false;
266 bool FakeUserManager::IsDemoApp(const std::string& user_id) const {
267 return false;
270 bool FakeUserManager::IsKioskApp(const std::string& user_id) const {
271 return false;
274 bool FakeUserManager::IsPublicAccountMarkedForRemoval(
275 const std::string& user_id) const {
276 return false;
279 } // namespace user_manager