1 // Copyright 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_system_tray_delegate.h"
9 #include "ash/session/session_state_delegate.h"
10 #include "ash/shell.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/time/time.h"
19 user::LoginStatus g_initial_status
= user::LOGGED_IN_USER
;
23 TestSystemTrayDelegate::TestSystemTrayDelegate()
24 : should_show_display_notification_(false),
25 login_status_(g_initial_status
),
26 session_length_limit_set_(false) {
29 TestSystemTrayDelegate::~TestSystemTrayDelegate() {
33 void TestSystemTrayDelegate::SetInitialLoginStatus(
34 user::LoginStatus login_status
) {
35 g_initial_status
= login_status
;
38 void TestSystemTrayDelegate::SetLoginStatus(user::LoginStatus login_status
) {
39 login_status_
= login_status
;
40 Shell::GetInstance()->UpdateAfterLoginStatusChange(login_status
);
43 void TestSystemTrayDelegate::SetSessionLengthLimitForTest(
44 const base::TimeDelta
& new_limit
) {
45 session_length_limit_
= new_limit
;
46 session_length_limit_set_
= true;
49 void TestSystemTrayDelegate::ClearSessionLengthLimit() {
50 session_length_limit_set_
= false;
53 user::LoginStatus
TestSystemTrayDelegate::GetUserLoginStatus() const {
54 // Initial login status has been changed for testing.
55 if (g_initial_status
!= user::LOGGED_IN_USER
&&
56 g_initial_status
== login_status_
) {
60 // At new user image screen manager->IsUserLoggedIn() would return true
61 // but there's no browser session available yet so use SessionStarted().
62 SessionStateDelegate
* delegate
=
63 Shell::GetInstance()->session_state_delegate();
65 if (!delegate
->IsActiveUserSessionStarted())
66 return ash::user::LOGGED_IN_NONE
;
67 if (delegate
->IsScreenLocked())
68 return user::LOGGED_IN_LOCKED
;
72 bool TestSystemTrayDelegate::ShouldShowDisplayNotification() {
73 return should_show_display_notification_
;
76 bool TestSystemTrayDelegate::GetSessionStartTime(
77 base::TimeTicks
* session_start_time
) {
78 // Just returns TimeTicks::Now(), so the remaining time is always the
79 // specified limit. This is useful for testing.
80 if (session_length_limit_set_
)
81 *session_start_time
= base::TimeTicks::Now();
82 return session_length_limit_set_
;
85 bool TestSystemTrayDelegate::GetSessionLengthLimit(
86 base::TimeDelta
* session_length_limit
) {
87 if (session_length_limit_set_
)
88 *session_length_limit
= session_length_limit_
;
89 return session_length_limit_set_
;
92 void TestSystemTrayDelegate::ShutDown() {
93 base::MessageLoop::current()->Quit();
96 void TestSystemTrayDelegate::SignOut() {
97 base::MessageLoop::current()->Quit();