1 // Copyright (c) 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_session_state_delegate.h" 6 7 #include "ash/shell.h" 8 #include "ash/system/user/login_status.h" 9 #include "base/strings/string16.h" 10 #include "base/strings/utf_string_conversions.h" 11 12 namespace ash { 13 namespace test { 14 15 TestSessionStateDelegate::TestSessionStateDelegate() 16 : has_active_user_(false), 17 active_user_session_started_(false), 18 can_lock_screen_(true), 19 screen_locked_(false), 20 user_adding_screen_running_(false), 21 logged_in_users_(1) { 22 } 23 24 TestSessionStateDelegate::~TestSessionStateDelegate() { 25 } 26 27 int TestSessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const { 28 return 3; 29 } 30 31 int TestSessionStateDelegate::NumberOfLoggedInUsers() const { 32 // TODO(skuhne): Add better test framework to test multiple profiles. 33 return has_active_user_ ? logged_in_users_ : 0; 34 } 35 36 bool TestSessionStateDelegate::IsActiveUserSessionStarted() const { 37 return active_user_session_started_; 38 } 39 40 bool TestSessionStateDelegate::CanLockScreen() const { 41 return has_active_user_ && can_lock_screen_; 42 } 43 44 bool TestSessionStateDelegate::IsScreenLocked() const { 45 return screen_locked_; 46 } 47 48 void TestSessionStateDelegate::LockScreen() { 49 if (CanLockScreen()) 50 screen_locked_ = true; 51 } 52 53 void TestSessionStateDelegate::UnlockScreen() { 54 screen_locked_ = false; 55 } 56 57 bool TestSessionStateDelegate::IsUserSessionBlocked() const { 58 return !IsActiveUserSessionStarted() || IsScreenLocked() || 59 user_adding_screen_running_; 60 } 61 62 void TestSessionStateDelegate::SetHasActiveUser(bool has_active_user) { 63 has_active_user_ = has_active_user; 64 if (!has_active_user) 65 active_user_session_started_ = false; 66 else 67 Shell::GetInstance()->ShowLauncher(); 68 } 69 70 void TestSessionStateDelegate::SetActiveUserSessionStarted( 71 bool active_user_session_started) { 72 active_user_session_started_ = active_user_session_started; 73 if (active_user_session_started) { 74 has_active_user_ = true; 75 Shell::GetInstance()->CreateLauncher(); 76 Shell::GetInstance()->UpdateAfterLoginStatusChange( 77 user::LOGGED_IN_USER); 78 } 79 } 80 81 void TestSessionStateDelegate::SetCanLockScreen(bool can_lock_screen) { 82 can_lock_screen_ = can_lock_screen; 83 } 84 85 void TestSessionStateDelegate::SetUserAddingScreenRunning( 86 bool user_adding_screen_running) { 87 user_adding_screen_running_ = user_adding_screen_running; 88 } 89 90 const base::string16 TestSessionStateDelegate::GetUserDisplayName( 91 MultiProfileIndex index) const { 92 return UTF8ToUTF16("ber tray ber tray ber tray ber tray"); 93 } 94 95 const std::string TestSessionStateDelegate::GetUserEmail( 96 MultiProfileIndex index) const { 97 switch (index) { 98 case 0: return "first@tray"; 99 case 1: return "second@tray"; 100 case 2: return "third@tray"; 101 default: return "someone@tray"; 102 } 103 } 104 105 const gfx::ImageSkia& TestSessionStateDelegate::GetUserImage( 106 MultiProfileIndex index) const { 107 return null_image_; 108 } 109 110 void TestSessionStateDelegate::GetLoggedInUsers(UserIdList* users) { 111 } 112 113 void TestSessionStateDelegate::SwitchActiveUser(const std::string& email) { 114 activated_user_ = email; 115 } 116 117 void TestSessionStateDelegate::AddSessionStateObserver( 118 SessionStateObserver* observer) { 119 } 120 121 void TestSessionStateDelegate::RemoveSessionStateObserver( 122 SessionStateObserver* observer) { 123 } 124 125 } // namespace test 126 } // namespace ash 127