OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/mock_user_manager.h" | 5 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
6 | 6 |
7 #include "base/task_runner.h" | 7 #include "base/task_runner.h" |
8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" | 8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" |
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 | 50 |
51 user_manager::User* MockUserManager::GetLoggedInUser() { | 51 user_manager::User* MockUserManager::GetLoggedInUser() { |
52 return user_list_.empty() ? NULL : user_list_.front(); | 52 return user_list_.empty() ? NULL : user_list_.front(); |
53 } | 53 } |
54 | 54 |
55 user_manager::UserList MockUserManager::GetUnlockUsers() const { | 55 user_manager::UserList MockUserManager::GetUnlockUsers() const { |
56 return user_list_; | 56 return user_list_; |
57 } | 57 } |
58 | 58 |
59 const AccountId& MockUserManager::GetOwnerAccountId() const { | 59 const std::string& MockUserManager::GetOwnerEmail() const { |
60 temporary_owner_account_id_ = GetLoggedInUser()->GetAccountId(); | 60 return GetLoggedInUser()->email(); |
61 return temporary_owner_account_id_; | |
62 } | 61 } |
63 | 62 |
64 const user_manager::User* MockUserManager::GetActiveUser() const { | 63 const user_manager::User* MockUserManager::GetActiveUser() const { |
65 return GetLoggedInUser(); | 64 return GetLoggedInUser(); |
66 } | 65 } |
67 | 66 |
68 user_manager::User* MockUserManager::GetActiveUser() { | 67 user_manager::User* MockUserManager::GetActiveUser() { |
69 return GetLoggedInUser(); | 68 return GetLoggedInUser(); |
70 } | 69 } |
71 | 70 |
72 const user_manager::User* MockUserManager::GetPrimaryUser() const { | 71 const user_manager::User* MockUserManager::GetPrimaryUser() const { |
73 return GetLoggedInUser(); | 72 return GetLoggedInUser(); |
74 } | 73 } |
75 | 74 |
76 BootstrapManager* MockUserManager::GetBootstrapManager() { | 75 BootstrapManager* MockUserManager::GetBootstrapManager() { |
77 return NULL; | 76 return NULL; |
78 } | 77 } |
79 | 78 |
80 MultiProfileUserController* MockUserManager::GetMultiProfileUserController() { | 79 MultiProfileUserController* MockUserManager::GetMultiProfileUserController() { |
81 return NULL; | 80 return NULL; |
82 } | 81 } |
83 | 82 |
84 UserImageManager* MockUserManager::GetUserImageManager( | 83 UserImageManager* MockUserManager::GetUserImageManager( |
85 const AccountId& account_id) { | 84 const std::string& user_id) { |
86 return NULL; | 85 return NULL; |
87 } | 86 } |
88 | 87 |
89 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() { | 88 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() { |
90 return supervised_user_manager_.get(); | 89 return supervised_user_manager_.get(); |
91 } | 90 } |
92 | 91 |
93 // Creates a new User instance. | 92 // Creates a new User instance. |
94 void MockUserManager::SetActiveUser(const AccountId& account_id) { | 93 void MockUserManager::SetActiveUser(const std::string& email) { |
95 ClearUserList(); | 94 ClearUserList(); |
96 AddUser(account_id); | 95 AddUser(email); |
97 } | 96 } |
98 | 97 |
99 UserFlow* MockUserManager::GetCurrentUserFlow() const { | 98 UserFlow* MockUserManager::GetCurrentUserFlow() const { |
100 return user_flow_.get(); | 99 return user_flow_.get(); |
101 } | 100 } |
102 | 101 |
103 UserFlow* MockUserManager::GetUserFlow(const AccountId&) const { | 102 UserFlow* MockUserManager::GetUserFlow(const std::string&) const { |
104 return user_flow_.get(); | 103 return user_flow_.get(); |
105 } | 104 } |
106 | 105 |
107 user_manager::User* MockUserManager::CreatePublicAccountUser( | 106 user_manager::User* MockUserManager::CreatePublicAccountUser( |
108 const AccountId& account_id) { | 107 const std::string& email) { |
109 ClearUserList(); | 108 ClearUserList(); |
110 user_manager::User* user = | 109 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); |
111 user_manager::User::CreatePublicAccountUser(account_id); | |
112 user_list_.push_back(user); | 110 user_list_.push_back(user); |
113 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 111 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
114 return user_list_.back(); | 112 return user_list_.back(); |
115 } | 113 } |
116 | 114 |
117 user_manager::User* MockUserManager::CreateKioskAppUser( | 115 user_manager::User* MockUserManager::CreateKioskAppUser( |
118 const AccountId& account_id) { | 116 const std::string& email) { |
119 ClearUserList(); | 117 ClearUserList(); |
120 user_list_.push_back(user_manager::User::CreateKioskAppUser(account_id)); | 118 user_list_.push_back(user_manager::User::CreateKioskAppUser(email)); |
121 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_.back()); | 119 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_.back()); |
122 return user_list_.back(); | 120 return user_list_.back(); |
123 } | 121 } |
124 | 122 |
125 void MockUserManager::AddUser(const AccountId& account_id) { | 123 void MockUserManager::AddUser(const std::string& email) { |
126 AddUserWithAffiliation(account_id, false); | 124 AddUserWithAffiliation(email, false); |
127 } | 125 } |
128 | 126 |
129 void MockUserManager::AddUserWithAffiliation(const AccountId& account_id, | 127 void MockUserManager::AddUserWithAffiliation(const std::string& email, |
130 bool is_affiliated) { | 128 bool is_affiliated) { |
131 user_manager::User* user = user_manager::User::CreateRegularUser(account_id); | 129 user_manager::User* user = user_manager::User::CreateRegularUser(email); |
132 user->set_affiliation(is_affiliated); | 130 user->set_affiliation(is_affiliated); |
133 user_list_.push_back(user); | 131 user_list_.push_back(user); |
134 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 132 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
135 } | 133 } |
136 | 134 |
137 void MockUserManager::ClearUserList() { | 135 void MockUserManager::ClearUserList() { |
138 // Can't use STLDeleteElements because of the protected destructor of User. | 136 // Can't use STLDeleteElements because of the protected destructor of User. |
139 for (user_manager::UserList::iterator user = user_list_.begin(); | 137 user_manager::UserList::iterator user; |
140 user != user_list_.end(); ++user) | 138 for (user = user_list_.begin(); user != user_list_.end(); ++user) |
141 delete *user; | 139 delete *user; |
142 user_list_.clear(); | 140 user_list_.clear(); |
143 } | 141 } |
144 | 142 |
145 bool MockUserManager::ShouldReportUser(const std::string& user_id) const { | 143 bool MockUserManager::ShouldReportUser(const std::string& user_id) const { |
146 for (const auto& user : user_list_) { | 144 for (const auto& user : user_list_) { |
147 if (user->email() == user_id) | 145 if (user->GetUserID() == user_id) { |
148 return user->is_affiliated(); | 146 return user->is_affiliated(); |
| 147 } |
149 } | 148 } |
150 NOTREACHED(); | 149 NOTREACHED(); |
151 return false; | 150 return false; |
152 } | 151 } |
153 | 152 |
154 } // namespace chromeos | 153 } // namespace chromeos |
OLD | NEW |