OLD | NEW |
---|---|
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/user_manager/user_info.h" | 16 #include "components/user_manager/user_info.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace ash { | 19 namespace ash { |
19 namespace test { | 20 namespace test { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // The the "canonicalized" user ID from a given |email| address. | 24 // The the "canonicalized" user ID from a given |email| address. |
24 std::string GetUserIDFromEmail(const std::string& email) { | 25 AccountId GetAccountIdFromEmail(const std::string& email) { |
25 std::string user_id = email; | 26 std::string user_id = email; |
26 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); |
27 return user_id; | 28 return AccountId::FromUserEmail(user_id); |
28 } | 29 } |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 class MockUserInfo : public user_manager::UserInfo { | 33 class MockUserInfo : public user_manager::UserInfo { |
33 public: | 34 public: |
34 explicit MockUserInfo(const std::string& id) : email_(id) {} | 35 explicit MockUserInfo(const std::string& display_email) |
36 : display_email_(display_email), | |
stevenjb
2015/10/23 17:17:02
Don't store display_email_ separately, there is th
Alexander Alekseev
2015/10/23 23:21:22
Display Email must be different from account id, t
stevenjb
2015/10/26 18:28:00
Acknowledged.
| |
37 account_id_(GetAccountIdFromEmail(display_email)) {} | |
35 ~MockUserInfo() override {} | 38 ~MockUserInfo() override {} |
36 | 39 |
37 void SetUserImage(const gfx::ImageSkia& user_image) { | 40 void SetUserImage(const gfx::ImageSkia& user_image) { |
38 user_image_ = user_image; | 41 user_image_ = user_image; |
39 } | 42 } |
40 | 43 |
41 base::string16 GetDisplayName() const override { | 44 base::string16 GetDisplayName() const override { |
42 return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); | 45 return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); |
43 } | 46 } |
44 | 47 |
45 base::string16 GetGivenName() const override { | 48 base::string16 GetGivenName() const override { |
46 return base::UTF8ToUTF16("Über Über Über Über"); | 49 return base::UTF8ToUTF16("Über Über Über Über"); |
47 } | 50 } |
48 | 51 |
49 std::string GetEmail() const override { return email_; } | 52 std::string GetEmail() const override { return display_email_; } |
50 | 53 |
51 std::string GetUserID() const override { | 54 AccountId GetAccountId() const override { return account_id_; } |
52 return GetUserIDFromEmail(GetEmail()); | |
53 } | |
54 | 55 |
55 const gfx::ImageSkia& GetImage() const override { return user_image_; } | 56 const gfx::ImageSkia& GetImage() const override { return user_image_; } |
56 | 57 |
57 // A test user image. | 58 // A test user image. |
58 gfx::ImageSkia user_image_; | 59 gfx::ImageSkia user_image_; |
59 | 60 |
60 std::string email_; | 61 std::string display_email_; |
62 AccountId account_id_; | |
61 | 63 |
62 DISALLOW_COPY_AND_ASSIGN(MockUserInfo); | 64 DISALLOW_COPY_AND_ASSIGN(MockUserInfo); |
63 }; | 65 }; |
64 | 66 |
65 // A test version of user_manager::UserManager which can be used for testing on | 67 // A test version of user_manager::UserManager which can be used for testing on |
66 // non-ChromeOS builds. | 68 // non-ChromeOS builds. |
67 class TestSessionStateDelegate::TestUserManager { | 69 class TestSessionStateDelegate::TestUserManager { |
68 public: | 70 public: |
69 TestUserManager() : session_started_(false) {} | 71 TestUserManager() : session_started_(false) {} |
70 | 72 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { | 210 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { |
209 return !GetActiveUserInfo()->GetImage().isNull(); | 211 return !GetActiveUserInfo()->GetImage().isNull(); |
210 } | 212 } |
211 | 213 |
212 gfx::ImageSkia TestSessionStateDelegate::GetAvatarImageForWindow( | 214 gfx::ImageSkia TestSessionStateDelegate::GetAvatarImageForWindow( |
213 aura::Window* window) const { | 215 aura::Window* window) const { |
214 return gfx::ImageSkia(); | 216 return gfx::ImageSkia(); |
215 } | 217 } |
216 | 218 |
217 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { | 219 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { |
220 const AccountId account_id(GetAccountIdFromEmail(user_id)); | |
218 // Make sure this is a user id and not an email address. | 221 // Make sure this is a user id and not an email address. |
219 EXPECT_EQ(user_id, GetUserIDFromEmail(user_id)); | 222 EXPECT_EQ(user_id, account_id.GetUserEmail()); |
220 active_user_index_ = 0; | 223 active_user_index_ = 0; |
221 for (std::vector<MockUserInfo*>::iterator iter = user_list_.begin(); | 224 for (std::vector<MockUserInfo*>::iterator iter = user_list_.begin(); |
222 iter != user_list_.end(); | 225 iter != user_list_.end(); |
223 ++iter) { | 226 ++iter) { |
224 if ((*iter)->GetUserID() == user_id) { | 227 if ((*iter)->GetAccountId() == account_id) { |
225 active_user_index_ = iter - user_list_.begin(); | 228 active_user_index_ = iter - user_list_.begin(); |
226 return; | 229 return; |
227 } | 230 } |
228 } | 231 } |
229 NOTREACHED() << "Unknown user:" << user_id; | 232 NOTREACHED() << "Unknown user:" << account_id.GetUserEmail(); |
230 } | 233 } |
231 | 234 |
232 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { | 235 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { |
233 SwitchActiveUser("someone@tray"); | 236 SwitchActiveUser("someone@tray"); |
234 } | 237 } |
235 | 238 |
236 bool TestSessionStateDelegate::IsMultiProfileAllowedByPrimaryUserPolicy() | 239 bool TestSessionStateDelegate::IsMultiProfileAllowedByPrimaryUserPolicy() |
237 const { | 240 const { |
238 return true; | 241 return true; |
239 } | 242 } |
240 | 243 |
241 void TestSessionStateDelegate::AddSessionStateObserver( | 244 void TestSessionStateDelegate::AddSessionStateObserver( |
242 SessionStateObserver* observer) { | 245 SessionStateObserver* observer) { |
243 } | 246 } |
244 | 247 |
245 void TestSessionStateDelegate::RemoveSessionStateObserver( | 248 void TestSessionStateDelegate::RemoveSessionStateObserver( |
246 SessionStateObserver* observer) { | 249 SessionStateObserver* observer) { |
247 } | 250 } |
248 | 251 |
249 } // namespace test | 252 } // namespace test |
250 } // namespace ash | 253 } // namespace ash |
OLD | NEW |