1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/fake_user_manager.h"
#include "chrome/browser/chromeos/login/fake_supervised_user_manager.h"
namespace {
// As defined in /chromeos/dbus/cryptohome_client.cc.
static const char kUserIdHashSuffix[] = "-hash";
} // namespace
namespace chromeos {
FakeUserManager::FakeUserManager()
: supervised_user_manager_(new FakeSupervisedUserManager),
primary_user_(NULL) {}
FakeUserManager::~FakeUserManager() {
// Can't use STLDeleteElements because of the private destructor of User.
for (UserList::iterator it = user_list_.begin(); it != user_list_.end();
it = user_list_.erase(it)) {
delete *it;
}
}
void FakeUserManager::AddUser(const std::string& email) {
User* user = User::CreateRegularUser(email);
user->set_username_hash(email + kUserIdHashSuffix);
user->SetStubImage(User::kProfileImageIndex, false);
user_list_.push_back(user);
}
void FakeUserManager::AddKioskAppUser(const std::string& kiosk_app_username) {
User* user = User::CreateKioskAppUser(kiosk_app_username);
user->set_username_hash(kiosk_app_username + kUserIdHashSuffix);
user_list_.push_back(user);
}
void FakeUserManager::LoginUser(const std::string& email) {
UserLoggedIn(email, email + kUserIdHashSuffix, false);
}
const UserList& FakeUserManager::GetUsers() const {
return user_list_;
}
UserList FakeUserManager::GetUsersAdmittedForMultiProfile() const {
UserList result;
for (UserList::const_iterator it = user_list_.begin();
it != user_list_.end();
++it) {
if ((*it)->GetType() == User::USER_TYPE_REGULAR && !(*it)->is_logged_in())
result.push_back(*it);
}
return result;
}
const UserList& FakeUserManager::GetLoggedInUsers() const {
return logged_in_users_;
}
void FakeUserManager::UserLoggedIn(const std::string& email,
const std::string& username_hash,
bool browser_restart) {
for (UserList::const_iterator it = user_list_.begin();
it != user_list_.end();
++it) {
if ((*it)->username_hash() == username_hash) {
(*it)->set_is_logged_in(true);
logged_in_users_.push_back(*it);
if (!primary_user_)
primary_user_ = *it;
break;
}
}
}
User* FakeUserManager::GetActiveUserInternal() const {
if (user_list_.size()) {
if (!active_user_id_.empty()) {
for (UserList::const_iterator it = user_list_.begin();
it != user_list_.end(); ++it) {
if ((*it)->email() == active_user_id_)
return *it;
}
}
return user_list_[0];
}
return NULL;
}
const User* FakeUserManager::GetActiveUser() const {
return GetActiveUserInternal();
}
User* FakeUserManager::GetActiveUser() {
return GetActiveUserInternal();
}
void FakeUserManager::SwitchActiveUser(const std::string& email) {
active_user_id_ = email;
}
void FakeUserManager::SaveUserDisplayName(
const std::string& username,
const string16& display_name) {
for (UserList::iterator it = user_list_.begin();
it != user_list_.end(); ++it) {
if ((*it)->email() == username) {
(*it)->set_display_name(display_name);
return;
}
}
}
void FakeUserManager::UpdateUserAccountData(const std::string&, const string16&,
const std::string&) {
// Not implemented
}
SupervisedUserManager* FakeUserManager::GetSupervisedUserManager() {
return supervised_user_manager_.get();
}
UserImageManager* FakeUserManager::GetUserImageManager() {
return NULL;
}
const UserList& FakeUserManager::GetLRULoggedInUsers() {
return user_list_;
}
UserList FakeUserManager::GetUnlockUsers() const {
return user_list_;
}
const std::string& FakeUserManager::GetOwnerEmail() {
return owner_email_;
}
bool FakeUserManager::IsKnownUser(const std::string& email) const {
return true;
}
const User* FakeUserManager::FindUser(const std::string& email) const {
return NULL;
}
User* FakeUserManager::FindUserAndModify(const std::string& email) {
return NULL;
}
const User* FakeUserManager::GetLoggedInUser() const {
return NULL;
}
User* FakeUserManager::GetLoggedInUser() {
return NULL;
}
const User* FakeUserManager::GetPrimaryUser() const {
return primary_user_;
}
User* FakeUserManager::GetUserByProfile(Profile* profile) const {
const std::string& user_name = profile->GetProfileName();
for (UserList::const_iterator it = user_list_.begin();
it != user_list_.end(); ++it) {
if ((*it)->email() == user_name)
return *it;
}
return primary_user_;
}
string16 FakeUserManager::GetUserDisplayName(
const std::string& username) const {
return string16();
}
std::string FakeUserManager::GetUserDisplayEmail(
const std::string& username) const {
return std::string();
}
bool FakeUserManager::IsCurrentUserOwner() const {
return false;
}
bool FakeUserManager::IsCurrentUserNew() const {
return false;
}
bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
return false;
}
bool FakeUserManager::CanCurrentUserLock() const {
return false;
}
bool FakeUserManager::IsUserLoggedIn() const {
return logged_in_users_.size() > 0;
}
bool FakeUserManager::IsLoggedInAsRegularUser() const {
return true;
}
bool FakeUserManager::IsLoggedInAsDemoUser() const {
return false;
}
bool FakeUserManager::IsLoggedInAsPublicAccount() const {
return false;
}
bool FakeUserManager::IsLoggedInAsGuest() const {
return false;
}
bool FakeUserManager::IsLoggedInAsLocallyManagedUser() const {
return false;
}
bool FakeUserManager::IsLoggedInAsKioskApp() const {
const User* active_user = GetActiveUser();
return active_user ?
active_user->GetType() == User::USER_TYPE_KIOSK_APP :
false;
}
bool FakeUserManager::IsLoggedInAsStub() const {
return false;
}
bool FakeUserManager::IsSessionStarted() const {
return false;
}
bool FakeUserManager::UserSessionsRestored() const {
return false;
}
bool FakeUserManager::HasBrowserRestarted() const {
return false;
}
bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
const std::string& email) const {
return false;
}
UserFlow* FakeUserManager::GetCurrentUserFlow() const {
return NULL;
}
UserFlow* FakeUserManager::GetUserFlow(const std::string& email) const {
return NULL;
}
bool FakeUserManager::GetAppModeChromeClientOAuthInfo(
std::string* chrome_client_id,
std::string* chrome_client_secret) {
return false;
}
bool FakeUserManager::AreLocallyManagedUsersAllowed() const {
return true;
}
base::FilePath FakeUserManager::GetUserProfileDir(
const std::string&email) const {
return base::FilePath();
}
bool FakeUserManager::RespectLocalePreference(
Profile* profile,
const User* user,
scoped_ptr<locale_util::SwitchLanguageCallback> callback) const {
return false;
}
} // namespace chromeos
|