1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// found in the LICENSE file.
4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ash/test/test_system_tray_delegate.h"
6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include <string>
8d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
95c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/session/session_state_delegate.h"
10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ash/shell.h"
111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ash/system/user/login_status.h"
12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "base/message_loop/message_loop.h"
13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "base/time/time.h"
14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace ash {
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace test {
17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace {
19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)user::LoginStatus g_initial_status = user::LOGGED_IN_USER;
21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}  // namespace
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)TestSystemTrayDelegate::TestSystemTrayDelegate()
25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    : should_show_display_notification_(false),
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      login_status_(g_initial_status),
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      session_length_limit_set_(false) {
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
29d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
30d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)TestSystemTrayDelegate::~TestSystemTrayDelegate() {
31d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
32d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
33d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// static
34d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void TestSystemTrayDelegate::SetInitialLoginStatus(
35d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    user::LoginStatus login_status) {
36d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  g_initial_status = login_status;
37d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
38d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
39d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void TestSystemTrayDelegate::SetLoginStatus(user::LoginStatus login_status) {
40d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  login_status_ = login_status;
41d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  Shell::GetInstance()->UpdateAfterLoginStatusChange(login_status);
42d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TestSystemTrayDelegate::SetSessionLengthLimitForTest(
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::TimeDelta& new_limit) {
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  session_length_limit_ = new_limit;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  session_length_limit_set_ = true;
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TestSystemTrayDelegate::ClearSessionLengthLimit() {
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  session_length_limit_set_ = false;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)user::LoginStatus TestSystemTrayDelegate::GetUserLoginStatus() const {
55d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Initial login status has been changed for testing.
56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (g_initial_status != user::LOGGED_IN_USER &&
57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      g_initial_status == login_status_) {
58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return login_status_;
59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
61d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // At new user image screen manager->IsUserLoggedIn() would return true
62d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // but there's no browser session available yet so use SessionStarted().
63d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  SessionStateDelegate* delegate =
64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      Shell::GetInstance()->session_state_delegate();
65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (!delegate->IsActiveUserSessionStarted())
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return ash::user::LOGGED_IN_NONE;
68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (delegate->IsScreenLocked())
69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return user::LOGGED_IN_LOCKED;
70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return login_status_;
71d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
72d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool TestSystemTrayDelegate::IsUserSupervised() const {
741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return login_status_ == ash::user::LOGGED_IN_SUPERVISED;
751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)bool TestSystemTrayDelegate::ShouldShowDisplayNotification() {
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return should_show_display_notification_;
79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool TestSystemTrayDelegate::GetSessionStartTime(
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::TimeTicks* session_start_time) {
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Just returns TimeTicks::Now(), so the remaining time is always the
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // specified limit. This is useful for testing.
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (session_length_limit_set_)
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    *session_start_time = base::TimeTicks::Now();
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return session_length_limit_set_;
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool TestSystemTrayDelegate::GetSessionLengthLimit(
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::TimeDelta* session_length_limit) {
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (session_length_limit_set_)
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    *session_length_limit = session_length_limit_;
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return session_length_limit_set_;
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void TestSystemTrayDelegate::ShutDown() {
98d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  base::MessageLoop::current()->Quit();
99d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
100d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
101d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void TestSystemTrayDelegate::SignOut() {
102d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  base::MessageLoop::current()->Quit();
103d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
104d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
105d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}  // namespace test
106d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}  // namespace ash
107