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

Side by Side Diff: ash/wm/lock_state_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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/lock_state_controller.h"
6
5 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
6 #include "ash/session_state_delegate.h" 8 #include "ash/session_state_delegate.h"
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
9 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
10 #include "ash/test/test_shell_delegate.h" 12 #include "ash/test/test_shell_delegate.h"
11 #include "ash/wm/lock_state_controller.h"
12 #include "ash/wm/lock_state_controller_impl2.h"
13 #include "ash/wm/power_button_controller.h" 13 #include "ash/wm/power_button_controller.h"
14 #include "ash/wm/session_state_animator.h" 14 #include "ash/wm/session_state_animator.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "ui/aura/env.h" 18 #include "ui/aura/env.h"
19 #include "ui/aura/root_window.h" 19 #include "ui/aura/root_window.h"
20 #include "ui/aura/test/event_generator.h" 20 #include "ui/aura/test/event_generator.h"
21 #include "ui/compositor/layer_animator.h" 21 #include "ui/compositor/layer_animator.h"
22 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 22 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 num_shutdown_requests_++; 92 num_shutdown_requests_++;
93 } 93 }
94 94
95 private: 95 private:
96 int num_lock_requests_; 96 int num_lock_requests_;
97 int num_shutdown_requests_; 97 int num_shutdown_requests_;
98 98
99 DISALLOW_COPY_AND_ASSIGN(TestLockStateControllerDelegate); 99 DISALLOW_COPY_AND_ASSIGN(TestLockStateControllerDelegate);
100 }; 100 };
101 101
102 class LockStateControllerImpl2Test : public AshTestBase { 102 class LockStateControllerTest : public AshTestBase {
103 public: 103 public:
104 LockStateControllerImpl2Test() : controller_(NULL), delegate_(NULL) {} 104 LockStateControllerTest() : controller_(NULL), delegate_(NULL) {}
105 virtual ~LockStateControllerImpl2Test() {} 105 virtual ~LockStateControllerTest() {}
106 106
107 virtual void SetUp() OVERRIDE { 107 virtual void SetUp() OVERRIDE {
108 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
109 ash::switches::kAshDisableNewLockAnimations));
110
111 AshTestBase::SetUp(); 108 AshTestBase::SetUp();
112 109
113 // We would control animations in a fine way: 110 // We would control animations in a fine way:
114 animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 111 animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
115 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION)); 112 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION));
116 // TODO(antrim) : restore 113 // TODO(antrim) : restore
117 // animator_helper_ = ui::test::CreateLayerAnimatorHelperForTest(); 114 // animator_helper_ = ui::test::CreateLayerAnimatorHelperForTest();
118 115
119 // Temporary disable animations so that observer is always called, and 116 // Temporary disable animations so that observer is always called, and
120 // no leaks happen during tests. 117 // no leaks happen during tests.
121 animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 118 animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
122 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 119 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
123 // TODO(antrim): once there is a way to mock time and run animations, make 120 // TODO(antrim): once there is a way to mock time and run animations, make
124 // sure that animations are finished even in simple tests. 121 // sure that animations are finished even in simple tests.
125 122
126 delegate_ = new TestLockStateControllerDelegate; 123 delegate_ = new TestLockStateControllerDelegate;
127 controller_ = Shell::GetInstance()->power_button_controller(); 124 controller_ = Shell::GetInstance()->power_button_controller();
128 lock_state_controller_ = static_cast<LockStateControllerImpl2*>( 125 lock_state_controller_ = static_cast<LockStateController*>(
129 Shell::GetInstance()->lock_state_controller()); 126 Shell::GetInstance()->lock_state_controller());
130 lock_state_controller_->SetDelegate(delegate_); // transfers ownership 127 lock_state_controller_->SetDelegate(delegate_); // transfers ownership
131 test_api_.reset( 128 test_api_.reset(new LockStateController::TestApi(lock_state_controller_));
132 new LockStateControllerImpl2::TestApi(lock_state_controller_));
133 animator_api_.reset( 129 animator_api_.reset(
134 new SessionStateAnimator::TestApi(lock_state_controller_-> 130 new SessionStateAnimator::TestApi(lock_state_controller_->
135 animator_.get())); 131 animator_.get()));
136 shell_delegate_ = reinterpret_cast<TestShellDelegate*>( 132 shell_delegate_ = reinterpret_cast<TestShellDelegate*>(
137 ash::Shell::GetInstance()->delegate()); 133 ash::Shell::GetInstance()->delegate());
138 session_state_delegate_ = Shell::GetInstance()->session_state_delegate(); 134 session_state_delegate_ = Shell::GetInstance()->session_state_delegate();
139 } 135 }
140 136
141 virtual void TearDown() { 137 virtual void TearDown() {
142 // TODO(antrim) : restore 138 // TODO(antrim) : restore
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 void Initialize(bool legacy_button, user::LoginStatus status) { 384 void Initialize(bool legacy_button, user::LoginStatus status) {
389 controller_->set_has_legacy_power_button_for_test(legacy_button); 385 controller_->set_has_legacy_power_button_for_test(legacy_button);
390 lock_state_controller_->OnLoginStateChanged(status); 386 lock_state_controller_->OnLoginStateChanged(status);
391 SetUserLoggedIn(status != user::LOGGED_IN_NONE); 387 SetUserLoggedIn(status != user::LOGGED_IN_NONE);
392 if (status == user::LOGGED_IN_GUEST) 388 if (status == user::LOGGED_IN_GUEST)
393 SetCanLockScreen(false); 389 SetCanLockScreen(false);
394 lock_state_controller_->OnLockStateChanged(false); 390 lock_state_controller_->OnLockStateChanged(false);
395 } 391 }
396 392
397 PowerButtonController* controller_; // not owned 393 PowerButtonController* controller_; // not owned
398 LockStateControllerImpl2* lock_state_controller_; // not owned 394 LockStateController* lock_state_controller_; // not owned
399 TestLockStateControllerDelegate* delegate_; // not owned 395 TestLockStateControllerDelegate* delegate_; // not owned
400 TestShellDelegate* shell_delegate_; // not owned 396 TestShellDelegate* shell_delegate_; // not owned
401 SessionStateDelegate* session_state_delegate_; // not owned 397 SessionStateDelegate* session_state_delegate_; // not owned
402 398
403 scoped_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration_mode_; 399 scoped_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration_mode_;
404 scoped_ptr<LockStateControllerImpl2::TestApi> test_api_; 400 scoped_ptr<LockStateController::TestApi> test_api_;
405 scoped_ptr<SessionStateAnimator::TestApi> animator_api_; 401 scoped_ptr<SessionStateAnimator::TestApi> animator_api_;
406 // TODO(antrim) : restore 402 // TODO(antrim) : restore
407 // scoped_ptr<ui::test::AnimationContainerTestHelper> animator_helper_; 403 // scoped_ptr<ui::test::AnimationContainerTestHelper> animator_helper_;
408 404
409 private: 405 private:
410 DISALLOW_COPY_AND_ASSIGN(LockStateControllerImpl2Test); 406 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest);
411 }; 407 };
412 408
413 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't 409 // 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 410 // 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 411 // time the button is pressed and shut down when it's pressed from the locked
416 // state. 412 // state.
417 // TODO(antrim): Reenable this: http://crbug.com/167048 413 // TODO(antrim): Reenable this: http://crbug.com/167048
418 TEST_F(LockStateControllerImpl2Test, DISABLED_LegacyLockAndShutDown) { 414 TEST_F(LockStateControllerTest, DISABLED_LegacyLockAndShutDown) {
419 Initialize(true, user::LOGGED_IN_USER); 415 Initialize(true, user::LOGGED_IN_USER);
420 416
421 ExpectUnlockedState(); 417 ExpectUnlockedState();
422 418
423 // We should request that the screen be locked immediately after seeing the 419 // We should request that the screen be locked immediately after seeing the
424 // power button get pressed. 420 // power button get pressed.
425 PressPowerButton(); 421 PressPowerButton();
426 422
427 ExpectPreLockAnimationStarted(); 423 ExpectPreLockAnimationStarted();
428 424
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 GenerateMouseMoveEvent(); 457 GenerateMouseMoveEvent();
462 EXPECT_FALSE(cursor_visible()); 458 EXPECT_FALSE(cursor_visible());
463 459
464 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 460 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
465 test_api_->trigger_real_shutdown_timeout(); 461 test_api_->trigger_real_shutdown_timeout();
466 EXPECT_EQ(1, NumShutdownRequests()); 462 EXPECT_EQ(1, NumShutdownRequests());
467 } 463 }
468 464
469 // Test that we start shutting down immediately if the power button is pressed 465 // Test that we start shutting down immediately if the power button is pressed
470 // while we're not logged in on an unofficial system. 466 // while we're not logged in on an unofficial system.
471 TEST_F(LockStateControllerImpl2Test, LegacyNotLoggedIn) { 467 TEST_F(LockStateControllerTest, LegacyNotLoggedIn) {
472 Initialize(true, user::LOGGED_IN_NONE); 468 Initialize(true, user::LOGGED_IN_NONE);
473 469
474 PressPowerButton(); 470 PressPowerButton();
475 ExpectShutdownAnimationStarted(); 471 ExpectShutdownAnimationStarted();
476 472
477 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 473 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
478 } 474 }
479 475
480 // Test that we start shutting down immediately if the power button is pressed 476 // 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. 477 // while we're logged in as a guest on an unofficial system.
482 TEST_F(LockStateControllerImpl2Test, LegacyGuest) { 478 TEST_F(LockStateControllerTest, LegacyGuest) {
483 Initialize(true, user::LOGGED_IN_GUEST); 479 Initialize(true, user::LOGGED_IN_GUEST);
484 480
485 PressPowerButton(); 481 PressPowerButton();
486 ExpectShutdownAnimationStarted(); 482 ExpectShutdownAnimationStarted();
487 483
488 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 484 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
489 } 485 }
490 486
491 // When we hold the power button while the user isn't logged in, we should shut 487 // When we hold the power button while the user isn't logged in, we should shut
492 // down the machine directly. 488 // down the machine directly.
493 TEST_F(LockStateControllerImpl2Test, ShutdownWhenNotLoggedIn) { 489 TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) {
494 Initialize(false, user::LOGGED_IN_NONE); 490 Initialize(false, user::LOGGED_IN_NONE);
495 491
496 // Press the power button and check that we start the shutdown timer. 492 // Press the power button and check that we start the shutdown timer.
497 PressPowerButton(); 493 PressPowerButton();
498 EXPECT_FALSE(test_api_->is_animating_lock()); 494 EXPECT_FALSE(test_api_->is_animating_lock());
499 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 495 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
500 ExpectShutdownAnimationStarted(); 496 ExpectShutdownAnimationStarted();
501 497
502 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f); 498 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
503 499
(...skipping 19 matching lines...) Expand all
523 EXPECT_EQ(0, NumShutdownRequests()); 519 EXPECT_EQ(0, NumShutdownRequests());
524 520
525 // When the timout fires, we should request a shutdown. 521 // When the timout fires, we should request a shutdown.
526 test_api_->trigger_real_shutdown_timeout(); 522 test_api_->trigger_real_shutdown_timeout();
527 523
528 EXPECT_EQ(1, NumShutdownRequests()); 524 EXPECT_EQ(1, NumShutdownRequests());
529 } 525 }
530 526
531 // Test that we lock the screen and deal with unlocking correctly. 527 // Test that we lock the screen and deal with unlocking correctly.
532 // TODO(antrim): Reenable this: http://crbug.com/167048 528 // TODO(antrim): Reenable this: http://crbug.com/167048
533 TEST_F(LockStateControllerImpl2Test, DISABLED_LockAndUnlock) { 529 TEST_F(LockStateControllerTest, DISABLED_LockAndUnlock) {
534 Initialize(false, user::LOGGED_IN_USER); 530 Initialize(false, user::LOGGED_IN_USER);
535 531
536 ExpectUnlockedState(); 532 ExpectUnlockedState();
537 533
538 // Press the power button and check that the lock timer is started and that we 534 // Press the power button and check that the lock timer is started and that we
539 // start lifting the non-screen-locker containers. 535 // start lifting the non-screen-locker containers.
540 PressPowerButton(); 536 PressPowerButton();
541 537
542 ExpectPreLockAnimationStarted(); 538 ExpectPreLockAnimationStarted();
543 EXPECT_TRUE(test_api_->is_lock_cancellable()); 539 EXPECT_TRUE(test_api_->is_lock_cancellable());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 579
584 ExpectUnlockAfterUIDestroyedAnimationStarted(); 580 ExpectUnlockAfterUIDestroyedAnimationStarted();
585 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 581 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
586 ExpectUnlockAfterUIDestroyedAnimationFinished(); 582 ExpectUnlockAfterUIDestroyedAnimationFinished();
587 583
588 ExpectUnlockedState(); 584 ExpectUnlockedState();
589 } 585 }
590 586
591 // Test that we deal with cancelling lock correctly. 587 // Test that we deal with cancelling lock correctly.
592 // TODO(antrim): Reenable this: http://crbug.com/167048 588 // TODO(antrim): Reenable this: http://crbug.com/167048
593 TEST_F(LockStateControllerImpl2Test, DISABLED_LockAndCancel) { 589 TEST_F(LockStateControllerTest, DISABLED_LockAndCancel) {
594 Initialize(false, user::LOGGED_IN_USER); 590 Initialize(false, user::LOGGED_IN_USER);
595 591
596 ExpectUnlockedState(); 592 ExpectUnlockedState();
597 593
598 // Press the power button and check that the lock timer is started and that we 594 // Press the power button and check that the lock timer is started and that we
599 // start lifting the non-screen-locker containers. 595 // start lifting the non-screen-locker containers.
600 PressPowerButton(); 596 PressPowerButton();
601 597
602 ExpectPreLockAnimationStarted(); 598 ExpectPreLockAnimationStarted();
603 EXPECT_TRUE(test_api_->is_lock_cancellable()); 599 EXPECT_TRUE(test_api_->is_lock_cancellable());
(...skipping 16 matching lines...) Expand all
620 // Expect no flickering, animation should proceed from mid-state. 616 // Expect no flickering, animation should proceed from mid-state.
621 EXPECT_EQ(transform_before_button_released, transform_after_button_released); 617 EXPECT_EQ(transform_before_button_released, transform_after_button_released);
622 618
623 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 619 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
624 ExpectUnlockedState(); 620 ExpectUnlockedState();
625 EXPECT_EQ(0, delegate_->num_lock_requests()); 621 EXPECT_EQ(0, delegate_->num_lock_requests());
626 } 622 }
627 623
628 // Test that we deal with cancelling lock correctly. 624 // Test that we deal with cancelling lock correctly.
629 // TODO(antrim): Reenable this: http://crbug.com/167048 625 // TODO(antrim): Reenable this: http://crbug.com/167048
630 TEST_F(LockStateControllerImpl2Test, 626 TEST_F(LockStateControllerTest,
631 DISABLED_LockAndCancelAndLockAgain) { 627 DISABLED_LockAndCancelAndLockAgain) {
632 Initialize(false, user::LOGGED_IN_USER); 628 Initialize(false, user::LOGGED_IN_USER);
633 629
634 ExpectUnlockedState(); 630 ExpectUnlockedState();
635 631
636 // Press the power button and check that the lock timer is started and that we 632 // Press the power button and check that the lock timer is started and that we
637 // start lifting the non-screen-locker containers. 633 // start lifting the non-screen-locker containers.
638 PressPowerButton(); 634 PressPowerButton();
639 635
640 ExpectPreLockAnimationStarted(); 636 ExpectPreLockAnimationStarted();
(...skipping 17 matching lines...) Expand all
658 EXPECT_EQ(0, delegate_->num_lock_requests()); 654 EXPECT_EQ(0, delegate_->num_lock_requests());
659 ExpectPreLockAnimationStarted(); 655 ExpectPreLockAnimationStarted();
660 656
661 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f); 657 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
662 ExpectPreLockAnimationFinished(); 658 ExpectPreLockAnimationFinished();
663 EXPECT_EQ(1, delegate_->num_lock_requests()); 659 EXPECT_EQ(1, delegate_->num_lock_requests());
664 } 660 }
665 661
666 // Hold the power button down from the unlocked state to eventual shutdown. 662 // Hold the power button down from the unlocked state to eventual shutdown.
667 // TODO(antrim): Reenable this: http://crbug.com/167048 663 // TODO(antrim): Reenable this: http://crbug.com/167048
668 TEST_F(LockStateControllerImpl2Test, DISABLED_LockToShutdown) { 664 TEST_F(LockStateControllerTest, DISABLED_LockToShutdown) {
669 Initialize(false, user::LOGGED_IN_USER); 665 Initialize(false, user::LOGGED_IN_USER);
670 666
671 // Hold the power button and lock the screen. 667 // Hold the power button and lock the screen.
672 PressPowerButton(); 668 PressPowerButton();
673 EXPECT_TRUE(test_api_->is_animating_lock()); 669 EXPECT_TRUE(test_api_->is_animating_lock());
674 670
675 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); 671 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
676 SystemLocks(); 672 SystemLocks();
677 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 673 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
678 674
(...skipping 12 matching lines...) Expand all
691 test_api_->trigger_shutdown_timeout(); 687 test_api_->trigger_shutdown_timeout();
692 688
693 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 689 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
694 EXPECT_EQ(0, NumShutdownRequests()); 690 EXPECT_EQ(0, NumShutdownRequests());
695 test_api_->trigger_real_shutdown_timeout(); 691 test_api_->trigger_real_shutdown_timeout();
696 EXPECT_EQ(1, NumShutdownRequests()); 692 EXPECT_EQ(1, NumShutdownRequests());
697 } 693 }
698 694
699 // Hold the power button down from the unlocked state to eventual shutdown, 695 // Hold the power button down from the unlocked state to eventual shutdown,
700 // then release the button while system does locking. 696 // then release the button while system does locking.
701 TEST_F(LockStateControllerImpl2Test, CancelLockToShutdown) { 697 TEST_F(LockStateControllerTest, CancelLockToShutdown) {
702 Initialize(false, user::LOGGED_IN_USER); 698 Initialize(false, user::LOGGED_IN_USER);
703 699
704 PressPowerButton(); 700 PressPowerButton();
705 701
706 // Hold the power button and lock the screen. 702 // Hold the power button and lock the screen.
707 EXPECT_TRUE(test_api_->is_animating_lock()); 703 EXPECT_TRUE(test_api_->is_animating_lock());
708 704
709 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); 705 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
710 SystemLocks(); 706 SystemLocks();
711 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f); 707 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f);
712 708
713 // Power button is released while system attempts to lock. 709 // Power button is released while system attempts to lock.
714 ReleasePowerButton(); 710 ReleasePowerButton();
715 711
716 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 712 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
717 713
718 EXPECT_FALSE(lock_state_controller_->ShutdownRequested()); 714 EXPECT_FALSE(lock_state_controller_->ShutdownRequested());
719 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 715 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
720 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 716 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
721 } 717 }
722 718
723 // Test that we handle the case where lock requests are ignored. 719 // Test that we handle the case where lock requests are ignored.
724 // TODO(antrim): Reenable this: http://crbug.com/167048 720 // TODO(antrim): Reenable this: http://crbug.com/167048
725 TEST_F(LockStateControllerImpl2Test, DISABLED_Lock) { 721 TEST_F(LockStateControllerTest, DISABLED_Lock) {
726 // We require animations to have a duration for this test. 722 // We require animations to have a duration for this test.
727 ui::ScopedAnimationDurationScaleMode normal_duration_mode( 723 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
728 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 724 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
729 725
730 Initialize(false, user::LOGGED_IN_USER); 726 Initialize(false, user::LOGGED_IN_USER);
731 727
732 // Hold the power button and lock the screen. 728 // Hold the power button and lock the screen.
733 PressPowerButton(); 729 PressPowerButton();
734 ExpectPreLockAnimationStarted(); 730 ExpectPreLockAnimationStarted();
735 731
736 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); 732 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
737 733
738 EXPECT_EQ(1, delegate_->num_lock_requests()); 734 EXPECT_EQ(1, delegate_->num_lock_requests());
739 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); 735 EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
740 // We shouldn't start the lock-to-shutdown timer until the screen has actually 736 // We shouldn't start the lock-to-shutdown timer until the screen has actually
741 // been locked and this was animated. 737 // been locked and this was animated.
742 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 738 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
743 739
744 // Act as if the request timed out. We should restore the windows. 740 // Act as if the request timed out. We should restore the windows.
745 test_api_->trigger_lock_fail_timeout(); 741 test_api_->trigger_lock_fail_timeout();
746 742
747 ExpectUnlockAfterUIDestroyedAnimationStarted(); 743 ExpectUnlockAfterUIDestroyedAnimationStarted();
748 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 744 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
749 ExpectUnlockAfterUIDestroyedAnimationFinished(); 745 ExpectUnlockAfterUIDestroyedAnimationFinished();
750 ExpectUnlockedState(); 746 ExpectUnlockedState();
751 } 747 }
752 748
753 // Test the basic operation of the lock button (not logged in). 749 // Test the basic operation of the lock button (not logged in).
754 TEST_F(LockStateControllerImpl2Test, LockButtonBasicNotLoggedIn) { 750 TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) {
755 // The lock button shouldn't do anything if we aren't logged in. 751 // The lock button shouldn't do anything if we aren't logged in.
756 Initialize(false, user::LOGGED_IN_NONE); 752 Initialize(false, user::LOGGED_IN_NONE);
757 753
758 PressLockButton(); 754 PressLockButton();
759 EXPECT_FALSE(test_api_->is_animating_lock()); 755 EXPECT_FALSE(test_api_->is_animating_lock());
760 ReleaseLockButton(); 756 ReleaseLockButton();
761 EXPECT_EQ(0, delegate_->num_lock_requests()); 757 EXPECT_EQ(0, delegate_->num_lock_requests());
762 } 758 }
763 759
764 // Test the basic operation of the lock button (guest). 760 // Test the basic operation of the lock button (guest).
765 TEST_F(LockStateControllerImpl2Test, LockButtonBasicGuest) { 761 TEST_F(LockStateControllerTest, LockButtonBasicGuest) {
766 // The lock button shouldn't do anything when we're logged in as a guest. 762 // The lock button shouldn't do anything when we're logged in as a guest.
767 Initialize(false, user::LOGGED_IN_GUEST); 763 Initialize(false, user::LOGGED_IN_GUEST);
768 764
769 PressLockButton(); 765 PressLockButton();
770 EXPECT_FALSE(test_api_->is_animating_lock()); 766 EXPECT_FALSE(test_api_->is_animating_lock());
771 ReleaseLockButton(); 767 ReleaseLockButton();
772 EXPECT_EQ(0, delegate_->num_lock_requests()); 768 EXPECT_EQ(0, delegate_->num_lock_requests());
773 } 769 }
774 770
775 // Test the basic operation of the lock button. 771 // Test the basic operation of the lock button.
776 // TODO(antrim): Reenable this: http://crbug.com/167048 772 // TODO(antrim): Reenable this: http://crbug.com/167048
777 TEST_F(LockStateControllerImpl2Test, DISABLED_LockButtonBasic) { 773 TEST_F(LockStateControllerTest, DISABLED_LockButtonBasic) {
778 // If we're logged in as a regular user, we should start the lock timer and 774 // If we're logged in as a regular user, we should start the lock timer and
779 // the pre-lock animation. 775 // the pre-lock animation.
780 Initialize(false, user::LOGGED_IN_USER); 776 Initialize(false, user::LOGGED_IN_USER);
781 777
782 PressLockButton(); 778 PressLockButton();
783 ExpectPreLockAnimationStarted(); 779 ExpectPreLockAnimationStarted();
784 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); 780 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
785 781
786 // If the button is released immediately, we shouldn't lock the screen. 782 // If the button is released immediately, we shouldn't lock the screen.
787 ReleaseLockButton(); 783 ReleaseLockButton();
(...skipping 28 matching lines...) Expand all
816 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 812 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
817 ExpectPastLockAnimationFinished(); 813 ExpectPastLockAnimationFinished();
818 814
819 PressLockButton(); 815 PressLockButton();
820 ReleaseLockButton(); 816 ReleaseLockButton();
821 ExpectPastLockAnimationFinished(); 817 ExpectPastLockAnimationFinished();
822 } 818 }
823 819
824 // Test that the power button takes priority over the lock button. 820 // Test that the power button takes priority over the lock button.
825 // TODO(antrim): Reenable this: http://crbug.com/167048 821 // TODO(antrim): Reenable this: http://crbug.com/167048
826 TEST_F(LockStateControllerImpl2Test, 822 TEST_F(LockStateControllerTest,
827 DISABLED_PowerButtonPreemptsLockButton) { 823 DISABLED_PowerButtonPreemptsLockButton) {
828 Initialize(false, user::LOGGED_IN_USER); 824 Initialize(false, user::LOGGED_IN_USER);
829 825
830 // While the lock button is down, hold the power button. 826 // While the lock button is down, hold the power button.
831 PressLockButton(); 827 PressLockButton();
832 ExpectPreLockAnimationStarted(); 828 ExpectPreLockAnimationStarted();
833 PressPowerButton(); 829 PressPowerButton();
834 ExpectPreLockAnimationStarted(); 830 ExpectPreLockAnimationStarted();
835 831
836 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); 832 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
(...skipping 18 matching lines...) Expand all
855 // Releasing the power button should stop the lock timer. 851 // Releasing the power button should stop the lock timer.
856 ReleasePowerButton(); 852 ReleasePowerButton();
857 ExpectPreLockAnimationCancel(); 853 ExpectPreLockAnimationCancel();
858 ReleaseLockButton(); 854 ReleaseLockButton();
859 ExpectPreLockAnimationCancel(); 855 ExpectPreLockAnimationCancel();
860 } 856 }
861 857
862 // When the screen is locked without going through the usual power-button 858 // When the screen is locked without going through the usual power-button
863 // slow-close path (e.g. via the wrench menu), test that we still show the 859 // slow-close path (e.g. via the wrench menu), test that we still show the
864 // fast-close animation. 860 // fast-close animation.
865 TEST_F(LockStateControllerImpl2Test, LockWithoutButton) { 861 TEST_F(LockStateControllerTest, LockWithoutButton) {
866 Initialize(false, user::LOGGED_IN_USER); 862 Initialize(false, user::LOGGED_IN_USER);
867 lock_state_controller_->OnStartingLock(); 863 lock_state_controller_->OnStartingLock();
868 864
869 ExpectPreLockAnimationStarted(); 865 ExpectPreLockAnimationStarted();
870 EXPECT_FALSE(test_api_->is_lock_cancellable()); 866 EXPECT_FALSE(test_api_->is_lock_cancellable());
871 867
872 // TODO(antrim): After time-faking is fixed, let the pre-lock animation 868 // TODO(antrim): After time-faking is fixed, let the pre-lock animation
873 // complete here and check that delegate_->num_lock_requests() is 0 to 869 // complete here and check that delegate_->num_lock_requests() is 0 to
874 // prevent http://crbug.com/172487 from regressing. 870 // prevent http://crbug.com/172487 from regressing.
875 } 871 }
876 872
877 // When we hear that the process is exiting but we haven't had a chance to 873 // When we hear that the process is exiting but we haven't had a chance to
878 // display an animation, we should just blank the screen. 874 // display an animation, we should just blank the screen.
879 TEST_F(LockStateControllerImpl2Test, ShutdownWithoutButton) { 875 TEST_F(LockStateControllerTest, ShutdownWithoutButton) {
880 Initialize(false, user::LOGGED_IN_USER); 876 Initialize(false, user::LOGGED_IN_USER);
881 lock_state_controller_->OnAppTerminating(); 877 lock_state_controller_->OnAppTerminating();
882 878
883 EXPECT_TRUE( 879 EXPECT_TRUE(
884 animator_api_->ContainersAreAnimated( 880 animator_api_->ContainersAreAnimated(
885 SessionStateAnimator::kAllContainersMask, 881 SessionStateAnimator::kAllContainersMask,
886 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); 882 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
887 GenerateMouseMoveEvent(); 883 GenerateMouseMoveEvent();
888 EXPECT_FALSE(cursor_visible()); 884 EXPECT_FALSE(cursor_visible());
889 } 885 }
890 886
891 // Test that we display the fast-close animation and shut down when we get an 887 // Test that we display the fast-close animation and shut down when we get an
892 // outside request to shut down (e.g. from the login or lock screen). 888 // outside request to shut down (e.g. from the login or lock screen).
893 TEST_F(LockStateControllerImpl2Test, RequestShutdownFromLoginScreen) { 889 TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) {
894 Initialize(false, user::LOGGED_IN_NONE); 890 Initialize(false, user::LOGGED_IN_NONE);
895 891
896 lock_state_controller_->RequestShutdown(); 892 lock_state_controller_->RequestShutdown();
897 893
898 ExpectShutdownAnimationStarted(); 894 ExpectShutdownAnimationStarted();
899 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 895 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
900 896
901 GenerateMouseMoveEvent(); 897 GenerateMouseMoveEvent();
902 EXPECT_FALSE(cursor_visible()); 898 EXPECT_FALSE(cursor_visible());
903 899
904 EXPECT_EQ(0, NumShutdownRequests()); 900 EXPECT_EQ(0, NumShutdownRequests());
905 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 901 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
906 test_api_->trigger_real_shutdown_timeout(); 902 test_api_->trigger_real_shutdown_timeout();
907 EXPECT_EQ(1, NumShutdownRequests()); 903 EXPECT_EQ(1, NumShutdownRequests());
908 } 904 }
909 905
910 TEST_F(LockStateControllerImpl2Test, RequestShutdownFromLockScreen) { 906 TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) {
911 Initialize(false, user::LOGGED_IN_USER); 907 Initialize(false, user::LOGGED_IN_USER);
912 908
913 SystemLocks(); 909 SystemLocks();
914 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 910 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
915 ExpectPastLockAnimationFinished(); 911 ExpectPastLockAnimationFinished();
916 912
917 lock_state_controller_->RequestShutdown(); 913 lock_state_controller_->RequestShutdown();
918 914
919 ExpectShutdownAnimationStarted(); 915 ExpectShutdownAnimationStarted();
920 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 916 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
921 917
922 GenerateMouseMoveEvent(); 918 GenerateMouseMoveEvent();
923 EXPECT_FALSE(cursor_visible()); 919 EXPECT_FALSE(cursor_visible());
924 920
925 EXPECT_EQ(0, NumShutdownRequests()); 921 EXPECT_EQ(0, NumShutdownRequests());
926 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 922 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
927 test_api_->trigger_real_shutdown_timeout(); 923 test_api_->trigger_real_shutdown_timeout();
928 EXPECT_EQ(1, NumShutdownRequests()); 924 EXPECT_EQ(1, NumShutdownRequests());
929 } 925 }
930 926
931 // TODO(antrim): Reenable this: http://crbug.com/167048 927 // TODO(antrim): Reenable this: http://crbug.com/167048
932 TEST_F(LockStateControllerImpl2Test, 928 TEST_F(LockStateControllerTest,
933 DISABLED_RequestAndCancelShutdownFromLockScreen) { 929 DISABLED_RequestAndCancelShutdownFromLockScreen) {
934 Initialize(false, user::LOGGED_IN_USER); 930 Initialize(false, user::LOGGED_IN_USER);
935 931
936 SystemLocks(); 932 SystemLocks();
937 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 933 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
938 ExpectLockedState(); 934 ExpectLockedState();
939 935
940 // Press the power button and check that we start the shutdown timer. 936 // Press the power button and check that we start the shutdown timer.
941 PressPowerButton(); 937 PressPowerButton();
942 EXPECT_FALSE(test_api_->is_animating_lock()); 938 EXPECT_FALSE(test_api_->is_animating_lock());
(...skipping 16 matching lines...) Expand all
959 float grayscale_after_button_release = 955 float grayscale_after_button_release =
960 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale(); 956 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale();
961 // Expect no flickering in undo animation. 957 // Expect no flickering in undo animation.
962 EXPECT_EQ(grayscale_before_button_release, grayscale_after_button_release); 958 EXPECT_EQ(grayscale_before_button_release, grayscale_after_button_release);
963 959
964 Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT); 960 Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT);
965 ExpectLockedState(); 961 ExpectLockedState();
966 } 962 }
967 963
968 // Test that we ignore power button presses when the screen is turned off. 964 // Test that we ignore power button presses when the screen is turned off.
969 TEST_F(LockStateControllerImpl2Test, IgnorePowerButtonIfScreenIsOff) { 965 TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) {
970 Initialize(false, user::LOGGED_IN_USER); 966 Initialize(false, user::LOGGED_IN_USER);
971 967
972 // When the screen brightness is at 0%, we shouldn't do anything in response 968 // When the screen brightness is at 0%, we shouldn't do anything in response
973 // to power button presses. 969 // to power button presses.
974 controller_->OnScreenBrightnessChanged(0.0); 970 controller_->OnScreenBrightnessChanged(0.0);
975 971
976 PressPowerButton(); 972 PressPowerButton();
977 EXPECT_FALSE(test_api_->is_animating_lock()); 973 EXPECT_FALSE(test_api_->is_animating_lock());
978 ReleasePowerButton(); 974 ReleasePowerButton();
979 975
980 // After increasing the brightness to 10%, we should start the timer like 976 // After increasing the brightness to 10%, we should start the timer like
981 // usual. 977 // usual.
982 controller_->OnScreenBrightnessChanged(10.0); 978 controller_->OnScreenBrightnessChanged(10.0);
983 979
984 PressPowerButton(); 980 PressPowerButton();
985 EXPECT_TRUE(test_api_->is_animating_lock()); 981 EXPECT_TRUE(test_api_->is_animating_lock());
986 } 982 }
987 983
988 // Test that hidden background appears and revers correctly on lock/cancel. 984 // Test that hidden background appears and revers correctly on lock/cancel.
989 // TODO(antrim): Reenable this: http://crbug.com/167048 985 // TODO(antrim): Reenable this: http://crbug.com/167048
990 TEST_F(LockStateControllerImpl2Test, 986 TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockCancel) {
991 DISABLED_TestHiddenBackgroundLockCancel) {
992 Initialize(false, user::LOGGED_IN_USER); 987 Initialize(false, user::LOGGED_IN_USER);
993 HideBackground(); 988 HideBackground();
994 989
995 EXPECT_TRUE(IsBackgroundHidden()); 990 EXPECT_TRUE(IsBackgroundHidden());
996 ExpectUnlockedState(); 991 ExpectUnlockedState();
997 PressPowerButton(); 992 PressPowerButton();
998 993
999 ExpectPreLockAnimationStarted(); 994 ExpectPreLockAnimationStarted();
1000 EXPECT_FALSE(IsBackgroundHidden()); 995 EXPECT_FALSE(IsBackgroundHidden());
1001 ExpectBackgroundIsShowing(); 996 ExpectBackgroundIsShowing();
1002 997
1003 // Forward only half way through. 998 // Forward only half way through.
1004 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); 999 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
1005 1000
1006 // Release the button before the lock timer fires. 1001 // Release the button before the lock timer fires.
1007 ReleasePowerButton(); 1002 ReleasePowerButton();
1008 ExpectPreLockAnimationCancel(); 1003 ExpectPreLockAnimationCancel();
1009 ExpectBackgroundIsHiding(); 1004 ExpectBackgroundIsHiding();
1010 EXPECT_FALSE(IsBackgroundHidden()); 1005 EXPECT_FALSE(IsBackgroundHidden());
1011 1006
1012 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 1007 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1013 1008
1014 ExpectUnlockedState(); 1009 ExpectUnlockedState();
1015 EXPECT_TRUE(IsBackgroundHidden()); 1010 EXPECT_TRUE(IsBackgroundHidden());
1016 } 1011 }
1017 1012
1018 // Test that hidden background appears and revers correctly on lock/unlock. 1013 // Test that hidden background appears and revers correctly on lock/unlock.
1019 // TODO(antrim): Reenable this: http://crbug.com/167048 1014 // TODO(antrim): Reenable this: http://crbug.com/167048
1020 TEST_F(LockStateControllerImpl2Test, 1015 TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockUnlock) {
1021 DISABLED_TestHiddenBackgroundLockUnlock) {
1022 Initialize(false, user::LOGGED_IN_USER); 1016 Initialize(false, user::LOGGED_IN_USER);
1023 HideBackground(); 1017 HideBackground();
1024 1018
1025 EXPECT_TRUE(IsBackgroundHidden()); 1019 EXPECT_TRUE(IsBackgroundHidden());
1026 ExpectUnlockedState(); 1020 ExpectUnlockedState();
1027 1021
1028 // Press the power button and check that the lock timer is started and that we 1022 // Press the power button and check that the lock timer is started and that we
1029 // start lifting the non-screen-locker containers. 1023 // start lifting the non-screen-locker containers.
1030 PressPowerButton(); 1024 PressPowerButton();
1031 1025
(...skipping 29 matching lines...) Expand all
1061 1055
1062 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 1056 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1063 ExpectUnlockAfterUIDestroyedAnimationFinished(); 1057 ExpectUnlockAfterUIDestroyedAnimationFinished();
1064 EXPECT_TRUE(IsBackgroundHidden()); 1058 EXPECT_TRUE(IsBackgroundHidden());
1065 1059
1066 ExpectUnlockedState(); 1060 ExpectUnlockedState();
1067 } 1061 }
1068 1062
1069 } // namespace test 1063 } // namespace test
1070 } // namespace ash 1064 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/lock_state_controller_impl2_unittest.cc ('k') | ash/wm/power_button_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698