• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "ash/test/test_system_tray_delegate.h"
6 
7 #include <string>
8 
9 #include "ash/session_state_delegate.h"
10 #include "ash/shell.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/time/time.h"
13 
14 namespace ash {
15 namespace test {
16 
17 namespace {
18 
19 user::LoginStatus g_initial_status = user::LOGGED_IN_USER;
20 
21 }  // namespace
22 
TestSystemTrayDelegate()23 TestSystemTrayDelegate::TestSystemTrayDelegate()
24     : should_show_display_notification_(false),
25       login_status_(g_initial_status),
26       session_length_limit_set_(false) {
27 }
28 
~TestSystemTrayDelegate()29 TestSystemTrayDelegate::~TestSystemTrayDelegate() {
30 }
31 
32 // static
SetInitialLoginStatus(user::LoginStatus login_status)33 void TestSystemTrayDelegate::SetInitialLoginStatus(
34     user::LoginStatus login_status) {
35   g_initial_status = login_status;
36 }
37 
SetLoginStatus(user::LoginStatus login_status)38 void TestSystemTrayDelegate::SetLoginStatus(user::LoginStatus login_status) {
39   login_status_ = login_status;
40   Shell::GetInstance()->UpdateAfterLoginStatusChange(login_status);
41 }
42 
SetSessionLengthLimitForTest(const base::TimeDelta & new_limit)43 void TestSystemTrayDelegate::SetSessionLengthLimitForTest(
44     const base::TimeDelta& new_limit) {
45   session_length_limit_ = new_limit;
46   session_length_limit_set_ = true;
47 }
48 
ClearSessionLengthLimit()49 void TestSystemTrayDelegate::ClearSessionLengthLimit() {
50   session_length_limit_set_ = false;
51 }
52 
GetUserLoginStatus() const53 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_) {
57     return login_status_;
58   }
59 
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();
64 
65   if (!delegate->IsActiveUserSessionStarted())
66     return ash::user::LOGGED_IN_NONE;
67   if (delegate->IsScreenLocked())
68     return user::LOGGED_IN_LOCKED;
69   return login_status_;
70 }
71 
ShouldShowDisplayNotification()72 bool TestSystemTrayDelegate::ShouldShowDisplayNotification() {
73   return should_show_display_notification_;
74 }
75 
GetSessionStartTime(base::TimeTicks * session_start_time)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_;
83 }
84 
GetSessionLengthLimit(base::TimeDelta * session_length_limit)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_;
90 }
91 
ShutDown()92 void TestSystemTrayDelegate::ShutDown() {
93   base::MessageLoop::current()->Quit();
94 }
95 
SignOut()96 void TestSystemTrayDelegate::SignOut() {
97   base::MessageLoop::current()->Quit();
98 }
99 
100 }  // namespace test
101 }  // namespace ash
102