Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(939)

Side by Side Diff: chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc

Issue 2504513002: Make FakeChromeUserManager subclass of ChromeUserManager (Closed)
Patch Set: Re-enable tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 5 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
11 #include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h" 11 #include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h"
12 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" 12 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h"
13 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 13 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" 14 #include "chrome/browser/chromeos/profiles/profile_helper.h"
15 #include "chrome/browser/chromeos/settings/cros_settings.h" 15 #include "chrome/browser/chromeos/settings/cros_settings.h"
16 #include "chrome/grit/theme_resources.h" 16 #include "chrome/grit/theme_resources.h"
17 #include "chromeos/chromeos_switches.h" 17 #include "chromeos/chromeos_switches.h"
18 #include "chromeos/login/login_state.h" 18 #include "chromeos/login/login_state.h"
19 #include "components/user_manager/user_image/user_image.h" 19 #include "components/user_manager/user_image/user_image.h"
20 #include "components/user_manager/user_names.h" 20 #include "components/user_manager/user_names.h"
21 #include "components/user_manager/user_type.h" 21 #include "components/user_manager/user_type.h"
22 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/image/image_skia.h" 23 #include "ui/gfx/image/image_skia.h"
24 24
25 namespace {
26
27 class FakeTaskRunner : public base::TaskRunner {
28 public:
29 bool PostDelayedTask(const tracked_objects::Location& from_here,
achuithb 2016/11/15 20:13:28 Add comment: // TaskRunner overrides. or something
yoshiki 2016/11/16 15:50:19 Done.
30 const base::Closure& task,
31 base::TimeDelta delay) override {
32 task.Run();
33 return true;
34 }
35 bool RunsTasksOnCurrentThread() const override { return true; }
36
37 protected:
38 ~FakeTaskRunner() override {}
39 };
achuithb 2016/11/15 20:13:28 DISALLOW_COPY_AND_ASSIGN in private section
yoshiki 2016/11/16 15:50:19 Done.
40
41 } // namespace
42
25 namespace chromeos { 43 namespace chromeos {
26 44
27 class FakeSupervisedUserManager; 45 class FakeSupervisedUserManager;
28 46
29 FakeChromeUserManager::FakeChromeUserManager() 47 FakeChromeUserManager::FakeChromeUserManager()
30 : supervised_user_manager_(new FakeSupervisedUserManager), 48 : ChromeUserManager(new FakeTaskRunner()),
49 supervised_user_manager_(new FakeSupervisedUserManager),
31 bootstrap_manager_(NULL), 50 bootstrap_manager_(NULL),
32 multi_profile_user_controller_(NULL) { 51 multi_profile_user_controller_(NULL) {
achuithb 2016/11/15 20:13:28 move the initialization of these to header
yoshiki 2016/11/16 15:50:19 Done.
33 ProfileHelper::SetProfileToUserForTestingEnabled(true); 52 ProfileHelper::SetProfileToUserForTestingEnabled(true);
34 } 53 }
35 54
36 FakeChromeUserManager::~FakeChromeUserManager() { 55 FakeChromeUserManager::~FakeChromeUserManager() {
37 ProfileHelper::SetProfileToUserForTestingEnabled(false); 56 ProfileHelper::SetProfileToUserForTestingEnabled(false);
38 } 57 }
39 58
40 const user_manager::User* FakeChromeUserManager::AddUser( 59 const user_manager::User* FakeChromeUserManager::AddUser(
41 const AccountId& account_id) { 60 const AccountId& account_id) {
42 return AddUserWithAffiliation(account_id, false); 61 return AddUserWithAffiliation(account_id, false);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 189
171 void FakeChromeUserManager::OnSessionStarted() {} 190 void FakeChromeUserManager::OnSessionStarted() {}
172 191
173 void FakeChromeUserManager::RemoveUser( 192 void FakeChromeUserManager::RemoveUser(
174 const AccountId& account_id, 193 const AccountId& account_id,
175 user_manager::RemoveUserDelegate* delegate) {} 194 user_manager::RemoveUserDelegate* delegate) {}
176 195
177 void FakeChromeUserManager::RemoveUserFromList(const AccountId& account_id) { 196 void FakeChromeUserManager::RemoveUserFromList(const AccountId& account_id) {
178 WallpaperManager::Get()->RemoveUserWallpaperInfo(account_id); 197 WallpaperManager::Get()->RemoveUserWallpaperInfo(account_id);
179 chromeos::ProfileHelper::Get()->RemoveUserFromListForTesting(account_id); 198 chromeos::ProfileHelper::Get()->RemoveUserFromListForTesting(account_id);
180 FakeUserManager::RemoveUserFromList(account_id); 199
200 const user_manager::UserList::iterator it =
201 std::find_if(users_.begin(), users_.end(),
202 [&account_id](const user_manager::User* user) {
203 return user->GetAccountId() == account_id;
204 });
205 if (it != users_.end()) {
206 if (primary_user_ == *it)
207 primary_user_ = nullptr;
208 if (active_user_ != *it)
209 delete *it;
210 users_.erase(it);
211 }
181 } 212 }
182 213
183 user_manager::UserList 214 user_manager::UserList
184 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { 215 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const {
185 CrosSettings* cros_settings = CrosSettings::Get(); 216 CrosSettings* cros_settings = CrosSettings::Get();
186 bool allow_new_user = true; 217 bool allow_new_user = true;
187 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); 218 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
188 bool supervised_users_allowed = AreSupervisedUsersAllowed(); 219 bool supervised_users_allowed = AreSupervisedUsersAllowed();
189 220
190 // Restricted either by policy or by owner. 221 // Restricted either by policy or by owner.
191 if (!allow_new_user || !supervised_users_allowed) 222 if (!allow_new_user || !supervised_users_allowed)
192 return user_manager::UserList(); 223 return user_manager::UserList();
193 224
194 return ChromeUserManager::GetUsersAllowedAsSupervisedUserManagers(GetUsers()); 225 return GetUsersAllowedAsSupervisedUserManagers(GetUsers());
195 } 226 }
196 227
197 user_manager::UserList FakeChromeUserManager::GetUsersAllowedForMultiProfile() 228 user_manager::UserList FakeChromeUserManager::GetUsersAllowedForMultiProfile()
198 const { 229 const {
199 // Supervised users are not allowed to use multi-profiles. 230 // Supervised users are not allowed to use multi-profiles.
200 if (GetLoggedInUsers().size() == 1 && 231 if (GetLoggedInUsers().size() == 1 &&
201 GetPrimaryUser()->GetType() != user_manager::USER_TYPE_REGULAR) { 232 GetPrimaryUser()->GetType() != user_manager::USER_TYPE_REGULAR) {
202 return user_manager::UserList(); 233 return user_manager::UserList();
203 } 234 }
204 235
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 std::string* out_resolved_locale) const { 318 std::string* out_resolved_locale) const {
288 NOTIMPLEMENTED(); 319 NOTIMPLEMENTED();
289 return; 320 return;
290 } 321 }
291 322
292 bool FakeChromeUserManager::IsValidDefaultUserImageId(int image_index) const { 323 bool FakeChromeUserManager::IsValidDefaultUserImageId(int image_index) const {
293 NOTIMPLEMENTED(); 324 NOTIMPLEMENTED();
294 return false; 325 return false;
295 } 326 }
296 327
328 // UserManager implementation:
329 void FakeChromeUserManager::Initialize() {
330 return ChromeUserManager::Initialize();
331 }
332
333 void FakeChromeUserManager::Shutdown() {
334 return ChromeUserManager::Shutdown();
335 }
336
337 const user_manager::UserList& FakeChromeUserManager::GetUsers() const {
338 return users_;
339 }
340
341 const user_manager::UserList& FakeChromeUserManager::GetLoggedInUsers() const {
342 return logged_in_users_;
343 }
344
345 const user_manager::UserList& FakeChromeUserManager::GetLRULoggedInUsers()
346 const {
347 return users_;
348 }
349
350 user_manager::UserList FakeChromeUserManager::GetUnlockUsers() const {
351 return users_;
352 }
353
354 void FakeChromeUserManager::UserLoggedIn(const AccountId& account_id,
355 const std::string& username_hash,
356 bool browser_restart) {
357 for (user_manager::UserList::const_iterator it = users_.begin();
achuithb 2016/11/15 20:13:28 range loop
yoshiki 2016/11/16 15:50:19 Done.
358 it != users_.end(); ++it) {
359 if ((*it)->username_hash() == username_hash) {
360 (*it)->set_is_logged_in(true);
361 (*it)->set_profile_is_created();
362 logged_in_users_.push_back(*it);
363
364 if (!primary_user_)
365 primary_user_ = *it;
366 break;
367 }
368 }
369 }
370
371 void FakeChromeUserManager::SwitchToLastActiveUser() {
372 NOTREACHED();
373 }
374
375 bool FakeChromeUserManager::IsKnownUser(const AccountId& account_id) const {
376 return true;
377 }
378
379 const user_manager::User* FakeChromeUserManager::FindUser(
380 const AccountId& account_id) const {
381 if (active_user_ != nullptr && active_user_->GetAccountId() == account_id)
382 return active_user_;
383
384 const user_manager::UserList& users = GetUsers();
385 for (user_manager::UserList::const_iterator it = users.begin();
achuithb 2016/11/15 20:13:28 Does a range loop not work here?
yoshiki 2016/11/16 15:50:19 Done.
386 it != users.end(); ++it) {
387 if ((*it)->GetAccountId() == account_id)
388 return *it;
389 }
390
391 return nullptr;
392 }
393
394 user_manager::User* FakeChromeUserManager::FindUserAndModify(
395 const AccountId& account_id) {
396 return nullptr;
397 }
398
399 const user_manager::User* FakeChromeUserManager::GetActiveUser() const {
400 return GetActiveUserInternal();
401 }
402
403 user_manager::User* FakeChromeUserManager::GetActiveUser() {
404 return GetActiveUserInternal();
405 }
406
407 const user_manager::User* FakeChromeUserManager::GetPrimaryUser() const {
408 return primary_user_;
409 }
410
411 void FakeChromeUserManager::SaveUserOAuthStatus(
412 const AccountId& account_id,
413 user_manager::User::OAuthTokenStatus oauth_token_status) {
414 NOTREACHED();
415 }
416
417 void FakeChromeUserManager::SaveForceOnlineSignin(const AccountId& account_id,
418 bool force_online_signin) {
419 NOTREACHED();
420 }
421
422 void FakeChromeUserManager::SaveUserDisplayName(
423 const AccountId& account_id,
424 const base::string16& display_name) {
425 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end();
achuithb 2016/11/15 20:13:28 range loop
yoshiki 2016/11/16 15:50:19 Done.
426 ++it) {
427 if ((*it)->GetAccountId() == account_id) {
428 (*it)->set_display_name(display_name);
429 return;
430 }
431 }
432 }
433
434 base::string16 FakeChromeUserManager::GetUserDisplayName(
435 const AccountId& account_id) const {
436 return base::string16();
437 }
438
439 void FakeChromeUserManager::SaveUserDisplayEmail(
440 const AccountId& account_id,
441 const std::string& display_email) {
442 NOTREACHED();
443 }
444
445 std::string FakeChromeUserManager::GetUserDisplayEmail(
446 const AccountId& account_id) const {
447 return std::string();
448 }
449
450 void FakeChromeUserManager::SaveUserType(
451 const AccountId& account_id,
452 const user_manager::UserType& user_type) {
453 NOTREACHED();
454 }
455
456 void FakeChromeUserManager::UpdateUserAccountData(
457 const AccountId& account_id,
458 const UserAccountData& account_data) {
459 NOTREACHED();
460 }
461
462 bool FakeChromeUserManager::IsCurrentUserOwner() const {
463 return false;
464 }
465
466 bool FakeChromeUserManager::IsCurrentUserNew() const {
467 return false;
468 }
469
470 bool FakeChromeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
471 return false;
472 }
473
474 bool FakeChromeUserManager::CanCurrentUserLock() const {
475 return false;
476 }
477
478 bool FakeChromeUserManager::IsUserLoggedIn() const {
479 return logged_in_users_.size() > 0;
480 }
481
482 bool FakeChromeUserManager::IsLoggedInAsUserWithGaiaAccount() const {
483 return true;
484 }
485
486 bool FakeChromeUserManager::IsLoggedInAsChildUser() const {
487 NOTREACHED();
488 return false;
489 }
490
491 bool FakeChromeUserManager::IsLoggedInAsPublicAccount() const {
492 return false;
493 }
494
495 bool FakeChromeUserManager::IsLoggedInAsGuest() const {
496 return false;
497 }
498
499 bool FakeChromeUserManager::IsLoggedInAsSupervisedUser() const {
500 return false;
501 }
502
503 bool FakeChromeUserManager::IsLoggedInAsKioskApp() const {
504 const user_manager::User* active_user = GetActiveUser();
505 return active_user
506 ? active_user->GetType() == user_manager::USER_TYPE_KIOSK_APP
507 : false;
508 }
509
510 bool FakeChromeUserManager::IsLoggedInAsArcKioskApp() const {
511 const user_manager::User* active_user = GetActiveUser();
512 return active_user
513 ? active_user->GetType() == user_manager::USER_TYPE_ARC_KIOSK_APP
514 : false;
515 }
516
517 bool FakeChromeUserManager::IsLoggedInAsStub() const {
518 return false;
519 }
520
521 bool FakeChromeUserManager::IsUserNonCryptohomeDataEphemeral(
522 const AccountId& account_id) const {
523 return false;
524 }
525
526 void FakeChromeUserManager::AddObserver(UserManager::Observer* obs) {
527 NOTREACHED();
528 }
529
530 void FakeChromeUserManager::RemoveObserver(UserManager::Observer* obs) {
531 NOTREACHED();
532 }
533
534 void FakeChromeUserManager::AddSessionStateObserver(
535 UserManager::UserSessionStateObserver* obs) {}
536
537 void FakeChromeUserManager::RemoveSessionStateObserver(
538 UserManager::UserSessionStateObserver* obs) {}
539
540 void FakeChromeUserManager::NotifyLocalStateChanged() {
541 NOTREACHED();
542 }
543
544 void FakeChromeUserManager::ChangeUserChildStatus(user_manager::User* user,
545 bool is_child) {
546 NOTREACHED();
547 }
548
549 bool FakeChromeUserManager::AreSupervisedUsersAllowed() const {
550 return true;
551 }
552
553 PrefService* FakeChromeUserManager::GetLocalState() const {
554 return nullptr;
555 }
556
557 void FakeChromeUserManager::SetIsCurrentUserNew(bool is_new) {
558 NOTREACHED();
559 }
560
561 const std::string& FakeChromeUserManager::GetApplicationLocale() const {
562 static const std::string default_locale("en-US");
563 return default_locale;
564 }
565
566 void FakeChromeUserManager::HandleUserOAuthTokenStatusChange(
567 const AccountId& account_id,
568 user_manager::User::OAuthTokenStatus status) const {
569 NOTREACHED();
570 }
571
572 void FakeChromeUserManager::LoadDeviceLocalAccounts(
573 std::set<AccountId>* users_set) {
574 NOTREACHED();
575 }
576
577 bool FakeChromeUserManager::IsEnterpriseManaged() const {
578 return false;
579 }
580
581 void FakeChromeUserManager::PerformPreUserListLoadingActions() {
582 NOTREACHED();
583 }
584
585 void FakeChromeUserManager::PerformPostUserListLoadingActions() {
586 NOTREACHED();
587 }
588
589 void FakeChromeUserManager::PerformPostUserLoggedInActions(
590 bool browser_restart) {
591 NOTREACHED();
592 }
593
594 bool FakeChromeUserManager::IsDemoApp(const AccountId& account_id) const {
595 return account_id == user_manager::DemoAccountId();
596 }
597
598 bool FakeChromeUserManager::IsDeviceLocalAccountMarkedForRemoval(
599 const AccountId& account_id) const {
600 return false;
601 }
602
603 void FakeChromeUserManager::DemoAccountLoggedIn() {
604 NOTREACHED();
605 }
606
607 void FakeChromeUserManager::KioskAppLoggedIn(user_manager::User* user) {}
608
609 void FakeChromeUserManager::PublicAccountUserLoggedIn(
610 user_manager::User* user) {
611 NOTREACHED();
612 }
613
614 void FakeChromeUserManager::SupervisedUserLoggedIn(
615 const AccountId& account_id) {
616 NOTREACHED();
617 }
618
619 void FakeChromeUserManager::OnUserRemoved(const AccountId& account_id) {
620 NOTREACHED();
621 }
622
623 void FakeChromeUserManager::SetUserAffiliation(
624 const std::string& user_email,
625 const AffiliationIDSet& user_affiliation_ids) {}
626
627 bool FakeChromeUserManager::ShouldReportUser(const std::string& user_id) const {
628 return false;
629 }
630
631 user_manager::User* FakeChromeUserManager::GetActiveUserInternal() const {
632 if (active_user_ != nullptr)
633 return active_user_;
634
635 if (!users_.empty()) {
achuithb 2016/11/15 20:13:28 Early return seems preferable here rather than nes
yoshiki 2016/11/16 15:50:19 Done.
636 if (active_account_id_.is_valid()) {
637 for (user_manager::UserList::const_iterator it = users_.begin();
achuithb 2016/11/15 20:13:28 range loop
yoshiki 2016/11/16 15:50:19 Done.
638 it != users_.end(); ++it) {
639 if ((*it)->GetAccountId() == active_account_id_)
640 return *it;
641 }
642 }
643 return users_[0];
644 }
645 return nullptr;
646 }
647
297 } // namespace chromeos 648 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698