[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / components / user_manager / fake_user_manager.cc
blob5e8d5613e3c1e8b555e93e078025fd6bf1542b97
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 user_manager::User* user = user_manager::User::CreateRegularUser(email);
43 users_.push_back(user);
44 return 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)
50 ++it;
51 if (it != users_.end()) {
52 delete *it;
53 users_.erase(it);
57 const user_manager::UserList& FakeUserManager::GetUsers() const {
58 return users_;
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);
69 return result;
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);
86 if (!primary_user_)
87 primary_user_ = *it;
88 break;
93 user_manager::User* FakeUserManager::GetActiveUserInternal() const {
94 if (users_.size()) {
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_)
99 return *it;
102 return users_[0];
104 return NULL;
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();
121 ++it) {
122 if ((*it)->email() == username) {
123 (*it)->set_display_name(display_name);
124 return;
129 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const {
130 return users_;
133 user_manager::UserList FakeUserManager::GetUnlockUsers() const {
134 return users_;
137 const std::string& FakeUserManager::GetOwnerEmail() const {
138 return owner_email_;
141 bool FakeUserManager::IsKnownUser(const std::string& email) const {
142 return true;
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)
151 return *it;
153 return NULL;
156 user_manager::User* FakeUserManager::FindUserAndModify(
157 const std::string& email) {
158 return NULL;
161 const user_manager::User* FakeUserManager::GetLoggedInUser() const {
162 return NULL;
165 user_manager::User* FakeUserManager::GetLoggedInUser() {
166 return NULL;
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 {
184 return false;
187 bool FakeUserManager::IsCurrentUserNew() const {
188 return false;
191 bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
192 return false;
195 bool FakeUserManager::CanCurrentUserLock() const {
196 return false;
199 bool FakeUserManager::IsUserLoggedIn() const {
200 return logged_in_users_.size() > 0;
203 bool FakeUserManager::IsLoggedInAsUserWithGaiaAccount() const {
204 return true;
207 bool FakeUserManager::IsLoggedInAsPublicAccount() const {
208 return false;
211 bool FakeUserManager::IsLoggedInAsGuest() const {
212 return false;
215 bool FakeUserManager::IsLoggedInAsSupervisedUser() const {
216 return false;
219 bool FakeUserManager::IsLoggedInAsKioskApp() const {
220 const user_manager::User* active_user = GetActiveUser();
221 return active_user
222 ? active_user->GetType() == user_manager::USER_TYPE_KIOSK_APP
223 : false;
226 bool FakeUserManager::IsLoggedInAsStub() const {
227 return false;
230 bool FakeUserManager::IsSessionStarted() const {
231 return false;
234 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
235 const std::string& email) const {
236 return false;
239 bool FakeUserManager::AreSupervisedUsersAllowed() const {
240 return true;
243 bool FakeUserManager::AreEphemeralUsersEnabled() const {
244 return false;
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 {
253 return NULL;
256 bool FakeUserManager::IsEnterpriseManaged() const {
257 return false;
260 bool FakeUserManager::IsDemoApp(const std::string& user_id) const {
261 return false;
264 bool FakeUserManager::IsKioskApp(const std::string& user_id) const {
265 return false;
268 bool FakeUserManager::IsPublicAccountMarkedForRemoval(
269 const std::string& user_id) const {
270 return false;
273 } // namespace user_manager