Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: ash/test/test_session_state_delegate.cc

Issue 1428213004: This CL replaces std::string user_id in ash/* with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ash/test/test_session_state_delegate.h" 5 #include "ash/test/test_session_state_delegate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/system/user/login_status.h" 11 #include "ash/system/user/login_status.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "components/signin/core/account_id/account_id.h" 15 #include "components/signin/core/account_id/account_id.h"
16 #include "components/user_manager/user_info.h" 16 #include "components/user_manager/user_info.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace ash { 19 namespace ash {
20 namespace test { 20 namespace test {
21 21
22 namespace { 22 namespace {
23 23
24 // The the "canonicalized" Account ID from a given |email| address. 24 // Returns the "canonicalized" email from a given |email| address.
25 AccountId GetAccountIdFromEmail(const std::string& email) { 25 std::string GetUserIdFromEmail(const std::string& email) {
26 std::string user_id = email; 26 std::string user_id = email;
27 std::transform(user_id.begin(), user_id.end(), user_id.begin(), ::tolower); 27 std::transform(user_id.begin(), user_id.end(), user_id.begin(), ::tolower);
28 return AccountId::FromUserEmail(user_id); 28 return user_id;
29 }
30
31 // Returns Account ID from a given |email| address.
32 AccountId GetAccountIdFromEmail(const std::string& email) {
33 return AccountId::FromUserEmail(GetUserIdFromEmail(email));
29 } 34 }
30 35
31 } // namespace 36 } // namespace
32 37
33 class MockUserInfo : public user_manager::UserInfo { 38 class MockUserInfo : public user_manager::UserInfo {
34 public: 39 public:
35 explicit MockUserInfo(const std::string& display_email) 40 explicit MockUserInfo(const std::string& display_email)
36 : display_email_(display_email), 41 : display_email_(display_email),
37 account_id_(GetAccountIdFromEmail(display_email)) {} 42 account_id_(GetAccountIdFromEmail(display_email)) {}
38 ~MockUserInfo() override {} 43 ~MockUserInfo() override {}
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 user_list_.push_back( 99 user_list_.push_back(
95 new MockUserInfo("Second@tray")); // This is intended to be capitalized. 100 new MockUserInfo("Second@tray")); // This is intended to be capitalized.
96 user_list_.push_back(new MockUserInfo("third@tray")); 101 user_list_.push_back(new MockUserInfo("third@tray"));
97 user_list_.push_back(new MockUserInfo("someone@tray")); 102 user_list_.push_back(new MockUserInfo("someone@tray"));
98 } 103 }
99 104
100 TestSessionStateDelegate::~TestSessionStateDelegate() { 105 TestSessionStateDelegate::~TestSessionStateDelegate() {
101 STLDeleteElements(&user_list_); 106 STLDeleteElements(&user_list_);
102 } 107 }
103 108
104 void TestSessionStateDelegate::AddUser(const std::string& user_id) { 109 void TestSessionStateDelegate::AddUser(const AccountId& account_id) {
105 user_list_.push_back(new MockUserInfo(user_id)); 110 user_list_.push_back(new MockUserInfo(account_id.GetUserEmail()));
106 } 111 }
107 112
108 const user_manager::UserInfo* TestSessionStateDelegate::GetActiveUserInfo() 113 const user_manager::UserInfo* TestSessionStateDelegate::GetActiveUserInfo()
109 const { 114 const {
110 return user_list_[active_user_index_]; 115 return user_list_[active_user_index_];
111 } 116 }
112 117
113 int TestSessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const { 118 int TestSessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const {
114 return 3; 119 return 3;
115 } 120 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 214
210 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { 215 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const {
211 return !GetActiveUserInfo()->GetImage().isNull(); 216 return !GetActiveUserInfo()->GetImage().isNull();
212 } 217 }
213 218
214 gfx::ImageSkia TestSessionStateDelegate::GetAvatarImageForWindow( 219 gfx::ImageSkia TestSessionStateDelegate::GetAvatarImageForWindow(
215 aura::Window* window) const { 220 aura::Window* window) const {
216 return gfx::ImageSkia(); 221 return gfx::ImageSkia();
217 } 222 }
218 223
219 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { 224 void TestSessionStateDelegate::SwitchActiveUser(const AccountId& account_id) {
220 const AccountId account_id(GetAccountIdFromEmail(user_id));
221 // Make sure this is a user id and not an email address. 225 // Make sure this is a user id and not an email address.
222 EXPECT_EQ(user_id, account_id.GetUserEmail()); 226 EXPECT_EQ(account_id.GetUserEmail(),
227 GetUserIdFromEmail(account_id.GetUserEmail()));
223 active_user_index_ = 0; 228 active_user_index_ = 0;
224 for (std::vector<MockUserInfo*>::iterator iter = user_list_.begin(); 229 for (std::vector<MockUserInfo*>::iterator iter = user_list_.begin();
225 iter != user_list_.end(); 230 iter != user_list_.end();
226 ++iter) { 231 ++iter) {
227 if ((*iter)->GetAccountId() == account_id) { 232 if ((*iter)->GetAccountId() == account_id) {
228 active_user_index_ = iter - user_list_.begin(); 233 active_user_index_ = iter - user_list_.begin();
229 return; 234 return;
230 } 235 }
231 } 236 }
232 NOTREACHED() << "Unknown user:" << account_id.GetUserEmail(); 237 NOTREACHED() << "Unknown user:" << account_id.GetUserEmail();
233 } 238 }
234 239
235 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { 240 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) {
236 SwitchActiveUser("someone@tray"); 241 SwitchActiveUser(AccountId::FromUserEmail("someone@tray"));
237 } 242 }
238 243
239 bool TestSessionStateDelegate::IsMultiProfileAllowedByPrimaryUserPolicy() 244 bool TestSessionStateDelegate::IsMultiProfileAllowedByPrimaryUserPolicy()
240 const { 245 const {
241 return true; 246 return true;
242 } 247 }
243 248
244 void TestSessionStateDelegate::AddSessionStateObserver( 249 void TestSessionStateDelegate::AddSessionStateObserver(
245 SessionStateObserver* observer) { 250 SessionStateObserver* observer) {
246 } 251 }
247 252
248 void TestSessionStateDelegate::RemoveSessionStateObserver( 253 void TestSessionStateDelegate::RemoveSessionStateObserver(
249 SessionStateObserver* observer) { 254 SessionStateObserver* observer) {
250 } 255 }
251 256
252 } // namespace test 257 } // namespace test
253 } // namespace ash 258 } // namespace ash
OLDNEW
« no previous file with comments | « ash/test/test_session_state_delegate.h ('k') | chrome/browser/chromeos/accessibility/accessibility_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698