Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ash / wm / session_state_controller_impl2_unittest.cc
blob08032e6b55c89a3e7e8c49241a844a62657c2624
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"
8 #include "ash/shell.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"
28 #if defined(OS_WIN)
29 #include "base/win/windows_version.h"
30 #endif
32 namespace ash {
34 using internal::SessionStateAnimator;
36 namespace test {
38 namespace {
40 bool cursor_visible() {
41 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible();
44 void CheckCalledCallback(bool* flag) {
45 if (flag)
46 (*flag) = true;
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)->
56 IsVisible();
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();
75 } // namespace
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 {
81 public:
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 {
91 num_lock_requests_++;
93 virtual void RequestShutdown() OVERRIDE {
94 num_shutdown_requests_++;
97 private:
98 int num_lock_requests_;
99 int num_shutdown_requests_;
101 DISALLOW_COPY_AND_ASSIGN(TestSessionStateControllerDelegate);
104 class SessionStateControllerImpl2Test : public AshTestBase {
105 public:
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
133 test_api_.reset(
134 new SessionStateControllerImpl2::TestApi(state_controller_));
135 animator_api_.reset(
136 new SessionStateAnimator::TestApi(state_controller_->
137 animator_.get()));
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();
148 protected:
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,
166 float factor) {
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());
176 EXPECT_TRUE(
177 animator_api_->ContainersAreAnimated(
178 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
179 SessionStateAnimator::ANIMATION_LIFT));
180 EXPECT_TRUE(
181 animator_api_->ContainersAreAnimated(
182 SessionStateAnimator::LAUNCHER,
183 SessionStateAnimator::ANIMATION_FADE_OUT));
184 EXPECT_TRUE(
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() {
192 EXPECT_TRUE(
193 animator_api_->ContainersAreAnimated(
194 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
195 SessionStateAnimator::ANIMATION_DROP));
196 EXPECT_TRUE(
197 animator_api_->ContainersAreAnimated(
198 SessionStateAnimator::LAUNCHER,
199 SessionStateAnimator::ANIMATION_FADE_IN));
202 void ExpectPreLockAnimationFinished() {
203 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
204 EXPECT_TRUE(
205 animator_api_->ContainersAreAnimated(
206 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
207 SessionStateAnimator::ANIMATION_LIFT));
208 EXPECT_TRUE(
209 animator_api_->ContainersAreAnimated(
210 SessionStateAnimator::LAUNCHER,
211 SessionStateAnimator::ANIMATION_FADE_OUT));
212 EXPECT_TRUE(
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());
220 EXPECT_TRUE(
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());
228 EXPECT_TRUE(
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());
236 EXPECT_TRUE(
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());
244 EXPECT_TRUE(
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());
252 EXPECT_TRUE(
253 animator_api_->ContainersAreAnimated(
254 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
255 SessionStateAnimator::ANIMATION_DROP));
256 EXPECT_TRUE(
257 animator_api_->ContainersAreAnimated(
258 SessionStateAnimator::LAUNCHER,
259 SessionStateAnimator::ANIMATION_FADE_IN));
262 void ExpectUnlockAfterUIDestroyedAnimationFinished() {
263 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
264 EXPECT_TRUE(
265 animator_api_->ContainersAreAnimated(
266 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
267 SessionStateAnimator::ANIMATION_DROP));
268 EXPECT_TRUE(
269 animator_api_->ContainersAreAnimated(
270 SessionStateAnimator::LAUNCHER,
271 SessionStateAnimator::ANIMATION_FADE_IN));
274 void ExpectShutdownAnimationStarted() {
275 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
276 EXPECT_TRUE(
277 animator_api_->RootWindowIsAnimated(
278 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
281 void ExpectShutdownAnimationFinished() {
282 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
283 EXPECT_TRUE(
284 animator_api_->RootWindowIsAnimated(
285 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
288 void ExpectShutdownAnimationCancel() {
289 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
290 EXPECT_TRUE(
291 animator_api_->RootWindowIsAnimated(
292 SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS));
295 void ExpectBackgroundIsShowing() {
296 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
297 EXPECT_TRUE(
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());
305 EXPECT_TRUE(
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,
320 &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,
341 &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());
371 void SystemLocks() {
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_;
409 private:
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
416 // state.
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.
425 PressPowerButton();
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());
442 SystemLocks();
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.
455 PressPowerButton();
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);
474 PressPowerButton();
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);
485 PressPowerButton();
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.
497 PressPowerButton();
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.
514 PressPowerButton();
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.
540 PressPowerButton();
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());
556 SystemLocks();
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
563 // stopped.
564 ExpectLockedState();
565 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
566 ReleasePowerButton();
567 ExpectLockedState();
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.
572 bool called = false;
573 SuccessfulAuthentication(&called);
575 ExpectUnlockBeforeUIDestroyedAnimationStarted();
576 EXPECT_FALSE(called);
577 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
578 ExpectUnlockBeforeUIDestroyedAnimationFinished();
580 EXPECT_TRUE(called);
582 SystemUnlocks();
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.
600 PressPowerButton();
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.
637 PressPowerButton();
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);
651 PressPowerButton();
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.
671 PressPowerButton();
672 EXPECT_TRUE(test_api_->is_animating_lock());
674 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
675 SystemLocks();
676 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
678 // When the lock-to-shutdown timeout fires, we should start the shutdown
679 // timer.
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);
703 PressPowerButton();
705 // Hold the power button and lock the screen.
706 EXPECT_TRUE(test_api_->is_animating_lock());
708 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
709 SystemLocks();
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.
732 PressPowerButton();
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);
757 PressLockButton();
758 EXPECT_FALSE(test_api_->is_animating_lock());
759 ReleaseLockButton();
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);
768 PressLockButton();
769 EXPECT_FALSE(test_api_->is_animating_lock());
770 ReleaseLockButton();
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);
781 PressLockButton();
782 ExpectPreLockAnimationStarted();
783 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
785 // If the button is released immediately, we shouldn't lock the screen.
786 ReleaseLockButton();
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.
795 PressLockButton();
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
801 // anything.
802 ReleaseLockButton();
803 PressLockButton();
804 ExpectPreLockAnimationFinished();
805 ReleaseLockButton();
807 // Pressing the button also shouldn't do anything after the screen is locked.
808 SystemLocks();
809 ExpectPostLockAnimationStarted();
811 PressLockButton();
812 ReleaseLockButton();
813 ExpectPostLockAnimationStarted();
815 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
816 ExpectPastLockAnimationFinished();
818 PressLockButton();
819 ReleaseLockButton();
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.
830 PressLockButton();
831 ExpectPreLockAnimationStarted();
832 PressPowerButton();
833 ExpectPreLockAnimationStarted();
835 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
837 // The lock timer shouldn't be stopped when the lock button is released.
838 ReleaseLockButton();
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.
847 PressPowerButton();
848 ExpectPreLockAnimationStarted();
849 PressLockButton();
850 ExpectPreLockAnimationStarted();
852 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
854 // Releasing the power button should stop the lock timer.
855 ReleasePowerButton();
856 ExpectPreLockAnimationCancel();
857 ReleaseLockButton();
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();
882 EXPECT_TRUE(
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);
912 SystemLocks();
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);
935 SystemLocks();
936 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
937 ExpectLockedState();
939 // Press the power button and check that we start the shutdown timer.
940 PressPowerButton();
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);
964 ExpectLockedState();
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);
975 PressPowerButton();
976 EXPECT_FALSE(test_api_->is_animating_lock());
977 ReleasePowerButton();
979 // After increasing the brightness to 10%, we should start the timer like
980 // usual.
981 controller_->OnScreenBrightnessChanged(10.0);
983 PressPowerButton();
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);
992 HideBackground();
994 EXPECT_TRUE(IsBackgroundHidden());
995 ExpectUnlockedState();
996 PressPowerButton();
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);
1022 HideBackground();
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.
1029 PressPowerButton();
1031 ExpectPreLockAnimationStarted();
1032 EXPECT_FALSE(IsBackgroundHidden());
1033 ExpectBackgroundIsShowing();
1035 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
1037 ExpectPreLockAnimationFinished();
1039 SystemLocks();
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();
1055 SystemUnlocks();
1057 ExpectUnlockAfterUIDestroyedAnimationStarted();
1058 ExpectBackgroundIsHiding();
1059 EXPECT_FALSE(IsBackgroundHidden());
1061 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1062 ExpectUnlockAfterUIDestroyedAnimationFinished();
1063 EXPECT_TRUE(IsBackgroundHidden());
1065 ExpectUnlockedState();
1068 } // namespace test
1069 } // namespace ash