blob: 3f1501f6fe357b1769b170fb6958f270049408d9 [file] [log] [blame]
[email protected]ab4f8c92013-05-30 19:07:471// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]882237512012-11-26 22:29:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cafaeca2013-10-01 21:08:325#include "ash/wm/lock_state_controller.h"
6
dchenga94547472016-04-08 08:41:117#include <memory>
dchengcbf0d9d2015-12-27 22:49:238#include <utility>
9
jamescook2b624c5a2016-06-08 01:34:0210#include "ash/common/session/session_state_delegate.h"
sky1593c7bf2016-10-07 21:07:5311#include "ash/common/test/test_session_state_delegate.h"
skye2bde2172016-07-01 18:27:0212#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
mswbc0a8b482016-06-30 02:21:1413#include "ash/common/wm_shell.h"
[email protected]882237512012-11-26 22:29:0714#include "ash/shell.h"
15#include "ash/test/ash_test_base.h"
[email protected]587926a2014-05-11 01:41:3616#include "ash/test/test_lock_state_controller_delegate.h"
bruthigca2e1492014-09-12 23:48:0617#include "ash/test/test_screenshot_delegate.h"
18#include "ash/test/test_session_state_animator.h"
[email protected]882237512012-11-26 22:29:0719#include "ash/test/test_shell_delegate.h"
[email protected]882237512012-11-26 22:29:0720#include "ash/wm/power_button_controller.h"
21#include "ash/wm/session_state_animator.h"
bruthigca2e1492014-09-12 23:48:0622#include "base/memory/scoped_vector.h"
[email protected]1e84c632013-06-27 23:12:2123#include "base/time/time.h"
sadrul522f2ec82016-07-19 22:38:4424#include "chromeos/dbus/dbus_thread_manager.h"
25#include "chromeos/dbus/fake_session_manager_client.h"
[email protected]1e31cbd2014-04-07 20:06:1126#include "ui/display/chromeos/display_configurator.h"
kylecharc354dd22016-10-24 21:03:5627#include "ui/display/fake_display_snapshot.h"
[email protected]44ab9f52014-04-15 16:26:5328#include "ui/display/types/display_constants.h"
sadrul522f2ec82016-07-19 22:38:4429#include "ui/events/test/event_generator.h"
30#include "ui/gfx/geometry/size.h"
[email protected]685442f32014-02-28 10:40:0631
[email protected]882237512012-11-26 22:29:0732namespace ash {
33namespace test {
34namespace {
[email protected]72e8d4e2012-12-17 15:02:3335
[email protected]882237512012-11-26 22:29:0736bool cursor_visible() {
mswbc0a8b482016-06-30 02:21:1437 return Shell::GetInstance()->cursor_manager()->IsCursorVisible();
[email protected]882237512012-11-26 22:29:0738}
39
40void CheckCalledCallback(bool* flag) {
[email protected]72e8d4e2012-12-17 15:02:3341 if (flag)
42 (*flag) = true;
[email protected]882237512012-11-26 22:29:0743}
[email protected]72e8d4e2012-12-17 15:02:3344
bruthigca2e1492014-09-12 23:48:0645} // namespace
[email protected]72e8d4e2012-12-17 15:02:3346
[email protected]cafaeca2013-10-01 21:08:3247class LockStateControllerTest : public AshTestBase {
[email protected]882237512012-11-26 22:29:0748 public:
jamescookb8dcef522016-06-25 14:42:5549 LockStateControllerTest()
sadrul522f2ec82016-07-19 22:38:4450 : power_button_controller_(nullptr),
51 lock_state_controller_(nullptr),
52 lock_state_controller_delegate_(nullptr),
53 session_manager_client_(nullptr),
54 test_animator_(nullptr) {}
dcheng28401c22014-10-28 01:26:1955 ~LockStateControllerTest() override {}
[email protected]882237512012-11-26 22:29:0756
dcheng28401c22014-10-28 01:26:1957 void SetUp() override {
sadrul522f2ec82016-07-19 22:38:4458 session_manager_client_ = new chromeos::FakeSessionManagerClient;
59 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
60 base::WrapUnique(session_manager_client_));
[email protected]882237512012-11-26 22:29:0761 AshTestBase::SetUp();
[email protected]72e8d4e2012-12-17 15:02:3362
dchenga94547472016-04-08 08:41:1163 std::unique_ptr<LockStateControllerDelegate> lock_state_controller_delegate(
bruthigca2e1492014-09-12 23:48:0664 lock_state_controller_delegate_ = new TestLockStateControllerDelegate);
65 test_animator_ = new TestSessionStateAnimator;
[email protected]72e8d4e2012-12-17 15:02:3366
bruthigca2e1492014-09-12 23:48:0667 lock_state_controller_ = Shell::GetInstance()->lock_state_controller();
dchengcbf0d9d2015-12-27 22:49:2368 lock_state_controller_->SetDelegate(
69 std::move(lock_state_controller_delegate));
bruthigca2e1492014-09-12 23:48:0670 lock_state_controller_->set_animator_for_test(test_animator_);
[email protected]76e52aad2012-12-20 18:34:1371
[email protected]cafaeca2013-10-01 21:08:3272 test_api_.reset(new LockStateController::TestApi(lock_state_controller_));
bruthigca2e1492014-09-12 23:48:0673
74 power_button_controller_ = Shell::GetInstance()->power_button_controller();
bruthigca2e1492014-09-12 23:48:0675
mswbc0a8b482016-06-30 02:21:1476 shell_delegate_ =
msw0414d4122016-07-06 22:58:4877 static_cast<TestShellDelegate*>(WmShell::Get()->delegate());
[email protected]72e8d4e2012-12-17 15:02:3378 }
79
sadrul522f2ec82016-07-19 22:38:4480 void TearDown() override {
81 AshTestBase::TearDown();
82 chromeos::DBusThreadManager::Shutdown();
83 }
84
[email protected]882237512012-11-26 22:29:0785 protected:
86 void GenerateMouseMoveEvent() {
[email protected]73c9fd02014-07-28 01:48:5287 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
[email protected]882237512012-11-26 22:29:0788 generator.MoveMouseTo(10, 10);
89 }
90
91 int NumShutdownRequests() {
bruthigca2e1492014-09-12 23:48:0692 return lock_state_controller_delegate_->num_shutdown_requests() +
jamescookb8dcef522016-06-25 14:42:5593 shell_delegate_->num_exit_requests();
[email protected]882237512012-11-26 22:29:0794 }
95
[email protected]72e8d4e2012-12-17 15:02:3396 void Advance(SessionStateAnimator::AnimationSpeed speed) {
bruthigca2e1492014-09-12 23:48:0697 test_animator_->Advance(test_animator_->GetDuration(speed));
[email protected]72e8d4e2012-12-17 15:02:3398 }
99
100 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed,
101 float factor) {
bruthigca2e1492014-09-12 23:48:06102 base::TimeDelta duration = test_animator_->GetDuration(speed);
103 base::TimeDelta partial_duration =
104 base::TimeDelta::FromInternalValue(duration.ToInternalValue() * factor);
105 test_animator_->Advance(partial_duration);
[email protected]72e8d4e2012-12-17 15:02:33106 }
107
108 void ExpectPreLockAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06109 SCOPED_TRACE("Failure in ExpectPreLockAnimationStarted");
110 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55111 EXPECT_TRUE(test_animator_->AreContainersAnimated(
112 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
113 SessionStateAnimator::ANIMATION_LIFT));
114 EXPECT_TRUE(test_animator_->AreContainersAnimated(
115 SessionStateAnimator::LAUNCHER,
116 SessionStateAnimator::ANIMATION_FADE_OUT));
117 EXPECT_TRUE(test_animator_->AreContainersAnimated(
118 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
119 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
[email protected]72e8d4e2012-12-17 15:02:33120 EXPECT_TRUE(test_api_->is_animating_lock());
121 }
122
bruthigca2e1492014-09-12 23:48:06123 void ExpectPreLockAnimationRunning() {
124 SCOPED_TRACE("Failure in ExpectPreLockAnimationRunning");
125 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55126 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));
bruthigca2e1492014-09-12 23:48:06132 EXPECT_TRUE(test_api_->is_animating_lock());
133 }
134
135 void ExpectPreLockAnimationCancel() {
136 SCOPED_TRACE("Failure in ExpectPreLockAnimationCancel");
137 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55138 EXPECT_TRUE(test_animator_->AreContainersAnimated(
139 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
140 SessionStateAnimator::ANIMATION_UNDO_LIFT));
141 EXPECT_TRUE(test_animator_->AreContainersAnimated(
142 SessionStateAnimator::LAUNCHER,
143 SessionStateAnimator::ANIMATION_FADE_IN));
[email protected]72e8d4e2012-12-17 15:02:33144 }
145
146 void ExpectPreLockAnimationFinished() {
bruthigca2e1492014-09-12 23:48:06147 SCOPED_TRACE("Failure in ExpectPreLockAnimationFinished");
jamescookb8dcef522016-06-25 14:42:55148 EXPECT_FALSE(test_animator_->AreContainersAnimated(
149 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
150 SessionStateAnimator::ANIMATION_LIFT));
151 EXPECT_FALSE(test_animator_->AreContainersAnimated(
152 SessionStateAnimator::LAUNCHER,
153 SessionStateAnimator::ANIMATION_FADE_OUT));
154 EXPECT_FALSE(test_animator_->AreContainersAnimated(
155 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
156 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
[email protected]72e8d4e2012-12-17 15:02:33157 }
158
159 void ExpectPostLockAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06160 SCOPED_TRACE("Failure in ExpectPostLockAnimationStarted");
161 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55162 EXPECT_TRUE(test_animator_->AreContainersAnimated(
163 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
164 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN));
[email protected]72e8d4e2012-12-17 15:02:33165 }
166
bruthigca2e1492014-09-12 23:48:06167 void ExpectPostLockAnimationFinished() {
168 SCOPED_TRACE("Failure in ExpectPostLockAnimationFinished");
jamescookb8dcef522016-06-25 14:42:55169 EXPECT_FALSE(test_animator_->AreContainersAnimated(
170 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
171 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN));
[email protected]72e8d4e2012-12-17 15:02:33172 }
173
174 void ExpectUnlockBeforeUIDestroyedAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06175 SCOPED_TRACE("Failure in ExpectUnlockBeforeUIDestroyedAnimationStarted");
176 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55177 EXPECT_TRUE(test_animator_->AreContainersAnimated(
178 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
179 SessionStateAnimator::ANIMATION_LIFT));
[email protected]72e8d4e2012-12-17 15:02:33180 }
181
182 void ExpectUnlockBeforeUIDestroyedAnimationFinished() {
bruthigca2e1492014-09-12 23:48:06183 SCOPED_TRACE("Failure in ExpectUnlockBeforeUIDestroyedAnimationFinished");
jamescookb8dcef522016-06-25 14:42:55184 EXPECT_FALSE(test_animator_->AreContainersAnimated(
185 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
186 SessionStateAnimator::ANIMATION_LIFT));
[email protected]72e8d4e2012-12-17 15:02:33187 }
188
189 void ExpectUnlockAfterUIDestroyedAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06190 SCOPED_TRACE("Failure in ExpectUnlockAfterUIDestroyedAnimationStarted");
191 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55192 EXPECT_TRUE(test_animator_->AreContainersAnimated(
193 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
194 SessionStateAnimator::ANIMATION_DROP));
195 EXPECT_TRUE(test_animator_->AreContainersAnimated(
196 SessionStateAnimator::LAUNCHER,
197 SessionStateAnimator::ANIMATION_FADE_IN));
[email protected]72e8d4e2012-12-17 15:02:33198 }
199
200 void ExpectUnlockAfterUIDestroyedAnimationFinished() {
bruthigca2e1492014-09-12 23:48:06201 SCOPED_TRACE("Failure in ExpectUnlockAfterUIDestroyedAnimationFinished");
202 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55203 EXPECT_FALSE(test_animator_->AreContainersAnimated(
204 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
205 SessionStateAnimator::ANIMATION_DROP));
206 EXPECT_FALSE(test_animator_->AreContainersAnimated(
207 SessionStateAnimator::LAUNCHER,
208 SessionStateAnimator::ANIMATION_FADE_IN));
[email protected]72e8d4e2012-12-17 15:02:33209 }
210
211 void ExpectShutdownAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06212 SCOPED_TRACE("Failure in ExpectShutdownAnimationStarted");
213 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55214 EXPECT_TRUE(test_animator_->AreContainersAnimated(
215 SessionStateAnimator::ROOT_CONTAINER,
216 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
[email protected]72e8d4e2012-12-17 15:02:33217 }
218
bruthigca2e1492014-09-12 23:48:06219 void ExpectShutdownAnimationFinished() {
220 SCOPED_TRACE("Failure in ExpectShutdownAnimationFinished");
221 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55222 EXPECT_FALSE(test_animator_->AreContainersAnimated(
223 SessionStateAnimator::ROOT_CONTAINER,
224 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
[email protected]72e8d4e2012-12-17 15:02:33225 }
226
227 void ExpectShutdownAnimationCancel() {
bruthigca2e1492014-09-12 23:48:06228 SCOPED_TRACE("Failure in ExpectShutdownAnimationCancel");
229 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55230 EXPECT_TRUE(test_animator_->AreContainersAnimated(
231 SessionStateAnimator::ROOT_CONTAINER,
232 SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS));
[email protected]72e8d4e2012-12-17 15:02:33233 }
234
msw607227f82016-08-30 17:22:39235 void ExpectWallpaperIsShowing() {
236 SCOPED_TRACE("Failure in ExpectWallpaperIsShowing");
bruthigca2e1492014-09-12 23:48:06237 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55238 EXPECT_TRUE(test_animator_->AreContainersAnimated(
msw607227f82016-08-30 17:22:39239 SessionStateAnimator::WALLPAPER,
jamescookb8dcef522016-06-25 14:42:55240 SessionStateAnimator::ANIMATION_FADE_IN));
[email protected]72e8d4e2012-12-17 15:02:33241 }
242
msw607227f82016-08-30 17:22:39243 void ExpectWallpaperIsHiding() {
244 SCOPED_TRACE("Failure in ExpectWallpaperIsHiding");
bruthigca2e1492014-09-12 23:48:06245 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55246 EXPECT_TRUE(test_animator_->AreContainersAnimated(
msw607227f82016-08-30 17:22:39247 SessionStateAnimator::WALLPAPER,
jamescookb8dcef522016-06-25 14:42:55248 SessionStateAnimator::ANIMATION_FADE_OUT));
[email protected]72e8d4e2012-12-17 15:02:33249 }
250
msw607227f82016-08-30 17:22:39251 void ExpectRestoringWallpaperVisibility() {
252 SCOPED_TRACE("Failure in ExpectRestoringWallpaperVisibility");
bruthigca2e1492014-09-12 23:48:06253 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55254 EXPECT_TRUE(test_animator_->AreContainersAnimated(
msw607227f82016-08-30 17:22:39255 SessionStateAnimator::WALLPAPER,
jamescookb8dcef522016-06-25 14:42:55256 SessionStateAnimator::ANIMATION_FADE_IN));
bruthigca2e1492014-09-12 23:48:06257 }
258
[email protected]72e8d4e2012-12-17 15:02:33259 void ExpectUnlockedState() {
bruthigca2e1492014-09-12 23:48:06260 SCOPED_TRACE("Failure in ExpectUnlockedState");
261 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
mswbc0a8b482016-06-30 02:21:14262 EXPECT_FALSE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked());
[email protected]72e8d4e2012-12-17 15:02:33263 }
264
265 void ExpectLockedState() {
bruthigca2e1492014-09-12 23:48:06266 SCOPED_TRACE("Failure in ExpectLockedState");
267 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
mswbc0a8b482016-06-30 02:21:14268 EXPECT_TRUE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked());
bruthigca2e1492014-09-12 23:48:06269 }
[email protected]72e8d4e2012-12-17 15:02:33270
msw607227f82016-08-30 17:22:39271 void HideWallpaper() { test_animator_->HideWallpaper(); }
[email protected]72e8d4e2012-12-17 15:02:33272
273 void PressPowerButton() {
bruthigca2e1492014-09-12 23:48:06274 power_button_controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
[email protected]72e8d4e2012-12-17 15:02:33275 }
276
277 void ReleasePowerButton() {
bruthigca2e1492014-09-12 23:48:06278 power_button_controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
[email protected]72e8d4e2012-12-17 15:02:33279 }
280
281 void PressLockButton() {
bruthigca2e1492014-09-12 23:48:06282 power_button_controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
[email protected]72e8d4e2012-12-17 15:02:33283 }
284
285 void ReleaseLockButton() {
bruthigca2e1492014-09-12 23:48:06286 power_button_controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
287 }
288
289 void PressVolumeDown() {
290 GetEventGenerator().PressKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE);
291 }
292
293 void ReleaseVolumeDown() {
294 GetEventGenerator().ReleaseKey(ui::VKEY_VOLUME_DOWN, ui::EF_NONE);
[email protected]72e8d4e2012-12-17 15:02:33295 }
296
297 void SystemLocks() {
[email protected]ab4f8c92013-05-30 19:07:47298 lock_state_controller_->OnLockStateChanged(true);
mswbc0a8b482016-06-30 02:21:14299 WmShell::Get()->GetSessionStateDelegate()->LockScreen();
[email protected]72e8d4e2012-12-17 15:02:33300 }
301
302 void SuccessfulAuthentication(bool* call_flag) {
303 base::Closure closure = base::Bind(&CheckCalledCallback, call_flag);
[email protected]ab4f8c92013-05-30 19:07:47304 lock_state_controller_->OnLockScreenHide(closure);
[email protected]72e8d4e2012-12-17 15:02:33305 }
306
307 void SystemUnlocks() {
[email protected]ab4f8c92013-05-30 19:07:47308 lock_state_controller_->OnLockStateChanged(false);
mswbc0a8b482016-06-30 02:21:14309 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen();
bruthigca2e1492014-09-12 23:48:06310 }
311
312 void EnableMaximizeMode(bool enable) {
skyc68696c2016-07-01 21:06:02313 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
314 enable);
[email protected]72e8d4e2012-12-17 15:02:33315 }
316
skye79274a2016-06-08 05:39:02317 void Initialize(bool legacy_button, LoginStatus status) {
bruthigca2e1492014-09-12 23:48:06318 power_button_controller_->set_has_legacy_power_button_for_test(
319 legacy_button);
[email protected]ab4f8c92013-05-30 19:07:47320 lock_state_controller_->OnLoginStateChanged(status);
skye79274a2016-06-08 05:39:02321 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN);
322 if (status == LoginStatus::GUEST)
sky8335eed2016-10-06 23:25:09323 TestSessionStateDelegate::SetCanLockScreen(false);
[email protected]ab4f8c92013-05-30 19:07:47324 lock_state_controller_->OnLockStateChanged(false);
[email protected]72e8d4e2012-12-17 15:02:33325 }
326
bruthigca2e1492014-09-12 23:48:06327 PowerButtonController* power_button_controller_; // not owned
jamescookb8dcef522016-06-25 14:42:55328 LockStateController* lock_state_controller_; // not owned
bruthigca2e1492014-09-12 23:48:06329 TestLockStateControllerDelegate*
jamescookb8dcef522016-06-25 14:42:55330 lock_state_controller_delegate_; // not owned
sadrul522f2ec82016-07-19 22:38:44331 // Ownership is passed on to chromeos::DBusThreadManager.
332 chromeos::FakeSessionManagerClient* session_manager_client_;
jamescookb8dcef522016-06-25 14:42:55333 TestSessionStateAnimator* test_animator_; // not owned
dchenga94547472016-04-08 08:41:11334 std::unique_ptr<LockStateController::TestApi> test_api_;
bruthigca2e1492014-09-12 23:48:06335 TestShellDelegate* shell_delegate_; // not owned
[email protected]882237512012-11-26 22:29:07336
337 private:
[email protected]cafaeca2013-10-01 21:08:32338 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest);
[email protected]882237512012-11-26 22:29:07339};
340
341// Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't
342// correctly report power button releases. We should lock immediately the first
343// time the button is pressed and shut down when it's pressed from the locked
344// state.
bruthigca2e1492014-09-12 23:48:06345TEST_F(LockStateControllerTest, LegacyLockAndShutDown) {
skye79274a2016-06-08 05:39:02346 Initialize(true, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33347
348 ExpectUnlockedState();
[email protected]882237512012-11-26 22:29:07349
350 // We should request that the screen be locked immediately after seeing the
351 // power button get pressed.
[email protected]72e8d4e2012-12-17 15:02:33352 PressPowerButton();
[email protected]882237512012-11-26 22:29:07353
[email protected]72e8d4e2012-12-17 15:02:33354 EXPECT_FALSE(test_api_->is_lock_cancellable());
355
bruthigca2e1492014-09-12 23:48:06356 ExpectPreLockAnimationStarted();
357 test_animator_->CompleteAllAnimations(true);
[email protected]72e8d4e2012-12-17 15:02:33358 ExpectPreLockAnimationFinished();
bruthigca2e1492014-09-12 23:48:06359
sadrul522f2ec82016-07-19 22:38:44360 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07361
362 // Notify that we locked successfully.
[email protected]ab4f8c92013-05-30 19:07:47363 lock_state_controller_->OnStartingLock();
bruthigca2e1492014-09-12 23:48:06364 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
[email protected]882237512012-11-26 22:29:07365
[email protected]72e8d4e2012-12-17 15:02:33366 SystemLocks();
[email protected]882237512012-11-26 22:29:07367
[email protected]72e8d4e2012-12-17 15:02:33368 ExpectPostLockAnimationStarted();
bruthigca2e1492014-09-12 23:48:06369 test_animator_->CompleteAllAnimations(true);
370 ExpectPostLockAnimationFinished();
[email protected]882237512012-11-26 22:29:07371
372 // We shouldn't progress towards the shutdown state, however.
373 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
374 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33375
376 ReleasePowerButton();
[email protected]882237512012-11-26 22:29:07377
378 // Hold the button again and check that we start shutting down.
[email protected]72e8d4e2012-12-17 15:02:33379 PressPowerButton();
[email protected]882237512012-11-26 22:29:07380
[email protected]72e8d4e2012-12-17 15:02:33381 ExpectShutdownAnimationStarted();
382
383 EXPECT_EQ(0, NumShutdownRequests());
[email protected]882237512012-11-26 22:29:07384 // Make sure a mouse move event won't show the cursor.
385 GenerateMouseMoveEvent();
386 EXPECT_FALSE(cursor_visible());
[email protected]72e8d4e2012-12-17 15:02:33387
[email protected]882237512012-11-26 22:29:07388 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
389 test_api_->trigger_real_shutdown_timeout();
390 EXPECT_EQ(1, NumShutdownRequests());
391}
392
393// Test that we start shutting down immediately if the power button is pressed
394// while we're not logged in on an unofficial system.
[email protected]cafaeca2013-10-01 21:08:32395TEST_F(LockStateControllerTest, LegacyNotLoggedIn) {
skye79274a2016-06-08 05:39:02396 Initialize(true, LoginStatus::NOT_LOGGED_IN);
[email protected]72e8d4e2012-12-17 15:02:33397
398 PressPowerButton();
399 ExpectShutdownAnimationStarted();
400
[email protected]882237512012-11-26 22:29:07401 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
402}
403
404// Test that we start shutting down immediately if the power button is pressed
405// while we're logged in as a guest on an unofficial system.
[email protected]cafaeca2013-10-01 21:08:32406TEST_F(LockStateControllerTest, LegacyGuest) {
skye79274a2016-06-08 05:39:02407 Initialize(true, LoginStatus::GUEST);
[email protected]72e8d4e2012-12-17 15:02:33408
409 PressPowerButton();
410 ExpectShutdownAnimationStarted();
411
[email protected]882237512012-11-26 22:29:07412 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
413}
414
415// When we hold the power button while the user isn't logged in, we should shut
416// down the machine directly.
[email protected]cafaeca2013-10-01 21:08:32417TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) {
skye79274a2016-06-08 05:39:02418 Initialize(false, LoginStatus::NOT_LOGGED_IN);
[email protected]882237512012-11-26 22:29:07419
420 // Press the power button and check that we start the shutdown timer.
[email protected]72e8d4e2012-12-17 15:02:33421 PressPowerButton();
422 EXPECT_FALSE(test_api_->is_animating_lock());
[email protected]882237512012-11-26 22:29:07423 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33424 ExpectShutdownAnimationStarted();
425
426 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
[email protected]882237512012-11-26 22:29:07427
428 // Release the power button before the shutdown timer fires.
[email protected]72e8d4e2012-12-17 15:02:33429 ReleasePowerButton();
430
[email protected]882237512012-11-26 22:29:07431 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33432 ExpectShutdownAnimationCancel();
433
434 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_REVERT, 0.5f);
[email protected]882237512012-11-26 22:29:07435
436 // Press the button again and make the shutdown timeout fire this time.
437 // Check that we start the timer for actually requesting the shutdown.
[email protected]72e8d4e2012-12-17 15:02:33438 PressPowerButton();
439
[email protected]882237512012-11-26 22:29:07440 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33441
442 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
443 ExpectShutdownAnimationFinished();
[email protected]882237512012-11-26 22:29:07444 test_api_->trigger_shutdown_timeout();
[email protected]72e8d4e2012-12-17 15:02:33445
[email protected]882237512012-11-26 22:29:07446 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
447 EXPECT_EQ(0, NumShutdownRequests());
[email protected]882237512012-11-26 22:29:07448
449 // When the timout fires, we should request a shutdown.
450 test_api_->trigger_real_shutdown_timeout();
[email protected]72e8d4e2012-12-17 15:02:33451
[email protected]882237512012-11-26 22:29:07452 EXPECT_EQ(1, NumShutdownRequests());
453}
454
455// Test that we lock the screen and deal with unlocking correctly.
bruthigca2e1492014-09-12 23:48:06456TEST_F(LockStateControllerTest, LockAndUnlock) {
skye79274a2016-06-08 05:39:02457 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07458
[email protected]72e8d4e2012-12-17 15:02:33459 ExpectUnlockedState();
[email protected]882237512012-11-26 22:29:07460
461 // Press the power button and check that the lock timer is started and that we
462 // start lifting the non-screen-locker containers.
[email protected]72e8d4e2012-12-17 15:02:33463 PressPowerButton();
[email protected]882237512012-11-26 22:29:07464
[email protected]72e8d4e2012-12-17 15:02:33465 ExpectPreLockAnimationStarted();
466 EXPECT_TRUE(test_api_->is_lock_cancellable());
sadrul522f2ec82016-07-19 22:38:44467 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]72e8d4e2012-12-17 15:02:33468
bruthigca2e1492014-09-12 23:48:06469 test_animator_->CompleteAllAnimations(true);
[email protected]72e8d4e2012-12-17 15:02:33470 ExpectPreLockAnimationFinished();
471
sadrul522f2ec82016-07-19 22:38:44472 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07473
474 // Notify that we locked successfully.
[email protected]ab4f8c92013-05-30 19:07:47475 lock_state_controller_->OnStartingLock();
[email protected]72e8d4e2012-12-17 15:02:33476 // We had that animation already.
bruthigca2e1492014-09-12 23:48:06477 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
[email protected]882237512012-11-26 22:29:07478
[email protected]72e8d4e2012-12-17 15:02:33479 SystemLocks();
480
481 ExpectPostLockAnimationStarted();
bruthigca2e1492014-09-12 23:48:06482 test_animator_->CompleteAllAnimations(true);
483 ExpectPostLockAnimationFinished();
[email protected]882237512012-11-26 22:29:07484
485 // When we release the power button, the lock-to-shutdown timer should be
486 // stopped.
[email protected]72e8d4e2012-12-17 15:02:33487 ExpectLockedState();
[email protected]882237512012-11-26 22:29:07488 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33489 ReleasePowerButton();
490 ExpectLockedState();
[email protected]882237512012-11-26 22:29:07491 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
492
493 // Notify that the screen has been unlocked. We should show the
494 // non-screen-locker windows.
[email protected]882237512012-11-26 22:29:07495 bool called = false;
[email protected]72e8d4e2012-12-17 15:02:33496 SuccessfulAuthentication(&called);
497
498 ExpectUnlockBeforeUIDestroyedAnimationStarted();
499 EXPECT_FALSE(called);
bruthigca2e1492014-09-12 23:48:06500 test_animator_->CompleteAllAnimations(true);
[email protected]72e8d4e2012-12-17 15:02:33501 ExpectUnlockBeforeUIDestroyedAnimationFinished();
502
[email protected]882237512012-11-26 22:29:07503 EXPECT_TRUE(called);
[email protected]72e8d4e2012-12-17 15:02:33504
505 SystemUnlocks();
506
507 ExpectUnlockAfterUIDestroyedAnimationStarted();
bruthigca2e1492014-09-12 23:48:06508 test_animator_->CompleteAllAnimations(true);
[email protected]72e8d4e2012-12-17 15:02:33509 ExpectUnlockAfterUIDestroyedAnimationFinished();
510
511 ExpectUnlockedState();
512}
513
514// Test that we deal with cancelling lock correctly.
bruthigca2e1492014-09-12 23:48:06515TEST_F(LockStateControllerTest, LockAndCancel) {
skye79274a2016-06-08 05:39:02516 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33517
518 ExpectUnlockedState();
519
520 // Press the power button and check that the lock timer is started and that we
521 // start lifting the non-screen-locker containers.
522 PressPowerButton();
523
524 ExpectPreLockAnimationStarted();
525 EXPECT_TRUE(test_api_->is_lock_cancellable());
526
527 // forward only half way through
528 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
529
[email protected]72e8d4e2012-12-17 15:02:33530 // Release the button before the lock timer fires.
531 ReleasePowerButton();
532
533 ExpectPreLockAnimationCancel();
534
[email protected]72e8d4e2012-12-17 15:02:33535 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
536 ExpectUnlockedState();
sadrul522f2ec82016-07-19 22:38:44537 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]72e8d4e2012-12-17 15:02:33538}
539
540// Test that we deal with cancelling lock correctly.
bruthigca2e1492014-09-12 23:48:06541TEST_F(LockStateControllerTest, LockAndCancelAndLockAgain) {
skye79274a2016-06-08 05:39:02542 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33543
544 ExpectUnlockedState();
545
546 // Press the power button and check that the lock timer is started and that we
547 // start lifting the non-screen-locker containers.
548 PressPowerButton();
549
550 ExpectPreLockAnimationStarted();
551 EXPECT_TRUE(test_api_->is_lock_cancellable());
552
553 // forward only half way through
554 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
555
556 // Release the button before the lock timer fires.
557 ReleasePowerButton();
558 ExpectPreLockAnimationCancel();
559
bruthigca2e1492014-09-12 23:48:06560 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS,
561 0.5f);
[email protected]72e8d4e2012-12-17 15:02:33562
563 PressPowerButton();
564 ExpectPreLockAnimationStarted();
565 EXPECT_TRUE(test_api_->is_lock_cancellable());
566
567 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
568
sadrul522f2ec82016-07-19 22:38:44569 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]72e8d4e2012-12-17 15:02:33570
571 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
572 ExpectPreLockAnimationFinished();
sadrul522f2ec82016-07-19 22:38:44573 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07574}
575
576// Hold the power button down from the unlocked state to eventual shutdown.
bruthigca2e1492014-09-12 23:48:06577TEST_F(LockStateControllerTest, LockToShutdown) {
skye79274a2016-06-08 05:39:02578 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07579
580 // Hold the power button and lock the screen.
[email protected]72e8d4e2012-12-17 15:02:33581 PressPowerButton();
582 EXPECT_TRUE(test_api_->is_animating_lock());
583
584 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
585 SystemLocks();
586 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
[email protected]882237512012-11-26 22:29:07587
588 // When the lock-to-shutdown timeout fires, we should start the shutdown
589 // timer.
590 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33591
[email protected]882237512012-11-26 22:29:07592 test_api_->trigger_lock_to_shutdown_timeout();
[email protected]72e8d4e2012-12-17 15:02:33593
594 ExpectShutdownAnimationStarted();
[email protected]882237512012-11-26 22:29:07595 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
[email protected]882237512012-11-26 22:29:07596
597 // Fire the shutdown timeout and check that we request shutdown.
[email protected]72e8d4e2012-12-17 15:02:33598 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
599 ExpectShutdownAnimationFinished();
[email protected]882237512012-11-26 22:29:07600 test_api_->trigger_shutdown_timeout();
[email protected]72e8d4e2012-12-17 15:02:33601
[email protected]882237512012-11-26 22:29:07602 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
603 EXPECT_EQ(0, NumShutdownRequests());
604 test_api_->trigger_real_shutdown_timeout();
605 EXPECT_EQ(1, NumShutdownRequests());
606}
607
[email protected]882237512012-11-26 22:29:07608// Hold the power button down from the unlocked state to eventual shutdown,
609// then release the button while system does locking.
[email protected]cafaeca2013-10-01 21:08:32610TEST_F(LockStateControllerTest, CancelLockToShutdown) {
skye79274a2016-06-08 05:39:02611 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07612
[email protected]72e8d4e2012-12-17 15:02:33613 PressPowerButton();
[email protected]882237512012-11-26 22:29:07614
615 // Hold the power button and lock the screen.
[email protected]72e8d4e2012-12-17 15:02:33616 EXPECT_TRUE(test_api_->is_animating_lock());
617
618 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
619 SystemLocks();
620 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f);
[email protected]882237512012-11-26 22:29:07621
622 // Power button is released while system attempts to lock.
[email protected]72e8d4e2012-12-17 15:02:33623 ReleasePowerButton();
624
625 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
[email protected]882237512012-11-26 22:29:07626
[email protected]ab4f8c92013-05-30 19:07:47627 EXPECT_FALSE(lock_state_controller_->ShutdownRequested());
[email protected]882237512012-11-26 22:29:07628 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
629 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
630}
631
bruthigca2e1492014-09-12 23:48:06632// TODO(bruthig): Investigate why this hangs on Windows 8 and whether it can be
633// safely enabled on OS_WIN.
634#ifndef OS_WIN
[email protected]882237512012-11-26 22:29:07635// Test that we handle the case where lock requests are ignored.
bruthigca2e1492014-09-12 23:48:06636TEST_F(LockStateControllerTest, Lock) {
skye79274a2016-06-08 05:39:02637 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07638
639 // Hold the power button and lock the screen.
[email protected]72e8d4e2012-12-17 15:02:33640 PressPowerButton();
641 ExpectPreLockAnimationStarted();
642
643 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
644
sadrul522f2ec82016-07-19 22:38:44645 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07646 EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
[email protected]882237512012-11-26 22:29:07647 // We shouldn't start the lock-to-shutdown timer until the screen has actually
[email protected]72e8d4e2012-12-17 15:02:33648 // been locked and this was animated.
[email protected]882237512012-11-26 22:29:07649 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
650
bruthigca2e1492014-09-12 23:48:06651 // Act as if the request timed out.
652 EXPECT_DEATH(test_api_->trigger_lock_fail_timeout(), "");
[email protected]72e8d4e2012-12-17 15:02:33653}
bruthigca2e1492014-09-12 23:48:06654#endif
[email protected]72e8d4e2012-12-17 15:02:33655
656// Test the basic operation of the lock button (not logged in).
[email protected]cafaeca2013-10-01 21:08:32657TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) {
[email protected]72e8d4e2012-12-17 15:02:33658 // The lock button shouldn't do anything if we aren't logged in.
skye79274a2016-06-08 05:39:02659 Initialize(false, LoginStatus::NOT_LOGGED_IN);
[email protected]72e8d4e2012-12-17 15:02:33660
661 PressLockButton();
662 EXPECT_FALSE(test_api_->is_animating_lock());
663 ReleaseLockButton();
sadrul522f2ec82016-07-19 22:38:44664 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]72e8d4e2012-12-17 15:02:33665}
666
667// Test the basic operation of the lock button (guest).
[email protected]cafaeca2013-10-01 21:08:32668TEST_F(LockStateControllerTest, LockButtonBasicGuest) {
[email protected]72e8d4e2012-12-17 15:02:33669 // The lock button shouldn't do anything when we're logged in as a guest.
skye79274a2016-06-08 05:39:02670 Initialize(false, LoginStatus::GUEST);
[email protected]72e8d4e2012-12-17 15:02:33671
672 PressLockButton();
673 EXPECT_FALSE(test_api_->is_animating_lock());
674 ReleaseLockButton();
sadrul522f2ec82016-07-19 22:38:44675 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07676}
677
678// Test the basic operation of the lock button.
bruthigca2e1492014-09-12 23:48:06679TEST_F(LockStateControllerTest, LockButtonBasic) {
[email protected]882237512012-11-26 22:29:07680 // If we're logged in as a regular user, we should start the lock timer and
681 // the pre-lock animation.
skye79274a2016-06-08 05:39:02682 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33683
684 PressLockButton();
685 ExpectPreLockAnimationStarted();
686 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
[email protected]882237512012-11-26 22:29:07687
688 // If the button is released immediately, we shouldn't lock the screen.
[email protected]72e8d4e2012-12-17 15:02:33689 ReleaseLockButton();
690 ExpectPreLockAnimationCancel();
691 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
692
693 ExpectUnlockedState();
sadrul522f2ec82016-07-19 22:38:44694 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07695
696 // Press the button again and let the lock timeout fire. We should request
697 // that the screen be locked.
[email protected]72e8d4e2012-12-17 15:02:33698 PressLockButton();
699 ExpectPreLockAnimationStarted();
700 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
sadrul522f2ec82016-07-19 22:38:44701 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07702
703 // Pressing the lock button while we have a pending lock request shouldn't do
704 // anything.
[email protected]72e8d4e2012-12-17 15:02:33705 ReleaseLockButton();
706 PressLockButton();
707 ExpectPreLockAnimationFinished();
708 ReleaseLockButton();
[email protected]882237512012-11-26 22:29:07709
710 // Pressing the button also shouldn't do anything after the screen is locked.
[email protected]72e8d4e2012-12-17 15:02:33711 SystemLocks();
712 ExpectPostLockAnimationStarted();
713
714 PressLockButton();
715 ReleaseLockButton();
716 ExpectPostLockAnimationStarted();
717
718 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
bruthigca2e1492014-09-12 23:48:06719 ExpectPostLockAnimationFinished();
[email protected]72e8d4e2012-12-17 15:02:33720
721 PressLockButton();
722 ReleaseLockButton();
bruthigca2e1492014-09-12 23:48:06723 ExpectPostLockAnimationFinished();
[email protected]882237512012-11-26 22:29:07724}
725
726// Test that the power button takes priority over the lock button.
bruthigca2e1492014-09-12 23:48:06727TEST_F(LockStateControllerTest, PowerButtonPreemptsLockButton) {
skye79274a2016-06-08 05:39:02728 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07729
730 // While the lock button is down, hold the power button.
[email protected]72e8d4e2012-12-17 15:02:33731 PressLockButton();
732 ExpectPreLockAnimationStarted();
[email protected]72e8d4e2012-12-17 15:02:33733
bruthigca2e1492014-09-12 23:48:06734 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
735 ExpectPreLockAnimationRunning();
736
737 PressPowerButton();
738 ExpectPreLockAnimationRunning();
739
740 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
741 ExpectPreLockAnimationRunning();
[email protected]882237512012-11-26 22:29:07742
743 // The lock timer shouldn't be stopped when the lock button is released.
[email protected]72e8d4e2012-12-17 15:02:33744 ReleaseLockButton();
bruthigca2e1492014-09-12 23:48:06745 ExpectPreLockAnimationRunning();
746
[email protected]72e8d4e2012-12-17 15:02:33747 ReleasePowerButton();
748 ExpectPreLockAnimationCancel();
749
750 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
751 ExpectUnlockedState();
[email protected]882237512012-11-26 22:29:07752
753 // Now press the power button first and then the lock button.
[email protected]72e8d4e2012-12-17 15:02:33754 PressPowerButton();
755 ExpectPreLockAnimationStarted();
[email protected]72e8d4e2012-12-17 15:02:33756
bruthigca2e1492014-09-12 23:48:06757 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
758
759 PressLockButton();
760 ExpectPreLockAnimationRunning();
761
762 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
[email protected]882237512012-11-26 22:29:07763
764 // Releasing the power button should stop the lock timer.
[email protected]72e8d4e2012-12-17 15:02:33765 ReleasePowerButton();
766 ExpectPreLockAnimationCancel();
bruthigca2e1492014-09-12 23:48:06767
768 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
769
[email protected]72e8d4e2012-12-17 15:02:33770 ReleaseLockButton();
771 ExpectPreLockAnimationCancel();
[email protected]882237512012-11-26 22:29:07772}
773
774// When the screen is locked without going through the usual power-button
775// slow-close path (e.g. via the wrench menu), test that we still show the
776// fast-close animation.
[email protected]cafaeca2013-10-01 21:08:32777TEST_F(LockStateControllerTest, LockWithoutButton) {
skye79274a2016-06-08 05:39:02778 Initialize(false, LoginStatus::USER);
[email protected]ab4f8c92013-05-30 19:07:47779 lock_state_controller_->OnStartingLock();
[email protected]72e8d4e2012-12-17 15:02:33780
781 ExpectPreLockAnimationStarted();
782 EXPECT_FALSE(test_api_->is_lock_cancellable());
bruthigca2e1492014-09-12 23:48:06783 EXPECT_LT(0u, test_animator_->GetAnimationCount());
[email protected]19c6c4e2013-01-28 16:25:48784
bruthigca2e1492014-09-12 23:48:06785 test_animator_->CompleteAllAnimations(true);
sadrul522f2ec82016-07-19 22:38:44786 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07787}
788
789// When we hear that the process is exiting but we haven't had a chance to
790// display an animation, we should just blank the screen.
[email protected]cafaeca2013-10-01 21:08:32791TEST_F(LockStateControllerTest, ShutdownWithoutButton) {
skye79274a2016-06-08 05:39:02792 Initialize(false, LoginStatus::USER);
[email protected]ab4f8c92013-05-30 19:07:47793 lock_state_controller_->OnAppTerminating();
[email protected]72e8d4e2012-12-17 15:02:33794
jamescookb8dcef522016-06-25 14:42:55795 EXPECT_TRUE(test_animator_->AreContainersAnimated(
796 SessionStateAnimator::kAllNonRootContainersMask,
797 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
[email protected]882237512012-11-26 22:29:07798 GenerateMouseMoveEvent();
799 EXPECT_FALSE(cursor_visible());
800}
801
802// Test that we display the fast-close animation and shut down when we get an
803// outside request to shut down (e.g. from the login or lock screen).
[email protected]cafaeca2013-10-01 21:08:32804TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) {
skye79274a2016-06-08 05:39:02805 Initialize(false, LoginStatus::NOT_LOGGED_IN);
[email protected]72e8d4e2012-12-17 15:02:33806
cschuet7f630ba2015-01-22 13:17:05807 lock_state_controller_->RequestShutdown();
[email protected]72e8d4e2012-12-17 15:02:33808
809 ExpectShutdownAnimationStarted();
810 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
811
[email protected]882237512012-11-26 22:29:07812 GenerateMouseMoveEvent();
813 EXPECT_FALSE(cursor_visible());
814
815 EXPECT_EQ(0, NumShutdownRequests());
816 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
817 test_api_->trigger_real_shutdown_timeout();
818 EXPECT_EQ(1, NumShutdownRequests());
819}
820
[email protected]cafaeca2013-10-01 21:08:32821TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) {
skye79274a2016-06-08 05:39:02822 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33823
824 SystemLocks();
bruthigca2e1492014-09-12 23:48:06825
[email protected]72e8d4e2012-12-17 15:02:33826 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
bruthigca2e1492014-09-12 23:48:06827 ExpectPostLockAnimationFinished();
[email protected]72e8d4e2012-12-17 15:02:33828
cschuet7f630ba2015-01-22 13:17:05829 lock_state_controller_->RequestShutdown();
[email protected]72e8d4e2012-12-17 15:02:33830
831 ExpectShutdownAnimationStarted();
832 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
833
[email protected]882237512012-11-26 22:29:07834 GenerateMouseMoveEvent();
835 EXPECT_FALSE(cursor_visible());
836
837 EXPECT_EQ(0, NumShutdownRequests());
838 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
839 test_api_->trigger_real_shutdown_timeout();
840 EXPECT_EQ(1, NumShutdownRequests());
841}
842
bruthigca2e1492014-09-12 23:48:06843TEST_F(LockStateControllerTest, RequestAndCancelShutdownFromLockScreen) {
skye79274a2016-06-08 05:39:02844 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33845
846 SystemLocks();
847 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
848 ExpectLockedState();
[email protected]882237512012-11-26 22:29:07849
850 // Press the power button and check that we start the shutdown timer.
[email protected]72e8d4e2012-12-17 15:02:33851 PressPowerButton();
852 EXPECT_FALSE(test_api_->is_animating_lock());
[email protected]882237512012-11-26 22:29:07853 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33854
855 ExpectShutdownAnimationStarted();
856
857 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
858
[email protected]882237512012-11-26 22:29:07859 // Release the power button before the shutdown timer fires.
[email protected]72e8d4e2012-12-17 15:02:33860 ReleasePowerButton();
861
[email protected]882237512012-11-26 22:29:07862 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33863
864 ExpectShutdownAnimationCancel();
865
bruthigca2e1492014-09-12 23:48:06866 Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT_SHUTDOWN);
[email protected]72e8d4e2012-12-17 15:02:33867 ExpectLockedState();
[email protected]882237512012-11-26 22:29:07868}
869
870// Test that we ignore power button presses when the screen is turned off.
[email protected]cafaeca2013-10-01 21:08:32871TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) {
skye79274a2016-06-08 05:39:02872 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07873
874 // When the screen brightness is at 0%, we shouldn't do anything in response
875 // to power button presses.
bruthigca2e1492014-09-12 23:48:06876 power_button_controller_->OnScreenBrightnessChanged(0.0);
[email protected]72e8d4e2012-12-17 15:02:33877 PressPowerButton();
878 EXPECT_FALSE(test_api_->is_animating_lock());
879 ReleasePowerButton();
[email protected]882237512012-11-26 22:29:07880
881 // After increasing the brightness to 10%, we should start the timer like
882 // usual.
bruthigca2e1492014-09-12 23:48:06883 power_button_controller_->OnScreenBrightnessChanged(10.0);
[email protected]72e8d4e2012-12-17 15:02:33884 PressPowerButton();
885 EXPECT_TRUE(test_api_->is_animating_lock());
[email protected]685442f32014-02-28 10:40:06886 ReleasePowerButton();
[email protected]72e8d4e2012-12-17 15:02:33887}
888
[email protected]685442f32014-02-28 10:40:06889TEST_F(LockStateControllerTest, HonorPowerButtonInDockedMode) {
890 // Create two outputs, the first internal and the second external.
[email protected]1e31cbd2014-04-07 20:06:11891 ui::DisplayConfigurator::DisplayStateList outputs;
[email protected]71da07e2014-03-18 21:16:04892
kylecharc354dd22016-10-24 21:03:56893 std::unique_ptr<ui::DisplaySnapshot> internal_display =
894 display::FakeDisplaySnapshot::Builder()
895 .SetId(123)
896 .SetNativeMode(gfx::Size(1, 1))
897 .SetType(ui::DISPLAY_CONNECTION_TYPE_INTERNAL)
898 .Build();
899 outputs.push_back(internal_display.get());
900
901 std::unique_ptr<ui::DisplaySnapshot> external_display =
902 display::FakeDisplaySnapshot::Builder()
903 .SetId(456)
904 .SetNativeMode(gfx::Size(1, 1))
905 .SetType(ui::DISPLAY_CONNECTION_TYPE_HDMI)
906 .Build();
907 outputs.push_back(external_display.get());
[email protected]685442f32014-02-28 10:40:06908
909 // When all of the displays are turned off (e.g. due to user inactivity), the
910 // power button should be ignored.
bruthigca2e1492014-09-12 23:48:06911 power_button_controller_->OnScreenBrightnessChanged(0.0);
kylecharc354dd22016-10-24 21:03:56912 internal_display->set_current_mode(nullptr);
913 external_display->set_current_mode(nullptr);
bruthigca2e1492014-09-12 23:48:06914 power_button_controller_->OnDisplayModeChanged(outputs);
[email protected]685442f32014-02-28 10:40:06915 PressPowerButton();
916 EXPECT_FALSE(test_api_->is_animating_lock());
917 ReleasePowerButton();
918
919 // When the screen brightness is 0% but the external display is still turned
920 // on (indicating either docked mode or the user having manually decreased the
921 // brightness to 0%), the power button should still be handled.
kylecharc354dd22016-10-24 21:03:56922 external_display->set_current_mode(external_display->modes().back().get());
bruthigca2e1492014-09-12 23:48:06923 power_button_controller_->OnDisplayModeChanged(outputs);
[email protected]685442f32014-02-28 10:40:06924 PressPowerButton();
925 EXPECT_TRUE(test_api_->is_animating_lock());
926 ReleasePowerButton();
927}
[email protected]685442f32014-02-28 10:40:06928
msw607227f82016-08-30 17:22:39929// Test that hidden wallpaper appears and revers correctly on lock/cancel.
930TEST_F(LockStateControllerTest, TestHiddenWallpaperLockCancel) {
skye79274a2016-06-08 05:39:02931 Initialize(false, LoginStatus::USER);
msw607227f82016-08-30 17:22:39932 HideWallpaper();
[email protected]72e8d4e2012-12-17 15:02:33933
[email protected]72e8d4e2012-12-17 15:02:33934 ExpectUnlockedState();
935 PressPowerButton();
936
937 ExpectPreLockAnimationStarted();
msw607227f82016-08-30 17:22:39938 ExpectWallpaperIsShowing();
[email protected]72e8d4e2012-12-17 15:02:33939
940 // Forward only half way through.
941 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
942
943 // Release the button before the lock timer fires.
944 ReleasePowerButton();
945 ExpectPreLockAnimationCancel();
msw607227f82016-08-30 17:22:39946 ExpectWallpaperIsHiding();
[email protected]72e8d4e2012-12-17 15:02:33947
bruthigca2e1492014-09-12 23:48:06948 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS);
949
950 // When the CancelPrelockAnimation sequence finishes it queues up a
msw607227f82016-08-30 17:22:39951 // restore wallpaper visibility sequence when the wallpaper is hidden.
952 ExpectRestoringWallpaperVisibility();
bruthigca2e1492014-09-12 23:48:06953
954 Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
[email protected]72e8d4e2012-12-17 15:02:33955
956 ExpectUnlockedState();
[email protected]72e8d4e2012-12-17 15:02:33957}
958
msw607227f82016-08-30 17:22:39959// Test that hidden wallpaper appears and revers correctly on lock/unlock.
960TEST_F(LockStateControllerTest, TestHiddenWallpaperLockUnlock) {
skye79274a2016-06-08 05:39:02961 Initialize(false, LoginStatus::USER);
msw607227f82016-08-30 17:22:39962 HideWallpaper();
[email protected]72e8d4e2012-12-17 15:02:33963
[email protected]72e8d4e2012-12-17 15:02:33964 ExpectUnlockedState();
965
966 // Press the power button and check that the lock timer is started and that we
967 // start lifting the non-screen-locker containers.
968 PressPowerButton();
969
970 ExpectPreLockAnimationStarted();
msw607227f82016-08-30 17:22:39971 ExpectWallpaperIsShowing();
[email protected]72e8d4e2012-12-17 15:02:33972
973 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
974
975 ExpectPreLockAnimationFinished();
976
977 SystemLocks();
978
979 ReleasePowerButton();
980
981 ExpectPostLockAnimationStarted();
982 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
bruthigca2e1492014-09-12 23:48:06983 ExpectPostLockAnimationFinished();
[email protected]72e8d4e2012-12-17 15:02:33984
985 ExpectLockedState();
986
987 SuccessfulAuthentication(NULL);
988
989 ExpectUnlockBeforeUIDestroyedAnimationStarted();
990 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
991 ExpectUnlockBeforeUIDestroyedAnimationFinished();
992
993 SystemUnlocks();
994
995 ExpectUnlockAfterUIDestroyedAnimationStarted();
msw607227f82016-08-30 17:22:39996 ExpectWallpaperIsHiding();
[email protected]72e8d4e2012-12-17 15:02:33997
998 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
bruthigca2e1492014-09-12 23:48:06999
1000 // When the StartUnlockAnimationAfterUIDestroyed sequence finishes it queues
msw607227f82016-08-30 17:22:391001 // up a restore wallpaper visibility sequence when the wallpaper is hidden.
1002 ExpectRestoringWallpaperVisibility();
bruthigca2e1492014-09-12 23:48:061003
1004 Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
1005
[email protected]72e8d4e2012-12-17 15:02:331006 ExpectUnlockAfterUIDestroyedAnimationFinished();
[email protected]72e8d4e2012-12-17 15:02:331007
1008 ExpectUnlockedState();
[email protected]882237512012-11-26 22:29:071009}
1010
bruthigca2e1492014-09-12 23:48:061011TEST_F(LockStateControllerTest, Screenshot) {
1012 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate();
1013 delegate->set_can_take_screenshot(true);
1014
1015 EnableMaximizeMode(false);
1016
1017 // Screenshot handling should not be active when not in maximize mode.
1018 ASSERT_EQ(0, delegate->handle_take_screenshot_count());
1019 PressVolumeDown();
1020 PressPowerButton();
1021 ReleasePowerButton();
1022 ReleaseVolumeDown();
1023 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1024
1025 EnableMaximizeMode(true);
1026
1027 // Pressing power alone does not take a screenshot.
1028 PressPowerButton();
1029 ReleasePowerButton();
1030 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1031
1032 // Press & release volume then pressing power does not take a screenshot.
1033 ASSERT_EQ(0, delegate->handle_take_screenshot_count());
1034 PressVolumeDown();
1035 ReleaseVolumeDown();
1036 PressPowerButton();
1037 ReleasePowerButton();
1038 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1039
1040 // Pressing power and then volume does not take a screenshot.
1041 ASSERT_EQ(0, delegate->handle_take_screenshot_count());
1042 PressPowerButton();
1043 ReleasePowerButton();
1044 PressVolumeDown();
1045 ReleaseVolumeDown();
1046 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1047
1048 // Holding volume down and pressing power takes a screenshot.
1049 ASSERT_EQ(0, delegate->handle_take_screenshot_count());
1050 PressVolumeDown();
1051 PressPowerButton();
1052 ReleasePowerButton();
1053 ReleaseVolumeDown();
1054 EXPECT_EQ(1, delegate->handle_take_screenshot_count());
1055}
1056
1057// Tests that a lock action is cancellable when quick lock is turned on and
1058// maximize mode is not active.
1059TEST_F(LockStateControllerTest, QuickLockWhileNotInMaximizeMode) {
skye79274a2016-06-08 05:39:021060 Initialize(false, LoginStatus::USER);
bruthigca2e1492014-09-12 23:48:061061 power_button_controller_->set_enable_quick_lock_for_test(true);
1062 EnableMaximizeMode(false);
1063
1064 PressPowerButton();
1065
1066 ExpectPreLockAnimationStarted();
1067 EXPECT_TRUE(test_api_->is_animating_lock());
1068 EXPECT_TRUE(lock_state_controller_->CanCancelLockAnimation());
1069
1070 ReleasePowerButton();
1071
sadrul522f2ec82016-07-19 22:38:441072 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
bruthigca2e1492014-09-12 23:48:061073}
1074
1075// Tests that a lock action is not cancellable when quick lock is turned on and
1076// maximize mode is active.
1077TEST_F(LockStateControllerTest, QuickLockWhileInMaximizeMode) {
skye79274a2016-06-08 05:39:021078 Initialize(false, LoginStatus::USER);
bruthigca2e1492014-09-12 23:48:061079 power_button_controller_->set_enable_quick_lock_for_test(true);
1080 EnableMaximizeMode(true);
1081
1082 PressPowerButton();
1083
1084 ExpectPreLockAnimationStarted();
1085 EXPECT_TRUE(test_api_->is_animating_lock());
1086 EXPECT_FALSE(lock_state_controller_->CanCancelLockAnimation());
1087
1088 ReleasePowerButton();
1089
1090 ExpectPreLockAnimationStarted();
1091
1092 test_animator_->CompleteAllAnimations(true);
sadrul522f2ec82016-07-19 22:38:441093 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
bruthigca2e1492014-09-12 23:48:061094}
1095
[email protected]882237512012-11-26 22:29:071096} // namespace test
1097} // namespace ash