Chromium Code Reviews| Index: ash/test/test_session_state_delegate.cc |
| diff --git a/ash/test/test_session_state_delegate.cc b/ash/test/test_session_state_delegate.cc |
| index f7efe1df4b49e163ab53a4a6e473fee330352287..ec8b40ab215cfe1db7d4118407b54c41de39e798 100644 |
| --- a/ash/test/test_session_state_delegate.cc |
| +++ b/ash/test/test_session_state_delegate.cc |
| @@ -7,12 +7,17 @@ |
| #include <algorithm> |
| #include <string> |
| +#include "ash/session/user_info.h" |
| #include "ash/shell.h" |
| #include "ash/system/user/login_status.h" |
| +#include "base/stl_util.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +namespace ash { |
| +namespace test { |
| + |
| namespace { |
| // The the "canonicalized" user ID from a given |email| address. |
| @@ -24,8 +29,40 @@ std::string GetUserIDFromEmail(const std::string& email) { |
| } // namespace |
| -namespace ash { |
| -namespace test { |
| +class MockUserInfo : public UserInfo { |
| + public: |
| + explicit MockUserInfo(const std::string& id) : email_(id) {} |
| + virtual ~MockUserInfo() {} |
| + |
| + void SetUserImage(const gfx::ImageSkia& user_image) { |
| + user_image_ = user_image; |
| + } |
| + |
| + virtual base::string16 GetDisplayName() const OVERRIDE { |
| + return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); |
|
Nikita (slow)
2014/04/29 13:59:27
nit: "user name user name user name"? :)
oshima
2014/04/29 17:59:54
This is added in
https://chromiumcodereview.appsp
|
| + } |
| + |
| + virtual base::string16 GetGivenName() const OVERRIDE { |
| + return base::UTF8ToUTF16("Über Über Über Über"); |
|
Nikita (slow)
2014/04/29 13:59:27
nit: "User User User"
|
| + } |
| + |
| + virtual std::string GetEmail() const OVERRIDE { return email_; } |
| + |
| + virtual std::string GetID() const OVERRIDE { |
| + return GetUserIDFromEmail(GetEmail()); |
| + } |
| + |
| + virtual const gfx::ImageSkia& GetImage() const OVERRIDE { |
| + return user_image_; |
| + } |
| + |
| + // A test user image. |
| + gfx::ImageSkia user_image_; |
| + |
| + std::string email_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MockUserInfo); |
| +}; |
| TestSessionStateDelegate::TestSessionStateDelegate() |
| : has_active_user_(false), |
| @@ -34,10 +71,22 @@ TestSessionStateDelegate::TestSessionStateDelegate() |
| should_lock_screen_before_suspending_(false), |
| screen_locked_(false), |
| user_adding_screen_running_(false), |
| - logged_in_users_(1) { |
| + logged_in_users_(1), |
| + active_user_index_(0) { |
| + user_list_.push_back( |
| + new MockUserInfo("First@tray")); // This is intended to be capitalized. |
| + user_list_.push_back( |
| + new MockUserInfo("Second@tray")); // This is intended to be capitalized. |
| + user_list_.push_back(new MockUserInfo("third@tray")); |
| + user_list_.push_back(new MockUserInfo("someone@tray")); |
| } |
| TestSessionStateDelegate::~TestSessionStateDelegate() { |
| + STLDeleteElements(&user_list_); |
| +} |
| + |
| +const UserInfo* TestSessionStateDelegate::GetActiveUserInfo() const { |
| + return user_list_[active_user_index_]; |
| } |
| content::BrowserContext* |
| @@ -136,51 +185,41 @@ void TestSessionStateDelegate::SetUserAddingScreenRunning( |
| void TestSessionStateDelegate::SetUserImage( |
| const gfx::ImageSkia& user_image) { |
| - user_image_ = user_image; |
| -} |
| - |
| -const base::string16 TestSessionStateDelegate::GetUserDisplayName( |
| - MultiProfileIndex index) const { |
| - return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); |
| + user_list_[active_user_index_]->SetUserImage(user_image); |
| } |
| -const base::string16 TestSessionStateDelegate::GetUserGivenName( |
| +const UserInfo* TestSessionStateDelegate::GetUserInfo( |
| MultiProfileIndex index) const { |
| - return base::UTF8ToUTF16("Über Über Über Über"); |
| + int max = user_list_.size(); |
| + return user_list_[index < max ? index : max - 1]; |
| } |
| -const std::string TestSessionStateDelegate::GetUserEmail( |
| - MultiProfileIndex index) const { |
| - switch (index) { |
| - case 0: return "First@tray"; // This is intended to be capitalized. |
| - case 1: return "Second@tray"; // This is intended to be capitalized. |
| - case 2: return "third@tray"; |
| - default: return "someone@tray"; |
| - } |
| -} |
| - |
| -const std::string TestSessionStateDelegate::GetUserID( |
| - MultiProfileIndex index) const { |
| - return GetUserIDFromEmail(GetUserEmail(index)); |
| -} |
| - |
| -const gfx::ImageSkia& TestSessionStateDelegate::GetUserImage( |
| +const UserInfo* TestSessionStateDelegate::GetUserInfo( |
| content::BrowserContext* context) const { |
| - return user_image_; |
| + return user_list_[active_user_index_]; |
| } |
| -bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) { |
| - return !user_image_.isNull(); |
| +bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { |
| + return !GetActiveUserInfo()->GetImage().isNull(); |
| } |
| void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { |
| // Make sure this is a user id and not an email address. |
| EXPECT_EQ(user_id, GetUserIDFromEmail(user_id)); |
| - activated_user_ = user_id; |
| + active_user_index_ = 0; |
| + for (std::vector<MockUserInfo*>::iterator iter = user_list_.begin(); |
| + iter != user_list_.end(); |
| + ++iter) { |
| + if ((*iter)->GetID() == user_id) { |
| + active_user_index_ = iter - user_list_.begin(); |
| + return; |
| + } |
| + } |
| + NOTREACHED() << "Unknown user:" << user_id; |
| } |
| void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { |
| - activated_user_ = "someone@tray"; |
| + SwitchActiveUser("someone@tray"); |
| } |
| void TestSessionStateDelegate::AddSessionStateObserver( |