[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 5 | #include "ash/wm/lock_state_controller.h" |
| 6 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 7 | #include <memory> |
dcheng | cbf0d9d | 2015-12-27 22:49:23 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
jamescook | 2b624c5a | 2016-06-08 01:34:02 | [diff] [blame] | 10 | #include "ash/common/session/session_state_delegate.h" |
jamescook | d9f152f | 2016-11-15 00:53:08 | [diff] [blame] | 11 | #include "ash/common/shutdown_controller.h" |
sky | 1593c7bf | 2016-10-07 21:07:53 | [diff] [blame] | 12 | #include "ash/common/test/test_session_state_delegate.h" |
sky | e2bde217 | 2016-07-01 18:27:02 | [diff] [blame] | 13 | #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 14 | #include "ash/common/wm_shell.h" |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 15 | #include "ash/shell.h" |
| 16 | #include "ash/test/ash_test_base.h" |
erg | 8f7f2a6 | 2016-11-03 00:20:20 | [diff] [blame] | 17 | #include "ash/test/lock_state_controller_test_api.h" |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 18 | #include "ash/test/test_screenshot_delegate.h" |
| 19 | #include "ash/test/test_session_state_animator.h" |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 20 | #include "ash/test/test_shell_delegate.h" |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 21 | #include "ash/wm/power_button_controller.h" |
| 22 | #include "ash/wm/session_state_animator.h" |
fdoray | ba12142 | 2016-12-23 19:51:48 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 24 | #include "base/memory/scoped_vector.h" |
[email protected] | 1e84c63 | 2013-06-27 23:12:21 | [diff] [blame] | 25 | #include "base/time/time.h" |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 26 | #include "chromeos/dbus/dbus_thread_manager.h" |
| 27 | #include "chromeos/dbus/fake_session_manager_client.h" |
kylechar | c354dd2 | 2016-10-24 21:03:56 | [diff] [blame] | 28 | #include "ui/display/fake_display_snapshot.h" |
kylechar | 731f85f9 | 2016-12-01 20:50:46 | [diff] [blame] | 29 | #include "ui/display/manager/chromeos/display_configurator.h" |
[email protected] | 44ab9f5 | 2014-04-15 16:26:53 | [diff] [blame] | 30 | #include "ui/display/types/display_constants.h" |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 31 | #include "ui/events/test/event_generator.h" |
| 32 | #include "ui/gfx/geometry/size.h" |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 33 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 34 | namespace ash { |
| 35 | namespace test { |
| 36 | namespace { |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 37 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 38 | bool cursor_visible() { |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 39 | return Shell::GetInstance()->cursor_manager()->IsCursorVisible(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void CheckCalledCallback(bool* flag) { |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 43 | if (flag) |
| 44 | (*flag) = true; |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 45 | } |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 46 | |
jamescook | d9f152f | 2016-11-15 00:53:08 | [diff] [blame] | 47 | // ShutdownController that tracks how many shutdown requests have been made. |
| 48 | class TestShutdownController : public ShutdownController { |
| 49 | public: |
| 50 | TestShutdownController() {} |
| 51 | ~TestShutdownController() override {} |
| 52 | |
| 53 | int num_shutdown_requests() const { return num_shutdown_requests_; } |
| 54 | |
| 55 | private: |
| 56 | // ShutdownController: |
| 57 | void ShutDownOrReboot() override { num_shutdown_requests_++; } |
| 58 | |
| 59 | int num_shutdown_requests_ = 0; |
| 60 | |
| 61 | DISALLOW_COPY_AND_ASSIGN(TestShutdownController); |
| 62 | }; |
| 63 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 64 | } // namespace |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 65 | |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 66 | class LockStateControllerTest : public AshTestBase { |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 67 | public: |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 68 | LockStateControllerTest() |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 69 | : power_button_controller_(nullptr), |
| 70 | lock_state_controller_(nullptr), |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 71 | session_manager_client_(nullptr), |
| 72 | test_animator_(nullptr) {} |
dcheng | 28401c2 | 2014-10-28 01:26:19 | [diff] [blame] | 73 | ~LockStateControllerTest() override {} |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 74 | |
dcheng | 28401c2 | 2014-10-28 01:26:19 | [diff] [blame] | 75 | void SetUp() override { |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 76 | session_manager_client_ = new chromeos::FakeSessionManagerClient; |
| 77 | chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 78 | base::WrapUnique(session_manager_client_)); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 79 | AshTestBase::SetUp(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 80 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 81 | test_animator_ = new TestSessionStateAnimator; |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 82 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 83 | lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 84 | lock_state_controller_->set_animator_for_test(test_animator_); |
[email protected] | 76e52aad | 2012-12-20 18:34:13 | [diff] [blame] | 85 | |
erg | 8f7f2a6 | 2016-11-03 00:20:20 | [diff] [blame] | 86 | test_api_.reset(new LockStateControllerTestApi(lock_state_controller_)); |
jamescook | d9f152f | 2016-11-15 00:53:08 | [diff] [blame] | 87 | test_api_->set_shutdown_controller(&test_shutdown_controller_); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 88 | |
| 89 | power_button_controller_ = Shell::GetInstance()->power_button_controller(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 90 | |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 91 | shell_delegate_ = |
msw | 0414d412 | 2016-07-06 22:58:48 | [diff] [blame] | 92 | static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 93 | } |
| 94 | |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 95 | void TearDown() override { |
| 96 | AshTestBase::TearDown(); |
| 97 | chromeos::DBusThreadManager::Shutdown(); |
| 98 | } |
| 99 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 100 | protected: |
| 101 | void GenerateMouseMoveEvent() { |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 102 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 103 | generator.MoveMouseTo(10, 10); |
| 104 | } |
| 105 | |
| 106 | int NumShutdownRequests() { |
jamescook | d9f152f | 2016-11-15 00:53:08 | [diff] [blame] | 107 | return test_shutdown_controller_.num_shutdown_requests() + |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 108 | shell_delegate_->num_exit_requests(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 111 | void Advance(SessionStateAnimator::AnimationSpeed speed) { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 112 | test_animator_->Advance(test_animator_->GetDuration(speed)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void AdvancePartially(SessionStateAnimator::AnimationSpeed speed, |
| 116 | float factor) { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 117 | base::TimeDelta duration = test_animator_->GetDuration(speed); |
| 118 | base::TimeDelta partial_duration = |
| 119 | base::TimeDelta::FromInternalValue(duration.ToInternalValue() * factor); |
| 120 | test_animator_->Advance(partial_duration); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void ExpectPreLockAnimationStarted() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 124 | SCOPED_TRACE("Failure in ExpectPreLockAnimationStarted"); |
| 125 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 126 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 127 | SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 128 | SessionStateAnimator::ANIMATION_LIFT)); |
| 129 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 130 | SessionStateAnimator::LAUNCHER, |
| 131 | SessionStateAnimator::ANIMATION_FADE_OUT)); |
| 132 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 133 | SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 134 | SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 135 | EXPECT_TRUE(test_api_->is_animating_lock()); |
| 136 | } |
| 137 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 138 | void ExpectPreLockAnimationRunning() { |
| 139 | SCOPED_TRACE("Failure in ExpectPreLockAnimationRunning"); |
| 140 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 141 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 142 | SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 143 | SessionStateAnimator::ANIMATION_LIFT)); |
| 144 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 145 | SessionStateAnimator::LAUNCHER, |
| 146 | SessionStateAnimator::ANIMATION_FADE_OUT)); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 147 | EXPECT_TRUE(test_api_->is_animating_lock()); |
| 148 | } |
| 149 | |
| 150 | void ExpectPreLockAnimationCancel() { |
| 151 | SCOPED_TRACE("Failure in ExpectPreLockAnimationCancel"); |
| 152 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 153 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 154 | SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 155 | SessionStateAnimator::ANIMATION_UNDO_LIFT)); |
| 156 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 157 | SessionStateAnimator::LAUNCHER, |
| 158 | SessionStateAnimator::ANIMATION_FADE_IN)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void ExpectPreLockAnimationFinished() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 162 | SCOPED_TRACE("Failure in ExpectPreLockAnimationFinished"); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 163 | EXPECT_FALSE(test_animator_->AreContainersAnimated( |
| 164 | SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 165 | SessionStateAnimator::ANIMATION_LIFT)); |
| 166 | EXPECT_FALSE(test_animator_->AreContainersAnimated( |
| 167 | SessionStateAnimator::LAUNCHER, |
| 168 | SessionStateAnimator::ANIMATION_FADE_OUT)); |
| 169 | EXPECT_FALSE(test_animator_->AreContainersAnimated( |
| 170 | SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 171 | SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void ExpectPostLockAnimationStarted() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 175 | SCOPED_TRACE("Failure in ExpectPostLockAnimationStarted"); |
| 176 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 177 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 178 | SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 179 | SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 180 | } |
| 181 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 182 | void ExpectPostLockAnimationFinished() { |
| 183 | SCOPED_TRACE("Failure in ExpectPostLockAnimationFinished"); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 184 | EXPECT_FALSE(test_animator_->AreContainersAnimated( |
| 185 | SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 186 | SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | void ExpectUnlockBeforeUIDestroyedAnimationStarted() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 190 | SCOPED_TRACE("Failure in ExpectUnlockBeforeUIDestroyedAnimationStarted"); |
| 191 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 192 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 193 | SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 194 | SessionStateAnimator::ANIMATION_LIFT)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | void ExpectUnlockBeforeUIDestroyedAnimationFinished() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 198 | SCOPED_TRACE("Failure in ExpectUnlockBeforeUIDestroyedAnimationFinished"); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 199 | EXPECT_FALSE(test_animator_->AreContainersAnimated( |
| 200 | SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 201 | SessionStateAnimator::ANIMATION_LIFT)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void ExpectUnlockAfterUIDestroyedAnimationStarted() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 205 | SCOPED_TRACE("Failure in ExpectUnlockAfterUIDestroyedAnimationStarted"); |
| 206 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 207 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 208 | SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 209 | SessionStateAnimator::ANIMATION_DROP)); |
| 210 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 211 | SessionStateAnimator::LAUNCHER, |
| 212 | SessionStateAnimator::ANIMATION_FADE_IN)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void ExpectUnlockAfterUIDestroyedAnimationFinished() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 216 | SCOPED_TRACE("Failure in ExpectUnlockAfterUIDestroyedAnimationFinished"); |
| 217 | EXPECT_EQ(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 218 | EXPECT_FALSE(test_animator_->AreContainersAnimated( |
| 219 | SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 220 | SessionStateAnimator::ANIMATION_DROP)); |
| 221 | EXPECT_FALSE(test_animator_->AreContainersAnimated( |
| 222 | SessionStateAnimator::LAUNCHER, |
| 223 | SessionStateAnimator::ANIMATION_FADE_IN)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void ExpectShutdownAnimationStarted() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 227 | SCOPED_TRACE("Failure in ExpectShutdownAnimationStarted"); |
| 228 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 229 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 230 | SessionStateAnimator::ROOT_CONTAINER, |
| 231 | SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 232 | } |
| 233 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 234 | void ExpectShutdownAnimationFinished() { |
| 235 | SCOPED_TRACE("Failure in ExpectShutdownAnimationFinished"); |
| 236 | EXPECT_EQ(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 237 | EXPECT_FALSE(test_animator_->AreContainersAnimated( |
| 238 | SessionStateAnimator::ROOT_CONTAINER, |
| 239 | SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void ExpectShutdownAnimationCancel() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 243 | SCOPED_TRACE("Failure in ExpectShutdownAnimationCancel"); |
| 244 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 245 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 246 | SessionStateAnimator::ROOT_CONTAINER, |
| 247 | SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 248 | } |
| 249 | |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 250 | void ExpectWallpaperIsShowing() { |
| 251 | SCOPED_TRACE("Failure in ExpectWallpaperIsShowing"); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 252 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 253 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 254 | SessionStateAnimator::WALLPAPER, |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 255 | SessionStateAnimator::ANIMATION_FADE_IN)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 256 | } |
| 257 | |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 258 | void ExpectWallpaperIsHiding() { |
| 259 | SCOPED_TRACE("Failure in ExpectWallpaperIsHiding"); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 260 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 261 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 262 | SessionStateAnimator::WALLPAPER, |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 263 | SessionStateAnimator::ANIMATION_FADE_OUT)); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 264 | } |
| 265 | |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 266 | void ExpectRestoringWallpaperVisibility() { |
| 267 | SCOPED_TRACE("Failure in ExpectRestoringWallpaperVisibility"); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 268 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 269 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 270 | SessionStateAnimator::WALLPAPER, |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 271 | SessionStateAnimator::ANIMATION_FADE_IN)); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 272 | } |
| 273 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 274 | void ExpectUnlockedState() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 275 | SCOPED_TRACE("Failure in ExpectUnlockedState"); |
| 276 | EXPECT_EQ(0u, test_animator_->GetAnimationCount()); |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 277 | EXPECT_FALSE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void ExpectLockedState() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 281 | SCOPED_TRACE("Failure in ExpectLockedState"); |
| 282 | EXPECT_EQ(0u, test_animator_->GetAnimationCount()); |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 283 | EXPECT_TRUE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked()); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 284 | } |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 285 | |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 286 | void HideWallpaper() { test_animator_->HideWallpaper(); } |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 287 | |
| 288 | void PressPowerButton() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 289 | power_button_controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void ReleasePowerButton() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 293 | power_button_controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void PressLockButton() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 297 | power_button_controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void ReleaseLockButton() { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 301 | power_button_controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 302 | } |
| 303 | |
| 304 | void PressVolumeDown() { |
| 305 | GetEventGenerator().PressKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
| 306 | } |
| 307 | |
| 308 | void ReleaseVolumeDown() { |
| 309 | GetEventGenerator().ReleaseKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void SystemLocks() { |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 313 | lock_state_controller_->OnLockStateChanged(true); |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 314 | WmShell::Get()->GetSessionStateDelegate()->LockScreen(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void SuccessfulAuthentication(bool* call_flag) { |
| 318 | base::Closure closure = base::Bind(&CheckCalledCallback, call_flag); |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 319 | lock_state_controller_->OnLockScreenHide(closure); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | void SystemUnlocks() { |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 323 | lock_state_controller_->OnLockStateChanged(false); |
msw | bc0a8b48 | 2016-06-30 02:21:14 | [diff] [blame] | 324 | WmShell::Get()->GetSessionStateDelegate()->UnlockScreen(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | void EnableMaximizeMode(bool enable) { |
sky | c68696c | 2016-07-01 21:06:02 | [diff] [blame] | 328 | WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 329 | enable); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 330 | } |
| 331 | |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 332 | void Initialize(bool legacy_button, LoginStatus status) { |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 333 | power_button_controller_->set_has_legacy_power_button_for_test( |
| 334 | legacy_button); |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 335 | lock_state_controller_->OnLoginStateChanged(status); |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 336 | SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); |
| 337 | if (status == LoginStatus::GUEST) |
sky | 8335eed | 2016-10-06 23:25:09 | [diff] [blame] | 338 | TestSessionStateDelegate::SetCanLockScreen(false); |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 339 | lock_state_controller_->OnLockStateChanged(false); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 340 | } |
| 341 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 342 | PowerButtonController* power_button_controller_; // not owned |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 343 | LockStateController* lock_state_controller_; // not owned |
jamescook | d9f152f | 2016-11-15 00:53:08 | [diff] [blame] | 344 | TestShutdownController test_shutdown_controller_; |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 345 | // Ownership is passed on to chromeos::DBusThreadManager. |
| 346 | chromeos::FakeSessionManagerClient* session_manager_client_; |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 347 | TestSessionStateAnimator* test_animator_; // not owned |
erg | 8f7f2a6 | 2016-11-03 00:20:20 | [diff] [blame] | 348 | std::unique_ptr<LockStateControllerTestApi> test_api_; |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 349 | TestShellDelegate* shell_delegate_; // not owned |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 350 | |
| 351 | private: |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 352 | DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't |
| 356 | // correctly report power button releases. We should lock immediately the first |
| 357 | // time the button is pressed and shut down when it's pressed from the locked |
| 358 | // state. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 359 | TEST_F(LockStateControllerTest, LegacyLockAndShutDown) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 360 | Initialize(true, LoginStatus::USER); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 361 | |
| 362 | ExpectUnlockedState(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 363 | |
| 364 | // We should request that the screen be locked immediately after seeing the |
| 365 | // power button get pressed. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 366 | PressPowerButton(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 367 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 368 | EXPECT_FALSE(test_api_->is_lock_cancellable()); |
| 369 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 370 | ExpectPreLockAnimationStarted(); |
| 371 | test_animator_->CompleteAllAnimations(true); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 372 | ExpectPreLockAnimationFinished(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 373 | |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 374 | EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 375 | |
| 376 | // Notify that we locked successfully. |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 377 | lock_state_controller_->OnStartingLock(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 378 | EXPECT_EQ(0u, test_animator_->GetAnimationCount()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 379 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 380 | SystemLocks(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 381 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 382 | ExpectPostLockAnimationStarted(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 383 | test_animator_->CompleteAllAnimations(true); |
| 384 | ExpectPostLockAnimationFinished(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 385 | |
| 386 | // We shouldn't progress towards the shutdown state, however. |
| 387 | EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 388 | EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 389 | |
| 390 | ReleasePowerButton(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 391 | |
| 392 | // Hold the button again and check that we start shutting down. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 393 | PressPowerButton(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 394 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 395 | ExpectShutdownAnimationStarted(); |
| 396 | |
| 397 | EXPECT_EQ(0, NumShutdownRequests()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 398 | // Make sure a mouse move event won't show the cursor. |
| 399 | GenerateMouseMoveEvent(); |
| 400 | EXPECT_FALSE(cursor_visible()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 401 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 402 | EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 403 | test_api_->trigger_real_shutdown_timeout(); |
| 404 | EXPECT_EQ(1, NumShutdownRequests()); |
| 405 | } |
| 406 | |
| 407 | // Test that we start shutting down immediately if the power button is pressed |
| 408 | // while we're not logged in on an unofficial system. |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 409 | TEST_F(LockStateControllerTest, LegacyNotLoggedIn) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 410 | Initialize(true, LoginStatus::NOT_LOGGED_IN); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 411 | |
| 412 | PressPowerButton(); |
| 413 | ExpectShutdownAnimationStarted(); |
| 414 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 415 | EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 416 | } |
| 417 | |
| 418 | // Test that we start shutting down immediately if the power button is pressed |
| 419 | // while we're logged in as a guest on an unofficial system. |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 420 | TEST_F(LockStateControllerTest, LegacyGuest) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 421 | Initialize(true, LoginStatus::GUEST); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 422 | |
| 423 | PressPowerButton(); |
| 424 | ExpectShutdownAnimationStarted(); |
| 425 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 426 | EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 427 | } |
| 428 | |
| 429 | // When we hold the power button while the user isn't logged in, we should shut |
| 430 | // down the machine directly. |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 431 | TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 432 | Initialize(false, LoginStatus::NOT_LOGGED_IN); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 433 | |
| 434 | // Press the power button and check that we start the shutdown timer. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 435 | PressPowerButton(); |
| 436 | EXPECT_FALSE(test_api_->is_animating_lock()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 437 | EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 438 | ExpectShutdownAnimationStarted(); |
| 439 | |
| 440 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 441 | |
| 442 | // Release the power button before the shutdown timer fires. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 443 | ReleasePowerButton(); |
| 444 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 445 | EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 446 | ExpectShutdownAnimationCancel(); |
| 447 | |
| 448 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_REVERT, 0.5f); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 449 | |
| 450 | // Press the button again and make the shutdown timeout fire this time. |
| 451 | // Check that we start the timer for actually requesting the shutdown. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 452 | PressPowerButton(); |
| 453 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 454 | EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 455 | |
| 456 | Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 457 | ExpectShutdownAnimationFinished(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 458 | test_api_->trigger_shutdown_timeout(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 459 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 460 | EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 461 | EXPECT_EQ(0, NumShutdownRequests()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 462 | |
| 463 | // When the timout fires, we should request a shutdown. |
| 464 | test_api_->trigger_real_shutdown_timeout(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 465 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 466 | EXPECT_EQ(1, NumShutdownRequests()); |
| 467 | } |
| 468 | |
| 469 | // Test that we lock the screen and deal with unlocking correctly. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 470 | TEST_F(LockStateControllerTest, LockAndUnlock) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 471 | Initialize(false, LoginStatus::USER); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 472 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 473 | ExpectUnlockedState(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 474 | |
| 475 | // Press the power button and check that the lock timer is started and that we |
| 476 | // start lifting the non-screen-locker containers. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 477 | PressPowerButton(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 478 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 479 | ExpectPreLockAnimationStarted(); |
| 480 | EXPECT_TRUE(test_api_->is_lock_cancellable()); |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 481 | EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 482 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 483 | test_animator_->CompleteAllAnimations(true); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 484 | ExpectPreLockAnimationFinished(); |
| 485 | |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 486 | EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 487 | |
| 488 | // Notify that we locked successfully. |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 489 | lock_state_controller_->OnStartingLock(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 490 | // We had that animation already. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 491 | EXPECT_EQ(0u, test_animator_->GetAnimationCount()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 492 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 493 | SystemLocks(); |
| 494 | |
| 495 | ExpectPostLockAnimationStarted(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 496 | test_animator_->CompleteAllAnimations(true); |
| 497 | ExpectPostLockAnimationFinished(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 498 | |
| 499 | // When we release the power button, the lock-to-shutdown timer should be |
| 500 | // stopped. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 501 | ExpectLockedState(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 502 | EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 503 | ReleasePowerButton(); |
| 504 | ExpectLockedState(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 505 | EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 506 | |
| 507 | // Notify that the screen has been unlocked. We should show the |
| 508 | // non-screen-locker windows. |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 509 | bool called = false; |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 510 | SuccessfulAuthentication(&called); |
| 511 | |
| 512 | ExpectUnlockBeforeUIDestroyedAnimationStarted(); |
| 513 | EXPECT_FALSE(called); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 514 | test_animator_->CompleteAllAnimations(true); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 515 | ExpectUnlockBeforeUIDestroyedAnimationFinished(); |
| 516 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 517 | EXPECT_TRUE(called); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 518 | |
| 519 | SystemUnlocks(); |
| 520 | |
| 521 | ExpectUnlockAfterUIDestroyedAnimationStarted(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 522 | test_animator_->CompleteAllAnimations(true); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 523 | ExpectUnlockAfterUIDestroyedAnimationFinished(); |
| 524 | |
| 525 | ExpectUnlockedState(); |
| 526 | } |
| 527 | |
| 528 | // Test that we deal with cancelling lock correctly. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 529 | TEST_F(LockStateControllerTest, LockAndCancel) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 530 | Initialize(false, LoginStatus::USER); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 531 | |
| 532 | ExpectUnlockedState(); |
| 533 | |
| 534 | // Press the power button and check that the lock timer is started and that we |
| 535 | // start lifting the non-screen-locker containers. |
| 536 | PressPowerButton(); |
| 537 | |
| 538 | ExpectPreLockAnimationStarted(); |
| 539 | EXPECT_TRUE(test_api_->is_lock_cancellable()); |
| 540 | |
| 541 | // forward only half way through |
| 542 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| 543 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 544 | // Release the button before the lock timer fires. |
| 545 | ReleasePowerButton(); |
| 546 | |
| 547 | ExpectPreLockAnimationCancel(); |
| 548 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 549 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 550 | ExpectUnlockedState(); |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 551 | EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | // Test that we deal with cancelling lock correctly. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 555 | TEST_F(LockStateControllerTest, LockAndCancelAndLockAgain) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 556 | Initialize(false, LoginStatus::USER); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 557 | |
| 558 | ExpectUnlockedState(); |
| 559 | |
| 560 | // Press the power button and check that the lock timer is started and that we |
| 561 | // start lifting the non-screen-locker containers. |
| 562 | PressPowerButton(); |
| 563 | |
| 564 | ExpectPreLockAnimationStarted(); |
| 565 | EXPECT_TRUE(test_api_->is_lock_cancellable()); |
| 566 | |
| 567 | // forward only half way through |
| 568 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| 569 | |
| 570 | // Release the button before the lock timer fires. |
| 571 | ReleasePowerButton(); |
| 572 | ExpectPreLockAnimationCancel(); |
| 573 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 574 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, |
| 575 | 0.5f); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 576 | |
| 577 | PressPowerButton(); |
| 578 | ExpectPreLockAnimationStarted(); |
| 579 | EXPECT_TRUE(test_api_->is_lock_cancellable()); |
| 580 | |
| 581 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f); |
| 582 | |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 583 | EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 584 | |
| 585 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f); |
| 586 | ExpectPreLockAnimationFinished(); |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 587 | EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | // Hold the power button down from the unlocked state to eventual shutdown. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 591 | TEST_F(LockStateControllerTest, LockToShutdown) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 592 | Initialize(false, LoginStatus::USER); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 593 | |
| 594 | // Hold the power button and lock the screen. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 595 | PressPowerButton(); |
| 596 | EXPECT_TRUE(test_api_->is_animating_lock()); |
| 597 | |
| 598 | Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| 599 | SystemLocks(); |
| 600 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 601 | |
| 602 | // When the lock-to-shutdown timeout fires, we should start the shutdown |
| 603 | // timer. |
| 604 | EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 605 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 606 | test_api_->trigger_lock_to_shutdown_timeout(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 607 | |
| 608 | ExpectShutdownAnimationStarted(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 609 | EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 610 | |
| 611 | // Fire the shutdown timeout and check that we request shutdown. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 612 | Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 613 | ExpectShutdownAnimationFinished(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 614 | test_api_->trigger_shutdown_timeout(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 615 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 616 | EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 617 | EXPECT_EQ(0, NumShutdownRequests()); |
| 618 | test_api_->trigger_real_shutdown_timeout(); |
| 619 | EXPECT_EQ(1, NumShutdownRequests()); |
| 620 | } |
| 621 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 622 | // Hold the power button down from the unlocked state to eventual shutdown, |
| 623 | // then release the button while system does locking. |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 624 | TEST_F(LockStateControllerTest, CancelLockToShutdown) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 625 | Initialize(false, LoginStatus::USER); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 626 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 627 | PressPowerButton(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 628 | |
| 629 | // Hold the power button and lock the screen. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 630 | EXPECT_TRUE(test_api_->is_animating_lock()); |
| 631 | |
| 632 | Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| 633 | SystemLocks(); |
| 634 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 635 | |
| 636 | // Power button is released while system attempts to lock. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 637 | ReleasePowerButton(); |
| 638 | |
| 639 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 640 | |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 641 | EXPECT_FALSE(lock_state_controller_->ShutdownRequested()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 642 | EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 643 | EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 644 | } |
| 645 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 646 | // Test that we handle the case where lock requests are ignored. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 647 | TEST_F(LockStateControllerTest, Lock) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 648 | Initialize(false, LoginStatus::USER); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 649 | |
| 650 | // Hold the power button and lock the screen. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 651 | PressPowerButton(); |
| 652 | ExpectPreLockAnimationStarted(); |
| 653 | |
| 654 | Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| 655 | |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 656 | EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 657 | EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 658 | // We shouldn't start the lock-to-shutdown timer until the screen has actually |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 659 | // been locked and this was animated. |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 660 | EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 661 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 662 | // Act as if the request timed out. |
| 663 | EXPECT_DEATH(test_api_->trigger_lock_fail_timeout(), ""); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 664 | } |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 665 | |
| 666 | // Test the basic operation of the lock button (not logged in). |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 667 | TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) { |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 668 | // The lock button shouldn't do anything if we aren't logged in. |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 669 | Initialize(false, LoginStatus::NOT_LOGGED_IN); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 670 | |
| 671 | PressLockButton(); |
| 672 | EXPECT_FALSE(test_api_->is_animating_lock()); |
| 673 | ReleaseLockButton(); |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 674 | EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // Test the basic operation of the lock button (guest). |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 678 | TEST_F(LockStateControllerTest, LockButtonBasicGuest) { |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 679 | // The lock button shouldn't do anything when we're logged in as a guest. |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 680 | Initialize(false, LoginStatus::GUEST); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 681 | |
| 682 | PressLockButton(); |
| 683 | EXPECT_FALSE(test_api_->is_animating_lock()); |
| 684 | ReleaseLockButton(); |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 685 | EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | // Test the basic operation of the lock button. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 689 | TEST_F(LockStateControllerTest, LockButtonBasic) { |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 690 | // If we're logged in as a regular user, we should start the lock timer and |
| 691 | // the pre-lock animation. |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 692 | Initialize(false, LoginStatus::USER); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 693 | |
| 694 | PressLockButton(); |
| 695 | ExpectPreLockAnimationStarted(); |
| 696 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 697 | |
| 698 | // If the button is released immediately, we shouldn't lock the screen. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 699 | ReleaseLockButton(); |
| 700 | ExpectPreLockAnimationCancel(); |
| 701 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 702 | |
| 703 | ExpectUnlockedState(); |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 704 | EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 705 | |
| 706 | // Press the button again and let the lock timeout fire. We should request |
| 707 | // that the screen be locked. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 708 | PressLockButton(); |
| 709 | ExpectPreLockAnimationStarted(); |
| 710 | Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 711 | EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 712 | |
| 713 | // Pressing the lock button while we have a pending lock request shouldn't do |
| 714 | // anything. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 715 | ReleaseLockButton(); |
| 716 | PressLockButton(); |
| 717 | ExpectPreLockAnimationFinished(); |
| 718 | ReleaseLockButton(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 719 | |
| 720 | // Pressing the button also shouldn't do anything after the screen is locked. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 721 | SystemLocks(); |
| 722 | ExpectPostLockAnimationStarted(); |
| 723 | |
| 724 | PressLockButton(); |
| 725 | ReleaseLockButton(); |
| 726 | ExpectPostLockAnimationStarted(); |
| 727 | |
| 728 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 729 | ExpectPostLockAnimationFinished(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 730 | |
| 731 | PressLockButton(); |
| 732 | ReleaseLockButton(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 733 | ExpectPostLockAnimationFinished(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | // Test that the power button takes priority over the lock button. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 737 | TEST_F(LockStateControllerTest, PowerButtonPreemptsLockButton) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 738 | Initialize(false, LoginStatus::USER); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 739 | |
| 740 | // While the lock button is down, hold the power button. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 741 | PressLockButton(); |
| 742 | ExpectPreLockAnimationStarted(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 743 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 744 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f); |
| 745 | ExpectPreLockAnimationRunning(); |
| 746 | |
| 747 | PressPowerButton(); |
| 748 | ExpectPreLockAnimationRunning(); |
| 749 | |
| 750 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f); |
| 751 | ExpectPreLockAnimationRunning(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 752 | |
| 753 | // The lock timer shouldn't be stopped when the lock button is released. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 754 | ReleaseLockButton(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 755 | ExpectPreLockAnimationRunning(); |
| 756 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 757 | ReleasePowerButton(); |
| 758 | ExpectPreLockAnimationCancel(); |
| 759 | |
| 760 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 761 | ExpectUnlockedState(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 762 | |
| 763 | // Now press the power button first and then the lock button. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 764 | PressPowerButton(); |
| 765 | ExpectPreLockAnimationStarted(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 766 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 767 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f); |
| 768 | |
| 769 | PressLockButton(); |
| 770 | ExpectPreLockAnimationRunning(); |
| 771 | |
| 772 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 773 | |
| 774 | // Releasing the power button should stop the lock timer. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 775 | ReleasePowerButton(); |
| 776 | ExpectPreLockAnimationCancel(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 777 | |
| 778 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f); |
| 779 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 780 | ReleaseLockButton(); |
| 781 | ExpectPreLockAnimationCancel(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | // When the screen is locked without going through the usual power-button |
| 785 | // slow-close path (e.g. via the wrench menu), test that we still show the |
| 786 | // fast-close animation. |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 787 | TEST_F(LockStateControllerTest, LockWithoutButton) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 788 | Initialize(false, LoginStatus::USER); |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 789 | lock_state_controller_->OnStartingLock(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 790 | |
| 791 | ExpectPreLockAnimationStarted(); |
| 792 | EXPECT_FALSE(test_api_->is_lock_cancellable()); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 793 | EXPECT_LT(0u, test_animator_->GetAnimationCount()); |
[email protected] | 19c6c4e | 2013-01-28 16:25:48 | [diff] [blame] | 794 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 795 | test_animator_->CompleteAllAnimations(true); |
sadrul | 522f2ec8 | 2016-07-19 22:38:44 | [diff] [blame] | 796 | EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | // When we hear that the process is exiting but we haven't had a chance to |
| 800 | // display an animation, we should just blank the screen. |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 801 | TEST_F(LockStateControllerTest, ShutdownWithoutButton) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 802 | Initialize(false, LoginStatus::USER); |
[email protected] | ab4f8c9 | 2013-05-30 19:07:47 | [diff] [blame] | 803 | lock_state_controller_->OnAppTerminating(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 804 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 805 | EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 806 | SessionStateAnimator::kAllNonRootContainersMask, |
| 807 | SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 808 | GenerateMouseMoveEvent(); |
| 809 | EXPECT_FALSE(cursor_visible()); |
| 810 | } |
| 811 | |
| 812 | // Test that we display the fast-close animation and shut down when we get an |
| 813 | // outside request to shut down (e.g. from the login or lock screen). |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 814 | TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 815 | Initialize(false, LoginStatus::NOT_LOGGED_IN); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 816 | |
cschuet | 7f630ba | 2015-01-22 13:17:05 | [diff] [blame] | 817 | lock_state_controller_->RequestShutdown(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 818 | |
| 819 | ExpectShutdownAnimationStarted(); |
| 820 | Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 821 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 822 | GenerateMouseMoveEvent(); |
| 823 | EXPECT_FALSE(cursor_visible()); |
| 824 | |
| 825 | EXPECT_EQ(0, NumShutdownRequests()); |
| 826 | EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 827 | test_api_->trigger_real_shutdown_timeout(); |
| 828 | EXPECT_EQ(1, NumShutdownRequests()); |
| 829 | } |
| 830 | |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 831 | TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 832 | Initialize(false, LoginStatus::USER); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 833 | |
| 834 | SystemLocks(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 835 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 836 | Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 837 | ExpectPostLockAnimationFinished(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 838 | |
cschuet | 7f630ba | 2015-01-22 13:17:05 | [diff] [blame] | 839 | lock_state_controller_->RequestShutdown(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 840 | |
| 841 | ExpectShutdownAnimationStarted(); |
| 842 | Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 843 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 844 | GenerateMouseMoveEvent(); |
| 845 | EXPECT_FALSE(cursor_visible()); |
| 846 | |
| 847 | EXPECT_EQ(0, NumShutdownRequests()); |
| 848 | EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 849 | test_api_->trigger_real_shutdown_timeout(); |
| 850 | EXPECT_EQ(1, NumShutdownRequests()); |
| 851 | } |
| 852 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 853 | TEST_F(LockStateControllerTest, RequestAndCancelShutdownFromLockScreen) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 854 | Initialize(false, LoginStatus::USER); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 855 | |
| 856 | SystemLocks(); |
| 857 | Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 858 | ExpectLockedState(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 859 | |
| 860 | // Press the power button and check that we start the shutdown timer. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 861 | PressPowerButton(); |
| 862 | EXPECT_FALSE(test_api_->is_animating_lock()); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 863 | EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 864 | |
| 865 | ExpectShutdownAnimationStarted(); |
| 866 | |
| 867 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f); |
| 868 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 869 | // Release the power button before the shutdown timer fires. |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 870 | ReleasePowerButton(); |
| 871 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 872 | EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 873 | |
| 874 | ExpectShutdownAnimationCancel(); |
| 875 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 876 | Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT_SHUTDOWN); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 877 | ExpectLockedState(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | // Test that we ignore power button presses when the screen is turned off. |
[email protected] | cafaeca | 2013-10-01 21:08:32 | [diff] [blame] | 881 | TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 882 | Initialize(false, LoginStatus::USER); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 883 | |
| 884 | // When the screen brightness is at 0%, we shouldn't do anything in response |
| 885 | // to power button presses. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 886 | power_button_controller_->OnScreenBrightnessChanged(0.0); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 887 | PressPowerButton(); |
| 888 | EXPECT_FALSE(test_api_->is_animating_lock()); |
| 889 | ReleasePowerButton(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 890 | |
| 891 | // After increasing the brightness to 10%, we should start the timer like |
| 892 | // usual. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 893 | power_button_controller_->OnScreenBrightnessChanged(10.0); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 894 | PressPowerButton(); |
| 895 | EXPECT_TRUE(test_api_->is_animating_lock()); |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 896 | ReleasePowerButton(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 897 | } |
| 898 | |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 899 | TEST_F(LockStateControllerTest, HonorPowerButtonInDockedMode) { |
| 900 | // Create two outputs, the first internal and the second external. |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 901 | display::DisplayConfigurator::DisplayStateList outputs; |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 902 | |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 903 | std::unique_ptr<display::DisplaySnapshot> internal_display = |
kylechar | c354dd2 | 2016-10-24 21:03:56 | [diff] [blame] | 904 | display::FakeDisplaySnapshot::Builder() |
| 905 | .SetId(123) |
| 906 | .SetNativeMode(gfx::Size(1, 1)) |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 907 | .SetType(display::DISPLAY_CONNECTION_TYPE_INTERNAL) |
kylechar | c354dd2 | 2016-10-24 21:03:56 | [diff] [blame] | 908 | .Build(); |
| 909 | outputs.push_back(internal_display.get()); |
| 910 | |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 911 | std::unique_ptr<display::DisplaySnapshot> external_display = |
kylechar | c354dd2 | 2016-10-24 21:03:56 | [diff] [blame] | 912 | display::FakeDisplaySnapshot::Builder() |
| 913 | .SetId(456) |
| 914 | .SetNativeMode(gfx::Size(1, 1)) |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 915 | .SetType(display::DISPLAY_CONNECTION_TYPE_HDMI) |
kylechar | c354dd2 | 2016-10-24 21:03:56 | [diff] [blame] | 916 | .Build(); |
| 917 | outputs.push_back(external_display.get()); |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 918 | |
| 919 | // When all of the displays are turned off (e.g. due to user inactivity), the |
| 920 | // power button should be ignored. |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 921 | power_button_controller_->OnScreenBrightnessChanged(0.0); |
kylechar | c354dd2 | 2016-10-24 21:03:56 | [diff] [blame] | 922 | internal_display->set_current_mode(nullptr); |
| 923 | external_display->set_current_mode(nullptr); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 924 | power_button_controller_->OnDisplayModeChanged(outputs); |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 925 | PressPowerButton(); |
| 926 | EXPECT_FALSE(test_api_->is_animating_lock()); |
| 927 | ReleasePowerButton(); |
| 928 | |
| 929 | // When the screen brightness is 0% but the external display is still turned |
| 930 | // on (indicating either docked mode or the user having manually decreased the |
| 931 | // brightness to 0%), the power button should still be handled. |
kylechar | c354dd2 | 2016-10-24 21:03:56 | [diff] [blame] | 932 | external_display->set_current_mode(external_display->modes().back().get()); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 933 | power_button_controller_->OnDisplayModeChanged(outputs); |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 934 | PressPowerButton(); |
| 935 | EXPECT_TRUE(test_api_->is_animating_lock()); |
| 936 | ReleasePowerButton(); |
| 937 | } |
[email protected] | 685442f3 | 2014-02-28 10:40:06 | [diff] [blame] | 938 | |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 939 | // Test that hidden wallpaper appears and revers correctly on lock/cancel. |
| 940 | TEST_F(LockStateControllerTest, TestHiddenWallpaperLockCancel) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 941 | Initialize(false, LoginStatus::USER); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 942 | HideWallpaper(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 943 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 944 | ExpectUnlockedState(); |
| 945 | PressPowerButton(); |
| 946 | |
| 947 | ExpectPreLockAnimationStarted(); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 948 | ExpectWallpaperIsShowing(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 949 | |
| 950 | // Forward only half way through. |
| 951 | AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| 952 | |
| 953 | // Release the button before the lock timer fires. |
| 954 | ReleasePowerButton(); |
| 955 | ExpectPreLockAnimationCancel(); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 956 | ExpectWallpaperIsHiding(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 957 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 958 | Advance(SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS); |
| 959 | |
| 960 | // When the CancelPrelockAnimation sequence finishes it queues up a |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 961 | // restore wallpaper visibility sequence when the wallpaper is hidden. |
| 962 | ExpectRestoringWallpaperVisibility(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 963 | |
| 964 | Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 965 | |
| 966 | ExpectUnlockedState(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 967 | } |
| 968 | |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 969 | // Test that hidden wallpaper appears and revers correctly on lock/unlock. |
| 970 | TEST_F(LockStateControllerTest, TestHiddenWallpaperLockUnlock) { |
sky | e79274a | 2016-06-08 05:39:02 | [diff] [blame] | 971 | Initialize(false, LoginStatus::USER); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 972 | HideWallpaper(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 973 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 974 | ExpectUnlockedState(); |
| 975 | |
| 976 | // Press the power button and check that the lock timer is started and that we |
| 977 | // start lifting the non-screen-locker containers. |
| 978 | PressPowerButton(); |
| 979 | |
| 980 | ExpectPreLockAnimationStarted(); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 981 | ExpectWallpaperIsShowing(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 982 | |
| 983 | Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| 984 | |
| 985 | ExpectPreLockAnimationFinished(); |
| 986 | |
| 987 | SystemLocks(); |
| 988 | |
| 989 | ReleasePowerButton(); |
| 990 | |
| 991 | ExpectPostLockAnimationStarted(); |
| 992 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 993 | ExpectPostLockAnimationFinished(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 994 | |
| 995 | ExpectLockedState(); |
| 996 | |
| 997 | SuccessfulAuthentication(NULL); |
| 998 | |
| 999 | ExpectUnlockBeforeUIDestroyedAnimationStarted(); |
| 1000 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 1001 | ExpectUnlockBeforeUIDestroyedAnimationFinished(); |
| 1002 | |
| 1003 | SystemUnlocks(); |
| 1004 | |
| 1005 | ExpectUnlockAfterUIDestroyedAnimationStarted(); |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 1006 | ExpectWallpaperIsHiding(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 1007 | |
| 1008 | Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 1009 | |
| 1010 | // When the StartUnlockAnimationAfterUIDestroyed sequence finishes it queues |
msw | 607227f8 | 2016-08-30 17:22:39 | [diff] [blame] | 1011 | // up a restore wallpaper visibility sequence when the wallpaper is hidden. |
| 1012 | ExpectRestoringWallpaperVisibility(); |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 1013 | |
| 1014 | Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); |
| 1015 | |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 1016 | ExpectUnlockAfterUIDestroyedAnimationFinished(); |
[email protected] | 72e8d4e | 2012-12-17 15:02:33 | [diff] [blame] | 1017 | |
| 1018 | ExpectUnlockedState(); |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 1019 | } |
| 1020 | |
bruthig | ca2e149 | 2014-09-12 23:48:06 | [diff] [blame] | 1021 | TEST_F(LockStateControllerTest, Screenshot) { |
| 1022 | test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); |
| 1023 | delegate->set_can_take_screenshot(true); |
| 1024 | |
| 1025 | EnableMaximizeMode(false); |
| 1026 | |
| 1027 | // Screenshot handling should not be active when not in maximize mode. |
| 1028 | ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1029 | PressVolumeDown(); |
| 1030 | PressPowerButton(); |
| 1031 | ReleasePowerButton(); |
| 1032 | ReleaseVolumeDown(); |
| 1033 | EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1034 | |
| 1035 | EnableMaximizeMode(true); |
| 1036 | |
| 1037 | // Pressing power alone does not take a screenshot. |
| 1038 | PressPowerButton(); |
| 1039 | ReleasePowerButton(); |
| 1040 | EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1041 | |
| 1042 | // Press & release volume then pressing power does not take a screenshot. |
| 1043 | ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1044 | PressVolumeDown(); |
| 1045 | ReleaseVolumeDown(); |
| 1046 | PressPowerButton(); |
| 1047 | ReleasePowerButton(); |
| 1048 | EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1049 | |
| 1050 | // Pressing power and then volume does not take a screenshot. |
| 1051 | ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1052 | PressPowerButton(); |
| 1053 | ReleasePowerButton(); |
| 1054 | PressVolumeDown(); |
| 1055 | ReleaseVolumeDown(); |
| 1056 | EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1057 | |
| 1058 | // Holding volume down and pressing power takes a screenshot. |
| 1059 | ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1060 | PressVolumeDown(); |
| 1061 | PressPowerButton(); |
| 1062 | ReleasePowerButton(); |
| 1063 | ReleaseVolumeDown(); |
| 1064 | EXPECT_EQ(1, delegate->handle_take_screenshot_count()); |
| 1065 | } |
| 1066 | |
[email protected] | 88223751 | 2012-11-26 22:29:07 | [diff] [blame] | 1067 | } // namespace test |
| 1068 | } // namespace ash |