| OLD | NEW |
| 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/login_status.h" | 9 #include "ash/login_status.h" |
| 10 #include "ash/session/session_controller.h" | 10 #include "ash/session/session_controller.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.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 { | |
| 18 | |
| 19 LoginStatus g_initial_status = LoginStatus::USER; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 TestSystemTrayDelegate::TestSystemTrayDelegate() | 17 TestSystemTrayDelegate::TestSystemTrayDelegate() |
| 24 : login_status_(g_initial_status), session_length_limit_set_(false) {} | 18 : login_status_(LoginStatus::USER), session_length_limit_set_(false) {} |
| 25 | 19 |
| 26 TestSystemTrayDelegate::~TestSystemTrayDelegate() {} | 20 TestSystemTrayDelegate::~TestSystemTrayDelegate() {} |
| 27 | 21 |
| 28 void TestSystemTrayDelegate::SetLoginStatus(LoginStatus login_status) { | 22 void TestSystemTrayDelegate::SetLoginStatus(LoginStatus login_status) { |
| 29 login_status_ = login_status; | 23 login_status_ = login_status; |
| 30 Shell::Get()->UpdateAfterLoginStatusChange(login_status); | 24 Shell::Get()->UpdateAfterLoginStatusChange(login_status); |
| 31 } | 25 } |
| 32 | 26 |
| 33 void TestSystemTrayDelegate::SetSessionLengthLimitForTest( | 27 void TestSystemTrayDelegate::SetSessionLengthLimitForTest( |
| 34 const base::TimeDelta& new_limit) { | 28 const base::TimeDelta& new_limit) { |
| 35 session_length_limit_ = new_limit; | 29 session_length_limit_ = new_limit; |
| 36 session_length_limit_set_ = true; | 30 session_length_limit_set_ = true; |
| 37 } | 31 } |
| 38 | 32 |
| 39 void TestSystemTrayDelegate::ClearSessionLengthLimit() { | 33 void TestSystemTrayDelegate::ClearSessionLengthLimit() { |
| 40 session_length_limit_set_ = false; | 34 session_length_limit_set_ = false; |
| 41 } | 35 } |
| 42 | 36 |
| 43 void TestSystemTrayDelegate::SetCurrentIME(const IMEInfo& info) { | 37 void TestSystemTrayDelegate::SetCurrentIME(const IMEInfo& info) { |
| 44 current_ime_ = info; | 38 current_ime_ = info; |
| 45 } | 39 } |
| 46 | 40 |
| 47 void TestSystemTrayDelegate::SetAvailableIMEList(const IMEInfoList& list) { | 41 void TestSystemTrayDelegate::SetAvailableIMEList(const IMEInfoList& list) { |
| 48 ime_list_ = list; | 42 ime_list_ = list; |
| 49 } | 43 } |
| 50 | 44 |
| 51 LoginStatus TestSystemTrayDelegate::GetUserLoginStatus() const { | 45 LoginStatus TestSystemTrayDelegate::GetUserLoginStatus() const { |
| 52 // Initial login status has been changed for testing. | |
| 53 if (g_initial_status != LoginStatus::USER && | |
| 54 g_initial_status == login_status_) { | |
| 55 return login_status_; | |
| 56 } | |
| 57 | |
| 58 // At new user image screen manager->IsUserLoggedIn() would return true | 46 // At new user image screen manager->IsUserLoggedIn() would return true |
| 59 // but there's no browser session available yet so use SessionStarted(). | 47 // but there's no browser session available yet so use SessionStarted(). |
| 60 SessionController* controller = Shell::Get()->session_controller(); | 48 SessionController* controller = Shell::Get()->session_controller(); |
| 61 | 49 |
| 62 if (!controller->IsActiveUserSessionStarted()) | 50 if (!controller->IsActiveUserSessionStarted()) |
| 63 return LoginStatus::NOT_LOGGED_IN; | 51 return LoginStatus::NOT_LOGGED_IN; |
| 64 if (controller->IsScreenLocked()) | 52 if (controller->IsScreenLocked()) |
| 65 return LoginStatus::LOCKED; | 53 return LoginStatus::LOCKED; |
| 66 return login_status_; | 54 return login_status_; |
| 67 } | 55 } |
| 68 | 56 |
| 69 std::string TestSystemTrayDelegate::GetSupervisedUserManager() const { | 57 std::string TestSystemTrayDelegate::GetSupervisedUserManager() const { |
| 70 if (!IsUserSupervised()) | 58 if (!Shell::Get()->session_controller()->IsUserSupervised()) |
| 71 return std::string(); | 59 return std::string(); |
| 72 return "manager@chrome.com"; | 60 return "manager@chrome.com"; |
| 73 } | 61 } |
| 74 | 62 |
| 75 bool TestSystemTrayDelegate::IsUserSupervised() const { | |
| 76 return login_status_ == LoginStatus::SUPERVISED; | |
| 77 } | |
| 78 | |
| 79 bool TestSystemTrayDelegate::GetSessionStartTime( | 63 bool TestSystemTrayDelegate::GetSessionStartTime( |
| 80 base::TimeTicks* session_start_time) { | 64 base::TimeTicks* session_start_time) { |
| 81 // Just returns TimeTicks::Now(), so the remaining time is always the | 65 // Just returns TimeTicks::Now(), so the remaining time is always the |
| 82 // specified limit. This is useful for testing. | 66 // specified limit. This is useful for testing. |
| 83 if (session_length_limit_set_) | 67 if (session_length_limit_set_) |
| 84 *session_start_time = base::TimeTicks::Now(); | 68 *session_start_time = base::TimeTicks::Now(); |
| 85 return session_length_limit_set_; | 69 return session_length_limit_set_; |
| 86 } | 70 } |
| 87 | 71 |
| 88 bool TestSystemTrayDelegate::GetSessionLengthLimit( | 72 bool TestSystemTrayDelegate::GetSessionLengthLimit( |
| 89 base::TimeDelta* session_length_limit) { | 73 base::TimeDelta* session_length_limit) { |
| 90 if (session_length_limit_set_) | 74 if (session_length_limit_set_) |
| 91 *session_length_limit = session_length_limit_; | 75 *session_length_limit = session_length_limit_; |
| 92 return session_length_limit_set_; | 76 return session_length_limit_set_; |
| 93 } | 77 } |
| 94 | 78 |
| 95 void TestSystemTrayDelegate::GetCurrentIME(IMEInfo* info) { | 79 void TestSystemTrayDelegate::GetCurrentIME(IMEInfo* info) { |
| 96 *info = current_ime_; | 80 *info = current_ime_; |
| 97 } | 81 } |
| 98 | 82 |
| 99 void TestSystemTrayDelegate::GetAvailableIMEList(IMEInfoList* list) { | 83 void TestSystemTrayDelegate::GetAvailableIMEList(IMEInfoList* list) { |
| 100 *list = ime_list_; | 84 *list = ime_list_; |
| 101 } | 85 } |
| 102 | 86 |
| 103 //////////////////////////////////////////////////////////////////////////////// | |
| 104 | |
| 105 ScopedInitialLoginStatus::ScopedInitialLoginStatus(LoginStatus new_status) | |
| 106 : old_status_(g_initial_status) { | |
| 107 g_initial_status = new_status; | |
| 108 } | |
| 109 | |
| 110 ScopedInitialLoginStatus::~ScopedInitialLoginStatus() { | |
| 111 g_initial_status = old_status_; | |
| 112 } | |
| 113 | |
| 114 } // namespace test | 87 } // namespace test |
| 115 } // namespace ash | 88 } // namespace ash |
| OLD | NEW |