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