Chromium Code Reviews| Index: ash/wm/lock_state_controller_unittest.cc |
| diff --git a/ash/wm/lock_state_controller_unittest.cc b/ash/wm/lock_state_controller_unittest.cc |
| index 80db34923ae149c837685486d42d91d2691f77b8..f5bc676e756c1cc571a1604fd8b1b8386895e739 100644 |
| --- a/ash/wm/lock_state_controller_unittest.cc |
| +++ b/ash/wm/lock_state_controller_unittest.cc |
| @@ -10,7 +10,9 @@ |
| #include "ash/shell_window_ids.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ash/test/test_lock_state_controller_delegate.h" |
| +#include "ash/test/test_screenshot_delegate.h" |
| #include "ash/test/test_shell_delegate.h" |
| +#include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| #include "ash/wm/power_button_controller.h" |
| #include "ash/wm/session_state_animator.h" |
| #include "base/command_line.h" |
| @@ -67,7 +69,7 @@ void HideBackground() { |
| GetContainer(kShellWindowId_DesktopBackgroundContainer)->Hide(); |
| } |
| -} // namespace |
| +} // namespace |
| class LockStateControllerTest : public AshTestBase { |
| public: |
| @@ -85,8 +87,8 @@ class LockStateControllerTest : public AshTestBase { |
| // Temporary disable animations so that observer is always called, and |
| // no leaks happen during tests. |
|
bruthig
2014/08/29 14:44:33
In order for the new QuickLock tests below to work
Daniel Erat
2014/08/29 14:58:26
i am frustrated by how long all of the tests in th
bruthig
2014/08/29 15:41:47
I actually spent quite a bit of time looking in to
|
| - animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| - ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
| + // animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| + // ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
| // TODO(antrim): once there is a way to mock time and run animations, make |
| // sure that animations are finished even in simple tests. |
| @@ -123,13 +125,13 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void Advance(SessionStateAnimator::AnimationSpeed speed) { |
| - // TODO (antrim) : restore |
| + // TODO(antrim) : restore |
| // animator_helper_->Advance(SessionStateAnimator::GetDuration(speed)); |
| } |
| void AdvancePartially(SessionStateAnimator::AnimationSpeed speed, |
| float factor) { |
| -// TODO (antrim) : restore |
| +// TODO(antrim) : restore |
| // base::TimeDelta duration = SessionStateAnimator::GetDuration(speed); |
| // base::TimeDelta partial_duration = |
| // base::TimeDelta::FromInternalValue(duration.ToInternalValue() * factor); |
| @@ -137,7 +139,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectPreLockAnimationStarted() { |
| - //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| @@ -165,7 +167,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectPreLockAnimationFinished() { |
| - //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| @@ -181,7 +183,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectPostLockAnimationStarted() { |
| - //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| @@ -189,7 +191,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectPastLockAnimationFinished() { |
| - //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| @@ -197,7 +199,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectUnlockBeforeUIDestroyedAnimationStarted() { |
| - //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| @@ -205,7 +207,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectUnlockBeforeUIDestroyedAnimationFinished() { |
| - //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| @@ -213,7 +215,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectUnlockAfterUIDestroyedAnimationStarted() { |
| - //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| @@ -225,7 +227,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectUnlockAfterUIDestroyedAnimationFinished() { |
| - //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| @@ -237,28 +239,28 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectShutdownAnimationStarted() { |
| - //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->RootWindowIsAnimated( |
| SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| } |
| void ExpectShutdownAnimationFinished() { |
| - //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->RootWindowIsAnimated( |
| SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| } |
| void ExpectShutdownAnimationCancel() { |
| - //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->RootWindowIsAnimated( |
| SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); |
| } |
| void ExpectBackgroundIsShowing() { |
| - //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::DESKTOP_BACKGROUND, |
| @@ -266,7 +268,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectBackgroundIsHiding() { |
| - //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE( |
| animator_api_->ContainersAreAnimated( |
| SessionStateAnimator::DESKTOP_BACKGROUND, |
| @@ -274,7 +276,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectUnlockedState() { |
| - //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| EXPECT_FALSE(session_state_delegate_->IsScreenLocked()); |
| aura::Window::Windows containers; |
| @@ -295,7 +297,7 @@ class LockStateControllerTest : public AshTestBase { |
| } |
| void ExpectLockedState() { |
| - //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| EXPECT_TRUE(session_state_delegate_->IsScreenLocked()); |
| aura::Window::Windows containers; |
| @@ -317,12 +319,12 @@ class LockStateControllerTest : public AshTestBase { |
| void PressPowerButton() { |
| controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| - //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| + // TODO(antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| } |
| void ReleasePowerButton() { |
| controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| - //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| + // TODO(antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| } |
| void PressLockButton() { |
| @@ -333,22 +335,35 @@ class LockStateControllerTest : public AshTestBase { |
| controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| } |
| + void PressVolumeDown() { |
| + GetEventGenerator().PressKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
| + } |
| + |
| + void ReleaseVolumeDown() { |
| + GetEventGenerator().ReleaseKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
| + } |
| + |
| void SystemLocks() { |
| lock_state_controller_->OnLockStateChanged(true); |
| session_state_delegate_->LockScreen(); |
| - //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| + // TODO(antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| } |
| void SuccessfulAuthentication(bool* call_flag) { |
| base::Closure closure = base::Bind(&CheckCalledCallback, call_flag); |
| lock_state_controller_->OnLockScreenHide(closure); |
| - //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| + // TODO(antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| } |
| void SystemUnlocks() { |
| lock_state_controller_->OnLockStateChanged(false); |
| session_state_delegate_->UnlockScreen(); |
| - //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| + // TODO(antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| + } |
| + |
| + void EnableMaximizeMode(bool enable) { |
| + Shell::GetInstance()->maximize_mode_controller()-> |
| + EnableMaximizeModeWindowManager(enable); |
| } |
| void Initialize(bool legacy_button, user::LoginStatus status) { |
| @@ -417,7 +432,7 @@ TEST_F(LockStateControllerTest, DISABLED_LegacyLockAndShutDown) { |
| // Notify that we locked successfully. |
| lock_state_controller_->OnStartingLock(); |
| // We had that animation already. |
| - //TODO (antrim) : restore |
| + // TODO(antrim) : restore |
| // EXPECT_FALSE(animator_helper_->IsAnimating()); |
| SystemLocks(); |
| @@ -532,7 +547,7 @@ TEST_F(LockStateControllerTest, DISABLED_LockAndUnlock) { |
| // Notify that we locked successfully. |
| lock_state_controller_->OnStartingLock(); |
| // We had that animation already. |
| - //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| + // TODO(antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| SystemLocks(); |
| @@ -1089,5 +1104,72 @@ TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockUnlock) { |
| ExpectUnlockedState(); |
| } |
| +// Tests that a screenshot can be taken by holding volume down and |
| +// pressing power. |
| +TEST_F(LockStateControllerTest, Screenshot) { |
| + Shell::GetInstance()->lock_state_controller()->SetDelegate( |
| + new test::TestLockStateControllerDelegate); |
| + test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); |
| + delegate->set_can_take_screenshot(true); |
| + |
| + // Pressing power alone does not take a screenshot. |
| + PressPowerButton(); |
| + ReleasePowerButton(); |
| + EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
| + |
| + // Press & release volume then pressing power does not take a screenshot. |
| + ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| + PressVolumeDown(); |
| + ReleaseVolumeDown(); |
| + PressPowerButton(); |
| + ReleasePowerButton(); |
| + EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
| + |
| + // Pressing power and then volume does not take a screenshot. |
| + ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| + PressPowerButton(); |
| + ReleasePowerButton(); |
| + PressVolumeDown(); |
| + ReleaseVolumeDown(); |
| + EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
| + |
| + // Holding volume down and pressing power takes a screenshot. |
| + ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| + PressVolumeDown(); |
| + PressPowerButton(); |
| + ReleasePowerButton(); |
| + ReleaseVolumeDown(); |
| + EXPECT_EQ(1, delegate->handle_take_screenshot_count()); |
| +} |
| + |
| +// Tests that a lock action is cancellable when quick lock is turned on and |
| +// maximize mode is not active. |
| +TEST_F(LockStateControllerTest, QuickLockWhileNotInMaximizeMode) { |
| + Initialize(false, user::LOGGED_IN_USER); |
| + controller_->set_enable_quick_lock_for_test(true); |
| + |
| + PressPowerButton(); |
| + |
| + EXPECT_TRUE(test_api_->is_animating_lock()); |
| + EXPECT_TRUE(lock_state_controller_->CanCancelLockAnimation()); |
| + |
| + ReleasePowerButton(); |
| +} |
| + |
| +// Tests that a lock action is not cancellable when quick lock is turned on and |
| +// maximize mode is active. |
| +TEST_F(LockStateControllerTest, QuickLockWhileInMaximizeMode) { |
| + Initialize(false, user::LOGGED_IN_USER); |
| + controller_->set_enable_quick_lock_for_test(true); |
| + EnableMaximizeMode(true); |
| + |
| + PressPowerButton(); |
| + |
| + EXPECT_TRUE(test_api_->is_animating_lock()); |
| + EXPECT_FALSE(lock_state_controller_->CanCancelLockAnimation()); |
| + |
| + ReleasePowerButton(); |
| +} |
| + |
| } // namespace test |
| } // namespace ash |