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

Side by Side Diff: ash/test/test_system_tray_delegate.cc

Issue 108213009: Adds TraySessionLengthLimitTest to ash_unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 2013 The Chromium Authors. All rights reserved. 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 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_system_tray_delegate.h" 5 #include "ash/test/test_system_tray_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/session_state_delegate.h" 9 #include "ash/session_state_delegate.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 13
14 namespace ash { 14 namespace ash {
15 namespace test { 15 namespace test {
16 16
17 namespace { 17 namespace {
18 18
19 user::LoginStatus g_initial_status = user::LOGGED_IN_USER; 19 user::LoginStatus g_initial_status = user::LOGGED_IN_USER;
20 20
21 } // namespace 21 } // namespace
22 22
23 TestSystemTrayDelegate::TestSystemTrayDelegate() 23 TestSystemTrayDelegate::TestSystemTrayDelegate()
24 : should_show_display_notification_(false), 24 : should_show_display_notification_(false),
25 login_status_(g_initial_status) { 25 login_status_(g_initial_status),
26 session_length_limit_set_(false) {
26 } 27 }
27 28
28 TestSystemTrayDelegate::~TestSystemTrayDelegate() { 29 TestSystemTrayDelegate::~TestSystemTrayDelegate() {
29 } 30 }
30 31
31 // static 32 // static
32 void TestSystemTrayDelegate::SetInitialLoginStatus( 33 void TestSystemTrayDelegate::SetInitialLoginStatus(
33 user::LoginStatus login_status) { 34 user::LoginStatus login_status) {
34 g_initial_status = login_status; 35 g_initial_status = login_status;
35 } 36 }
36 37
37 void TestSystemTrayDelegate::SetLoginStatus(user::LoginStatus login_status) { 38 void TestSystemTrayDelegate::SetLoginStatus(user::LoginStatus login_status) {
38 login_status_ = login_status; 39 login_status_ = login_status;
39 Shell::GetInstance()->UpdateAfterLoginStatusChange(login_status); 40 Shell::GetInstance()->UpdateAfterLoginStatusChange(login_status);
40 } 41 }
41 42
43 void TestSystemTrayDelegate::SetSessionLengthLimitForTest(
44 const base::TimeDelta& new_limit) {
45 session_length_limit_ = new_limit;
46 session_length_limit_set_ = true;
47 }
48
49 void TestSystemTrayDelegate::ClearSessionLengthLimit() {
50 session_length_limit_set_ = false;
51 }
52
42 user::LoginStatus TestSystemTrayDelegate::GetUserLoginStatus() const { 53 user::LoginStatus TestSystemTrayDelegate::GetUserLoginStatus() const {
43 // Initial login status has been changed for testing. 54 // Initial login status has been changed for testing.
44 if (g_initial_status != user::LOGGED_IN_USER && 55 if (g_initial_status != user::LOGGED_IN_USER &&
45 g_initial_status == login_status_) { 56 g_initial_status == login_status_) {
46 return login_status_; 57 return login_status_;
47 } 58 }
48 59
49 // At new user image screen manager->IsUserLoggedIn() would return true 60 // At new user image screen manager->IsUserLoggedIn() would return true
50 // but there's no browser session available yet so use SessionStarted(). 61 // but there's no browser session available yet so use SessionStarted().
51 SessionStateDelegate* delegate = 62 SessionStateDelegate* delegate =
52 Shell::GetInstance()->session_state_delegate(); 63 Shell::GetInstance()->session_state_delegate();
53 64
54 if (!delegate->IsActiveUserSessionStarted()) 65 if (!delegate->IsActiveUserSessionStarted())
55 return ash::user::LOGGED_IN_NONE; 66 return ash::user::LOGGED_IN_NONE;
56 if (delegate->IsScreenLocked()) 67 if (delegate->IsScreenLocked())
57 return user::LOGGED_IN_LOCKED; 68 return user::LOGGED_IN_LOCKED;
58 return login_status_; 69 return login_status_;
59 } 70 }
60 71
61 bool TestSystemTrayDelegate::ShouldShowDisplayNotification() { 72 bool TestSystemTrayDelegate::ShouldShowDisplayNotification() {
62 return should_show_display_notification_; 73 return should_show_display_notification_;
63 } 74 }
64 75
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
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
65 void TestSystemTrayDelegate::ShutDown() { 92 void TestSystemTrayDelegate::ShutDown() {
66 base::MessageLoop::current()->Quit(); 93 base::MessageLoop::current()->Quit();
67 } 94 }
68 95
69 void TestSystemTrayDelegate::SignOut() { 96 void TestSystemTrayDelegate::SignOut() {
70 base::MessageLoop::current()->Quit(); 97 base::MessageLoop::current()->Quit();
71 } 98 }
72 99
73 } // namespace test 100 } // namespace test
74 } // namespace ash 101 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698