1 // Copyright (c) 2012 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. 4 5 #include "chrome/browser/chromeos/login/mock_user_manager.h" 6 7 #include "chrome/browser/chromeos/login/fake_supervised_user_manager.h" 8 9 namespace chromeos { 10 11 MockUserManager::MockUserManager() 12 : user_flow_(new DefaultUserFlow()), 13 supervised_user_manager_(new FakeSupervisedUserManager()) {} 14 15 MockUserManager::~MockUserManager() { 16 ClearUserList(); 17 } 18 19 const UserList& MockUserManager::GetUsers() const { 20 return user_list_; 21 } 22 23 const User* MockUserManager::GetLoggedInUser() const { 24 return user_list_.empty() ? NULL : user_list_.front(); 25 } 26 27 User* MockUserManager::GetLoggedInUser() { 28 return user_list_.empty() ? NULL : user_list_.front(); 29 } 30 31 UserList MockUserManager::GetUnlockUsers() const { 32 return user_list_; 33 } 34 35 const std::string& MockUserManager::GetOwnerEmail() { 36 return GetLoggedInUser()->email(); 37 } 38 39 const User* MockUserManager::GetActiveUser() const { 40 return GetLoggedInUser(); 41 } 42 43 User* MockUserManager::GetActiveUser() { 44 return GetLoggedInUser(); 45 } 46 47 const User* MockUserManager::GetPrimaryUser() const { 48 return GetLoggedInUser(); 49 } 50 51 User* MockUserManager::GetUserByProfile(Profile* profile) const { 52 return user_list_.empty() ? NULL : user_list_.front(); 53 } 54 55 UserImageManager* MockUserManager::GetUserImageManager() { 56 return user_image_manager_.get(); 57 } 58 59 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() { 60 return supervised_user_manager_.get(); 61 } 62 63 // Creates a new User instance. 64 void MockUserManager::SetActiveUser(const std::string& email) { 65 ClearUserList(); 66 AddUser(email); 67 } 68 69 UserFlow* MockUserManager::GetCurrentUserFlow() const { 70 return user_flow_.get(); 71 } 72 73 UserFlow* MockUserManager::GetUserFlow(const std::string&) const { 74 return user_flow_.get(); 75 } 76 77 User* MockUserManager::CreatePublicAccountUser(const std::string& email) { 78 ClearUserList(); 79 user_list_.push_back(User::CreatePublicAccountUser(email)); 80 return user_list_.back(); 81 } 82 83 void MockUserManager::AddUser(const std::string& email) { 84 user_list_.push_back(User::CreateRegularUser(email)); 85 } 86 87 void MockUserManager::ClearUserList() { 88 // Can't use STLDeleteElements because of the protected destructor of User. 89 UserList::iterator user; 90 for (user = user_list_.begin(); user != user_list_.end(); ++user) 91 delete *user; 92 user_list_.clear(); 93 } 94 95 bool MockUserManager::RespectLocalePreference( 96 Profile* profile, 97 const User* user, 98 scoped_ptr<locale_util::SwitchLanguageCallback> callback) const { 99 return false; 100 } 101 102 } // namespace chromeos 103