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.
5 #include "ash/wm/session_state_controller_impl2.h"
7 #include "ash/ash_switches.h"
9 #include "ash/shell_window_ids.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/test_shell_delegate.h"
12 #include "ash/wm/power_button_controller.h"
13 #include "ash/wm/session_state_animator.h"
14 #include "ash/wm/session_state_controller.h"
15 #include "base/command_line.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/time.h"
18 #include "ui/aura/env.h"
19 #include "ui/aura/root_window.h"
20 #include "ui/aura/test/event_generator.h"
21 #include "ui/compositor/layer_animator.h"
22 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
23 #include "ui/compositor/scoped_layer_animation_settings.h"
24 #include "ui/compositor/test/compositor_test_support.h"
25 #include "ui/gfx/rect.h"
26 #include "ui/gfx/size.h"
29 #include "base/win/windows_version.h"
34 using internal::SessionStateAnimator
;
40 bool cursor_visible() {
41 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible();
44 void CheckCalledCallback(bool* flag
) {
49 aura::Window
* GetContainer(int container
) {
50 aura::RootWindow
* root_window
= Shell::GetPrimaryRootWindow();
51 return Shell::GetContainer(root_window
, container
);
54 bool IsBackgroundHidden() {
55 return !GetContainer(internal::kShellWindowId_DesktopBackgroundContainer
)->
59 void ShowBackground() {
60 ui::ScopedLayerAnimationSettings
settings(
61 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer
)->
62 layer()->GetAnimator());
63 settings
.SetTransitionDuration(base::TimeDelta());
64 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer
)->Show();
67 void HideBackground() {
68 ui::ScopedLayerAnimationSettings
settings(
69 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer
)->
70 layer()->GetAnimator());
71 settings
.SetTransitionDuration(base::TimeDelta());
72 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer
)->Hide();
77 // Fake implementation of PowerButtonControllerDelegate that just logs requests
78 // to lock the screen and shut down the device.
79 class TestSessionStateControllerDelegate
:
80 public SessionStateControllerDelegate
{
82 TestSessionStateControllerDelegate()
83 : num_lock_requests_(0),
84 num_shutdown_requests_(0) {}
86 int num_lock_requests() const { return num_lock_requests_
; }
87 int num_shutdown_requests() const { return num_shutdown_requests_
; }
89 // SessionStateControllerDelegate implementation.
90 virtual void RequestLockScreen() OVERRIDE
{
93 virtual void RequestShutdown() OVERRIDE
{
94 num_shutdown_requests_
++;
98 int num_lock_requests_
;
99 int num_shutdown_requests_
;
101 DISALLOW_COPY_AND_ASSIGN(TestSessionStateControllerDelegate
);
104 class SessionStateControllerImpl2Test
: public AshTestBase
{
106 SessionStateControllerImpl2Test() : controller_(NULL
), delegate_(NULL
) {}
107 virtual ~SessionStateControllerImpl2Test() {}
109 virtual void SetUp() OVERRIDE
{
110 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
111 ash::switches::kAshDisableNewLockAnimations
));
113 AshTestBase::SetUp();
115 // We would control animations in a fine way:
116 animation_duration_mode_
.reset(new ui::ScopedAnimationDurationScaleMode(
117 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION
));
118 // TODO(antrim) : restore
119 // animator_helper_ = ui::test::CreateLayerAnimatorHelperForTest();
121 // Temporary disable animations so that observer is always called, and
122 // no leaks happen during tests.
123 animation_duration_mode_
.reset(new ui::ScopedAnimationDurationScaleMode(
124 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION
));
125 // TODO(antrim): once there is a way to mock time and run animations, make
126 // sure that animations are finished even in simple tests.
128 delegate_
= new TestSessionStateControllerDelegate
;
129 controller_
= Shell::GetInstance()->power_button_controller();
130 state_controller_
= static_cast<SessionStateControllerImpl2
*>(
131 Shell::GetInstance()->session_state_controller());
132 state_controller_
->SetDelegate(delegate_
); // transfers ownership
134 new SessionStateControllerImpl2::TestApi(state_controller_
));
136 new SessionStateAnimator::TestApi(state_controller_
->
138 shell_delegate_
= reinterpret_cast<TestShellDelegate
*>(
139 ash::Shell::GetInstance()->delegate());
142 virtual void TearDown() {
143 // TODO(antrim) : restore
144 // animator_helper_->AdvanceUntilDone();
145 AshTestBase::TearDown();
149 void GenerateMouseMoveEvent() {
150 aura::test::EventGenerator
generator(
151 Shell::GetPrimaryRootWindow());
152 generator
.MoveMouseTo(10, 10);
155 int NumShutdownRequests() {
156 return delegate_
->num_shutdown_requests() +
157 shell_delegate_
->num_exit_requests();
160 void Advance(SessionStateAnimator::AnimationSpeed speed
) {
161 // TODO (antrim) : restore
162 // animator_helper_->Advance(SessionStateAnimator::GetDuration(speed));
165 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed
,
167 // TODO (antrim) : restore
168 // base::TimeDelta duration = SessionStateAnimator::GetDuration(speed);
169 // base::TimeDelta partial_duration =
170 // base::TimeDelta::FromInternalValue(duration.ToInternalValue() * factor);
171 // animator_helper_->Advance(partial_duration);
174 void ExpectPreLockAnimationStarted() {
175 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
177 animator_api_
->ContainersAreAnimated(
178 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS
,
179 SessionStateAnimator::ANIMATION_LIFT
));
181 animator_api_
->ContainersAreAnimated(
182 SessionStateAnimator::LAUNCHER
,
183 SessionStateAnimator::ANIMATION_FADE_OUT
));
185 animator_api_
->ContainersAreAnimated(
186 SessionStateAnimator::LOCK_SCREEN_CONTAINERS
,
187 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY
));
188 EXPECT_TRUE(test_api_
->is_animating_lock());
191 void ExpectPreLockAnimationCancel() {
193 animator_api_
->ContainersAreAnimated(
194 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS
,
195 SessionStateAnimator::ANIMATION_DROP
));
197 animator_api_
->ContainersAreAnimated(
198 SessionStateAnimator::LAUNCHER
,
199 SessionStateAnimator::ANIMATION_FADE_IN
));
202 void ExpectPreLockAnimationFinished() {
203 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
205 animator_api_
->ContainersAreAnimated(
206 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS
,
207 SessionStateAnimator::ANIMATION_LIFT
));
209 animator_api_
->ContainersAreAnimated(
210 SessionStateAnimator::LAUNCHER
,
211 SessionStateAnimator::ANIMATION_FADE_OUT
));
213 animator_api_
->ContainersAreAnimated(
214 SessionStateAnimator::LOCK_SCREEN_CONTAINERS
,
215 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY
));
218 void ExpectPostLockAnimationStarted() {
219 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
221 animator_api_
->ContainersAreAnimated(
222 SessionStateAnimator::LOCK_SCREEN_CONTAINERS
,
223 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN
));
226 void ExpectPastLockAnimationFinished() {
227 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
229 animator_api_
->ContainersAreAnimated(
230 SessionStateAnimator::LOCK_SCREEN_CONTAINERS
,
231 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN
));
234 void ExpectUnlockBeforeUIDestroyedAnimationStarted() {
235 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
237 animator_api_
->ContainersAreAnimated(
238 SessionStateAnimator::LOCK_SCREEN_CONTAINERS
,
239 SessionStateAnimator::ANIMATION_LIFT
));
242 void ExpectUnlockBeforeUIDestroyedAnimationFinished() {
243 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
245 animator_api_
->ContainersAreAnimated(
246 SessionStateAnimator::LOCK_SCREEN_CONTAINERS
,
247 SessionStateAnimator::ANIMATION_LIFT
));
250 void ExpectUnlockAfterUIDestroyedAnimationStarted() {
251 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
253 animator_api_
->ContainersAreAnimated(
254 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS
,
255 SessionStateAnimator::ANIMATION_DROP
));
257 animator_api_
->ContainersAreAnimated(
258 SessionStateAnimator::LAUNCHER
,
259 SessionStateAnimator::ANIMATION_FADE_IN
));
262 void ExpectUnlockAfterUIDestroyedAnimationFinished() {
263 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
265 animator_api_
->ContainersAreAnimated(
266 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS
,
267 SessionStateAnimator::ANIMATION_DROP
));
269 animator_api_
->ContainersAreAnimated(
270 SessionStateAnimator::LAUNCHER
,
271 SessionStateAnimator::ANIMATION_FADE_IN
));
274 void ExpectShutdownAnimationStarted() {
275 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
277 animator_api_
->RootWindowIsAnimated(
278 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS
));
281 void ExpectShutdownAnimationFinished() {
282 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
284 animator_api_
->RootWindowIsAnimated(
285 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS
));
288 void ExpectShutdownAnimationCancel() {
289 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
291 animator_api_
->RootWindowIsAnimated(
292 SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS
));
295 void ExpectBackgroundIsShowing() {
296 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
298 animator_api_
->ContainersAreAnimated(
299 SessionStateAnimator::DESKTOP_BACKGROUND
,
300 SessionStateAnimator::ANIMATION_FADE_IN
));
303 void ExpectBackgroundIsHiding() {
304 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
306 animator_api_
->ContainersAreAnimated(
307 SessionStateAnimator::DESKTOP_BACKGROUND
,
308 SessionStateAnimator::ANIMATION_FADE_OUT
));
311 void ExpectUnlockedState() {
312 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
313 EXPECT_FALSE(shell_delegate_
->IsScreenLocked());
315 aura::Window::Windows containers
;
317 SessionStateAnimator::GetContainers(
318 SessionStateAnimator::LAUNCHER
|
319 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS
,
321 for (aura::Window::Windows::const_iterator it
= containers
.begin();
322 it
!= containers
.end(); ++it
) {
323 aura::Window
* window
= *it
;
324 ui::Layer
* layer
= window
->layer();
325 EXPECT_EQ(1.0f
, layer
->opacity());
326 EXPECT_EQ(0.0f
, layer
->layer_brightness());
327 EXPECT_EQ(0.0f
, layer
->layer_saturation());
328 EXPECT_EQ(gfx::Transform(), layer
->transform());
332 void ExpectLockedState() {
333 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
334 EXPECT_TRUE(shell_delegate_
->IsScreenLocked());
336 aura::Window::Windows containers
;
338 SessionStateAnimator::GetContainers(
339 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS
|
340 SessionStateAnimator::LOCK_SCREEN_CONTAINERS
,
342 for (aura::Window::Windows::const_iterator it
= containers
.begin();
343 it
!= containers
.end(); ++it
) {
344 aura::Window
* window
= *it
;
345 ui::Layer
* layer
= window
->layer();
346 EXPECT_EQ(1.0f
, layer
->opacity());
347 EXPECT_EQ(0.0f
, layer
->layer_brightness());
348 EXPECT_EQ(0.0f
, layer
->layer_saturation());
349 EXPECT_EQ(gfx::Transform(), layer
->transform());
353 void PressPowerButton() {
354 controller_
->OnPowerButtonEvent(true, base::TimeTicks::Now());
355 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
358 void ReleasePowerButton() {
359 controller_
->OnPowerButtonEvent(false, base::TimeTicks::Now());
360 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
363 void PressLockButton() {
364 controller_
->OnLockButtonEvent(true, base::TimeTicks::Now());
367 void ReleaseLockButton() {
368 controller_
->OnLockButtonEvent(false, base::TimeTicks::Now());
372 state_controller_
->OnLockStateChanged(true);
373 shell_delegate_
->LockScreen();
374 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
377 void SuccessfulAuthentication(bool* call_flag
) {
378 base::Closure closure
= base::Bind(&CheckCalledCallback
, call_flag
);
379 state_controller_
->OnLockScreenHide(closure
);
380 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
383 void SystemUnlocks() {
384 state_controller_
->OnLockStateChanged(false);
385 shell_delegate_
->UnlockScreen();
386 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
389 void Initialize(bool legacy_button
, user::LoginStatus status
) {
390 controller_
->set_has_legacy_power_button_for_test(legacy_button
);
391 state_controller_
->OnLoginStateChanged(status
);
392 SetUserLoggedIn(status
!= user::LOGGED_IN_NONE
);
393 if (status
== user::LOGGED_IN_GUEST
)
394 SetCanLockScreen(false);
395 state_controller_
->OnLockStateChanged(false);
398 PowerButtonController
* controller_
; // not owned
399 SessionStateControllerImpl2
* state_controller_
; // not owned
400 TestSessionStateControllerDelegate
* delegate_
; // not owned
401 TestShellDelegate
* shell_delegate_
; // not owned
403 scoped_ptr
<ui::ScopedAnimationDurationScaleMode
> animation_duration_mode_
;
404 scoped_ptr
<SessionStateControllerImpl2::TestApi
> test_api_
;
405 scoped_ptr
<SessionStateAnimator::TestApi
> animator_api_
;
406 // TODO(antrim) : restore
407 // scoped_ptr<ui::test::AnimationContainerTestHelper> animator_helper_;
410 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerImpl2Test
);
413 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't
414 // correctly report power button releases. We should lock immediately the first
415 // time the button is pressed and shut down when it's pressed from the locked
417 // TODO(antrim): Reenable this: http://crbug.com/167048
418 TEST_F(SessionStateControllerImpl2Test
, DISABLED_LegacyLockAndShutDown
) {
419 Initialize(true, user::LOGGED_IN_USER
);
421 ExpectUnlockedState();
423 // We should request that the screen be locked immediately after seeing the
424 // power button get pressed.
427 ExpectPreLockAnimationStarted();
429 EXPECT_FALSE(test_api_
->is_lock_cancellable());
431 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
433 ExpectPreLockAnimationFinished();
434 EXPECT_EQ(1, delegate_
->num_lock_requests());
436 // Notify that we locked successfully.
437 state_controller_
->OnStartingLock();
438 // We had that animation already.
439 //TODO (antrim) : restore
440 // EXPECT_FALSE(animator_helper_->IsAnimating());
444 ExpectPostLockAnimationStarted();
445 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
446 ExpectPastLockAnimationFinished();
448 // We shouldn't progress towards the shutdown state, however.
449 EXPECT_FALSE(test_api_
->lock_to_shutdown_timer_is_running());
450 EXPECT_FALSE(test_api_
->shutdown_timer_is_running());
452 ReleasePowerButton();
454 // Hold the button again and check that we start shutting down.
457 ExpectShutdownAnimationStarted();
459 EXPECT_EQ(0, NumShutdownRequests());
460 // Make sure a mouse move event won't show the cursor.
461 GenerateMouseMoveEvent();
462 EXPECT_FALSE(cursor_visible());
464 EXPECT_TRUE(test_api_
->real_shutdown_timer_is_running());
465 test_api_
->trigger_real_shutdown_timeout();
466 EXPECT_EQ(1, NumShutdownRequests());
469 // Test that we start shutting down immediately if the power button is pressed
470 // while we're not logged in on an unofficial system.
471 TEST_F(SessionStateControllerImpl2Test
, LegacyNotLoggedIn
) {
472 Initialize(true, user::LOGGED_IN_NONE
);
475 ExpectShutdownAnimationStarted();
477 EXPECT_TRUE(test_api_
->real_shutdown_timer_is_running());
480 // Test that we start shutting down immediately if the power button is pressed
481 // while we're logged in as a guest on an unofficial system.
482 TEST_F(SessionStateControllerImpl2Test
, LegacyGuest
) {
483 Initialize(true, user::LOGGED_IN_GUEST
);
486 ExpectShutdownAnimationStarted();
488 EXPECT_TRUE(test_api_
->real_shutdown_timer_is_running());
491 // When we hold the power button while the user isn't logged in, we should shut
492 // down the machine directly.
493 TEST_F(SessionStateControllerImpl2Test
, ShutdownWhenNotLoggedIn
) {
494 Initialize(false, user::LOGGED_IN_NONE
);
496 // Press the power button and check that we start the shutdown timer.
498 EXPECT_FALSE(test_api_
->is_animating_lock());
499 EXPECT_TRUE(test_api_
->shutdown_timer_is_running());
500 ExpectShutdownAnimationStarted();
502 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN
, 0.5f
);
504 // Release the power button before the shutdown timer fires.
505 ReleasePowerButton();
507 EXPECT_FALSE(test_api_
->shutdown_timer_is_running());
508 ExpectShutdownAnimationCancel();
510 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_REVERT
, 0.5f
);
512 // Press the button again and make the shutdown timeout fire this time.
513 // Check that we start the timer for actually requesting the shutdown.
516 EXPECT_TRUE(test_api_
->shutdown_timer_is_running());
518 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN
);
519 ExpectShutdownAnimationFinished();
520 test_api_
->trigger_shutdown_timeout();
522 EXPECT_TRUE(test_api_
->real_shutdown_timer_is_running());
523 EXPECT_EQ(0, NumShutdownRequests());
525 // When the timout fires, we should request a shutdown.
526 test_api_
->trigger_real_shutdown_timeout();
528 EXPECT_EQ(1, NumShutdownRequests());
531 // Test that we lock the screen and deal with unlocking correctly.
532 // TODO(antrim): Reenable this: http://crbug.com/167048
533 TEST_F(SessionStateControllerImpl2Test
, DISABLED_LockAndUnlock
) {
534 Initialize(false, user::LOGGED_IN_USER
);
536 ExpectUnlockedState();
538 // Press the power button and check that the lock timer is started and that we
539 // start lifting the non-screen-locker containers.
542 ExpectPreLockAnimationStarted();
543 EXPECT_TRUE(test_api_
->is_lock_cancellable());
544 EXPECT_EQ(0, delegate_
->num_lock_requests());
546 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
);
547 ExpectPreLockAnimationFinished();
549 EXPECT_EQ(1, delegate_
->num_lock_requests());
551 // Notify that we locked successfully.
552 state_controller_
->OnStartingLock();
553 // We had that animation already.
554 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
558 ExpectPostLockAnimationStarted();
559 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
560 ExpectPastLockAnimationFinished();
562 // When we release the power button, the lock-to-shutdown timer should be
565 EXPECT_TRUE(test_api_
->lock_to_shutdown_timer_is_running());
566 ReleasePowerButton();
568 EXPECT_FALSE(test_api_
->lock_to_shutdown_timer_is_running());
570 // Notify that the screen has been unlocked. We should show the
571 // non-screen-locker windows.
573 SuccessfulAuthentication(&called
);
575 ExpectUnlockBeforeUIDestroyedAnimationStarted();
576 EXPECT_FALSE(called
);
577 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
578 ExpectUnlockBeforeUIDestroyedAnimationFinished();
584 ExpectUnlockAfterUIDestroyedAnimationStarted();
585 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
586 ExpectUnlockAfterUIDestroyedAnimationFinished();
588 ExpectUnlockedState();
591 // Test that we deal with cancelling lock correctly.
592 // TODO(antrim): Reenable this: http://crbug.com/167048
593 TEST_F(SessionStateControllerImpl2Test
, DISABLED_LockAndCancel
) {
594 Initialize(false, user::LOGGED_IN_USER
);
596 ExpectUnlockedState();
598 // Press the power button and check that the lock timer is started and that we
599 // start lifting the non-screen-locker containers.
602 ExpectPreLockAnimationStarted();
603 EXPECT_TRUE(test_api_
->is_lock_cancellable());
605 // forward only half way through
606 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
, 0.5f
);
608 gfx::Transform transform_before_button_released
=
609 GetContainer(internal::kShellWindowId_DefaultContainer
)->
610 layer()->transform();
612 // Release the button before the lock timer fires.
613 ReleasePowerButton();
615 ExpectPreLockAnimationCancel();
617 gfx::Transform transform_after_button_released
=
618 GetContainer(internal::kShellWindowId_DefaultContainer
)->
619 layer()->transform();
620 // Expect no flickering, animation should proceed from mid-state.
621 EXPECT_EQ(transform_before_button_released
, transform_after_button_released
);
623 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
624 ExpectUnlockedState();
625 EXPECT_EQ(0, delegate_
->num_lock_requests());
628 // Test that we deal with cancelling lock correctly.
629 // TODO(antrim): Reenable this: http://crbug.com/167048
630 TEST_F(SessionStateControllerImpl2Test
, DISABLED_LockAndCancelAndLockAgain
) {
631 Initialize(false, user::LOGGED_IN_USER
);
633 ExpectUnlockedState();
635 // Press the power button and check that the lock timer is started and that we
636 // start lifting the non-screen-locker containers.
639 ExpectPreLockAnimationStarted();
640 EXPECT_TRUE(test_api_
->is_lock_cancellable());
642 // forward only half way through
643 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
, 0.5f
);
645 // Release the button before the lock timer fires.
646 ReleasePowerButton();
647 ExpectPreLockAnimationCancel();
649 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
, 0.5f
);
652 ExpectPreLockAnimationStarted();
653 EXPECT_TRUE(test_api_
->is_lock_cancellable());
655 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
, 0.6f
);
657 EXPECT_EQ(0, delegate_
->num_lock_requests());
658 ExpectPreLockAnimationStarted();
660 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
, 0.6f
);
661 ExpectPreLockAnimationFinished();
662 EXPECT_EQ(1, delegate_
->num_lock_requests());
665 // Hold the power button down from the unlocked state to eventual shutdown.
666 // TODO(antrim): Reenable this: http://crbug.com/167048
667 TEST_F(SessionStateControllerImpl2Test
, DISABLED_LockToShutdown
) {
668 Initialize(false, user::LOGGED_IN_USER
);
670 // Hold the power button and lock the screen.
672 EXPECT_TRUE(test_api_
->is_animating_lock());
674 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
);
676 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
678 // When the lock-to-shutdown timeout fires, we should start the shutdown
680 EXPECT_TRUE(test_api_
->lock_to_shutdown_timer_is_running());
682 test_api_
->trigger_lock_to_shutdown_timeout();
684 ExpectShutdownAnimationStarted();
685 EXPECT_TRUE(test_api_
->shutdown_timer_is_running());
687 // Fire the shutdown timeout and check that we request shutdown.
688 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN
);
689 ExpectShutdownAnimationFinished();
690 test_api_
->trigger_shutdown_timeout();
692 EXPECT_TRUE(test_api_
->real_shutdown_timer_is_running());
693 EXPECT_EQ(0, NumShutdownRequests());
694 test_api_
->trigger_real_shutdown_timeout();
695 EXPECT_EQ(1, NumShutdownRequests());
698 // Hold the power button down from the unlocked state to eventual shutdown,
699 // then release the button while system does locking.
700 TEST_F(SessionStateControllerImpl2Test
, CancelLockToShutdown
) {
701 Initialize(false, user::LOGGED_IN_USER
);
705 // Hold the power button and lock the screen.
706 EXPECT_TRUE(test_api_
->is_animating_lock());
708 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
);
710 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
, 0.5f
);
712 // Power button is released while system attempts to lock.
713 ReleasePowerButton();
715 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
717 EXPECT_FALSE(state_controller_
->ShutdownRequested());
718 EXPECT_FALSE(test_api_
->lock_to_shutdown_timer_is_running());
719 EXPECT_FALSE(test_api_
->shutdown_timer_is_running());
722 // Test that we handle the case where lock requests are ignored.
723 // TODO(antrim): Reenable this: http://crbug.com/167048
724 TEST_F(SessionStateControllerImpl2Test
, DISABLED_Lock
) {
725 // We require animations to have a duration for this test.
726 ui::ScopedAnimationDurationScaleMode
normal_duration_mode(
727 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION
);
729 Initialize(false, user::LOGGED_IN_USER
);
731 // Hold the power button and lock the screen.
733 ExpectPreLockAnimationStarted();
735 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
);
737 EXPECT_EQ(1, delegate_
->num_lock_requests());
738 EXPECT_TRUE(test_api_
->lock_fail_timer_is_running());
739 // We shouldn't start the lock-to-shutdown timer until the screen has actually
740 // been locked and this was animated.
741 EXPECT_FALSE(test_api_
->lock_to_shutdown_timer_is_running());
743 // Act as if the request timed out. We should restore the windows.
744 test_api_
->trigger_lock_fail_timeout();
746 ExpectUnlockAfterUIDestroyedAnimationStarted();
747 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
748 ExpectUnlockAfterUIDestroyedAnimationFinished();
749 ExpectUnlockedState();
752 // Test the basic operation of the lock button (not logged in).
753 TEST_F(SessionStateControllerImpl2Test
, LockButtonBasicNotLoggedIn
) {
754 // The lock button shouldn't do anything if we aren't logged in.
755 Initialize(false, user::LOGGED_IN_NONE
);
758 EXPECT_FALSE(test_api_
->is_animating_lock());
760 EXPECT_EQ(0, delegate_
->num_lock_requests());
763 // Test the basic operation of the lock button (guest).
764 TEST_F(SessionStateControllerImpl2Test
, LockButtonBasicGuest
) {
765 // The lock button shouldn't do anything when we're logged in as a guest.
766 Initialize(false, user::LOGGED_IN_GUEST
);
769 EXPECT_FALSE(test_api_
->is_animating_lock());
771 EXPECT_EQ(0, delegate_
->num_lock_requests());
774 // Test the basic operation of the lock button.
775 // TODO(antrim): Reenable this: http://crbug.com/167048
776 TEST_F(SessionStateControllerImpl2Test
, DISABLED_LockButtonBasic
) {
777 // If we're logged in as a regular user, we should start the lock timer and
778 // the pre-lock animation.
779 Initialize(false, user::LOGGED_IN_USER
);
782 ExpectPreLockAnimationStarted();
783 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
, 0.5f
);
785 // If the button is released immediately, we shouldn't lock the screen.
787 ExpectPreLockAnimationCancel();
788 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
790 ExpectUnlockedState();
791 EXPECT_EQ(0, delegate_
->num_lock_requests());
793 // Press the button again and let the lock timeout fire. We should request
794 // that the screen be locked.
796 ExpectPreLockAnimationStarted();
797 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
);
798 EXPECT_EQ(1, delegate_
->num_lock_requests());
800 // Pressing the lock button while we have a pending lock request shouldn't do
804 ExpectPreLockAnimationFinished();
807 // Pressing the button also shouldn't do anything after the screen is locked.
809 ExpectPostLockAnimationStarted();
813 ExpectPostLockAnimationStarted();
815 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
816 ExpectPastLockAnimationFinished();
820 ExpectPastLockAnimationFinished();
823 // Test that the power button takes priority over the lock button.
824 // TODO(antrim): Reenable this: http://crbug.com/167048
825 TEST_F(SessionStateControllerImpl2Test
,
826 DISABLED_PowerButtonPreemptsLockButton
) {
827 Initialize(false, user::LOGGED_IN_USER
);
829 // While the lock button is down, hold the power button.
831 ExpectPreLockAnimationStarted();
833 ExpectPreLockAnimationStarted();
835 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
, 0.5f
);
837 // The lock timer shouldn't be stopped when the lock button is released.
839 ExpectPreLockAnimationStarted();
840 ReleasePowerButton();
841 ExpectPreLockAnimationCancel();
843 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
844 ExpectUnlockedState();
846 // Now press the power button first and then the lock button.
848 ExpectPreLockAnimationStarted();
850 ExpectPreLockAnimationStarted();
852 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
, 0.5f
);
854 // Releasing the power button should stop the lock timer.
855 ReleasePowerButton();
856 ExpectPreLockAnimationCancel();
858 ExpectPreLockAnimationCancel();
861 // When the screen is locked without going through the usual power-button
862 // slow-close path (e.g. via the wrench menu), test that we still show the
863 // fast-close animation.
864 TEST_F(SessionStateControllerImpl2Test
, LockWithoutButton
) {
865 Initialize(false, user::LOGGED_IN_USER
);
866 state_controller_
->OnStartingLock();
868 ExpectPreLockAnimationStarted();
869 EXPECT_FALSE(test_api_
->is_lock_cancellable());
871 // TODO(antrim): After time-faking is fixed, let the pre-lock animation
872 // complete here and check that delegate_->num_lock_requests() is 0 to
873 // prevent http://crbug.com/172487 from regressing.
876 // When we hear that the process is exiting but we haven't had a chance to
877 // display an animation, we should just blank the screen.
878 TEST_F(SessionStateControllerImpl2Test
, ShutdownWithoutButton
) {
879 Initialize(false, user::LOGGED_IN_USER
);
880 state_controller_
->OnAppTerminating();
883 animator_api_
->ContainersAreAnimated(
884 SessionStateAnimator::kAllContainersMask
,
885 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY
));
886 GenerateMouseMoveEvent();
887 EXPECT_FALSE(cursor_visible());
890 // Test that we display the fast-close animation and shut down when we get an
891 // outside request to shut down (e.g. from the login or lock screen).
892 TEST_F(SessionStateControllerImpl2Test
, RequestShutdownFromLoginScreen
) {
893 Initialize(false, user::LOGGED_IN_NONE
);
895 state_controller_
->RequestShutdown();
897 ExpectShutdownAnimationStarted();
898 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN
);
900 GenerateMouseMoveEvent();
901 EXPECT_FALSE(cursor_visible());
903 EXPECT_EQ(0, NumShutdownRequests());
904 EXPECT_TRUE(test_api_
->real_shutdown_timer_is_running());
905 test_api_
->trigger_real_shutdown_timeout();
906 EXPECT_EQ(1, NumShutdownRequests());
909 TEST_F(SessionStateControllerImpl2Test
, RequestShutdownFromLockScreen
) {
910 Initialize(false, user::LOGGED_IN_USER
);
913 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN
);
914 ExpectPastLockAnimationFinished();
916 state_controller_
->RequestShutdown();
918 ExpectShutdownAnimationStarted();
919 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN
);
921 GenerateMouseMoveEvent();
922 EXPECT_FALSE(cursor_visible());
924 EXPECT_EQ(0, NumShutdownRequests());
925 EXPECT_TRUE(test_api_
->real_shutdown_timer_is_running());
926 test_api_
->trigger_real_shutdown_timeout();
927 EXPECT_EQ(1, NumShutdownRequests());
930 // TODO(antrim): Reenable this: http://crbug.com/167048
931 TEST_F(SessionStateControllerImpl2Test
,
932 DISABLED_RequestAndCancelShutdownFromLockScreen
) {
933 Initialize(false, user::LOGGED_IN_USER
);
936 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN
);
939 // Press the power button and check that we start the shutdown timer.
941 EXPECT_FALSE(test_api_
->is_animating_lock());
942 EXPECT_TRUE(test_api_
->shutdown_timer_is_running());
944 ExpectShutdownAnimationStarted();
946 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN
, 0.5f
);
948 float grayscale_before_button_release
=
949 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale();
951 // Release the power button before the shutdown timer fires.
952 ReleasePowerButton();
954 EXPECT_FALSE(test_api_
->shutdown_timer_is_running());
956 ExpectShutdownAnimationCancel();
958 float grayscale_after_button_release
=
959 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale();
960 // Expect no flickering in undo animation.
961 EXPECT_EQ(grayscale_before_button_release
, grayscale_after_button_release
);
963 Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT
);
967 // Test that we ignore power button presses when the screen is turned off.
968 TEST_F(SessionStateControllerImpl2Test
, IgnorePowerButtonIfScreenIsOff
) {
969 Initialize(false, user::LOGGED_IN_USER
);
971 // When the screen brightness is at 0%, we shouldn't do anything in response
972 // to power button presses.
973 controller_
->OnScreenBrightnessChanged(0.0);
976 EXPECT_FALSE(test_api_
->is_animating_lock());
977 ReleasePowerButton();
979 // After increasing the brightness to 10%, we should start the timer like
981 controller_
->OnScreenBrightnessChanged(10.0);
984 EXPECT_TRUE(test_api_
->is_animating_lock());
987 // Test that hidden background appears and revers correctly on lock/cancel.
988 // TODO(antrim): Reenable this: http://crbug.com/167048
989 TEST_F(SessionStateControllerImpl2Test
,
990 DISABLED_TestHiddenBackgroundLockCancel
) {
991 Initialize(false, user::LOGGED_IN_USER
);
994 EXPECT_TRUE(IsBackgroundHidden());
995 ExpectUnlockedState();
998 ExpectPreLockAnimationStarted();
999 EXPECT_FALSE(IsBackgroundHidden());
1000 ExpectBackgroundIsShowing();
1002 // Forward only half way through.
1003 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
, 0.5f
);
1005 // Release the button before the lock timer fires.
1006 ReleasePowerButton();
1007 ExpectPreLockAnimationCancel();
1008 ExpectBackgroundIsHiding();
1009 EXPECT_FALSE(IsBackgroundHidden());
1011 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
1013 ExpectUnlockedState();
1014 EXPECT_TRUE(IsBackgroundHidden());
1017 // Test that hidden background appears and revers correctly on lock/unlock.
1018 // TODO(antrim): Reenable this: http://crbug.com/167048
1019 TEST_F(SessionStateControllerImpl2Test
,
1020 DISABLED_TestHiddenBackgroundLockUnlock
) {
1021 Initialize(false, user::LOGGED_IN_USER
);
1024 EXPECT_TRUE(IsBackgroundHidden());
1025 ExpectUnlockedState();
1027 // Press the power button and check that the lock timer is started and that we
1028 // start lifting the non-screen-locker containers.
1031 ExpectPreLockAnimationStarted();
1032 EXPECT_FALSE(IsBackgroundHidden());
1033 ExpectBackgroundIsShowing();
1035 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE
);
1037 ExpectPreLockAnimationFinished();
1041 ReleasePowerButton();
1043 ExpectPostLockAnimationStarted();
1044 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
1045 ExpectPastLockAnimationFinished();
1047 ExpectLockedState();
1049 SuccessfulAuthentication(NULL
);
1051 ExpectUnlockBeforeUIDestroyedAnimationStarted();
1052 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
1053 ExpectUnlockBeforeUIDestroyedAnimationFinished();
1057 ExpectUnlockAfterUIDestroyedAnimationStarted();
1058 ExpectBackgroundIsHiding();
1059 EXPECT_FALSE(IsBackgroundHidden());
1061 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS
);
1062 ExpectUnlockAfterUIDestroyedAnimationFinished();
1063 EXPECT_TRUE(IsBackgroundHidden());
1065 ExpectUnlockedState();