| 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/session/user_info.h" |
| 10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 11 #include "ash/system/user/login_status.h" | 12 #include "ash/system/user/login_status.h" |
| 13 #include "base/stl_util.h" |
| 12 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 18 namespace ash { |
| 19 namespace test { |
| 20 |
| 16 namespace { | 21 namespace { |
| 17 | 22 |
| 18 // The the "canonicalized" user ID from a given |email| address. | 23 // The the "canonicalized" user ID from a given |email| address. |
| 19 std::string GetUserIDFromEmail(const std::string& email) { | 24 std::string GetUserIDFromEmail(const std::string& email) { |
| 20 std::string user_id = email; | 25 std::string user_id = email; |
| 21 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); |
| 22 return user_id; | 27 return user_id; |
| 23 } | 28 } |
| 24 | 29 |
| 25 } // namespace | 30 } // namespace |
| 26 | 31 |
| 27 namespace ash { | 32 class MockUserInfo : public UserInfo { |
| 28 namespace test { | 33 public: |
| 34 explicit MockUserInfo(const std::string& id) : email_(id) {} |
| 35 virtual ~MockUserInfo() {} |
| 36 |
| 37 void SetUserImage(const gfx::ImageSkia& user_image) { |
| 38 user_image_ = user_image; |
| 39 } |
| 40 |
| 41 virtual base::string16 GetDisplayName() const OVERRIDE { |
| 42 return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); |
| 43 } |
| 44 |
| 45 virtual base::string16 GetGivenName() const OVERRIDE { |
| 46 return base::UTF8ToUTF16("Über Über Über Über"); |
| 47 } |
| 48 |
| 49 virtual std::string GetEmail() const OVERRIDE { return email_; } |
| 50 |
| 51 virtual std::string GetID() const OVERRIDE { |
| 52 return GetUserIDFromEmail(GetEmail()); |
| 53 } |
| 54 |
| 55 virtual const gfx::ImageSkia& GetImage() const OVERRIDE { |
| 56 return user_image_; |
| 57 } |
| 58 |
| 59 // A test user image. |
| 60 gfx::ImageSkia user_image_; |
| 61 |
| 62 std::string email_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(MockUserInfo); |
| 65 }; |
| 29 | 66 |
| 30 TestSessionStateDelegate::TestSessionStateDelegate() | 67 TestSessionStateDelegate::TestSessionStateDelegate() |
| 31 : has_active_user_(false), | 68 : has_active_user_(false), |
| 32 active_user_session_started_(false), | 69 active_user_session_started_(false), |
| 33 can_lock_screen_(true), | 70 can_lock_screen_(true), |
| 34 should_lock_screen_before_suspending_(false), | 71 should_lock_screen_before_suspending_(false), |
| 35 screen_locked_(false), | 72 screen_locked_(false), |
| 36 user_adding_screen_running_(false), | 73 user_adding_screen_running_(false), |
| 37 logged_in_users_(1) { | 74 logged_in_users_(1), |
| 75 active_user_index_(0) { |
| 76 user_list_.push_back( |
| 77 new MockUserInfo("First@tray")); // This is intended to be capitalized. |
| 78 user_list_.push_back( |
| 79 new MockUserInfo("Second@tray")); // This is intended to be capitalized. |
| 80 user_list_.push_back(new MockUserInfo("third@tray")); |
| 81 user_list_.push_back(new MockUserInfo("someone@tray")); |
| 38 } | 82 } |
| 39 | 83 |
| 40 TestSessionStateDelegate::~TestSessionStateDelegate() { | 84 TestSessionStateDelegate::~TestSessionStateDelegate() { |
| 85 STLDeleteElements(&user_list_); |
| 86 } |
| 87 |
| 88 const UserInfo* TestSessionStateDelegate::GetActiveUserInfo() const { |
| 89 return user_list_[active_user_index_]; |
| 41 } | 90 } |
| 42 | 91 |
| 43 content::BrowserContext* | 92 content::BrowserContext* |
| 44 TestSessionStateDelegate::GetBrowserContextByIndex( | 93 TestSessionStateDelegate::GetBrowserContextByIndex( |
| 45 MultiProfileIndex index) { | 94 MultiProfileIndex index) { |
| 46 return NULL; | 95 return NULL; |
| 47 } | 96 } |
| 48 | 97 |
| 49 content::BrowserContext* | 98 content::BrowserContext* |
| 50 TestSessionStateDelegate::GetBrowserContextForWindow( | 99 TestSessionStateDelegate::GetBrowserContextForWindow( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 should_lock_screen_before_suspending_ = should_lock; | 178 should_lock_screen_before_suspending_ = should_lock; |
| 130 } | 179 } |
| 131 | 180 |
| 132 void TestSessionStateDelegate::SetUserAddingScreenRunning( | 181 void TestSessionStateDelegate::SetUserAddingScreenRunning( |
| 133 bool user_adding_screen_running) { | 182 bool user_adding_screen_running) { |
| 134 user_adding_screen_running_ = user_adding_screen_running; | 183 user_adding_screen_running_ = user_adding_screen_running; |
| 135 } | 184 } |
| 136 | 185 |
| 137 void TestSessionStateDelegate::SetUserImage( | 186 void TestSessionStateDelegate::SetUserImage( |
| 138 const gfx::ImageSkia& user_image) { | 187 const gfx::ImageSkia& user_image) { |
| 139 user_image_ = user_image; | 188 user_list_[active_user_index_]->SetUserImage(user_image); |
| 140 } | 189 } |
| 141 | 190 |
| 142 const base::string16 TestSessionStateDelegate::GetUserDisplayName( | 191 const UserInfo* TestSessionStateDelegate::GetUserInfo( |
| 143 MultiProfileIndex index) const { | 192 MultiProfileIndex index) const { |
| 144 return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); | 193 int max = user_list_.size(); |
| 194 return user_list_[index < max ? index : max - 1]; |
| 145 } | 195 } |
| 146 | 196 |
| 147 const base::string16 TestSessionStateDelegate::GetUserGivenName( | 197 const UserInfo* TestSessionStateDelegate::GetUserInfo( |
| 148 MultiProfileIndex index) const { | 198 content::BrowserContext* context) const { |
| 149 return base::UTF8ToUTF16("Über Über Über Über"); | 199 return user_list_[active_user_index_]; |
| 150 } | 200 } |
| 151 | 201 |
| 152 const std::string TestSessionStateDelegate::GetUserEmail( | 202 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { |
| 153 MultiProfileIndex index) const { | 203 return !GetActiveUserInfo()->GetImage().isNull(); |
| 154 switch (index) { | |
| 155 case 0: return "First@tray"; // This is intended to be capitalized. | |
| 156 case 1: return "Second@tray"; // This is intended to be capitalized. | |
| 157 case 2: return "third@tray"; | |
| 158 default: return "someone@tray"; | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 const std::string TestSessionStateDelegate::GetUserID( | |
| 163 MultiProfileIndex index) const { | |
| 164 return GetUserIDFromEmail(GetUserEmail(index)); | |
| 165 } | |
| 166 | |
| 167 const gfx::ImageSkia& TestSessionStateDelegate::GetUserImage( | |
| 168 content::BrowserContext* context) const { | |
| 169 return user_image_; | |
| 170 } | |
| 171 | |
| 172 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) { | |
| 173 return !user_image_.isNull(); | |
| 174 } | 204 } |
| 175 | 205 |
| 176 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { | 206 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { |
| 177 // Make sure this is a user id and not an email address. | 207 // Make sure this is a user id and not an email address. |
| 178 EXPECT_EQ(user_id, GetUserIDFromEmail(user_id)); | 208 EXPECT_EQ(user_id, GetUserIDFromEmail(user_id)); |
| 179 activated_user_ = user_id; | 209 active_user_index_ = 0; |
| 210 for (std::vector<MockUserInfo*>::iterator iter = user_list_.begin(); |
| 211 iter != user_list_.end(); |
| 212 ++iter) { |
| 213 if ((*iter)->GetID() == user_id) { |
| 214 active_user_index_ = iter - user_list_.begin(); |
| 215 return; |
| 216 } |
| 217 } |
| 218 NOTREACHED() << "Unknown user:" << user_id; |
| 180 } | 219 } |
| 181 | 220 |
| 182 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { | 221 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { |
| 183 activated_user_ = "someone@tray"; | 222 SwitchActiveUser("someone@tray"); |
| 184 } | 223 } |
| 185 | 224 |
| 186 void TestSessionStateDelegate::AddSessionStateObserver( | 225 void TestSessionStateDelegate::AddSessionStateObserver( |
| 187 SessionStateObserver* observer) { | 226 SessionStateObserver* observer) { |
| 188 } | 227 } |
| 189 | 228 |
| 190 void TestSessionStateDelegate::RemoveSessionStateObserver( | 229 void TestSessionStateDelegate::RemoveSessionStateObserver( |
| 191 SessionStateObserver* observer) { | 230 SessionStateObserver* observer) { |
| 192 } | 231 } |
| 193 | 232 |
| 194 } // namespace test | 233 } // namespace test |
| 195 } // namespace ash | 234 } // namespace ash |
| OLD | NEW |