ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / mock_user_manager.cc
blobac5df0acdfc3ce0764d162f41f5c0d422c32939c
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 "chrome/browser/chromeos/login/users/mock_user_manager.h"
7 #include "base/task_runner.h"
8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
11 namespace {
13 class FakeTaskRunner : public base::TaskRunner {
14 public:
15 bool PostDelayedTask(const tracked_objects::Location& from_here,
16 const base::Closure& task,
17 base::TimeDelta delay) override {
18 task.Run();
19 return true;
21 bool RunsTasksOnCurrentThread() const override { return true; }
23 protected:
24 ~FakeTaskRunner() override {}
27 } // namespace
29 namespace chromeos {
31 MockUserManager::MockUserManager()
32 : ChromeUserManager(new FakeTaskRunner(), new FakeTaskRunner()),
33 user_flow_(new DefaultUserFlow()),
34 supervised_user_manager_(new FakeSupervisedUserManager()) {
35 ProfileHelper::SetProfileToUserForTestingEnabled(true);
38 MockUserManager::~MockUserManager() {
39 ProfileHelper::SetProfileToUserForTestingEnabled(false);
40 ClearUserList();
43 const user_manager::UserList& MockUserManager::GetUsers() const {
44 return user_list_;
47 const user_manager::User* MockUserManager::GetLoggedInUser() const {
48 return user_list_.empty() ? NULL : user_list_.front();
51 user_manager::User* MockUserManager::GetLoggedInUser() {
52 return user_list_.empty() ? NULL : user_list_.front();
55 user_manager::UserList MockUserManager::GetUnlockUsers() const {
56 return user_list_;
59 const std::string& MockUserManager::GetOwnerEmail() const {
60 return GetLoggedInUser()->email();
63 const user_manager::User* MockUserManager::GetActiveUser() const {
64 return GetLoggedInUser();
67 user_manager::User* MockUserManager::GetActiveUser() {
68 return GetLoggedInUser();
71 const user_manager::User* MockUserManager::GetPrimaryUser() const {
72 return GetLoggedInUser();
75 MultiProfileUserController* MockUserManager::GetMultiProfileUserController() {
76 return NULL;
79 UserImageManager* MockUserManager::GetUserImageManager(
80 const std::string& user_id) {
81 return NULL;
84 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() {
85 return supervised_user_manager_.get();
88 // Creates a new User instance.
89 void MockUserManager::SetActiveUser(const std::string& email) {
90 ClearUserList();
91 AddUser(email);
94 UserFlow* MockUserManager::GetCurrentUserFlow() const {
95 return user_flow_.get();
98 UserFlow* MockUserManager::GetUserFlow(const std::string&) const {
99 return user_flow_.get();
102 user_manager::User* MockUserManager::CreatePublicAccountUser(
103 const std::string& email) {
104 ClearUserList();
105 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email);
106 user_list_.push_back(user);
107 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
108 return user_list_.back();
111 user_manager::User* MockUserManager::CreateKioskAppUser(
112 const std::string& email) {
113 ClearUserList();
114 user_list_.push_back(user_manager::User::CreateKioskAppUser(email));
115 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_.back());
116 return user_list_.back();
119 void MockUserManager::AddUser(const std::string& email) {
120 user_manager::User* user = user_manager::User::CreateRegularUser(email);
121 user_list_.push_back(user);
122 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
125 void MockUserManager::ClearUserList() {
126 // Can't use STLDeleteElements because of the protected destructor of User.
127 user_manager::UserList::iterator user;
128 for (user = user_list_.begin(); user != user_list_.end(); ++user)
129 delete *user;
130 user_list_.clear();
133 } // namespace chromeos