| 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" | |
| 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" | 12 #include "base/stl_util.h" |
| 14 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "components/user_manager/user_info.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // The the "canonicalized" user ID from a given |email| address. | 23 // The the "canonicalized" user ID from a given |email| address. |
| 24 std::string GetUserIDFromEmail(const std::string& email) { | 24 std::string GetUserIDFromEmail(const std::string& email) { |
| 25 std::string user_id = email; | 25 std::string user_id = email; |
| 26 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); |
| 27 return user_id; | 27 return user_id; |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 class MockUserInfo : public UserInfo { | 32 class MockUserInfo : public user_manager::UserInfo { |
| 33 public: | 33 public: |
| 34 explicit MockUserInfo(const std::string& id) : email_(id) {} | 34 explicit MockUserInfo(const std::string& id) : email_(id) {} |
| 35 virtual ~MockUserInfo() {} | 35 virtual ~MockUserInfo() {} |
| 36 | 36 |
| 37 void SetUserImage(const gfx::ImageSkia& user_image) { | 37 void SetUserImage(const gfx::ImageSkia& user_image) { |
| 38 user_image_ = user_image; | 38 user_image_ = user_image; |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual base::string16 GetDisplayName() const OVERRIDE { | 41 virtual base::string16 GetDisplayName() const OVERRIDE { |
| 42 return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); | 42 return base::UTF8ToUTF16("Über tray Über tray Über tray Über tray"); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 TestSessionStateDelegate::~TestSessionStateDelegate() { | 84 TestSessionStateDelegate::~TestSessionStateDelegate() { |
| 85 STLDeleteElements(&user_list_); | 85 STLDeleteElements(&user_list_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void TestSessionStateDelegate::AddUser(const std::string user_id) { | 88 void TestSessionStateDelegate::AddUser(const std::string user_id) { |
| 89 user_list_.push_back(new MockUserInfo(user_id)); | 89 user_list_.push_back(new MockUserInfo(user_id)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 const UserInfo* TestSessionStateDelegate::GetActiveUserInfo() const { | 92 const user_manager::UserInfo* TestSessionStateDelegate::GetActiveUserInfo() |
| 93 const { |
| 93 return user_list_[active_user_index_]; | 94 return user_list_[active_user_index_]; |
| 94 } | 95 } |
| 95 | 96 |
| 96 content::BrowserContext* | 97 content::BrowserContext* |
| 97 TestSessionStateDelegate::GetBrowserContextByIndex( | 98 TestSessionStateDelegate::GetBrowserContextByIndex( |
| 98 MultiProfileIndex index) { | 99 MultiProfileIndex index) { |
| 99 return NULL; | 100 return NULL; |
| 100 } | 101 } |
| 101 | 102 |
| 102 content::BrowserContext* | 103 content::BrowserContext* |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 void TestSessionStateDelegate::SetUserAddingScreenRunning( | 186 void TestSessionStateDelegate::SetUserAddingScreenRunning( |
| 186 bool user_adding_screen_running) { | 187 bool user_adding_screen_running) { |
| 187 user_adding_screen_running_ = user_adding_screen_running; | 188 user_adding_screen_running_ = user_adding_screen_running; |
| 188 } | 189 } |
| 189 | 190 |
| 190 void TestSessionStateDelegate::SetUserImage( | 191 void TestSessionStateDelegate::SetUserImage( |
| 191 const gfx::ImageSkia& user_image) { | 192 const gfx::ImageSkia& user_image) { |
| 192 user_list_[active_user_index_]->SetUserImage(user_image); | 193 user_list_[active_user_index_]->SetUserImage(user_image); |
| 193 } | 194 } |
| 194 | 195 |
| 195 const UserInfo* TestSessionStateDelegate::GetUserInfo( | 196 const user_manager::UserInfo* TestSessionStateDelegate::GetUserInfo( |
| 196 MultiProfileIndex index) const { | 197 MultiProfileIndex index) const { |
| 197 int max = static_cast<int>(user_list_.size()); | 198 int max = static_cast<int>(user_list_.size()); |
| 198 return user_list_[index < max ? index : max - 1]; | 199 return user_list_[index < max ? index : max - 1]; |
| 199 } | 200 } |
| 200 | 201 |
| 201 const UserInfo* TestSessionStateDelegate::GetUserInfo( | 202 const user_manager::UserInfo* TestSessionStateDelegate::GetUserInfo( |
| 202 content::BrowserContext* context) const { | 203 content::BrowserContext* context) const { |
| 203 return user_list_[active_user_index_]; | 204 return user_list_[active_user_index_]; |
| 204 } | 205 } |
| 205 | 206 |
| 206 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { | 207 bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const { |
| 207 return !GetActiveUserInfo()->GetImage().isNull(); | 208 return !GetActiveUserInfo()->GetImage().isNull(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { | 211 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { |
| 211 // Make sure this is a user id and not an email address. | 212 // Make sure this is a user id and not an email address. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 229 void TestSessionStateDelegate::AddSessionStateObserver( | 230 void TestSessionStateDelegate::AddSessionStateObserver( |
| 230 SessionStateObserver* observer) { | 231 SessionStateObserver* observer) { |
| 231 } | 232 } |
| 232 | 233 |
| 233 void TestSessionStateDelegate::RemoveSessionStateObserver( | 234 void TestSessionStateDelegate::RemoveSessionStateObserver( |
| 234 SessionStateObserver* observer) { | 235 SessionStateObserver* observer) { |
| 235 } | 236 } |
| 236 | 237 |
| 237 } // namespace test | 238 } // namespace test |
| 238 } // namespace ash | 239 } // namespace ash |
| OLD | NEW |