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
3 // found in the LICENSE file.
5 #include "ash/test/test_session_state_delegate.h"
10 #include "ash/shell.h"
11 #include "ash/system/user/login_status.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h"
18 // The the "canonicalized" user ID from a given |email| address.
19 std::string
GetUserIDFromEmail(const std::string
& email
) {
20 std::string user_id
= email
;
21 std::transform(user_id
.begin(), user_id
.end(), user_id
.begin(), ::tolower
);
30 TestSessionStateDelegate::TestSessionStateDelegate()
31 : has_active_user_(false),
32 active_user_session_started_(false),
33 can_lock_screen_(true),
34 should_lock_screen_before_suspending_(false),
35 screen_locked_(false),
36 user_adding_screen_running_(false),
38 num_transfer_to_desktop_of_user_calls_(0) {
41 TestSessionStateDelegate::~TestSessionStateDelegate() {
44 int TestSessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const {
48 int TestSessionStateDelegate::NumberOfLoggedInUsers() const {
49 // TODO(skuhne): Add better test framework to test multiple profiles.
50 return has_active_user_
? logged_in_users_
: 0;
53 bool TestSessionStateDelegate::IsActiveUserSessionStarted() const {
54 return active_user_session_started_
;
57 bool TestSessionStateDelegate::CanLockScreen() const {
58 return has_active_user_
&& can_lock_screen_
;
61 bool TestSessionStateDelegate::IsScreenLocked() const {
62 return screen_locked_
;
65 bool TestSessionStateDelegate::ShouldLockScreenBeforeSuspending() const {
66 return should_lock_screen_before_suspending_
;
69 void TestSessionStateDelegate::LockScreen() {
71 screen_locked_
= true;
74 void TestSessionStateDelegate::UnlockScreen() {
75 screen_locked_
= false;
78 bool TestSessionStateDelegate::IsUserSessionBlocked() const {
79 return !IsActiveUserSessionStarted() || IsScreenLocked() ||
80 user_adding_screen_running_
;
83 void TestSessionStateDelegate::SetHasActiveUser(bool has_active_user
) {
84 has_active_user_
= has_active_user
;
86 active_user_session_started_
= false;
88 Shell::GetInstance()->ShowLauncher();
91 void TestSessionStateDelegate::SetActiveUserSessionStarted(
92 bool active_user_session_started
) {
93 active_user_session_started_
= active_user_session_started
;
94 if (active_user_session_started
) {
95 has_active_user_
= true;
96 Shell::GetInstance()->CreateLauncher();
97 Shell::GetInstance()->UpdateAfterLoginStatusChange(
98 user::LOGGED_IN_USER
);
102 void TestSessionStateDelegate::SetCanLockScreen(bool can_lock_screen
) {
103 can_lock_screen_
= can_lock_screen
;
106 void TestSessionStateDelegate::SetShouldLockScreenBeforeSuspending(
108 should_lock_screen_before_suspending_
= should_lock
;
111 void TestSessionStateDelegate::SetUserAddingScreenRunning(
112 bool user_adding_screen_running
) {
113 user_adding_screen_running_
= user_adding_screen_running
;
116 const base::string16
TestSessionStateDelegate::GetUserDisplayName(
117 MultiProfileIndex index
) const {
118 return UTF8ToUTF16("Über tray Über tray Über tray Über tray");
121 const std::string
TestSessionStateDelegate::GetUserEmail(
122 MultiProfileIndex index
) const {
124 case 0: return "First@tray"; // This is intended to be capitalized.
125 case 1: return "Second@tray"; // This is intended to be capitalized.
126 case 2: return "third@tray";
127 default: return "someone@tray";
131 const std::string
TestSessionStateDelegate::GetUserID(
132 MultiProfileIndex index
) const {
133 return GetUserIDFromEmail(GetUserEmail(index
));
136 const gfx::ImageSkia
& TestSessionStateDelegate::GetUserImage(
137 MultiProfileIndex index
) const {
141 void TestSessionStateDelegate::GetLoggedInUsers(UserIdList
* users
) {
144 void TestSessionStateDelegate::SwitchActiveUser(const std::string
& user_id
) {
145 // Make sure this is a user id and not an email address.
146 EXPECT_EQ(user_id
, GetUserIDFromEmail(user_id
));
147 activated_user_
= user_id
;
150 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user
) {
151 activated_user_
= "someone@tray";
154 void TestSessionStateDelegate::AddSessionStateObserver(
155 SessionStateObserver
* observer
) {
158 void TestSessionStateDelegate::RemoveSessionStateObserver(
159 SessionStateObserver
* observer
) {
162 bool TestSessionStateDelegate::TransferWindowToDesktopOfUser(
163 aura::Window
* window
,
164 ash::MultiProfileIndex index
) {
165 num_transfer_to_desktop_of_user_calls_
++;