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 std::string& MockUserManager::GetOwnerEmail() const { | 59 const AccountId& MockUserManager::GetOwnerAccountId() const { |
60 return GetLoggedInUser()->email(); | 60 temporary_owner_account_id_ = GetLoggedInUser()->GetAccountId(); |
61 return temporary_owner_account_id_; | |
61 } | 62 } |
62 | 63 |
63 const user_manager::User* MockUserManager::GetActiveUser() const { | 64 const user_manager::User* MockUserManager::GetActiveUser() const { |
64 return GetLoggedInUser(); | 65 return GetLoggedInUser(); |
65 } | 66 } |
66 | 67 |
67 user_manager::User* MockUserManager::GetActiveUser() { | 68 user_manager::User* MockUserManager::GetActiveUser() { |
68 return GetLoggedInUser(); | 69 return GetLoggedInUser(); |
69 } | 70 } |
70 | 71 |
71 const user_manager::User* MockUserManager::GetPrimaryUser() const { | 72 const user_manager::User* MockUserManager::GetPrimaryUser() const { |
72 return GetLoggedInUser(); | 73 return GetLoggedInUser(); |
73 } | 74 } |
74 | 75 |
75 BootstrapManager* MockUserManager::GetBootstrapManager() { | 76 BootstrapManager* MockUserManager::GetBootstrapManager() { |
76 return NULL; | 77 return NULL; |
77 } | 78 } |
78 | 79 |
79 MultiProfileUserController* MockUserManager::GetMultiProfileUserController() { | 80 MultiProfileUserController* MockUserManager::GetMultiProfileUserController() { |
80 return NULL; | 81 return NULL; |
81 } | 82 } |
82 | 83 |
83 UserImageManager* MockUserManager::GetUserImageManager( | 84 UserImageManager* MockUserManager::GetUserImageManager( |
84 const std::string& user_id) { | 85 const AccountId& account_id) { |
85 return NULL; | 86 return NULL; |
86 } | 87 } |
87 | 88 |
88 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() { | 89 SupervisedUserManager* MockUserManager::GetSupervisedUserManager() { |
89 return supervised_user_manager_.get(); | 90 return supervised_user_manager_.get(); |
90 } | 91 } |
91 | 92 |
92 // Creates a new User instance. | 93 // Creates a new User instance. |
93 void MockUserManager::SetActiveUser(const std::string& email) { | 94 void MockUserManager::SetActiveUser(const AccountId& account_id) { |
94 ClearUserList(); | 95 ClearUserList(); |
95 AddUser(email); | 96 AddUser(account_id); |
96 } | 97 } |
97 | 98 |
98 UserFlow* MockUserManager::GetCurrentUserFlow() const { | 99 UserFlow* MockUserManager::GetCurrentUserFlow() const { |
99 return user_flow_.get(); | 100 return user_flow_.get(); |
100 } | 101 } |
101 | 102 |
102 UserFlow* MockUserManager::GetUserFlow(const std::string&) const { | 103 UserFlow* MockUserManager::GetUserFlow(const AccountId&) const { |
103 return user_flow_.get(); | 104 return user_flow_.get(); |
104 } | 105 } |
105 | 106 |
106 user_manager::User* MockUserManager::CreatePublicAccountUser( | 107 user_manager::User* MockUserManager::CreatePublicAccountUser( |
107 const std::string& email) { | 108 const AccountId& account_id) { |
108 ClearUserList(); | 109 ClearUserList(); |
109 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); | 110 user_manager::User* user = |
111 user_manager::User::CreatePublicAccountUser(account_id); | |
110 user_list_.push_back(user); | 112 user_list_.push_back(user); |
111 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 113 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
112 return user_list_.back(); | 114 return user_list_.back(); |
113 } | 115 } |
114 | 116 |
115 user_manager::User* MockUserManager::CreateKioskAppUser( | 117 user_manager::User* MockUserManager::CreateKioskAppUser( |
116 const std::string& email) { | 118 const AccountId& account_id) { |
117 ClearUserList(); | 119 ClearUserList(); |
118 user_list_.push_back(user_manager::User::CreateKioskAppUser(email)); | 120 user_list_.push_back(user_manager::User::CreateKioskAppUser(account_id)); |
119 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_.back()); | 121 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user_list_.back()); |
120 return user_list_.back(); | 122 return user_list_.back(); |
121 } | 123 } |
122 | 124 |
123 void MockUserManager::AddUser(const std::string& email) { | 125 void MockUserManager::AddUser(const AccountId& account_id) { |
124 AddUserWithAffiliation(email, false); | 126 AddUserWithAffiliation(account_id, false); |
125 } | 127 } |
126 | 128 |
127 void MockUserManager::AddUserWithAffiliation(const std::string& email, | 129 void MockUserManager::AddUserWithAffiliation(const AccountId& account_id, |
128 bool is_affiliated) { | 130 bool is_affiliated) { |
129 user_manager::User* user = user_manager::User::CreateRegularUser(email); | 131 user_manager::User* user = user_manager::User::CreateRegularUser(account_id); |
130 user->set_affiliation(is_affiliated); | 132 user->set_affiliation(is_affiliated); |
131 user_list_.push_back(user); | 133 user_list_.push_back(user); |
132 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); | 134 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); |
133 } | 135 } |
134 | 136 |
135 void MockUserManager::ClearUserList() { | 137 void MockUserManager::ClearUserList() { |
136 // Can't use STLDeleteElements because of the protected destructor of User. | 138 // Can't use STLDeleteElements because of the protected destructor of User. |
137 user_manager::UserList::iterator user; | 139 user_manager::UserList::iterator user; |
achuithb
2015/10/28 23:11:45
move this into for loop initializer
Alexander Alekseev
2015/10/29 02:00:41
Done.
| |
138 for (user = user_list_.begin(); user != user_list_.end(); ++user) | 140 for (user = user_list_.begin(); user != user_list_.end(); ++user) |
139 delete *user; | 141 delete *user; |
140 user_list_.clear(); | 142 user_list_.clear(); |
141 } | 143 } |
142 | 144 |
143 bool MockUserManager::ShouldReportUser(const std::string& user_id) const { | 145 bool MockUserManager::ShouldReportUser(const std::string& user_id) const { |
144 for (const auto& user : user_list_) { | 146 for (const auto& user : user_list_) { |
145 if (user->GetUserID() == user_id) { | 147 if (user->email() == user_id) { |
achuithb
2015/10/28 23:11:45
drop {}
Alexander Alekseev
2015/10/29 02:00:41
Done.
| |
146 return user->is_affiliated(); | 148 return user->is_affiliated(); |
147 } | 149 } |
148 } | 150 } |
149 NOTREACHED(); | 151 NOTREACHED(); |
150 return false; | 152 return false; |
151 } | 153 } |
152 | 154 |
153 } // namespace chromeos | 155 } // namespace chromeos |
OLD | NEW |