diff options
Diffstat (limited to 'ash/test')
-rw-r--r-- | ash/test/ash_test_base.cc | 10 | ||||
-rw-r--r-- | ash/test/test_session_state_delegate.cc | 63 | ||||
-rw-r--r-- | ash/test/test_session_state_delegate.h | 67 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.cc | 65 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.h | 38 |
5 files changed, 158 insertions, 85 deletions
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index 3346c3c..24b004f 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -14,6 +14,7 @@ #include "ash/shell.h" #include "ash/test/display_manager_test_api.h" #include "ash/test/shell_test_api.h" +#include "ash/test/test_session_state_delegate.h" #include "ash/test/test_shell_delegate.h" #include "ash/wm/coordinate_conversion.h" #include "base/command_line.h" @@ -275,15 +276,18 @@ void AshTestBase::RunAllPendingInMessageLoop() { } void AshTestBase::SetSessionStarted(bool session_started) { - test_shell_delegate_->SetSessionStarted(session_started); + test_shell_delegate_->test_session_state_delegate()-> + SetActiveUserSessionStarted(session_started); } void AshTestBase::SetUserLoggedIn(bool user_logged_in) { - test_shell_delegate_->SetUserLoggedIn(user_logged_in); + test_shell_delegate_->test_session_state_delegate()-> + SetHasActiveUser(user_logged_in); } void AshTestBase::SetCanLockScreen(bool can_lock_screen) { - test_shell_delegate_->SetCanLockScreen(can_lock_screen); + test_shell_delegate_->test_session_state_delegate()-> + SetCanLockScreen(can_lock_screen); } } // namespace test diff --git a/ash/test/test_session_state_delegate.cc b/ash/test/test_session_state_delegate.cc new file mode 100644 index 0000000..881f4982 --- /dev/null +++ b/ash/test/test_session_state_delegate.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/test/test_session_state_delegate.h" + +namespace ash { +namespace test { + +TestSessionStateDelegate::TestSessionStateDelegate() + : has_active_user_(true), + active_user_session_started_(true), + can_lock_screen_(true), + screen_locked_(false) { +} + +TestSessionStateDelegate::~TestSessionStateDelegate() { +} + +bool TestSessionStateDelegate::HasActiveUser() const { + return has_active_user_; +} + +bool TestSessionStateDelegate::IsActiveUserSessionStarted() const { + return active_user_session_started_; +} + +bool TestSessionStateDelegate::CanLockScreen() const { + return has_active_user_ && can_lock_screen_; +} + +bool TestSessionStateDelegate::IsScreenLocked() const { + return screen_locked_; +} + +void TestSessionStateDelegate::LockScreen() { + if (CanLockScreen()) + screen_locked_ = true; +} + +void TestSessionStateDelegate::UnlockScreen() { + screen_locked_ = false; +} + +void TestSessionStateDelegate::SetHasActiveUser(bool has_active_user) { + has_active_user_ = has_active_user; + if (!has_active_user) + active_user_session_started_ = false; +} + +void TestSessionStateDelegate::SetActiveUserSessionStarted( + bool active_user_session_started) { + active_user_session_started_ = active_user_session_started; + if (active_user_session_started) + has_active_user_ = true; +} + +void TestSessionStateDelegate::SetCanLockScreen(bool can_lock_screen) { + can_lock_screen_ = can_lock_screen; +} + +} // namespace test +} // namespace ash diff --git a/ash/test/test_session_state_delegate.h b/ash/test/test_session_state_delegate.h new file mode 100644 index 0000000..807e335 --- /dev/null +++ b/ash/test/test_session_state_delegate.h @@ -0,0 +1,67 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_TEST_TEST_SESSION_STATE_DELEGATE_H_ +#define ASH_TEST_TEST_SESSION_STATE_DELEGATE_H_ + +#include "ash/session_state_delegate.h" +#include "base/basictypes.h" +#include "base/compiler_specific.h" + +namespace ash { +namespace test { + +class TestSessionStateDelegate : public SessionStateDelegate { + public: + TestSessionStateDelegate(); + virtual ~TestSessionStateDelegate(); + + // SessionStateDelegate: + virtual bool HasActiveUser() const OVERRIDE; + virtual bool IsActiveUserSessionStarted() const OVERRIDE; + virtual bool CanLockScreen() const OVERRIDE; + virtual bool IsScreenLocked() const OVERRIDE; + virtual void LockScreen() OVERRIDE; + virtual void UnlockScreen() OVERRIDE; + + // Updates the internal state that indicates whether a session is in progress + // and there is an active user. If |has_active_user| is |false|, + // |active_user_session_started_| is reset to |false| as well (see below for + // the difference between these two flags). + void SetHasActiveUser(bool has_active_user); + + // Updates the internal state that indicates whether the session has been + // fully started for the active user. If |active_user_session_started| is + // |true|, |has_active_user_| is set to |true| as well (see below for the + // difference between these two flags). + void SetActiveUserSessionStarted(bool active_user_session_started); + + // Updates the internal state that indicates whether the screen can be locked. + // Locking will only actually be allowed when this value is |true| and there + // is an active user. + void SetCanLockScreen(bool can_lock_screen); + + private: + // Whether a session is in progress and there is an active user. + bool has_active_user_; + + // When a user becomes active, the profile and browser UI are not immediately + // available. Only once this flag becomes |true| is the browser startup + // complete and both profile and UI are fully available. + bool active_user_session_started_; + + // Whether the screen can be locked. Locking will only actually be allowed + // when this is |true| and there is an active user. + bool can_lock_screen_; + + // Whether the screen is currently locked. + bool screen_locked_; + + DISALLOW_COPY_AND_ASSIGN(TestSessionStateDelegate); +}; + +} // namespace test +} // namespace ash + +#endif // ASH_TEST_TEST_SESSION_STATE_DELEGATE_H_ diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index ea971d7..8013d08 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -8,10 +8,13 @@ #include "ash/caps_lock_delegate_stub.h" #include "ash/host/root_window_host_factory.h" +#include "ash/session_state_delegate.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "ash/test/test_launcher_delegate.h" +#include "ash/test/test_session_state_delegate.h" #include "ash/wm/window_util.h" +#include "base/logging.h" #include "content/public/test/test_browser_context.h" #include "ui/aura/window.h" @@ -19,32 +22,17 @@ namespace ash { namespace test { TestShellDelegate::TestShellDelegate() - : locked_(false), - session_started_(true), - spoken_feedback_enabled_(false), + : spoken_feedback_enabled_(false), high_contrast_enabled_(false), screen_magnifier_enabled_(false), screen_magnifier_type_(kDefaultMagnifierType), - user_logged_in_(true), - can_lock_screen_(true), - num_exit_requests_(0) { + num_exit_requests_(0), + test_session_state_delegate_(NULL) { } TestShellDelegate::~TestShellDelegate() { } -bool TestShellDelegate::IsUserLoggedIn() const { - return user_logged_in_; -} - -bool TestShellDelegate::IsSessionStarted() const { - return session_started_; -} - -bool TestShellDelegate::IsGuestSession() const { - return false; -} - bool TestShellDelegate::IsFirstRunAfterBoot() const { return false; } @@ -57,22 +45,6 @@ bool TestShellDelegate::IsRunningInForcedAppMode() const { return false; } -bool TestShellDelegate::CanLockScreen() const { - return user_logged_in_ && can_lock_screen_; -} - -void TestShellDelegate::LockScreen() { - locked_ = true; -} - -void TestShellDelegate::UnlockScreen() { - locked_ = false; -} - -bool TestShellDelegate::IsScreenLocked() const { - return locked_; -} - void TestShellDelegate::PreInit() { } @@ -185,6 +157,12 @@ CapsLockDelegate* TestShellDelegate::CreateCapsLockDelegate() { return new CapsLockDelegateStub; } +SessionStateDelegate* TestShellDelegate::CreateSessionStateDelegate() { + DCHECK(!test_session_state_delegate_); + test_session_state_delegate_ = new TestSessionStateDelegate(); + return test_session_state_delegate_; +} + aura::client::UserActionClient* TestShellDelegate::CreateUserActionClient() { return NULL; } @@ -229,26 +207,13 @@ RootWindowHostFactory* TestShellDelegate::CreateRootWindowHostFactory() { return RootWindowHostFactory::Create(); } -void TestShellDelegate::SetSessionStarted(bool session_started) { - session_started_ = session_started; - if (session_started) - user_logged_in_ = true; -} - -void TestShellDelegate::SetUserLoggedIn(bool user_logged_in) { - user_logged_in_ = user_logged_in; - if (!user_logged_in) - session_started_ = false; -} - -void TestShellDelegate::SetCanLockScreen(bool can_lock_screen) { - can_lock_screen_ = can_lock_screen; -} - base::string16 TestShellDelegate::GetProductName() const { return base::string16(); } +TestSessionStateDelegate* TestShellDelegate::test_session_state_delegate() { + return test_session_state_delegate_; +} } // namespace test } // namespace ash diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h index 1ff9ce9..6c95ea8 100644 --- a/ash/test/test_shell_delegate.h +++ b/ash/test/test_shell_delegate.h @@ -18,7 +18,7 @@ class KeyboardControllerProxy; namespace ash { namespace test { -class AshTestBase; +class TestSessionStateDelegate; class TestShellDelegate : public ShellDelegate { public: @@ -26,16 +26,9 @@ class TestShellDelegate : public ShellDelegate { virtual ~TestShellDelegate(); // Overridden from ShellDelegate: - virtual bool IsUserLoggedIn() const OVERRIDE; - virtual bool IsSessionStarted() const OVERRIDE; - virtual bool IsGuestSession() const OVERRIDE; virtual bool IsFirstRunAfterBoot() const OVERRIDE; virtual bool IsMultiProfilesEnabled() const OVERRIDE; virtual bool IsRunningInForcedAppMode() const OVERRIDE; - virtual bool CanLockScreen() const OVERRIDE; - virtual void LockScreen() OVERRIDE; - virtual void UnlockScreen() OVERRIDE; - virtual bool IsScreenLocked() const OVERRIDE; virtual void PreInit() OVERRIDE; virtual void Shutdown() OVERRIDE; virtual void Exit() OVERRIDE; @@ -68,6 +61,7 @@ class TestShellDelegate : public ShellDelegate { virtual SystemTrayDelegate* CreateSystemTrayDelegate() OVERRIDE; virtual UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE; virtual CapsLockDelegate* CreateCapsLockDelegate() OVERRIDE; + virtual SessionStateDelegate* CreateSessionStateDelegate() OVERRIDE; virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE; virtual void OpenFeedbackPage() OVERRIDE; virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE; @@ -85,39 +79,19 @@ class TestShellDelegate : public ShellDelegate { int num_exit_requests() const { return num_exit_requests_; } + TestSessionStateDelegate* test_session_state_delegate(); + private: - friend class ash::test::AshTestBase; - - // Given |session_started| will update internal state. - // If |session_started| is true this method will also set - // |user_logged_in_| to true. - // When session is started it always means that user has logged in. - // Possible situation is that user has already logged in but session has not - // been started (user selects avatar and login window is still open). - void SetSessionStarted(bool session_started); - - // Given |user_logged_in| will update internal state. - // If |user_logged_in| is false this method will also set |session_started_| - // to false. When user is not logged in it always means that session - // hasn't been started too. - void SetUserLoggedIn(bool user_logged_in); - - // Sets the internal state that indicates whether the user can lock the - // screen. - void SetCanLockScreen(bool can_lock_screen); - - bool locked_; - bool session_started_; bool spoken_feedback_enabled_; bool high_contrast_enabled_; bool screen_magnifier_enabled_; MagnifierType screen_magnifier_type_; - bool user_logged_in_; - bool can_lock_screen_; int num_exit_requests_; scoped_ptr<content::BrowserContext> current_browser_context_; + TestSessionStateDelegate* test_session_state_delegate_; // Not owned. + DISALLOW_COPY_AND_ASSIGN(TestShellDelegate); }; |