Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: trunk/src/ash/test/test_session_state_delegate.cc

Issue 260783002: Revert 267158 "CleanUp: Introduce UserInfo. Move session_state s..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "ash/shell.h" 10 #include "ash/shell.h"
12 #include "ash/system/user/login_status.h" 11 #include "ash/system/user/login_status.h"
13 #include "base/stl_util.h"
14 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
15 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
16 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
17 15
18 namespace ash {
19 namespace test {
20
21 namespace { 16 namespace {
22 17
23 // The the "canonicalized" user ID from a given |email| address. 18 // The the "canonicalized" user ID from a given |email| address.
24 std::string GetUserIDFromEmail(const std::string& email) { 19 std::string GetUserIDFromEmail(const std::string& email) {
25 std::string user_id = email; 20 std::string user_id = email;
26 std::transform(user_id.begin(), user_id.end(), user_id.begin(), ::tolower); 21 std::transform(user_id.begin(), user_id.end(), user_id.begin(), ::tolower);
27 return user_id; 22 return user_id;
28 } 23 }
29 24
30 } // namespace 25 } // namespace
31 26
32 class MockUserInfo : public UserInfo { 27 namespace ash {
33 public: 28 namespace test {
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 };
66 29
67 TestSessionStateDelegate::TestSessionStateDelegate() 30 TestSessionStateDelegate::TestSessionStateDelegate()
68 : has_active_user_(false), 31 : has_active_user_(false),
69 active_user_session_started_(false), 32 active_user_session_started_(false),
70 can_lock_screen_(true), 33 can_lock_screen_(true),
71 should_lock_screen_before_suspending_(false), 34 should_lock_screen_before_suspending_(false),
72 screen_locked_(false), 35 screen_locked_(false),
73 user_adding_screen_running_(false), 36 user_adding_screen_running_(false),
74 logged_in_users_(1), 37 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"));
82 } 38 }
83 39
84 TestSessionStateDelegate::~TestSessionStateDelegate() { 40 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_];
94 } 41 }
95 42
96 content::BrowserContext* 43 content::BrowserContext*
97 TestSessionStateDelegate::GetBrowserContextByIndex( 44 TestSessionStateDelegate::GetBrowserContextByIndex(
98 MultiProfileIndex index) { 45 MultiProfileIndex index) {
99 return NULL; 46 return NULL;
100 } 47 }
101 48
102 content::BrowserContext* 49 content::BrowserContext*
103 TestSessionStateDelegate::GetBrowserContextForWindow( 50 TestSessionStateDelegate::GetBrowserContextForWindow(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 should_lock_screen_before_suspending_ = should_lock; 129 should_lock_screen_before_suspending_ = should_lock;
183 } 130 }
184 131
185 void TestSessionStateDelegate::SetUserAddingScreenRunning( 132 void TestSessionStateDelegate::SetUserAddingScreenRunning(
186 bool user_adding_screen_running) { 133 bool user_adding_screen_running) {
187 user_adding_screen_running_ = user_adding_screen_running; 134 user_adding_screen_running_ = user_adding_screen_running;
188 } 135 }
189 136
190 void TestSessionStateDelegate::SetUserImage( 137 void TestSessionStateDelegate::SetUserImage(
191 const gfx::ImageSkia& user_image) { 138 const gfx::ImageSkia& user_image) {
192 user_list_[active_user_index_]->SetUserImage(user_image); 139 user_image_ = user_image;
193 } 140 }
194 141
195 const UserInfo* TestSessionStateDelegate::GetUserInfo( 142 const base::string16 TestSessionStateDelegate::GetUserDisplayName(
196 MultiProfileIndex index) const { 143 MultiProfileIndex index) const {
197 int max = static_cast<int>(user_list_.size()); 144 return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray");
198 return user_list_[index < max ? index : max - 1];
199 } 145 }
200 146
201 const UserInfo* TestSessionStateDelegate::GetUserInfo( 147 const base::string16 TestSessionStateDelegate::GetUserGivenName(
202 content::BrowserContext* context) const { 148 MultiProfileIndex index) const {
203 return user_list_[active_user_index_]; 149 return base::UTF8ToUTF16("Über Über Über Über");
204 } 150 }
205 151
206 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { 152 const std::string TestSessionStateDelegate::GetUserEmail(
207 return !GetActiveUserInfo()->GetImage().isNull(); 153 MultiProfileIndex index) const {
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();
208 } 174 }
209 175
210 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { 176 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) {
211 // Make sure this is a user id and not an email address. 177 // Make sure this is a user id and not an email address.
212 EXPECT_EQ(user_id, GetUserIDFromEmail(user_id)); 178 EXPECT_EQ(user_id, GetUserIDFromEmail(user_id));
213 active_user_index_ = 0; 179 activated_user_ = user_id;
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;
223 } 180 }
224 181
225 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) { 182 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) {
226 SwitchActiveUser("someone@tray"); 183 activated_user_ = "someone@tray";
227 } 184 }
228 185
229 void TestSessionStateDelegate::AddSessionStateObserver( 186 void TestSessionStateDelegate::AddSessionStateObserver(
230 SessionStateObserver* observer) { 187 SessionStateObserver* observer) {
231 } 188 }
232 189
233 void TestSessionStateDelegate::RemoveSessionStateObserver( 190 void TestSessionStateDelegate::RemoveSessionStateObserver(
234 SessionStateObserver* observer) { 191 SessionStateObserver* observer) {
235 } 192 }
236 193
237 } // namespace test 194 } // namespace test
238 } // namespace ash 195 } // namespace ash
OLDNEW
« no previous file with comments | « trunk/src/ash/test/test_session_state_delegate.h ('k') | trunk/src/ash/test/test_shell_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698