blob: d77ec9963f46523ac946518806f7ede92e066fcd [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"
jamescookd9f152f2016-11-15 00:53:0811#include "ash/common/shutdown_controller.h"
sky1593c7bf2016-10-07 21:07:5312#include "ash/common/test/test_session_state_delegate.h"
skye2bde2172016-07-01 18:27:0213#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
mswbc0a8b482016-06-30 02:21:1414#include "ash/common/wm_shell.h"
[email protected]882237512012-11-26 22:29:0715#include "ash/shell.h"
16#include "ash/test/ash_test_base.h"
erg8f7f2a62016-11-03 00:20:2017#include "ash/test/lock_state_controller_test_api.h"
bruthigca2e1492014-09-12 23:48:0618#include "ash/test/test_screenshot_delegate.h"
19#include "ash/test/test_session_state_animator.h"
[email protected]882237512012-11-26 22:29:0720#include "ash/test/test_shell_delegate.h"
[email protected]882237512012-11-26 22:29:0721#include "ash/wm/power_button_controller.h"
22#include "ash/wm/session_state_animator.h"
fdorayba121422016-12-23 19:51:4823#include "base/memory/ptr_util.h"
bruthigca2e1492014-09-12 23:48:0624#include "base/memory/scoped_vector.h"
[email protected]1e84c632013-06-27 23:12:2125#include "base/time/time.h"
sadrul522f2ec82016-07-19 22:38:4426#include "chromeos/dbus/dbus_thread_manager.h"
27#include "chromeos/dbus/fake_session_manager_client.h"
kylecharc354dd22016-10-24 21:03:5628#include "ui/display/fake_display_snapshot.h"
kylechar731f85f92016-12-01 20:50:4629#include "ui/display/manager/chromeos/display_configurator.h"
[email protected]44ab9f52014-04-15 16:26:5330#include "ui/display/types/display_constants.h"
sadrul522f2ec82016-07-19 22:38:4431#include "ui/events/test/event_generator.h"
32#include "ui/gfx/geometry/size.h"
[email protected]685442f32014-02-28 10:40:0633
[email protected]882237512012-11-26 22:29:0734namespace ash {
35namespace test {
36namespace {
[email protected]72e8d4e2012-12-17 15:02:3337
[email protected]882237512012-11-26 22:29:0738bool cursor_visible() {
mswbc0a8b482016-06-30 02:21:1439 return Shell::GetInstance()->cursor_manager()->IsCursorVisible();
[email protected]882237512012-11-26 22:29:0740}
41
42void CheckCalledCallback(bool* flag) {
[email protected]72e8d4e2012-12-17 15:02:3343 if (flag)
44 (*flag) = true;
[email protected]882237512012-11-26 22:29:0745}
[email protected]72e8d4e2012-12-17 15:02:3346
jamescookd9f152f2016-11-15 00:53:0847// ShutdownController that tracks how many shutdown requests have been made.
48class 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
bruthigca2e1492014-09-12 23:48:0664} // namespace
[email protected]72e8d4e2012-12-17 15:02:3365
[email protected]cafaeca2013-10-01 21:08:3266class LockStateControllerTest : public AshTestBase {
[email protected]882237512012-11-26 22:29:0767 public:
jamescookb8dcef522016-06-25 14:42:5568 LockStateControllerTest()
sadrul522f2ec82016-07-19 22:38:4469 : power_button_controller_(nullptr),
70 lock_state_controller_(nullptr),
sadrul522f2ec82016-07-19 22:38:4471 session_manager_client_(nullptr),
72 test_animator_(nullptr) {}
dcheng28401c22014-10-28 01:26:1973 ~LockStateControllerTest() override {}
[email protected]882237512012-11-26 22:29:0774
dcheng28401c22014-10-28 01:26:1975 void SetUp() override {
sadrul522f2ec82016-07-19 22:38:4476 session_manager_client_ = new chromeos::FakeSessionManagerClient;
77 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
78 base::WrapUnique(session_manager_client_));
[email protected]882237512012-11-26 22:29:0779 AshTestBase::SetUp();
[email protected]72e8d4e2012-12-17 15:02:3380
bruthigca2e1492014-09-12 23:48:0681 test_animator_ = new TestSessionStateAnimator;
[email protected]72e8d4e2012-12-17 15:02:3382
bruthigca2e1492014-09-12 23:48:0683 lock_state_controller_ = Shell::GetInstance()->lock_state_controller();
bruthigca2e1492014-09-12 23:48:0684 lock_state_controller_->set_animator_for_test(test_animator_);
[email protected]76e52aad2012-12-20 18:34:1385
erg8f7f2a62016-11-03 00:20:2086 test_api_.reset(new LockStateControllerTestApi(lock_state_controller_));
jamescookd9f152f2016-11-15 00:53:0887 test_api_->set_shutdown_controller(&test_shutdown_controller_);
bruthigca2e1492014-09-12 23:48:0688
89 power_button_controller_ = Shell::GetInstance()->power_button_controller();
bruthigca2e1492014-09-12 23:48:0690
mswbc0a8b482016-06-30 02:21:1491 shell_delegate_ =
msw0414d4122016-07-06 22:58:4892 static_cast<TestShellDelegate*>(WmShell::Get()->delegate());
[email protected]72e8d4e2012-12-17 15:02:3393 }
94
sadrul522f2ec82016-07-19 22:38:4495 void TearDown() override {
96 AshTestBase::TearDown();
97 chromeos::DBusThreadManager::Shutdown();
98 }
99
[email protected]882237512012-11-26 22:29:07100 protected:
101 void GenerateMouseMoveEvent() {
[email protected]73c9fd02014-07-28 01:48:52102 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
[email protected]882237512012-11-26 22:29:07103 generator.MoveMouseTo(10, 10);
104 }
105
106 int NumShutdownRequests() {
jamescookd9f152f2016-11-15 00:53:08107 return test_shutdown_controller_.num_shutdown_requests() +
jamescookb8dcef522016-06-25 14:42:55108 shell_delegate_->num_exit_requests();
[email protected]882237512012-11-26 22:29:07109 }
110
[email protected]72e8d4e2012-12-17 15:02:33111 void Advance(SessionStateAnimator::AnimationSpeed speed) {
bruthigca2e1492014-09-12 23:48:06112 test_animator_->Advance(test_animator_->GetDuration(speed));
[email protected]72e8d4e2012-12-17 15:02:33113 }
114
115 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed,
116 float factor) {
bruthigca2e1492014-09-12 23:48:06117 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]72e8d4e2012-12-17 15:02:33121 }
122
123 void ExpectPreLockAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06124 SCOPED_TRACE("Failure in ExpectPreLockAnimationStarted");
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));
132 EXPECT_TRUE(test_animator_->AreContainersAnimated(
133 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
134 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
[email protected]72e8d4e2012-12-17 15:02:33135 EXPECT_TRUE(test_api_->is_animating_lock());
136 }
137
bruthigca2e1492014-09-12 23:48:06138 void ExpectPreLockAnimationRunning() {
139 SCOPED_TRACE("Failure in ExpectPreLockAnimationRunning");
140 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55141 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));
bruthigca2e1492014-09-12 23:48:06147 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());
jamescookb8dcef522016-06-25 14:42:55153 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]72e8d4e2012-12-17 15:02:33159 }
160
161 void ExpectPreLockAnimationFinished() {
bruthigca2e1492014-09-12 23:48:06162 SCOPED_TRACE("Failure in ExpectPreLockAnimationFinished");
jamescookb8dcef522016-06-25 14:42:55163 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]72e8d4e2012-12-17 15:02:33172 }
173
174 void ExpectPostLockAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06175 SCOPED_TRACE("Failure in ExpectPostLockAnimationStarted");
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_RAISE_TO_SCREEN));
[email protected]72e8d4e2012-12-17 15:02:33180 }
181
bruthigca2e1492014-09-12 23:48:06182 void ExpectPostLockAnimationFinished() {
183 SCOPED_TRACE("Failure in ExpectPostLockAnimationFinished");
jamescookb8dcef522016-06-25 14:42:55184 EXPECT_FALSE(test_animator_->AreContainersAnimated(
185 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
186 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN));
[email protected]72e8d4e2012-12-17 15:02:33187 }
188
189 void ExpectUnlockBeforeUIDestroyedAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06190 SCOPED_TRACE("Failure in ExpectUnlockBeforeUIDestroyedAnimationStarted");
191 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55192 EXPECT_TRUE(test_animator_->AreContainersAnimated(
193 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
194 SessionStateAnimator::ANIMATION_LIFT));
[email protected]72e8d4e2012-12-17 15:02:33195 }
196
197 void ExpectUnlockBeforeUIDestroyedAnimationFinished() {
bruthigca2e1492014-09-12 23:48:06198 SCOPED_TRACE("Failure in ExpectUnlockBeforeUIDestroyedAnimationFinished");
jamescookb8dcef522016-06-25 14:42:55199 EXPECT_FALSE(test_animator_->AreContainersAnimated(
200 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
201 SessionStateAnimator::ANIMATION_LIFT));
[email protected]72e8d4e2012-12-17 15:02:33202 }
203
204 void ExpectUnlockAfterUIDestroyedAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06205 SCOPED_TRACE("Failure in ExpectUnlockAfterUIDestroyedAnimationStarted");
206 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55207 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]72e8d4e2012-12-17 15:02:33213 }
214
215 void ExpectUnlockAfterUIDestroyedAnimationFinished() {
bruthigca2e1492014-09-12 23:48:06216 SCOPED_TRACE("Failure in ExpectUnlockAfterUIDestroyedAnimationFinished");
217 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55218 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]72e8d4e2012-12-17 15:02:33224 }
225
226 void ExpectShutdownAnimationStarted() {
bruthigca2e1492014-09-12 23:48:06227 SCOPED_TRACE("Failure in ExpectShutdownAnimationStarted");
228 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55229 EXPECT_TRUE(test_animator_->AreContainersAnimated(
230 SessionStateAnimator::ROOT_CONTAINER,
231 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
[email protected]72e8d4e2012-12-17 15:02:33232 }
233
bruthigca2e1492014-09-12 23:48:06234 void ExpectShutdownAnimationFinished() {
235 SCOPED_TRACE("Failure in ExpectShutdownAnimationFinished");
236 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55237 EXPECT_FALSE(test_animator_->AreContainersAnimated(
238 SessionStateAnimator::ROOT_CONTAINER,
239 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
[email protected]72e8d4e2012-12-17 15:02:33240 }
241
242 void ExpectShutdownAnimationCancel() {
bruthigca2e1492014-09-12 23:48:06243 SCOPED_TRACE("Failure in ExpectShutdownAnimationCancel");
244 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55245 EXPECT_TRUE(test_animator_->AreContainersAnimated(
246 SessionStateAnimator::ROOT_CONTAINER,
247 SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS));
[email protected]72e8d4e2012-12-17 15:02:33248 }
249
msw607227f82016-08-30 17:22:39250 void ExpectWallpaperIsShowing() {
251 SCOPED_TRACE("Failure in ExpectWallpaperIsShowing");
bruthigca2e1492014-09-12 23:48:06252 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55253 EXPECT_TRUE(test_animator_->AreContainersAnimated(
msw607227f82016-08-30 17:22:39254 SessionStateAnimator::WALLPAPER,
jamescookb8dcef522016-06-25 14:42:55255 SessionStateAnimator::ANIMATION_FADE_IN));
[email protected]72e8d4e2012-12-17 15:02:33256 }
257
msw607227f82016-08-30 17:22:39258 void ExpectWallpaperIsHiding() {
259 SCOPED_TRACE("Failure in ExpectWallpaperIsHiding");
bruthigca2e1492014-09-12 23:48:06260 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55261 EXPECT_TRUE(test_animator_->AreContainersAnimated(
msw607227f82016-08-30 17:22:39262 SessionStateAnimator::WALLPAPER,
jamescookb8dcef522016-06-25 14:42:55263 SessionStateAnimator::ANIMATION_FADE_OUT));
[email protected]72e8d4e2012-12-17 15:02:33264 }
265
msw607227f82016-08-30 17:22:39266 void ExpectRestoringWallpaperVisibility() {
267 SCOPED_TRACE("Failure in ExpectRestoringWallpaperVisibility");
bruthigca2e1492014-09-12 23:48:06268 EXPECT_LT(0u, test_animator_->GetAnimationCount());
jamescookb8dcef522016-06-25 14:42:55269 EXPECT_TRUE(test_animator_->AreContainersAnimated(
msw607227f82016-08-30 17:22:39270 SessionStateAnimator::WALLPAPER,
jamescookb8dcef522016-06-25 14:42:55271 SessionStateAnimator::ANIMATION_FADE_IN));
bruthigca2e1492014-09-12 23:48:06272 }
273
[email protected]72e8d4e2012-12-17 15:02:33274 void ExpectUnlockedState() {
bruthigca2e1492014-09-12 23:48:06275 SCOPED_TRACE("Failure in ExpectUnlockedState");
276 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
mswbc0a8b482016-06-30 02:21:14277 EXPECT_FALSE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked());
[email protected]72e8d4e2012-12-17 15:02:33278 }
279
280 void ExpectLockedState() {
bruthigca2e1492014-09-12 23:48:06281 SCOPED_TRACE("Failure in ExpectLockedState");
282 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
mswbc0a8b482016-06-30 02:21:14283 EXPECT_TRUE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked());
bruthigca2e1492014-09-12 23:48:06284 }
[email protected]72e8d4e2012-12-17 15:02:33285
msw607227f82016-08-30 17:22:39286 void HideWallpaper() { test_animator_->HideWallpaper(); }
[email protected]72e8d4e2012-12-17 15:02:33287
288 void PressPowerButton() {
bruthigca2e1492014-09-12 23:48:06289 power_button_controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
[email protected]72e8d4e2012-12-17 15:02:33290 }
291
292 void ReleasePowerButton() {
bruthigca2e1492014-09-12 23:48:06293 power_button_controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
[email protected]72e8d4e2012-12-17 15:02:33294 }
295
296 void PressLockButton() {
bruthigca2e1492014-09-12 23:48:06297 power_button_controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
[email protected]72e8d4e2012-12-17 15:02:33298 }
299
300 void ReleaseLockButton() {
bruthigca2e1492014-09-12 23:48:06301 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]72e8d4e2012-12-17 15:02:33310 }
311
312 void SystemLocks() {
[email protected]ab4f8c92013-05-30 19:07:47313 lock_state_controller_->OnLockStateChanged(true);
mswbc0a8b482016-06-30 02:21:14314 WmShell::Get()->GetSessionStateDelegate()->LockScreen();
[email protected]72e8d4e2012-12-17 15:02:33315 }
316
317 void SuccessfulAuthentication(bool* call_flag) {
318 base::Closure closure = base::Bind(&CheckCalledCallback, call_flag);
[email protected]ab4f8c92013-05-30 19:07:47319 lock_state_controller_->OnLockScreenHide(closure);
[email protected]72e8d4e2012-12-17 15:02:33320 }
321
322 void SystemUnlocks() {
[email protected]ab4f8c92013-05-30 19:07:47323 lock_state_controller_->OnLockStateChanged(false);
mswbc0a8b482016-06-30 02:21:14324 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen();
bruthigca2e1492014-09-12 23:48:06325 }
326
327 void EnableMaximizeMode(bool enable) {
skyc68696c2016-07-01 21:06:02328 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
329 enable);
[email protected]72e8d4e2012-12-17 15:02:33330 }
331
skye79274a2016-06-08 05:39:02332 void Initialize(bool legacy_button, LoginStatus status) {
bruthigca2e1492014-09-12 23:48:06333 power_button_controller_->set_has_legacy_power_button_for_test(
334 legacy_button);
[email protected]ab4f8c92013-05-30 19:07:47335 lock_state_controller_->OnLoginStateChanged(status);
skye79274a2016-06-08 05:39:02336 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN);
337 if (status == LoginStatus::GUEST)
sky8335eed2016-10-06 23:25:09338 TestSessionStateDelegate::SetCanLockScreen(false);
[email protected]ab4f8c92013-05-30 19:07:47339 lock_state_controller_->OnLockStateChanged(false);
[email protected]72e8d4e2012-12-17 15:02:33340 }
341
bruthigca2e1492014-09-12 23:48:06342 PowerButtonController* power_button_controller_; // not owned
jamescookb8dcef522016-06-25 14:42:55343 LockStateController* lock_state_controller_; // not owned
jamescookd9f152f2016-11-15 00:53:08344 TestShutdownController test_shutdown_controller_;
sadrul522f2ec82016-07-19 22:38:44345 // Ownership is passed on to chromeos::DBusThreadManager.
346 chromeos::FakeSessionManagerClient* session_manager_client_;
jamescookb8dcef522016-06-25 14:42:55347 TestSessionStateAnimator* test_animator_; // not owned
erg8f7f2a62016-11-03 00:20:20348 std::unique_ptr<LockStateControllerTestApi> test_api_;
bruthigca2e1492014-09-12 23:48:06349 TestShellDelegate* shell_delegate_; // not owned
[email protected]882237512012-11-26 22:29:07350
351 private:
[email protected]cafaeca2013-10-01 21:08:32352 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest);
[email protected]882237512012-11-26 22:29:07353};
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.
bruthigca2e1492014-09-12 23:48:06359TEST_F(LockStateControllerTest, LegacyLockAndShutDown) {
skye79274a2016-06-08 05:39:02360 Initialize(true, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33361
362 ExpectUnlockedState();
[email protected]882237512012-11-26 22:29:07363
364 // We should request that the screen be locked immediately after seeing the
365 // power button get pressed.
[email protected]72e8d4e2012-12-17 15:02:33366 PressPowerButton();
[email protected]882237512012-11-26 22:29:07367
[email protected]72e8d4e2012-12-17 15:02:33368 EXPECT_FALSE(test_api_->is_lock_cancellable());
369
bruthigca2e1492014-09-12 23:48:06370 ExpectPreLockAnimationStarted();
371 test_animator_->CompleteAllAnimations(true);
[email protected]72e8d4e2012-12-17 15:02:33372 ExpectPreLockAnimationFinished();
bruthigca2e1492014-09-12 23:48:06373
sadrul522f2ec82016-07-19 22:38:44374 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07375
376 // Notify that we locked successfully.
[email protected]ab4f8c92013-05-30 19:07:47377 lock_state_controller_->OnStartingLock();
bruthigca2e1492014-09-12 23:48:06378 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
[email protected]882237512012-11-26 22:29:07379
[email protected]72e8d4e2012-12-17 15:02:33380 SystemLocks();
[email protected]882237512012-11-26 22:29:07381
[email protected]72e8d4e2012-12-17 15:02:33382 ExpectPostLockAnimationStarted();
bruthigca2e1492014-09-12 23:48:06383 test_animator_->CompleteAllAnimations(true);
384 ExpectPostLockAnimationFinished();
[email protected]882237512012-11-26 22:29:07385
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]72e8d4e2012-12-17 15:02:33389
390 ReleasePowerButton();
[email protected]882237512012-11-26 22:29:07391
392 // Hold the button again and check that we start shutting down.
[email protected]72e8d4e2012-12-17 15:02:33393 PressPowerButton();
[email protected]882237512012-11-26 22:29:07394
[email protected]72e8d4e2012-12-17 15:02:33395 ExpectShutdownAnimationStarted();
396
397 EXPECT_EQ(0, NumShutdownRequests());
[email protected]882237512012-11-26 22:29:07398 // Make sure a mouse move event won't show the cursor.
399 GenerateMouseMoveEvent();
400 EXPECT_FALSE(cursor_visible());
[email protected]72e8d4e2012-12-17 15:02:33401
[email protected]882237512012-11-26 22:29:07402 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]cafaeca2013-10-01 21:08:32409TEST_F(LockStateControllerTest, LegacyNotLoggedIn) {
skye79274a2016-06-08 05:39:02410 Initialize(true, LoginStatus::NOT_LOGGED_IN);
[email protected]72e8d4e2012-12-17 15:02:33411
412 PressPowerButton();
413 ExpectShutdownAnimationStarted();
414
[email protected]882237512012-11-26 22:29:07415 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]cafaeca2013-10-01 21:08:32420TEST_F(LockStateControllerTest, LegacyGuest) {
skye79274a2016-06-08 05:39:02421 Initialize(true, LoginStatus::GUEST);
[email protected]72e8d4e2012-12-17 15:02:33422
423 PressPowerButton();
424 ExpectShutdownAnimationStarted();
425
[email protected]882237512012-11-26 22:29:07426 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]cafaeca2013-10-01 21:08:32431TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) {
skye79274a2016-06-08 05:39:02432 Initialize(false, LoginStatus::NOT_LOGGED_IN);
[email protected]882237512012-11-26 22:29:07433
434 // Press the power button and check that we start the shutdown timer.
[email protected]72e8d4e2012-12-17 15:02:33435 PressPowerButton();
436 EXPECT_FALSE(test_api_->is_animating_lock());
[email protected]882237512012-11-26 22:29:07437 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33438 ExpectShutdownAnimationStarted();
439
440 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
[email protected]882237512012-11-26 22:29:07441
442 // Release the power button before the shutdown timer fires.
[email protected]72e8d4e2012-12-17 15:02:33443 ReleasePowerButton();
444
[email protected]882237512012-11-26 22:29:07445 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33446 ExpectShutdownAnimationCancel();
447
448 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_REVERT, 0.5f);
[email protected]882237512012-11-26 22:29:07449
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]72e8d4e2012-12-17 15:02:33452 PressPowerButton();
453
[email protected]882237512012-11-26 22:29:07454 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33455
456 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
457 ExpectShutdownAnimationFinished();
[email protected]882237512012-11-26 22:29:07458 test_api_->trigger_shutdown_timeout();
[email protected]72e8d4e2012-12-17 15:02:33459
[email protected]882237512012-11-26 22:29:07460 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
461 EXPECT_EQ(0, NumShutdownRequests());
[email protected]882237512012-11-26 22:29:07462
463 // When the timout fires, we should request a shutdown.
464 test_api_->trigger_real_shutdown_timeout();
[email protected]72e8d4e2012-12-17 15:02:33465
[email protected]882237512012-11-26 22:29:07466 EXPECT_EQ(1, NumShutdownRequests());
467}
468
469// Test that we lock the screen and deal with unlocking correctly.
bruthigca2e1492014-09-12 23:48:06470TEST_F(LockStateControllerTest, LockAndUnlock) {
skye79274a2016-06-08 05:39:02471 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07472
[email protected]72e8d4e2012-12-17 15:02:33473 ExpectUnlockedState();
[email protected]882237512012-11-26 22:29:07474
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]72e8d4e2012-12-17 15:02:33477 PressPowerButton();
[email protected]882237512012-11-26 22:29:07478
[email protected]72e8d4e2012-12-17 15:02:33479 ExpectPreLockAnimationStarted();
480 EXPECT_TRUE(test_api_->is_lock_cancellable());
sadrul522f2ec82016-07-19 22:38:44481 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]72e8d4e2012-12-17 15:02:33482
bruthigca2e1492014-09-12 23:48:06483 test_animator_->CompleteAllAnimations(true);
[email protected]72e8d4e2012-12-17 15:02:33484 ExpectPreLockAnimationFinished();
485
sadrul522f2ec82016-07-19 22:38:44486 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07487
488 // Notify that we locked successfully.
[email protected]ab4f8c92013-05-30 19:07:47489 lock_state_controller_->OnStartingLock();
[email protected]72e8d4e2012-12-17 15:02:33490 // We had that animation already.
bruthigca2e1492014-09-12 23:48:06491 EXPECT_EQ(0u, test_animator_->GetAnimationCount());
[email protected]882237512012-11-26 22:29:07492
[email protected]72e8d4e2012-12-17 15:02:33493 SystemLocks();
494
495 ExpectPostLockAnimationStarted();
bruthigca2e1492014-09-12 23:48:06496 test_animator_->CompleteAllAnimations(true);
497 ExpectPostLockAnimationFinished();
[email protected]882237512012-11-26 22:29:07498
499 // When we release the power button, the lock-to-shutdown timer should be
500 // stopped.
[email protected]72e8d4e2012-12-17 15:02:33501 ExpectLockedState();
[email protected]882237512012-11-26 22:29:07502 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33503 ReleasePowerButton();
504 ExpectLockedState();
[email protected]882237512012-11-26 22:29:07505 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]882237512012-11-26 22:29:07509 bool called = false;
[email protected]72e8d4e2012-12-17 15:02:33510 SuccessfulAuthentication(&called);
511
512 ExpectUnlockBeforeUIDestroyedAnimationStarted();
513 EXPECT_FALSE(called);
bruthigca2e1492014-09-12 23:48:06514 test_animator_->CompleteAllAnimations(true);
[email protected]72e8d4e2012-12-17 15:02:33515 ExpectUnlockBeforeUIDestroyedAnimationFinished();
516
[email protected]882237512012-11-26 22:29:07517 EXPECT_TRUE(called);
[email protected]72e8d4e2012-12-17 15:02:33518
519 SystemUnlocks();
520
521 ExpectUnlockAfterUIDestroyedAnimationStarted();
bruthigca2e1492014-09-12 23:48:06522 test_animator_->CompleteAllAnimations(true);
[email protected]72e8d4e2012-12-17 15:02:33523 ExpectUnlockAfterUIDestroyedAnimationFinished();
524
525 ExpectUnlockedState();
526}
527
528// Test that we deal with cancelling lock correctly.
bruthigca2e1492014-09-12 23:48:06529TEST_F(LockStateControllerTest, LockAndCancel) {
skye79274a2016-06-08 05:39:02530 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33531
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]72e8d4e2012-12-17 15:02:33544 // Release the button before the lock timer fires.
545 ReleasePowerButton();
546
547 ExpectPreLockAnimationCancel();
548
[email protected]72e8d4e2012-12-17 15:02:33549 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
550 ExpectUnlockedState();
sadrul522f2ec82016-07-19 22:38:44551 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]72e8d4e2012-12-17 15:02:33552}
553
554// Test that we deal with cancelling lock correctly.
bruthigca2e1492014-09-12 23:48:06555TEST_F(LockStateControllerTest, LockAndCancelAndLockAgain) {
skye79274a2016-06-08 05:39:02556 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33557
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
bruthigca2e1492014-09-12 23:48:06574 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS,
575 0.5f);
[email protected]72e8d4e2012-12-17 15:02:33576
577 PressPowerButton();
578 ExpectPreLockAnimationStarted();
579 EXPECT_TRUE(test_api_->is_lock_cancellable());
580
581 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
582
sadrul522f2ec82016-07-19 22:38:44583 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]72e8d4e2012-12-17 15:02:33584
585 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
586 ExpectPreLockAnimationFinished();
sadrul522f2ec82016-07-19 22:38:44587 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07588}
589
590// Hold the power button down from the unlocked state to eventual shutdown.
bruthigca2e1492014-09-12 23:48:06591TEST_F(LockStateControllerTest, LockToShutdown) {
skye79274a2016-06-08 05:39:02592 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07593
594 // Hold the power button and lock the screen.
[email protected]72e8d4e2012-12-17 15:02:33595 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]882237512012-11-26 22:29:07601
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]72e8d4e2012-12-17 15:02:33605
[email protected]882237512012-11-26 22:29:07606 test_api_->trigger_lock_to_shutdown_timeout();
[email protected]72e8d4e2012-12-17 15:02:33607
608 ExpectShutdownAnimationStarted();
[email protected]882237512012-11-26 22:29:07609 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
[email protected]882237512012-11-26 22:29:07610
611 // Fire the shutdown timeout and check that we request shutdown.
[email protected]72e8d4e2012-12-17 15:02:33612 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
613 ExpectShutdownAnimationFinished();
[email protected]882237512012-11-26 22:29:07614 test_api_->trigger_shutdown_timeout();
[email protected]72e8d4e2012-12-17 15:02:33615
[email protected]882237512012-11-26 22:29:07616 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]882237512012-11-26 22:29:07622// Hold the power button down from the unlocked state to eventual shutdown,
623// then release the button while system does locking.
[email protected]cafaeca2013-10-01 21:08:32624TEST_F(LockStateControllerTest, CancelLockToShutdown) {
skye79274a2016-06-08 05:39:02625 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07626
[email protected]72e8d4e2012-12-17 15:02:33627 PressPowerButton();
[email protected]882237512012-11-26 22:29:07628
629 // Hold the power button and lock the screen.
[email protected]72e8d4e2012-12-17 15:02:33630 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]882237512012-11-26 22:29:07635
636 // Power button is released while system attempts to lock.
[email protected]72e8d4e2012-12-17 15:02:33637 ReleasePowerButton();
638
639 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
[email protected]882237512012-11-26 22:29:07640
[email protected]ab4f8c92013-05-30 19:07:47641 EXPECT_FALSE(lock_state_controller_->ShutdownRequested());
[email protected]882237512012-11-26 22:29:07642 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
643 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
644}
645
[email protected]882237512012-11-26 22:29:07646// Test that we handle the case where lock requests are ignored.
bruthigca2e1492014-09-12 23:48:06647TEST_F(LockStateControllerTest, Lock) {
skye79274a2016-06-08 05:39:02648 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07649
650 // Hold the power button and lock the screen.
[email protected]72e8d4e2012-12-17 15:02:33651 PressPowerButton();
652 ExpectPreLockAnimationStarted();
653
654 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
655
sadrul522f2ec82016-07-19 22:38:44656 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07657 EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
[email protected]882237512012-11-26 22:29:07658 // We shouldn't start the lock-to-shutdown timer until the screen has actually
[email protected]72e8d4e2012-12-17 15:02:33659 // been locked and this was animated.
[email protected]882237512012-11-26 22:29:07660 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
661
bruthigca2e1492014-09-12 23:48:06662 // Act as if the request timed out.
663 EXPECT_DEATH(test_api_->trigger_lock_fail_timeout(), "");
[email protected]72e8d4e2012-12-17 15:02:33664}
[email protected]72e8d4e2012-12-17 15:02:33665
666// Test the basic operation of the lock button (not logged in).
[email protected]cafaeca2013-10-01 21:08:32667TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) {
[email protected]72e8d4e2012-12-17 15:02:33668 // The lock button shouldn't do anything if we aren't logged in.
skye79274a2016-06-08 05:39:02669 Initialize(false, LoginStatus::NOT_LOGGED_IN);
[email protected]72e8d4e2012-12-17 15:02:33670
671 PressLockButton();
672 EXPECT_FALSE(test_api_->is_animating_lock());
673 ReleaseLockButton();
sadrul522f2ec82016-07-19 22:38:44674 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]72e8d4e2012-12-17 15:02:33675}
676
677// Test the basic operation of the lock button (guest).
[email protected]cafaeca2013-10-01 21:08:32678TEST_F(LockStateControllerTest, LockButtonBasicGuest) {
[email protected]72e8d4e2012-12-17 15:02:33679 // The lock button shouldn't do anything when we're logged in as a guest.
skye79274a2016-06-08 05:39:02680 Initialize(false, LoginStatus::GUEST);
[email protected]72e8d4e2012-12-17 15:02:33681
682 PressLockButton();
683 EXPECT_FALSE(test_api_->is_animating_lock());
684 ReleaseLockButton();
sadrul522f2ec82016-07-19 22:38:44685 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07686}
687
688// Test the basic operation of the lock button.
bruthigca2e1492014-09-12 23:48:06689TEST_F(LockStateControllerTest, LockButtonBasic) {
[email protected]882237512012-11-26 22:29:07690 // If we're logged in as a regular user, we should start the lock timer and
691 // the pre-lock animation.
skye79274a2016-06-08 05:39:02692 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33693
694 PressLockButton();
695 ExpectPreLockAnimationStarted();
696 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
[email protected]882237512012-11-26 22:29:07697
698 // If the button is released immediately, we shouldn't lock the screen.
[email protected]72e8d4e2012-12-17 15:02:33699 ReleaseLockButton();
700 ExpectPreLockAnimationCancel();
701 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
702
703 ExpectUnlockedState();
sadrul522f2ec82016-07-19 22:38:44704 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07705
706 // Press the button again and let the lock timeout fire. We should request
707 // that the screen be locked.
[email protected]72e8d4e2012-12-17 15:02:33708 PressLockButton();
709 ExpectPreLockAnimationStarted();
710 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
sadrul522f2ec82016-07-19 22:38:44711 EXPECT_EQ(1, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07712
713 // Pressing the lock button while we have a pending lock request shouldn't do
714 // anything.
[email protected]72e8d4e2012-12-17 15:02:33715 ReleaseLockButton();
716 PressLockButton();
717 ExpectPreLockAnimationFinished();
718 ReleaseLockButton();
[email protected]882237512012-11-26 22:29:07719
720 // Pressing the button also shouldn't do anything after the screen is locked.
[email protected]72e8d4e2012-12-17 15:02:33721 SystemLocks();
722 ExpectPostLockAnimationStarted();
723
724 PressLockButton();
725 ReleaseLockButton();
726 ExpectPostLockAnimationStarted();
727
728 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
bruthigca2e1492014-09-12 23:48:06729 ExpectPostLockAnimationFinished();
[email protected]72e8d4e2012-12-17 15:02:33730
731 PressLockButton();
732 ReleaseLockButton();
bruthigca2e1492014-09-12 23:48:06733 ExpectPostLockAnimationFinished();
[email protected]882237512012-11-26 22:29:07734}
735
736// Test that the power button takes priority over the lock button.
bruthigca2e1492014-09-12 23:48:06737TEST_F(LockStateControllerTest, PowerButtonPreemptsLockButton) {
skye79274a2016-06-08 05:39:02738 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07739
740 // While the lock button is down, hold the power button.
[email protected]72e8d4e2012-12-17 15:02:33741 PressLockButton();
742 ExpectPreLockAnimationStarted();
[email protected]72e8d4e2012-12-17 15:02:33743
bruthigca2e1492014-09-12 23:48:06744 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]882237512012-11-26 22:29:07752
753 // The lock timer shouldn't be stopped when the lock button is released.
[email protected]72e8d4e2012-12-17 15:02:33754 ReleaseLockButton();
bruthigca2e1492014-09-12 23:48:06755 ExpectPreLockAnimationRunning();
756
[email protected]72e8d4e2012-12-17 15:02:33757 ReleasePowerButton();
758 ExpectPreLockAnimationCancel();
759
760 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
761 ExpectUnlockedState();
[email protected]882237512012-11-26 22:29:07762
763 // Now press the power button first and then the lock button.
[email protected]72e8d4e2012-12-17 15:02:33764 PressPowerButton();
765 ExpectPreLockAnimationStarted();
[email protected]72e8d4e2012-12-17 15:02:33766
bruthigca2e1492014-09-12 23:48:06767 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
768
769 PressLockButton();
770 ExpectPreLockAnimationRunning();
771
772 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
[email protected]882237512012-11-26 22:29:07773
774 // Releasing the power button should stop the lock timer.
[email protected]72e8d4e2012-12-17 15:02:33775 ReleasePowerButton();
776 ExpectPreLockAnimationCancel();
bruthigca2e1492014-09-12 23:48:06777
778 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
779
[email protected]72e8d4e2012-12-17 15:02:33780 ReleaseLockButton();
781 ExpectPreLockAnimationCancel();
[email protected]882237512012-11-26 22:29:07782}
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]cafaeca2013-10-01 21:08:32787TEST_F(LockStateControllerTest, LockWithoutButton) {
skye79274a2016-06-08 05:39:02788 Initialize(false, LoginStatus::USER);
[email protected]ab4f8c92013-05-30 19:07:47789 lock_state_controller_->OnStartingLock();
[email protected]72e8d4e2012-12-17 15:02:33790
791 ExpectPreLockAnimationStarted();
792 EXPECT_FALSE(test_api_->is_lock_cancellable());
bruthigca2e1492014-09-12 23:48:06793 EXPECT_LT(0u, test_animator_->GetAnimationCount());
[email protected]19c6c4e2013-01-28 16:25:48794
bruthigca2e1492014-09-12 23:48:06795 test_animator_->CompleteAllAnimations(true);
sadrul522f2ec82016-07-19 22:38:44796 EXPECT_EQ(0, session_manager_client_->request_lock_screen_call_count());
[email protected]882237512012-11-26 22:29:07797}
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]cafaeca2013-10-01 21:08:32801TEST_F(LockStateControllerTest, ShutdownWithoutButton) {
skye79274a2016-06-08 05:39:02802 Initialize(false, LoginStatus::USER);
[email protected]ab4f8c92013-05-30 19:07:47803 lock_state_controller_->OnAppTerminating();
[email protected]72e8d4e2012-12-17 15:02:33804
jamescookb8dcef522016-06-25 14:42:55805 EXPECT_TRUE(test_animator_->AreContainersAnimated(
806 SessionStateAnimator::kAllNonRootContainersMask,
807 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
[email protected]882237512012-11-26 22:29:07808 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]cafaeca2013-10-01 21:08:32814TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) {
skye79274a2016-06-08 05:39:02815 Initialize(false, LoginStatus::NOT_LOGGED_IN);
[email protected]72e8d4e2012-12-17 15:02:33816
cschuet7f630ba2015-01-22 13:17:05817 lock_state_controller_->RequestShutdown();
[email protected]72e8d4e2012-12-17 15:02:33818
819 ExpectShutdownAnimationStarted();
820 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
821
[email protected]882237512012-11-26 22:29:07822 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]cafaeca2013-10-01 21:08:32831TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) {
skye79274a2016-06-08 05:39:02832 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33833
834 SystemLocks();
bruthigca2e1492014-09-12 23:48:06835
[email protected]72e8d4e2012-12-17 15:02:33836 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
bruthigca2e1492014-09-12 23:48:06837 ExpectPostLockAnimationFinished();
[email protected]72e8d4e2012-12-17 15:02:33838
cschuet7f630ba2015-01-22 13:17:05839 lock_state_controller_->RequestShutdown();
[email protected]72e8d4e2012-12-17 15:02:33840
841 ExpectShutdownAnimationStarted();
842 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
843
[email protected]882237512012-11-26 22:29:07844 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
bruthigca2e1492014-09-12 23:48:06853TEST_F(LockStateControllerTest, RequestAndCancelShutdownFromLockScreen) {
skye79274a2016-06-08 05:39:02854 Initialize(false, LoginStatus::USER);
[email protected]72e8d4e2012-12-17 15:02:33855
856 SystemLocks();
857 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
858 ExpectLockedState();
[email protected]882237512012-11-26 22:29:07859
860 // Press the power button and check that we start the shutdown timer.
[email protected]72e8d4e2012-12-17 15:02:33861 PressPowerButton();
862 EXPECT_FALSE(test_api_->is_animating_lock());
[email protected]882237512012-11-26 22:29:07863 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33864
865 ExpectShutdownAnimationStarted();
866
867 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
868
[email protected]882237512012-11-26 22:29:07869 // Release the power button before the shutdown timer fires.
[email protected]72e8d4e2012-12-17 15:02:33870 ReleasePowerButton();
871
[email protected]882237512012-11-26 22:29:07872 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
[email protected]72e8d4e2012-12-17 15:02:33873
874 ExpectShutdownAnimationCancel();
875
bruthigca2e1492014-09-12 23:48:06876 Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT_SHUTDOWN);
[email protected]72e8d4e2012-12-17 15:02:33877 ExpectLockedState();
[email protected]882237512012-11-26 22:29:07878}
879
880// Test that we ignore power button presses when the screen is turned off.
[email protected]cafaeca2013-10-01 21:08:32881TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) {
skye79274a2016-06-08 05:39:02882 Initialize(false, LoginStatus::USER);
[email protected]882237512012-11-26 22:29:07883
884 // When the screen brightness is at 0%, we shouldn't do anything in response
885 // to power button presses.
bruthigca2e1492014-09-12 23:48:06886 power_button_controller_->OnScreenBrightnessChanged(0.0);
[email protected]72e8d4e2012-12-17 15:02:33887 PressPowerButton();
888 EXPECT_FALSE(test_api_->is_animating_lock());
889 ReleasePowerButton();
[email protected]882237512012-11-26 22:29:07890
891 // After increasing the brightness to 10%, we should start the timer like
892 // usual.
bruthigca2e1492014-09-12 23:48:06893 power_button_controller_->OnScreenBrightnessChanged(10.0);
[email protected]72e8d4e2012-12-17 15:02:33894 PressPowerButton();
895 EXPECT_TRUE(test_api_->is_animating_lock());
[email protected]685442f32014-02-28 10:40:06896 ReleasePowerButton();
[email protected]72e8d4e2012-12-17 15:02:33897}
898
[email protected]685442f32014-02-28 10:40:06899TEST_F(LockStateControllerTest, HonorPowerButtonInDockedMode) {
900 // Create two outputs, the first internal and the second external.
kylechar7a067ec2017-01-07 01:16:28901 display::DisplayConfigurator::DisplayStateList outputs;
[email protected]71da07e2014-03-18 21:16:04902
kylechar7a067ec2017-01-07 01:16:28903 std::unique_ptr<display::DisplaySnapshot> internal_display =
kylecharc354dd22016-10-24 21:03:56904 display::FakeDisplaySnapshot::Builder()
905 .SetId(123)
906 .SetNativeMode(gfx::Size(1, 1))
kylechar7a067ec2017-01-07 01:16:28907 .SetType(display::DISPLAY_CONNECTION_TYPE_INTERNAL)
kylecharc354dd22016-10-24 21:03:56908 .Build();
909 outputs.push_back(internal_display.get());
910
kylechar7a067ec2017-01-07 01:16:28911 std::unique_ptr<display::DisplaySnapshot> external_display =
kylecharc354dd22016-10-24 21:03:56912 display::FakeDisplaySnapshot::Builder()
913 .SetId(456)
914 .SetNativeMode(gfx::Size(1, 1))
kylechar7a067ec2017-01-07 01:16:28915 .SetType(display::DISPLAY_CONNECTION_TYPE_HDMI)
kylecharc354dd22016-10-24 21:03:56916 .Build();
917 outputs.push_back(external_display.get());
[email protected]685442f32014-02-28 10:40:06918
919 // When all of the displays are turned off (e.g. due to user inactivity), the
920 // power button should be ignored.
bruthigca2e1492014-09-12 23:48:06921 power_button_controller_->OnScreenBrightnessChanged(0.0);
kylecharc354dd22016-10-24 21:03:56922 internal_display->set_current_mode(nullptr);
923 external_display->set_current_mode(nullptr);
bruthigca2e1492014-09-12 23:48:06924 power_button_controller_->OnDisplayModeChanged(outputs);
[email protected]685442f32014-02-28 10:40:06925 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.
kylecharc354dd22016-10-24 21:03:56932 external_display->set_current_mode(external_display->modes().back().get());
bruthigca2e1492014-09-12 23:48:06933 power_button_controller_->OnDisplayModeChanged(outputs);
[email protected]685442f32014-02-28 10:40:06934 PressPowerButton();
935 EXPECT_TRUE(test_api_->is_animating_lock());
936 ReleasePowerButton();
937}
[email protected]685442f32014-02-28 10:40:06938
msw607227f82016-08-30 17:22:39939// Test that hidden wallpaper appears and revers correctly on lock/cancel.
940TEST_F(LockStateControllerTest, TestHiddenWallpaperLockCancel) {
skye79274a2016-06-08 05:39:02941 Initialize(false, LoginStatus::USER);
msw607227f82016-08-30 17:22:39942 HideWallpaper();
[email protected]72e8d4e2012-12-17 15:02:33943
[email protected]72e8d4e2012-12-17 15:02:33944 ExpectUnlockedState();
945 PressPowerButton();
946
947 ExpectPreLockAnimationStarted();
msw607227f82016-08-30 17:22:39948 ExpectWallpaperIsShowing();
[email protected]72e8d4e2012-12-17 15:02:33949
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();
msw607227f82016-08-30 17:22:39956 ExpectWallpaperIsHiding();
[email protected]72e8d4e2012-12-17 15:02:33957
bruthigca2e1492014-09-12 23:48:06958 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS);
959
960 // When the CancelPrelockAnimation sequence finishes it queues up a
msw607227f82016-08-30 17:22:39961 // restore wallpaper visibility sequence when the wallpaper is hidden.
962 ExpectRestoringWallpaperVisibility();
bruthigca2e1492014-09-12 23:48:06963
964 Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
[email protected]72e8d4e2012-12-17 15:02:33965
966 ExpectUnlockedState();
[email protected]72e8d4e2012-12-17 15:02:33967}
968
msw607227f82016-08-30 17:22:39969// Test that hidden wallpaper appears and revers correctly on lock/unlock.
970TEST_F(LockStateControllerTest, TestHiddenWallpaperLockUnlock) {
skye79274a2016-06-08 05:39:02971 Initialize(false, LoginStatus::USER);
msw607227f82016-08-30 17:22:39972 HideWallpaper();
[email protected]72e8d4e2012-12-17 15:02:33973
[email protected]72e8d4e2012-12-17 15:02:33974 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();
msw607227f82016-08-30 17:22:39981 ExpectWallpaperIsShowing();
[email protected]72e8d4e2012-12-17 15:02:33982
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);
bruthigca2e1492014-09-12 23:48:06993 ExpectPostLockAnimationFinished();
[email protected]72e8d4e2012-12-17 15:02:33994
995 ExpectLockedState();
996
997 SuccessfulAuthentication(NULL);
998
999 ExpectUnlockBeforeUIDestroyedAnimationStarted();
1000 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1001 ExpectUnlockBeforeUIDestroyedAnimationFinished();
1002
1003 SystemUnlocks();
1004
1005 ExpectUnlockAfterUIDestroyedAnimationStarted();
msw607227f82016-08-30 17:22:391006 ExpectWallpaperIsHiding();
[email protected]72e8d4e2012-12-17 15:02:331007
1008 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
bruthigca2e1492014-09-12 23:48:061009
1010 // When the StartUnlockAnimationAfterUIDestroyed sequence finishes it queues
msw607227f82016-08-30 17:22:391011 // up a restore wallpaper visibility sequence when the wallpaper is hidden.
1012 ExpectRestoringWallpaperVisibility();
bruthigca2e1492014-09-12 23:48:061013
1014 Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
1015
[email protected]72e8d4e2012-12-17 15:02:331016 ExpectUnlockAfterUIDestroyedAnimationFinished();
[email protected]72e8d4e2012-12-17 15:02:331017
1018 ExpectUnlockedState();
[email protected]882237512012-11-26 22:29:071019}
1020
bruthigca2e1492014-09-12 23:48:061021TEST_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]882237512012-11-26 22:29:071067} // namespace test
1068} // namespace ash