Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: ash/wm/power_button_controller_unittest.cc

Issue 24980006: ash: Remove old lock animation implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge again Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/lock_state_controller_unittest.cc ('k') | ash/wm/session_state_controller_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/ash_switches.h"
6 #include "ash/session_state_delegate.h"
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/test/test_shell_delegate.h"
10 #include "ash/wm/lock_state_controller.h"
11 #include "ash/wm/power_button_controller.h"
12 #include "ash/wm/session_state_animator.h"
13 #include "ash/wm/session_state_controller_impl.h"
14 #include "base/command_line.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/time/time.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/root_window.h"
19 #include "ui/aura/test/event_generator.h"
20 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
21 #include "ui/gfx/rect.h"
22 #include "ui/gfx/size.h"
23
24 namespace ash {
25 namespace test {
26 namespace {
27 bool cursor_visible() {
28 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible();
29 }
30 }
31
32 // Fake implementation of PowerButtonControllerDelegate that just logs requests
33 // to lock the screen and shut down the device.
34 class TestPowerButtonControllerDelegate :
35 public LockStateControllerDelegate {
36 public:
37 TestPowerButtonControllerDelegate()
38 : num_lock_requests_(0),
39 num_shutdown_requests_(0) {}
40
41 int num_lock_requests() const { return num_lock_requests_; }
42 int num_shutdown_requests() const { return num_shutdown_requests_; }
43
44 // PowerButtonControllerDelegate implementation.
45 virtual void RequestLockScreen() OVERRIDE {
46 num_lock_requests_++;
47 }
48 virtual void RequestShutdown() OVERRIDE {
49 num_shutdown_requests_++;
50 }
51
52 private:
53 int num_lock_requests_;
54 int num_shutdown_requests_;
55
56 DISALLOW_COPY_AND_ASSIGN(TestPowerButtonControllerDelegate);
57 };
58
59 class PowerButtonControllerTest : public AshTestBase {
60 public:
61 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {}
62 virtual ~PowerButtonControllerTest() {}
63
64 virtual void SetUp() OVERRIDE {
65 CommandLine::ForCurrentProcess()->AppendSwitch(
66 ash::switches::kAshDisableNewLockAnimations);
67
68 AshTestBase::SetUp();
69 delegate_ = new TestPowerButtonControllerDelegate;
70 controller_ = Shell::GetInstance()->power_button_controller();
71 lock_state_controller_ = static_cast<SessionStateControllerImpl*>(
72 Shell::GetInstance()->lock_state_controller());
73 lock_state_controller_->SetDelegate(delegate_); // transfers ownership
74 test_api_.reset(new SessionStateControllerImpl::TestApi(
75 lock_state_controller_));
76 animator_api_.reset(new internal::SessionStateAnimator::TestApi(
77 lock_state_controller_->animator_.get()));
78 shell_delegate_ = reinterpret_cast<TestShellDelegate*>(
79 ash::Shell::GetInstance()->delegate());
80 state_delegate_ = Shell::GetInstance()->session_state_delegate();
81 }
82
83 protected:
84 void GenerateMouseMoveEvent() {
85 aura::test::EventGenerator generator(
86 Shell::GetPrimaryRootWindow());
87 generator.MoveMouseTo(10, 10);
88 }
89
90 int NumShutdownRequests() {
91 return delegate_->num_shutdown_requests() +
92 shell_delegate_->num_exit_requests();
93 }
94
95 PowerButtonController* controller_; // not owned
96 SessionStateControllerImpl* lock_state_controller_; // not owned
97 TestPowerButtonControllerDelegate* delegate_; // not owned
98 TestShellDelegate* shell_delegate_; // not owned
99 SessionStateDelegate* state_delegate_; // not owned
100
101 scoped_ptr<SessionStateControllerImpl::TestApi> test_api_;
102 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_;
103
104 private:
105 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest);
106 };
107
108 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't
109 // correctly report power button releases. We should lock immediately the first
110 // time the button is pressed and shut down when it's pressed from the locked
111 // state.
112 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) {
113 controller_->set_has_legacy_power_button_for_test(true);
114 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
115 lock_state_controller_->OnLockStateChanged(false);
116
117 // We should request that the screen be locked immediately after seeing the
118 // power button get pressed.
119 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
120 EXPECT_TRUE(
121 animator_api_->ContainersAreAnimated(
122 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
123 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE));
124 EXPECT_FALSE(test_api_->lock_timer_is_running());
125 EXPECT_EQ(1, delegate_->num_lock_requests());
126
127 // Notify that we locked successfully.
128 lock_state_controller_->OnStartingLock();
129 EXPECT_TRUE(
130 animator_api_->ContainersAreAnimated(
131 internal::SessionStateAnimator::LAUNCHER,
132 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
133 EXPECT_TRUE(
134 animator_api_->ContainersAreAnimated(
135 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
136 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE));
137 EXPECT_TRUE(
138 animator_api_->ContainersAreAnimated(
139 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
140 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
141
142 // Notify that the lock window is visible. We should make it fade in.
143 lock_state_controller_->OnLockStateChanged(true);
144 state_delegate_->LockScreen();
145 EXPECT_TRUE(
146 animator_api_->ContainersAreAnimated(
147 internal::SessionStateAnimator::kAllLockScreenContainersMask,
148 internal::SessionStateAnimator::ANIMATION_FADE_IN));
149
150 // We shouldn't progress towards the shutdown state, however.
151 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
152 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
153 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
154
155 // Hold the button again and check that we start shutting down.
156 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
157 EXPECT_EQ(0, NumShutdownRequests());
158
159 // Previously we're checking that the all containers group was animated which
160 // was in fact checking that
161 // 1. All user session containers have transform (including wallpaper).
162 // They're in this state after lock.
163 // 2. Screen locker and related containers are in fact animating
164 // (as shutdown is in progress).
165 // With http://crbug.com/144737 we no longer animate user session wallpaper
166 // during lock so it makes sense only to check that screen lock and related
167 // containers are animated during shutdown.
168 EXPECT_TRUE(
169 animator_api_->ContainersAreAnimated(
170 internal::SessionStateAnimator::kAllLockScreenContainersMask,
171 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE));
172 // Make sure a mouse move event won't show the cursor.
173 GenerateMouseMoveEvent();
174 EXPECT_FALSE(cursor_visible());
175 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
176 test_api_->trigger_real_shutdown_timeout();
177 EXPECT_EQ(1, NumShutdownRequests());
178 }
179
180 // Test that we start shutting down immediately if the power button is pressed
181 // while we're not logged in on an unofficial system.
182 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) {
183 controller_->set_has_legacy_power_button_for_test(true);
184 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
185 lock_state_controller_->OnLockStateChanged(false);
186 SetUserLoggedIn(false);
187 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
188 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
189 }
190
191 // Test that we start shutting down immediately if the power button is pressed
192 // while we're logged in as a guest on an unofficial system.
193 TEST_F(PowerButtonControllerTest, LegacyGuest) {
194 controller_->set_has_legacy_power_button_for_test(true);
195 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST);
196 lock_state_controller_->OnLockStateChanged(false);
197 SetCanLockScreen(false);
198 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
199 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
200 }
201
202 // When we hold the power button while the user isn't logged in, we should shut
203 // down the machine directly.
204 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) {
205 controller_->set_has_legacy_power_button_for_test(false);
206 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
207 lock_state_controller_->OnLockStateChanged(false);
208 SetUserLoggedIn(false);
209
210 // Press the power button and check that we start the shutdown timer.
211 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
212 EXPECT_FALSE(test_api_->lock_timer_is_running());
213 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
214 EXPECT_TRUE(
215 animator_api_->ContainersAreAnimated(
216 internal::SessionStateAnimator::kAllContainersMask,
217 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE));
218
219 // Release the power button before the shutdown timer fires.
220 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
221 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
222 EXPECT_TRUE(
223 animator_api_->ContainersAreAnimated(
224 internal::SessionStateAnimator::kAllContainersMask,
225 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE));
226
227 // Press the button again and make the shutdown timeout fire this time.
228 // Check that we start the timer for actually requesting the shutdown.
229 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
230 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
231 test_api_->trigger_shutdown_timeout();
232 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
233 EXPECT_EQ(0, NumShutdownRequests());
234 EXPECT_TRUE(
235 animator_api_->ContainersAreAnimated(
236 internal::SessionStateAnimator::LAUNCHER |
237 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
238 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
239 EXPECT_TRUE(
240 animator_api_->ContainersAreAnimated(
241 internal::SessionStateAnimator::kAllLockScreenContainersMask,
242 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE));
243
244 // When the timout fires, we should request a shutdown.
245 test_api_->trigger_real_shutdown_timeout();
246 EXPECT_EQ(1, NumShutdownRequests());
247 }
248
249 // Test that we lock the screen and deal with unlocking correctly.
250 TEST_F(PowerButtonControllerTest, LockAndUnlock) {
251 controller_->set_has_legacy_power_button_for_test(false);
252 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
253 lock_state_controller_->OnLockStateChanged(false);
254
255 // We should initially be showing the screen locker containers, since they
256 // also contain login-related windows that we want to show during the
257 // logging-in animation.
258 EXPECT_TRUE(
259 animator_api_->ContainersAreAnimated(
260 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
261 internal::SessionStateAnimator::ANIMATION_RESTORE));
262
263 // Press the power button and check that the lock timer is started and that we
264 // start scaling the non-screen-locker containers.
265 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
266 EXPECT_TRUE(test_api_->lock_timer_is_running());
267 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
268 EXPECT_TRUE(
269 animator_api_->ContainersAreAnimated(
270 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
271 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE));
272
273 // Release the button before the lock timer fires.
274 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
275 EXPECT_FALSE(test_api_->lock_timer_is_running());
276 EXPECT_TRUE(
277 animator_api_->ContainersAreAnimated(
278 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
279 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE));
280
281 // Press the button and fire the lock timer. We should request that the
282 // screen be locked, but we should still be in the slow-close animation.
283 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
284 EXPECT_TRUE(test_api_->lock_timer_is_running());
285 EXPECT_EQ(0, delegate_->num_lock_requests());
286 test_api_->trigger_lock_timeout();
287 EXPECT_EQ(1, delegate_->num_lock_requests());
288 EXPECT_TRUE(
289 animator_api_->ContainersAreAnimated(
290 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
291 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE));
292
293 // Notify that we locked successfully.
294 lock_state_controller_->OnStartingLock();
295 EXPECT_TRUE(
296 animator_api_->ContainersAreAnimated(
297 internal::SessionStateAnimator::LAUNCHER,
298 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
299 EXPECT_TRUE(
300 animator_api_->ContainersAreAnimated(
301 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
302 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE));
303 EXPECT_TRUE(
304 animator_api_->ContainersAreAnimated(
305 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
306 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
307
308 // Notify that the lock window is visible. We should make it fade in.
309 lock_state_controller_->OnLockStateChanged(true);
310 state_delegate_->LockScreen();
311 EXPECT_TRUE(
312 animator_api_->ContainersAreAnimated(
313 internal::SessionStateAnimator::kAllLockScreenContainersMask,
314 internal::SessionStateAnimator::ANIMATION_FADE_IN));
315
316 // When we release the power button, the lock-to-shutdown timer should be
317 // stopped.
318 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
319 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
320 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
321
322 // Notify that the screen has been unlocked. We should show the
323 // non-screen-locker windows.
324 lock_state_controller_->OnLockStateChanged(false);
325 state_delegate_->UnlockScreen();
326 EXPECT_TRUE(
327 animator_api_->ContainersAreAnimated(
328 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
329 internal::SessionStateAnimator::LAUNCHER |
330 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
331 internal::SessionStateAnimator::ANIMATION_RESTORE));
332 }
333
334 // Hold the power button down from the unlocked state to eventual shutdown.
335 TEST_F(PowerButtonControllerTest, LockToShutdown) {
336 controller_->set_has_legacy_power_button_for_test(false);
337 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
338 lock_state_controller_->OnLockStateChanged(false);
339
340 // Hold the power button and lock the screen.
341 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
342 EXPECT_TRUE(test_api_->lock_timer_is_running());
343 test_api_->trigger_lock_timeout();
344 lock_state_controller_->OnStartingLock();
345 lock_state_controller_->OnLockStateChanged(true);
346 state_delegate_->LockScreen();
347
348 // When the lock-to-shutdown timeout fires, we should start the shutdown
349 // timer.
350 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
351 test_api_->trigger_lock_to_shutdown_timeout();
352 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
353 EXPECT_TRUE(
354 animator_api_->ContainersAreAnimated(
355 internal::SessionStateAnimator::kAllContainersMask,
356 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE));
357
358 // Fire the shutdown timeout and check that we request shutdown.
359 test_api_->trigger_shutdown_timeout();
360 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
361 EXPECT_EQ(0, NumShutdownRequests());
362 test_api_->trigger_real_shutdown_timeout();
363 EXPECT_EQ(1, NumShutdownRequests());
364 }
365
366
367 // Hold the power button down from the unlocked state to eventual shutdown,
368 // then release the button while system does locking.
369 TEST_F(PowerButtonControllerTest, CancelLockToShutdown) {
370 controller_->set_has_legacy_power_button_for_test(false);
371
372 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
373 lock_state_controller_->OnLockStateChanged(false);
374
375 // Hold the power button and lock the screen.
376 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
377 EXPECT_TRUE(test_api_->lock_timer_is_running());
378 test_api_->trigger_lock_timeout();
379 lock_state_controller_->OnStartingLock();
380
381 // Power button is released while system attempts to lock.
382 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
383 lock_state_controller_->OnLockStateChanged(true);
384 state_delegate_->LockScreen();
385
386 EXPECT_FALSE(lock_state_controller_->ShutdownRequested());
387 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
388 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
389 }
390
391 // Test that we handle the case where lock requests are ignored.
392 TEST_F(PowerButtonControllerTest, LockFail) {
393 // We require animations to have a duration for this test.
394 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
395 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
396
397 controller_->set_has_legacy_power_button_for_test(false);
398 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
399 lock_state_controller_->OnLockStateChanged(false);
400
401 // Hold the power button and lock the screen.
402 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
403 EXPECT_TRUE(test_api_->lock_timer_is_running());
404 EXPECT_TRUE(
405 animator_api_->ContainersAreAnimated(
406 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
407 internal::SessionStateAnimator::LAUNCHER |
408 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
409 internal::SessionStateAnimator::ANIMATION_RESTORE));
410 test_api_->trigger_lock_timeout();
411 EXPECT_EQ(1, delegate_->num_lock_requests());
412 EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
413
414 // We shouldn't start the lock-to-shutdown timer until the screen has actually
415 // been locked.
416 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
417
418 // Act as if the request timed out. We should restore the windows.
419 test_api_->trigger_lock_fail_timeout();
420 EXPECT_TRUE(
421 animator_api_->ContainersAreAnimated(
422 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
423 internal::SessionStateAnimator::ANIMATION_RESTORE));
424 }
425
426 // Test the basic operation of the lock button.
427 TEST_F(PowerButtonControllerTest, LockButtonBasic) {
428 controller_->set_has_legacy_power_button_for_test(false);
429 // The lock button shouldn't do anything if we aren't logged in.
430 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
431 lock_state_controller_->OnLockStateChanged(false);
432 SetUserLoggedIn(false);
433 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
434 EXPECT_FALSE(test_api_->lock_timer_is_running());
435 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
436 EXPECT_EQ(0, delegate_->num_lock_requests());
437
438 // Ditto for when we're logged in as a guest.
439 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST);
440 SetUserLoggedIn(true);
441 SetCanLockScreen(false);
442 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
443 EXPECT_FALSE(test_api_->lock_timer_is_running());
444 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
445 EXPECT_EQ(0, delegate_->num_lock_requests());
446
447 // If we're logged in as a regular user, we should start the lock timer and
448 // the pre-lock animation.
449 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
450 SetCanLockScreen(true);
451 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
452 EXPECT_TRUE(test_api_->lock_timer_is_running());
453 EXPECT_TRUE(
454 animator_api_->ContainersAreAnimated(
455 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
456 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE));
457
458 // If the button is released immediately, we shouldn't lock the screen.
459 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
460 EXPECT_FALSE(test_api_->lock_timer_is_running());
461 EXPECT_TRUE(
462 animator_api_->ContainersAreAnimated(
463 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
464 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE));
465 EXPECT_EQ(0, delegate_->num_lock_requests());
466
467 // Press the button again and let the lock timeout fire. We should request
468 // that the screen be locked.
469 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
470 EXPECT_TRUE(test_api_->lock_timer_is_running());
471 test_api_->trigger_lock_timeout();
472 EXPECT_EQ(1, delegate_->num_lock_requests());
473
474 // Pressing the lock button while we have a pending lock request shouldn't do
475 // anything.
476 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
477 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
478 EXPECT_FALSE(test_api_->lock_timer_is_running());
479 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
480
481 // Pressing the button also shouldn't do anything after the screen is locked.
482 lock_state_controller_->OnStartingLock();
483 lock_state_controller_->OnLockStateChanged(true);
484 state_delegate_->LockScreen();
485 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
486 EXPECT_FALSE(test_api_->lock_timer_is_running());
487 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
488 }
489
490 // Test that the power button takes priority over the lock button.
491 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) {
492 controller_->set_has_legacy_power_button_for_test(false);
493 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
494 lock_state_controller_->OnLockStateChanged(false);
495
496 // While the lock button is down, hold the power button.
497 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
498 EXPECT_TRUE(test_api_->lock_timer_is_running());
499 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
500 EXPECT_TRUE(test_api_->lock_timer_is_running());
501
502 // The lock timer shouldn't be stopped when the lock button is released.
503 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
504 EXPECT_TRUE(test_api_->lock_timer_is_running());
505 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
506 EXPECT_FALSE(test_api_->lock_timer_is_running());
507
508 // Now press the power button first and then the lock button.
509 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
510 EXPECT_TRUE(test_api_->lock_timer_is_running());
511 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
512 EXPECT_TRUE(test_api_->lock_timer_is_running());
513
514 // Releasing the power button should stop the lock timer.
515 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
516 EXPECT_FALSE(test_api_->lock_timer_is_running());
517 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
518 EXPECT_FALSE(test_api_->lock_timer_is_running());
519 }
520
521 // When the screen is locked without going through the usual power-button
522 // slow-close path (e.g. via the wrench menu), test that we still show the
523 // fast-close animation.
524 TEST_F(PowerButtonControllerTest, LockWithoutButton) {
525 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
526 lock_state_controller_->OnStartingLock();
527 EXPECT_TRUE(
528 animator_api_->ContainersAreAnimated(
529 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
530 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE));
531 }
532
533 // When we hear that the process is exiting but we haven't had a chance to
534 // display an animation, we should just blank the screen.
535 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) {
536 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
537 lock_state_controller_->OnAppTerminating();
538 EXPECT_TRUE(
539 animator_api_->ContainersAreAnimated(
540 internal::SessionStateAnimator::kAllContainersMask,
541 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
542 GenerateMouseMoveEvent();
543 EXPECT_FALSE(cursor_visible());
544 }
545
546 // Test that we display the fast-close animation and shut down when we get an
547 // outside request to shut down (e.g. from the login or lock screen).
548 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) {
549 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
550 lock_state_controller_->OnLockStateChanged(false);
551 SetUserLoggedIn(false);
552 lock_state_controller_->RequestShutdown();
553 EXPECT_TRUE(
554 animator_api_->ContainersAreAnimated(
555 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
556 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
557 EXPECT_TRUE(
558 animator_api_->ContainersAreAnimated(
559 internal::SessionStateAnimator::kAllLockScreenContainersMask,
560 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE));
561 GenerateMouseMoveEvent();
562 EXPECT_FALSE(cursor_visible());
563
564 EXPECT_EQ(0, NumShutdownRequests());
565 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
566 test_api_->trigger_real_shutdown_timeout();
567 EXPECT_EQ(1, NumShutdownRequests());
568 }
569
570 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) {
571 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
572 lock_state_controller_->OnLockStateChanged(true);
573 state_delegate_->LockScreen();
574 lock_state_controller_->RequestShutdown();
575 EXPECT_TRUE(
576 animator_api_->ContainersAreAnimated(
577 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
578 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
579 EXPECT_TRUE(
580 animator_api_->ContainersAreAnimated(
581 internal::SessionStateAnimator::kAllLockScreenContainersMask,
582 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE));
583 GenerateMouseMoveEvent();
584 EXPECT_FALSE(cursor_visible());
585
586 EXPECT_EQ(0, NumShutdownRequests());
587 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
588 test_api_->trigger_real_shutdown_timeout();
589 EXPECT_EQ(1, NumShutdownRequests());
590 }
591
592 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) {
593 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
594 lock_state_controller_->OnLockStateChanged(true);
595 state_delegate_->LockScreen();
596
597 // Press the power button and check that we start the shutdown timer.
598 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
599 EXPECT_FALSE(test_api_->lock_timer_is_running());
600 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
601 EXPECT_TRUE(
602 animator_api_->ContainersAreAnimated(
603 internal::SessionStateAnimator::kAllContainersMask,
604 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE));
605
606 // Release the power button before the shutdown timer fires.
607 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
608 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
609 EXPECT_TRUE(
610 animator_api_->ContainersAreAnimated(
611 internal::SessionStateAnimator::kAllLockScreenContainersMask,
612 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE));
613 EXPECT_TRUE(
614 animator_api_->ContainersAreAnimated(
615 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
616 internal::SessionStateAnimator::ANIMATION_RESTORE));
617 }
618
619 // Test that we ignore power button presses when the screen is turned off.
620 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) {
621 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
622
623 // When the screen brightness is at 0%, we shouldn't do anything in response
624 // to power button presses.
625 controller_->OnScreenBrightnessChanged(0.0);
626 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
627 EXPECT_FALSE(test_api_->lock_timer_is_running());
628
629 // After increasing the brightness to 10%, we should start the timer like
630 // usual.
631 controller_->OnScreenBrightnessChanged(10.0);
632 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
633 EXPECT_TRUE(test_api_->lock_timer_is_running());
634 }
635
636 } // namespace test
637 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/lock_state_controller_unittest.cc ('k') | ash/wm/session_state_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698