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 GetUserID() 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 void TestSessionStateDelegate::AddUser(const std::string user_id) { |
| 89 user_list_.push_back(new MockUserInfo(user_id)); |
| 90 } |
| 91 |
| 92 const UserInfo* TestSessionStateDelegate::GetActiveUserInfo() const { |
| 93 return user_list_[active_user_index_]; |
41 } | 94 } |
42 | 95 |
43 content::BrowserContext* | 96 content::BrowserContext* |
44 TestSessionStateDelegate::GetBrowserContextByIndex( | 97 TestSessionStateDelegate::GetBrowserContextByIndex( |
45 MultiProfileIndex index) { | 98 MultiProfileIndex index) { |
46 return NULL; | 99 return NULL; |
47 } | 100 } |
48 | 101 |
49 content::BrowserContext* | 102 content::BrowserContext* |
50 TestSessionStateDelegate::GetBrowserContextForWindow( | 103 TestSessionStateDelegate::GetBrowserContextForWindow( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 should_lock_screen_before_suspending_ = should_lock; | 182 should_lock_screen_before_suspending_ = should_lock; |
130 } | 183 } |
131 | 184 |
132 void TestSessionStateDelegate::SetUserAddingScreenRunning( | 185 void TestSessionStateDelegate::SetUserAddingScreenRunning( |
133 bool user_adding_screen_running) { | 186 bool user_adding_screen_running) { |
134 user_adding_screen_running_ = user_adding_screen_running; | 187 user_adding_screen_running_ = user_adding_screen_running; |
135 } | 188 } |
136 | 189 |
137 void TestSessionStateDelegate::SetUserImage( | 190 void TestSessionStateDelegate::SetUserImage( |
138 const gfx::ImageSkia& user_image) { | 191 const gfx::ImageSkia& user_image) { |
139 user_image_ = user_image; | 192 user_list_[active_user_index_]->SetUserImage(user_image); |
140 } | 193 } |
141 | 194 |
142 const base::string16 TestSessionStateDelegate::GetUserDisplayName( | 195 const UserInfo* TestSessionStateDelegate::GetUserInfo( |
143 MultiProfileIndex index) const { | 196 MultiProfileIndex index) const { |
144 return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); | 197 int max = static_cast<int>(user_list_.size()); |
| 198 return user_list_[index < max ? index : max - 1]; |
145 } | 199 } |
146 | 200 |
147 const base::string16 TestSessionStateDelegate::GetUserGivenName( | 201 const UserInfo* TestSessionStateDelegate::GetUserInfo( |
148 MultiProfileIndex index) const { | 202 content::BrowserContext* context) const { |
149 return base::UTF8ToUTF16("Über Über Über Über"); | 203 return user_list_[active_user_index_]; |
150 } | 204 } |
151 | 205 |
152 const std::string TestSessionStateDelegate::GetUserEmail( | 206 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { |
153 MultiProfileIndex index) const { | 207 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 } | 208 } |
175 | 209 |
176 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { | 210 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { |
177 // Make sure this is a user id and not an email address. | 211 // Make sure this is a user id and not an email address. |
178 EXPECT_EQ(user_id, GetUserIDFromEmail(user_id)); | 212 EXPECT_EQ(user_id, GetUserIDFromEmail(user_id)); |
179 activated_user_ = user_id; | 213 active_user_index_ = 0; |
| 214 for (std::vector<MockUserInfo*>::iterator iter = user_list_.begin(); |
| 215 iter != user_list_.end(); |
| 216 ++iter) { |
| 217 if ((*iter)->GetUserID() == user_id) { |
| 218 active_user_index_ = iter - user_list_.begin(); |
| 219 return; |
| 220 } |
| 221 } |
| 222 NOTREACHED() << "Unknown user:" << user_id; |
180 } | 223 } |
181 | 224 |
182 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { | 225 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { |
183 activated_user_ = "someone@tray"; | 226 SwitchActiveUser("someone@tray"); |
184 } | 227 } |
185 | 228 |
186 void TestSessionStateDelegate::AddSessionStateObserver( | 229 void TestSessionStateDelegate::AddSessionStateObserver( |
187 SessionStateObserver* observer) { | 230 SessionStateObserver* observer) { |
188 } | 231 } |
189 | 232 |
190 void TestSessionStateDelegate::RemoveSessionStateObserver( | 233 void TestSessionStateDelegate::RemoveSessionStateObserver( |
191 SessionStateObserver* observer) { | 234 SessionStateObserver* observer) { |
192 } | 235 } |
193 | 236 |
194 } // namespace test | 237 } // namespace test |
195 } // namespace ash | 238 } // namespace ash |
OLD | NEW |