Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / mock_user_manager.cc
blob0e79f653b2c2480f152826e8634aa0dff21f33ff
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 BootstrapManager* MockUserManager::GetBootstrapManager() {
76 return NULL;
79 MultiProfileUserController* MockUserManager::GetMultiProfileUserController() {
80 return NULL;
83 UserImageManager* MockUserManager::GetUserImageManager(
84 const std::string& user_id) {
85 return NULL;
88 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() {
89 return supervised_user_manager_.get();
92 // Creates a new User instance.
93 void MockUserManager::SetActiveUser(const std::string& email) {
94 ClearUserList();
95 AddUser(email);
98 UserFlow* MockUserManager::GetCurrentUserFlow() const {
99 return user_flow_.get();
102 UserFlow* MockUserManager::GetUserFlow(const std::string&) const {
103 return user_flow_.get();
106 user_manager::User* MockUserManager::CreatePublicAccountUser(
107 const std::string& email) {
108 ClearUserList();
109 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email);
110 user_list_.push_back(user);
111 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
112 return user_list_.back();
115 user_manager::User* MockUserManager::CreateKioskAppUser(
116 const std::string& email) {
117 ClearUserList();
118 user_list_.push_back(user_manager::User::CreateKioskAppUser(email));
119 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_.back());
120 return user_list_.back();
123 void MockUserManager::AddUser(const std::string& email) {
124 AddUserWithAffiliation(email, false);
127 void MockUserManager::AddUserWithAffiliation(const std::string& email,
128 bool is_affiliated) {
129 user_manager::User* user = user_manager::User::CreateRegularUser(email);
130 user->set_affiliation(is_affiliated);
131 user_list_.push_back(user);
132 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
135 void MockUserManager::ClearUserList() {
136 // Can't use STLDeleteElements because of the protected destructor of User.
137 user_manager::UserList::iterator user;
138 for (user = user_list_.begin(); user != user_list_.end(); ++user)
139 delete *user;
140 user_list_.clear();
143 bool MockUserManager::ShouldReportUser(const std::string& user_id) const {
144 for (const auto& user : user_list_) {
145 if (user->GetUserID() == user_id) {
146 return user->is_affiliated();
149 NOTREACHED();
150 return false;
153 } // namespace chromeos