Chromium Code Reviews| Index: ash/wm/session_state_controller_impl2_unittest.cc |
| diff --git a/ash/wm/session_state_controller_impl2_unittest.cc b/ash/wm/session_state_controller_impl2_unittest.cc |
| index df32b3a4b3ff37b071dede7fcc3e11e9833e3856..a451ac20dcb0eb09525c57323272b8de762329fa 100644 |
| --- a/ash/wm/session_state_controller_impl2_unittest.cc |
| +++ b/ash/wm/session_state_controller_impl2_unittest.cc |
| @@ -6,6 +6,7 @@ |
| #include "ash/ash_switches.h" |
| #include "ash/shell.h" |
| +#include "ash/shell_window_ids.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ash/test/test_shell_delegate.h" |
| #include "ash/wm/cursor_manager.h" |
| @@ -18,21 +19,55 @@ |
| #include "ui/aura/env.h" |
| #include "ui/aura/root_window.h" |
| #include "ui/aura/test/event_generator.h" |
| +#include "ui/compositor/scoped_layer_animation_settings.h" |
| #include "ui/gfx/rect.h" |
| #include "ui/gfx/size.h" |
| namespace ash { |
| + |
| +using internal::SessionStateAnimator; |
| + |
| namespace test { |
| + |
| namespace { |
| + |
| bool cursor_visible() { |
| return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); |
| } |
| void CheckCalledCallback(bool* flag) { |
| - (*flag) = true; |
| + if (flag) |
| + (*flag) = true; |
| +} |
| + |
| +aura::Window* GetContainer(int container ) { |
|
Nikita (slow)
2012/12/07 17:54:08
nit: extra space
|
| + aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| + return Shell::GetContainer(root_window, container); |
| +} |
| + |
| +bool IsBackgroundHidden() { |
| + return !GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> |
|
Nikita (slow)
2012/12/07 17:54:08
nit: Such alignment looks better:
return !GetCont
|
| + IsVisible(); |
| } |
| + |
| +void ShowBackground() { |
| + ui::ScopedLayerAnimationSettings settings( |
| + GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> |
| + layer()->GetAnimator()); |
| + settings.SetTransitionDuration(base::TimeDelta()); |
| + GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->Show(); |
| +} |
| + |
| +void HideBackground() { |
| + ui::ScopedLayerAnimationSettings settings( |
| + GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> |
| + layer()->GetAnimator()); |
| + settings.SetTransitionDuration(base::TimeDelta()); |
| + GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->Hide(); |
| } |
| +} // namespace |
| + |
| // Fake implementation of PowerButtonControllerDelegate that just logs requests |
| // to lock the screen and shut down the device. |
| class TestSessionStateControllerDelegate : |
| @@ -70,6 +105,11 @@ class SessionStateControllerImpl2Test : public AshTestBase { |
| ash::switches::kAshNewLockAnimationsEnabled); |
| AshTestBase::SetUp(); |
| + |
| + // We would control animations in a fine way: |
| + ui::LayerAnimator::set_disable_animations_for_test(false); |
| + animator_helper_ = ui::LayerAnimator::CreateAnimatorHelperForTest(); |
| + |
| delegate_ = new TestSessionStateControllerDelegate; |
| controller_ = Shell::GetInstance()->power_button_controller(); |
| state_controller_ = static_cast<SessionStateControllerImpl2*>( |
| @@ -78,12 +118,17 @@ class SessionStateControllerImpl2Test : public AshTestBase { |
| test_api_.reset( |
| new SessionStateControllerImpl2::TestApi(state_controller_)); |
| animator_api_.reset( |
| - new internal::SessionStateAnimator::TestApi(state_controller_-> |
| + new SessionStateAnimator::TestApi(state_controller_-> |
| animator_.get())); |
| shell_delegate_ = reinterpret_cast<TestShellDelegate*>( |
| ash::Shell::GetInstance()->delegate()); |
| } |
| + void TearDown() { |
| + animator_helper_->ForwardWhileRunning(); |
| + AshTestBase::TearDown(); |
| + } |
| + |
| protected: |
| void GenerateMouseMoveEvent() { |
| aura::test::EventGenerator generator( |
| @@ -96,13 +141,250 @@ class SessionStateControllerImpl2Test : public AshTestBase { |
| shell_delegate_->num_exit_requests(); |
| } |
| + void Forward(SessionStateAnimator::AnimationSpeed speed) { |
| + animator_helper_->Forward(SessionStateAnimator::GetDuration(speed)); |
| + } |
| + |
| + void ForwardPartially(SessionStateAnimator::AnimationSpeed speed, |
| + float factor) { |
| + base::TimeDelta duration = SessionStateAnimator::GetDuration(speed); |
| + base::TimeDelta partial_duration = |
| + base::TimeDelta::FromInternalValue(duration.ToInternalValue() * factor); |
| + animator_helper_->Forward(partial_duration); |
| + } |
| + |
| + void ExpectLockPartOneAnimationStarted() { |
| + EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_LIFT)); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LAUNCHER, |
| + SessionStateAnimator::ANIMATION_FADE_OUT)); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| + EXPECT_TRUE(test_api_->is_animating_lock()); |
| + } |
| + |
| + void ExpectLockPartOneAnimationUndo() { |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_DROP)); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LAUNCHER, |
| + SessionStateAnimator::ANIMATION_FADE_IN)); |
| + } |
|
Nikita (slow)
2012/12/07 17:54:08
Nit: Check that lock is not seen?
|
| + |
| + void ExpectLockPartOneAnimationFinished() { |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_LIFT)); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LAUNCHER, |
| + SessionStateAnimator::ANIMATION_FADE_OUT)); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| + } |
| + |
| + void ExpectLockPartTwoAnimationStarted() { |
| + EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| + } |
| + |
| + void ExpectLockPartTwoAnimationFinished() { |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| + } |
| + |
| + void ExpectUnlockPartOneAnimationStarted() { |
| + EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_LIFT)); |
| + } |
| + |
| + void ExpectUnlockPartOneAnimationFinished() { |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_LIFT)); |
| + } |
| + |
| + void ExpectUnlockPartTwoAnimationStarted() { |
| + EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_DROP)); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LAUNCHER, |
| + SessionStateAnimator::ANIMATION_FADE_IN)); |
| + } |
| + |
| + void ExpectUnlockPartTwoAnimationFinished() { |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| + SessionStateAnimator::ANIMATION_DROP)); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::LAUNCHER, |
| + SessionStateAnimator::ANIMATION_FADE_IN)); |
| + } |
| + |
| + void ExpectShutdownAnimationStarted() { |
| + EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->RootWindowIsAnimated( |
| + SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| + } |
| + |
| + void ExpectShutdownAnimationFinished() { |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->RootWindowIsAnimated( |
| + SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| + } |
| + |
| + void ExpectShutdownAnimationUndo() { |
| + EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->RootWindowIsAnimated( |
| + SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); |
| + } |
| + |
| + void ExpectBackgroundIsShowing() { |
| + EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::DESKTOP_BACKGROUND, |
| + SessionStateAnimator::ANIMATION_FADE_IN)); |
| + } |
| + |
| + void ExpectBackgroundIsHiding() { |
| + EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE( |
| + animator_api_->ContainersAreAnimated( |
| + SessionStateAnimator::DESKTOP_BACKGROUND, |
| + SessionStateAnimator::ANIMATION_FADE_OUT)); |
| + } |
| + |
| + void ExpectUnlockedState() { |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + EXPECT_FALSE(shell_delegate_->IsScreenLocked()); |
| + |
| + aura::Window::Windows containers; |
| + |
| + SessionStateAnimator::GetContainers( |
| + SessionStateAnimator::LAUNCHER | |
| + SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| + &containers); |
| + for (aura::Window::Windows::const_iterator it = containers.begin(); |
|
Nikita (slow)
2012/12/07 17:54:08
Export lines 303-310 as a separate function.
Lines
|
| + it != containers.end(); ++it) { |
| + aura::Window* window = *it; |
| + ui::Layer* layer = window->layer(); |
| + EXPECT_EQ(1.0f, layer->opacity()); |
| + EXPECT_EQ(0.0f, layer->layer_brightness()); |
| + EXPECT_EQ(0.0f, layer->layer_saturation()); |
| + EXPECT_EQ(gfx::Transform(), layer->transform()); |
| + } |
| + } |
| + |
| + void ExpectLockedState() { |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + EXPECT_TRUE(shell_delegate_->IsScreenLocked()); |
| + |
| + aura::Window::Windows containers; |
| + |
|
Nikita (slow)
2012/12/07 17:54:08
As discussed, add check that _lock_ background is
|
| + SessionStateAnimator::GetContainers( |
| + SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS | |
| + SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| + &containers); |
| + for (aura::Window::Windows::const_iterator it = containers.begin(); |
| + it != containers.end(); ++it) { |
| + aura::Window* window = *it; |
| + ui::Layer* layer = window->layer(); |
| + EXPECT_EQ(1.0f, layer->opacity()); |
| + EXPECT_EQ(0.0f, layer->layer_brightness()); |
| + EXPECT_EQ(0.0f, layer->layer_saturation()); |
| + EXPECT_EQ(gfx::Transform(), layer->transform()); |
| + } |
| + } |
| + |
| + void PressPowerButton() { |
| + controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| + animator_helper_->Ping(); |
| + } |
| + |
| + void ReleasePowerButton() { |
| + controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| + animator_helper_->Ping(); |
| + } |
| + |
| + void PressLockButton() { |
| + controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| + } |
| + |
| + void ReleaseLockButton() { |
| + controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| + } |
| + |
| + void SystemLocks() { |
| + state_controller_->OnLockStateChanged(true); |
| + shell_delegate_->LockScreen(); |
| + animator_helper_->Ping(); |
| + } |
| + |
| + void SuccessfulAuthentication(bool* call_flag) { |
| + base::Closure closure = base::Bind(&CheckCalledCallback, call_flag); |
| + state_controller_->OnLockScreenHide(closure); |
| + animator_helper_->Ping(); |
| + } |
| + |
| + void SystemUnlocks() { |
| + state_controller_->OnLockStateChanged(false); |
| + shell_delegate_->UnlockScreen(); |
| + animator_helper_->Ping(); |
| + } |
| + |
| + void Initialize(bool legacy_button, user::LoginStatus status) { |
| + controller_->set_has_legacy_power_button_for_test(legacy_button); |
| + state_controller_->OnLoginStateChanged(status); |
| + SetUserLoggedIn(status != user::LOGGED_IN_NONE); |
| + if (status == user::LOGGED_IN_GUEST) |
| + SetCanLockScreen(false); |
| + state_controller_->OnLockStateChanged(false); |
| + } |
| + |
| PowerButtonController* controller_; // not owned |
| SessionStateControllerImpl2* state_controller_; // not owned |
| TestSessionStateControllerDelegate* delegate_; // not owned |
| TestShellDelegate* shell_delegate_; // not owned |
| scoped_ptr<SessionStateControllerImpl2::TestApi> test_api_; |
| - scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; |
| + scoped_ptr<SessionStateAnimator::TestApi> animator_api_; |
| + scoped_ptr<ui::test::AnimationContainerTestHelper> animator_helper_; |
| private: |
| DISALLOW_COPY_AND_ASSIGN(SessionStateControllerImpl2Test); |
| @@ -113,60 +395,50 @@ class SessionStateControllerImpl2Test : public AshTestBase { |
| // time the button is pressed and shut down when it's pressed from the locked |
| // state. |
| TEST_F(SessionStateControllerImpl2Test, LegacyLockAndShutDown) { |
| - controller_->set_has_legacy_power_button_for_test(true); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - state_controller_->OnLockStateChanged(false); |
| + Initialize(true, user::LOGGED_IN_USER); |
|
Nikita (slow)
2012/12/07 17:54:08
nit: /* legacy button */
|
| + |
| + ExpectUnlockedState(); |
| // We should request that the screen be locked immediately after seeing the |
| // power button get pressed. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| + PressPowerButton(); |
| + |
| + ExpectLockPartOneAnimationStarted(); |
|
Nikita (slow)
2012/12/07 17:54:08
nit: empty line
|
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| + EXPECT_FALSE(test_api_->is_lock_undoable()); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + |
| + ExpectLockPartOneAnimationFinished(); |
| EXPECT_EQ(1, delegate_->num_lock_requests()); |
| // Notify that we locked successfully. |
| state_controller_->OnStartingLock(); |
| + // We had that animation already. |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| - |
| - |
| - // Notify that the lock window is visible. We should make it fade in. |
| - state_controller_->OnLockStateChanged(true); |
| - shell_delegate_->LockScreen(); |
| + SystemLocks(); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| - internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| + ExpectLockPartTwoAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectLockPartTwoAnimationFinished(); |
| // We shouldn't progress towards the shutdown state, however. |
| EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| + |
| + ReleasePowerButton(); |
| // Hold the button again and check that we start shutting down. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_EQ(0, NumShutdownRequests()); |
| + PressPowerButton(); |
| - EXPECT_TRUE( |
| - animator_api_->RootWindowIsAnimated( |
| - internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| + ExpectShutdownAnimationStarted(); |
| + |
| + EXPECT_EQ(0, NumShutdownRequests()); |
| // Make sure a mouse move event won't show the cursor. |
| GenerateMouseMoveEvent(); |
| EXPECT_FALSE(cursor_visible()); |
| + |
| EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| test_api_->trigger_real_shutdown_timeout(); |
| EXPECT_EQ(1, NumShutdownRequests()); |
| @@ -175,207 +447,246 @@ TEST_F(SessionStateControllerImpl2Test, LegacyLockAndShutDown) { |
| // Test that we start shutting down immediately if the power button is pressed |
| // while we're not logged in on an unofficial system. |
| TEST_F(SessionStateControllerImpl2Test, LegacyNotLoggedIn) { |
| - controller_->set_has_legacy_power_button_for_test(true); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| - state_controller_->OnLockStateChanged(false); |
| - SetUserLoggedIn(false); |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| + Initialize(true, user::LOGGED_IN_NONE); |
| + |
| + PressPowerButton(); |
| + ExpectShutdownAnimationStarted(); |
| + |
| EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| } |
| // Test that we start shutting down immediately if the power button is pressed |
| // while we're logged in as a guest on an unofficial system. |
| TEST_F(SessionStateControllerImpl2Test, LegacyGuest) { |
| - controller_->set_has_legacy_power_button_for_test(true); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); |
| - state_controller_->OnLockStateChanged(false); |
| - SetCanLockScreen(false); |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| + Initialize(true, user::LOGGED_IN_GUEST); |
| + |
| + PressPowerButton(); |
| + ExpectShutdownAnimationStarted(); |
| + |
| EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| } |
| // When we hold the power button while the user isn't logged in, we should shut |
| // down the machine directly. |
| TEST_F(SessionStateControllerImpl2Test, ShutdownWhenNotLoggedIn) { |
| - controller_->set_has_legacy_power_button_for_test(false); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| - state_controller_->OnLockStateChanged(false); |
| - SetUserLoggedIn(false); |
| + Initialize(false, user::LOGGED_IN_NONE); |
| // Press the power button and check that we start the shutdown timer. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| + PressPowerButton(); |
| + EXPECT_FALSE(test_api_->is_animating_lock()); |
| EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->RootWindowIsAnimated( |
| - internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| + ExpectShutdownAnimationStarted(); |
| + |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f); |
| // Release the power button before the shutdown timer fires. |
| - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| + ReleasePowerButton(); |
| + |
| EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->RootWindowIsAnimated( |
| - internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); |
| + ExpectShutdownAnimationUndo(); |
| + |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_REVERT, 0.5f); |
| // Press the button again and make the shutdown timeout fire this time. |
| // Check that we start the timer for actually requesting the shutdown. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| + PressPowerButton(); |
| + |
| EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| + ExpectShutdownAnimationFinished(); |
| test_api_->trigger_shutdown_timeout(); |
| + |
| EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| EXPECT_EQ(0, NumShutdownRequests()); |
| - EXPECT_TRUE( |
| - animator_api_->RootWindowIsAnimated( |
| - internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| // When the timout fires, we should request a shutdown. |
| test_api_->trigger_real_shutdown_timeout(); |
| + |
| EXPECT_EQ(1, NumShutdownRequests()); |
| } |
| // Test that we lock the screen and deal with unlocking correctly. |
| TEST_F(SessionStateControllerImpl2Test, LockAndUnlock) { |
| - controller_->set_has_legacy_power_button_for_test(false); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - state_controller_->OnLockStateChanged(false); |
| + Initialize(false, user::LOGGED_IN_USER); |
| - // We should initially be showing the screen locker containers, since they |
| - // also contain login-related windows that we want to show during the |
| - // logging-in animation. |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| - internal::SessionStateAnimator::ANIMATION_RESTORE)); |
| + ExpectUnlockedState(); |
| // Press the power button and check that the lock timer is started and that we |
| // start lifting the non-screen-locker containers. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| + PressPowerButton(); |
| - // Release the button before the lock timer fires. |
| - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_DROP)); |
| - |
| - // Press the button and fire the lock timer. We should request that the |
| - // screen be locked, but we should still be in the lift animation. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| + ExpectLockPartOneAnimationStarted(); |
| + EXPECT_TRUE(test_api_->is_lock_undoable()); |
| EXPECT_EQ(0, delegate_->num_lock_requests()); |
| - test_api_->trigger_lock_timeout(); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| + ExpectLockPartOneAnimationFinished(); |
| + |
| EXPECT_EQ(1, delegate_->num_lock_requests()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| // Notify that we locked successfully. |
| state_controller_->OnStartingLock(); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| + // We had that animation already. |
| + EXPECT_FALSE(animator_helper_->IsAnimating()); |
| - // Notify that the lock window is visible. We should make it raise in. |
| - state_controller_->OnLockStateChanged(true); |
| - shell_delegate_->LockScreen(); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| - internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| + SystemLocks(); |
| + |
| + ExpectLockPartTwoAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectLockPartTwoAnimationFinished(); |
| // When we release the power button, the lock-to-shutdown timer should be |
| // stopped. |
| + ExpectLockedState(); |
| EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| + ReleasePowerButton(); |
| + ExpectLockedState(); |
| EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| // Notify that the screen has been unlocked. We should show the |
| // non-screen-locker windows. |
| - state_controller_->OnLockStateChanged(false); |
| - shell_delegate_->UnlockScreen(); |
| bool called = false; |
| - base::Closure closure = base::Bind(&CheckCalledCallback, &called); |
| - state_controller_->OnLockScreenHide(closure); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| + SuccessfulAuthentication(&called); |
| + |
| + ExpectUnlockPartOneAnimationStarted(); |
| + EXPECT_FALSE(called); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectUnlockPartOneAnimationFinished(); |
| + |
| EXPECT_TRUE(called); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_DROP)); |
| + |
| + SystemUnlocks(); |
| + |
| + ExpectUnlockPartTwoAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectUnlockPartTwoAnimationFinished(); |
| + |
| + ExpectUnlockedState(); |
| +} |
| + |
| +// Test that we deal with cancelling lock correctly. |
| +TEST_F(SessionStateControllerImpl2Test, LockAndCancel) { |
| + Initialize(false, user::LOGGED_IN_USER); |
| + |
| + ExpectUnlockedState(); |
| + |
| + // Press the power button and check that the lock timer is started and that we |
| + // start lifting the non-screen-locker containers. |
| + PressPowerButton(); |
| + |
| + ExpectLockPartOneAnimationStarted(); |
| + EXPECT_TRUE(test_api_->is_lock_undoable()); |
| + |
| + // forward only half way through |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| + |
| + gfx::Transform transform_before_button_released = |
| + GetContainer(internal::kShellWindowId_DefaultContainer)-> |
| + layer()->transform(); |
| + |
| + // Release the button before the lock timer fires. |
| + ReleasePowerButton(); |
| + |
| + ExpectLockPartOneAnimationUndo(); |
| + |
| + gfx::Transform transform_after_button_released = |
| + GetContainer(internal::kShellWindowId_DefaultContainer)-> |
| + layer()->transform(); |
| + // Expect no flickering, animation should proceed from mid-state. |
| + EXPECT_EQ(transform_before_button_released, transform_after_button_released); |
| + |
|
Nikita (slow)
2012/12/07 17:54:08
// TODO(antrim): Check that background is correctl
|
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectUnlockedState(); |
| + EXPECT_EQ(0, delegate_->num_lock_requests()); |
| +} |
| + |
| +// Test that we deal with cancelling lock correctly. |
| +TEST_F(SessionStateControllerImpl2Test, LockAndCancelAndLockAgain) { |
| + Initialize(false, user::LOGGED_IN_USER); |
| + |
| + ExpectUnlockedState(); |
| + |
| + // Press the power button and check that the lock timer is started and that we |
| + // start lifting the non-screen-locker containers. |
| + PressPowerButton(); |
| + |
| + ExpectLockPartOneAnimationStarted(); |
| + EXPECT_TRUE(test_api_->is_lock_undoable()); |
| + |
| + // forward only half way through |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| + |
| + // Release the button before the lock timer fires. |
| + ReleasePowerButton(); |
| + ExpectLockPartOneAnimationUndo(); |
| + |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f); |
| + |
| + PressPowerButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + EXPECT_TRUE(test_api_->is_lock_undoable()); |
| + |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f); |
| + |
| + EXPECT_EQ(0, delegate_->num_lock_requests()); |
| + ExpectLockPartOneAnimationStarted(); |
| + |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f); |
| + ExpectLockPartOneAnimationFinished(); |
| + EXPECT_EQ(1, delegate_->num_lock_requests()); |
| } |
| // Hold the power button down from the unlocked state to eventual shutdown. |
| TEST_F(SessionStateControllerImpl2Test, LockToShutdown) { |
| - controller_->set_has_legacy_power_button_for_test(false); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - state_controller_->OnLockStateChanged(false); |
| + Initialize(false, user::LOGGED_IN_USER); |
| // Hold the power button and lock the screen. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - test_api_->trigger_lock_timeout(); |
| - state_controller_->OnStartingLock(); |
| - state_controller_->OnLockStateChanged(true); |
| - shell_delegate_->LockScreen(); |
| + PressPowerButton(); |
| + EXPECT_TRUE(test_api_->is_animating_lock()); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| + SystemLocks(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| // When the lock-to-shutdown timeout fires, we should start the shutdown |
| // timer. |
| EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| + |
| test_api_->trigger_lock_to_shutdown_timeout(); |
| + |
| + ExpectShutdownAnimationStarted(); |
| EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| - internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| // Fire the shutdown timeout and check that we request shutdown. |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| + ExpectShutdownAnimationFinished(); |
| test_api_->trigger_shutdown_timeout(); |
| + |
| EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| EXPECT_EQ(0, NumShutdownRequests()); |
| test_api_->trigger_real_shutdown_timeout(); |
| EXPECT_EQ(1, NumShutdownRequests()); |
| } |
| - |
| // Hold the power button down from the unlocked state to eventual shutdown, |
| // then release the button while system does locking. |
| TEST_F(SessionStateControllerImpl2Test, CancelLockToShutdown) { |
| - controller_->set_has_legacy_power_button_for_test(false); |
| + Initialize(false, user::LOGGED_IN_USER); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - state_controller_->OnLockStateChanged(false); |
| + PressPowerButton(); |
| // Hold the power button and lock the screen. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - test_api_->trigger_lock_timeout(); |
| - state_controller_->OnStartingLock(); |
| + EXPECT_TRUE(test_api_->is_animating_lock()); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| + SystemLocks(); |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f); |
| // Power button is released while system attempts to lock. |
| - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| - state_controller_->OnLockStateChanged(true); |
| - shell_delegate_->LockScreen(); |
| + ReleasePowerButton(); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| EXPECT_FALSE(state_controller_->ShutdownRequested()); |
| EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| @@ -387,154 +698,156 @@ TEST_F(SessionStateControllerImpl2Test, Lock) { |
| // We require animations to have a duration for this test. |
| ui::LayerAnimator::set_disable_animations_for_test(false); |
| - controller_->set_has_legacy_power_button_for_test(false); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - state_controller_->OnLockStateChanged(false); |
| + Initialize(false, user::LOGGED_IN_USER); |
| // Hold the power button and lock the screen. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| - test_api_->trigger_lock_timeout(); |
| + PressPowerButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| + |
| EXPECT_EQ(1, delegate_->num_lock_requests()); |
| EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); |
| - |
| // We shouldn't start the lock-to-shutdown timer until the screen has actually |
| - // been locked. |
| + // been locked and this was animated. |
| EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| // Act as if the request timed out. We should restore the windows. |
| test_api_->trigger_lock_fail_timeout(); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_DROP)); |
| + |
| + ExpectUnlockPartTwoAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectUnlockPartTwoAnimationFinished(); |
| + ExpectUnlockedState(); |
| } |
| -// Test the basic operation of the lock button. |
| -TEST_F(SessionStateControllerImpl2Test, LockButtonBasic) { |
| - controller_->set_has_legacy_power_button_for_test(false); |
| +// Test the basic operation of the lock button (not logged in). |
| +TEST_F(SessionStateControllerImpl2Test, LockButtonBasicNotLoggedIn) { |
| // The lock button shouldn't do anything if we aren't logged in. |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| - state_controller_->OnLockStateChanged(false); |
| - SetUserLoggedIn(false); |
| - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| + Initialize(false, user::LOGGED_IN_NONE); |
| + |
| + PressLockButton(); |
| + EXPECT_FALSE(test_api_->is_animating_lock()); |
| + ReleaseLockButton(); |
| EXPECT_EQ(0, delegate_->num_lock_requests()); |
| +} |
| - // Ditto for when we're logged in as a guest. |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); |
| - SetUserLoggedIn(true); |
| - SetCanLockScreen(false); |
| - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| +// Test the basic operation of the lock button (guest). |
| +TEST_F(SessionStateControllerImpl2Test, LockButtonBasicGuest) { |
| + // The lock button shouldn't do anything when we're logged in as a guest. |
| + Initialize(false, user::LOGGED_IN_GUEST); |
| + |
| + PressLockButton(); |
| + EXPECT_FALSE(test_api_->is_animating_lock()); |
| + ReleaseLockButton(); |
| EXPECT_EQ(0, delegate_->num_lock_requests()); |
| +} |
| +// Test the basic operation of the lock button. |
| +TEST_F(SessionStateControllerImpl2Test, LockButtonBasic) { |
| // If we're logged in as a regular user, we should start the lock timer and |
| // the pre-lock animation. |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - SetCanLockScreen(true); |
| - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| + Initialize(false, user::LOGGED_IN_USER); |
| + |
| + PressLockButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| // If the button is released immediately, we shouldn't lock the screen. |
| - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_DROP)); |
| + ReleaseLockButton(); |
| + ExpectLockPartOneAnimationUndo(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + |
| + ExpectUnlockedState(); |
| EXPECT_EQ(0, delegate_->num_lock_requests()); |
| // Press the button again and let the lock timeout fire. We should request |
| // that the screen be locked. |
| - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - test_api_->trigger_lock_timeout(); |
| + PressLockButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| EXPECT_EQ(1, delegate_->num_lock_requests()); |
| // Pressing the lock button while we have a pending lock request shouldn't do |
| // anything. |
| - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| + ReleaseLockButton(); |
| + PressLockButton(); |
| + ExpectLockPartOneAnimationFinished(); |
| + ReleaseLockButton(); |
| // Pressing the button also shouldn't do anything after the screen is locked. |
| - state_controller_->OnStartingLock(); |
| - state_controller_->OnLockStateChanged(true); |
| - shell_delegate_->LockScreen(); |
| - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| + SystemLocks(); |
| + ExpectLockPartTwoAnimationStarted(); |
| + |
| + PressLockButton(); |
| + ReleaseLockButton(); |
| + ExpectLockPartTwoAnimationStarted(); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectLockPartTwoAnimationFinished(); |
| + |
| + PressLockButton(); |
| + ReleaseLockButton(); |
| + ExpectLockPartTwoAnimationFinished(); |
| } |
| // Test that the power button takes priority over the lock button. |
| TEST_F(SessionStateControllerImpl2Test, PowerButtonPreemptsLockButton) { |
| - controller_->set_has_legacy_power_button_for_test(false); |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - state_controller_->OnLockStateChanged(false); |
| + Initialize(false, user::LOGGED_IN_USER); |
| // While the lock button is down, hold the power button. |
| - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| + PressLockButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + PressPowerButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| // The lock timer shouldn't be stopped when the lock button is released. |
| - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| + ReleaseLockButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + ReleasePowerButton(); |
| + ExpectLockPartOneAnimationUndo(); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectUnlockedState(); |
| // Now press the power button first and then the lock button. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| + PressPowerButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + PressLockButton(); |
| + ExpectLockPartOneAnimationStarted(); |
| + |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| // Releasing the power button should stop the lock timer. |
| - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| + ReleasePowerButton(); |
| + ExpectLockPartOneAnimationUndo(); |
| + ReleaseLockButton(); |
| + ExpectLockPartOneAnimationUndo(); |
| } |
| // When the screen is locked without going through the usual power-button |
| // slow-close path (e.g. via the wrench menu), test that we still show the |
| // fast-close animation. |
| TEST_F(SessionStateControllerImpl2Test, LockWithoutButton) { |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| + Initialize(false, user::LOGGED_IN_USER); |
| state_controller_->OnStartingLock(); |
| - EXPECT_TRUE( |
| - animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | |
| - internal::SessionStateAnimator::LAUNCHER, |
| - internal::SessionStateAnimator::ANIMATION_LIFT)); |
| + |
| + ExpectLockPartOneAnimationStarted(); |
| + EXPECT_FALSE(test_api_->is_lock_undoable()); |
| } |
| // When we hear that the process is exiting but we haven't had a chance to |
| // display an animation, we should just blank the screen. |
| TEST_F(SessionStateControllerImpl2Test, ShutdownWithoutButton) { |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| + Initialize(false, user::LOGGED_IN_USER); |
| state_controller_->OnAppTerminating(); |
| + |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| - internal::SessionStateAnimator::kAllContainersMask, |
| - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| + SessionStateAnimator::kAllContainersMask, |
| + SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| GenerateMouseMoveEvent(); |
| EXPECT_FALSE(cursor_visible()); |
| } |
| @@ -542,13 +855,13 @@ TEST_F(SessionStateControllerImpl2Test, ShutdownWithoutButton) { |
| // Test that we display the fast-close animation and shut down when we get an |
| // outside request to shut down (e.g. from the login or lock screen). |
| TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLoginScreen) { |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| - state_controller_->OnLockStateChanged(false); |
| - SetUserLoggedIn(false); |
| + Initialize(false, user::LOGGED_IN_NONE); |
| + |
| state_controller_->RequestShutdown(); |
| - EXPECT_TRUE( |
| - animator_api_->RootWindowIsAnimated( |
| - internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| + |
| + ExpectShutdownAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| + |
| GenerateMouseMoveEvent(); |
| EXPECT_FALSE(cursor_visible()); |
| @@ -559,13 +872,17 @@ TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLoginScreen) { |
| } |
| TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLockScreen) { |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - state_controller_->OnLockStateChanged(true); |
| - shell_delegate_->LockScreen(); |
| + Initialize(false, user::LOGGED_IN_USER); |
| + |
| + SystemLocks(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| + ExpectLockPartTwoAnimationFinished(); |
| + |
| state_controller_->RequestShutdown(); |
| - EXPECT_TRUE( |
| - animator_api_->RootWindowIsAnimated( |
| - internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| + |
| + ExpectShutdownAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| + |
| GenerateMouseMoveEvent(); |
| EXPECT_FALSE(cursor_visible()); |
| @@ -577,41 +894,133 @@ TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLockScreen) { |
| TEST_F(SessionStateControllerImpl2Test, |
| RequestAndCancelShutdownFromLockScreen) { |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| - state_controller_->OnLockStateChanged(true); |
| - shell_delegate_->LockScreen(); |
| + Initialize(false, user::LOGGED_IN_USER); |
| + |
| + SystemLocks(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| + ExpectLockedState(); |
| // Press the power button and check that we start the shutdown timer. |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| + PressPowerButton(); |
| + EXPECT_FALSE(test_api_->is_animating_lock()); |
| EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->RootWindowIsAnimated( |
| - internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| + |
| + ExpectShutdownAnimationStarted(); |
| + |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f); |
| + |
| + float grayscale_before_button_release = |
| + Shell::GetPrimaryRootWindow()->layer()->layer_grayscale(); |
| // Release the power button before the shutdown timer fires. |
| - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| + ReleasePowerButton(); |
| + |
| EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| - EXPECT_TRUE( |
| - animator_api_->RootWindowIsAnimated( |
| - internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); |
| + |
| + ExpectShutdownAnimationUndo(); |
| + |
| + float grayscale_after_button_release = |
| + Shell::GetPrimaryRootWindow()->layer()->layer_grayscale(); |
| + // Expect no flickering in undo animation. |
| + EXPECT_EQ(grayscale_before_button_release, grayscale_after_button_release); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_REVERT); |
| + ExpectLockedState(); |
| } |
| // Test that we ignore power button presses when the screen is turned off. |
| TEST_F(SessionStateControllerImpl2Test, IgnorePowerButtonIfScreenIsOff) { |
| - state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| + Initialize(false, user::LOGGED_IN_USER); |
| // When the screen brightness is at 0%, we shouldn't do anything in response |
| // to power button presses. |
| controller_->OnScreenBrightnessChanged(0.0); |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| + |
| + PressPowerButton(); |
| + EXPECT_FALSE(test_api_->is_animating_lock()); |
| + ReleasePowerButton(); |
| // After increasing the brightness to 10%, we should start the timer like |
| // usual. |
| controller_->OnScreenBrightnessChanged(10.0); |
| - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| + |
| + PressPowerButton(); |
| + EXPECT_TRUE(test_api_->is_animating_lock()); |
| +} |
| + |
| +// Test that hidden background appears and revers correctly on lock/cancel. |
| +TEST_F(SessionStateControllerImpl2Test, TestHiddenBackgroundLockCancel) { |
| + Initialize(false, user::LOGGED_IN_USER); |
| + HideBackground(); |
| + |
| + EXPECT_TRUE(IsBackgroundHidden()); |
| + ExpectUnlockedState(); |
| + PressPowerButton(); |
| + |
| + ExpectLockPartOneAnimationStarted(); |
| + EXPECT_FALSE(IsBackgroundHidden()); |
| + ExpectBackgroundIsShowing(); |
| + |
| + // Forward only half way through. |
| + ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| + |
| + // Release the button before the lock timer fires. |
| + ReleasePowerButton(); |
| + ExpectLockPartOneAnimationUndo(); |
| + ExpectBackgroundIsHiding(); |
| + EXPECT_FALSE(IsBackgroundHidden()); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + |
| + ExpectUnlockedState(); |
| + EXPECT_TRUE(IsBackgroundHidden()); |
| +} |
| + |
| +// Test that hidden background appears and revers correctly on lock/unlock. |
| +TEST_F(SessionStateControllerImpl2Test, TestHiddenBackgroundLockUnlock) { |
| + Initialize(false, user::LOGGED_IN_USER); |
| + HideBackground(); |
| + |
| + EXPECT_TRUE(IsBackgroundHidden()); |
| + ExpectUnlockedState(); |
| + |
| + // Press the power button and check that the lock timer is started and that we |
| + // start lifting the non-screen-locker containers. |
| + PressPowerButton(); |
| + |
| + ExpectLockPartOneAnimationStarted(); |
| + EXPECT_FALSE(IsBackgroundHidden()); |
| + ExpectBackgroundIsShowing(); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| + |
| + ExpectLockPartOneAnimationFinished(); |
| + |
| + SystemLocks(); |
| + |
| + ExpectLockPartTwoAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectLockPartTwoAnimationFinished(); |
| + |
| + ExpectLockedState(); |
| + |
| + SuccessfulAuthentication(NULL); |
| + |
| + ExpectUnlockPartOneAnimationStarted(); |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectUnlockPartOneAnimationFinished(); |
| + |
| + SystemUnlocks(); |
| + |
| + ExpectUnlockPartTwoAnimationStarted(); |
| + ExpectBackgroundIsHiding(); |
| + EXPECT_FALSE(IsBackgroundHidden()); |
| + |
| + Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| + ExpectUnlockPartTwoAnimationFinished(); |
| + EXPECT_TRUE(IsBackgroundHidden()); |
| + |
| + ExpectUnlockedState(); |
| } |
| } // namespace test |