| OLD | NEW |
| 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" | 5 #include "ash/wm/lock_state_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 test_api_.reset(new LockStateControllerTestApi(lock_state_controller_)); | 86 test_api_.reset(new LockStateControllerTestApi(lock_state_controller_)); |
| 87 test_api_->set_shutdown_controller(&test_shutdown_controller_); | 87 test_api_->set_shutdown_controller(&test_shutdown_controller_); |
| 88 | 88 |
| 89 power_button_controller_ = Shell::GetInstance()->power_button_controller(); | 89 power_button_controller_ = Shell::GetInstance()->power_button_controller(); |
| 90 | 90 |
| 91 shell_delegate_ = | 91 shell_delegate_ = |
| 92 static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); | 92 static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void TearDown() override { | 95 void TearDown() override { |
| 96 const bool is_mash = WmShell::Get()->IsRunningInMash(); |
| 96 AshTestBase::TearDown(); | 97 AshTestBase::TearDown(); |
| 97 chromeos::DBusThreadManager::Shutdown(); | 98 // Mash shuts down DBus during normal destruction. |
| 99 if (!is_mash) |
| 100 chromeos::DBusThreadManager::Shutdown(); |
| 98 } | 101 } |
| 99 | 102 |
| 100 protected: | 103 protected: |
| 101 void GenerateMouseMoveEvent() { | 104 void GenerateMouseMoveEvent() { |
| 102 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 105 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 103 generator.MoveMouseTo(10, 10); | 106 generator.MoveMouseTo(10, 10); |
| 104 } | 107 } |
| 105 | 108 |
| 106 int NumShutdownRequests() { | 109 int NumShutdownRequests() { |
| 107 return test_shutdown_controller_.num_shutdown_requests() + | 110 return test_shutdown_controller_.num_shutdown_requests() + |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ReleasePowerButton(); | 393 ReleasePowerButton(); |
| 391 | 394 |
| 392 // Hold the button again and check that we start shutting down. | 395 // Hold the button again and check that we start shutting down. |
| 393 PressPowerButton(); | 396 PressPowerButton(); |
| 394 | 397 |
| 395 ExpectShutdownAnimationStarted(); | 398 ExpectShutdownAnimationStarted(); |
| 396 | 399 |
| 397 EXPECT_EQ(0, NumShutdownRequests()); | 400 EXPECT_EQ(0, NumShutdownRequests()); |
| 398 // Make sure a mouse move event won't show the cursor. | 401 // Make sure a mouse move event won't show the cursor. |
| 399 GenerateMouseMoveEvent(); | 402 GenerateMouseMoveEvent(); |
| 400 EXPECT_FALSE(cursor_visible()); | 403 // TODO: CursorManager not created in mash. http://crbug.com/631103. |
| 404 if (!WmShell::Get()->IsRunningInMash()) |
| 405 EXPECT_FALSE(cursor_visible()); |
| 401 | 406 |
| 402 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 407 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 403 test_api_->trigger_real_shutdown_timeout(); | 408 test_api_->trigger_real_shutdown_timeout(); |
| 404 EXPECT_EQ(1, NumShutdownRequests()); | 409 EXPECT_EQ(1, NumShutdownRequests()); |
| 405 } | 410 } |
| 406 | 411 |
| 407 // Test that we start shutting down immediately if the power button is pressed | 412 // Test that we start shutting down immediately if the power button is pressed |
| 408 // while we're not logged in on an unofficial system. | 413 // while we're not logged in on an unofficial system. |
| 409 TEST_F(LockStateControllerTest, LegacyNotLoggedIn) { | 414 TEST_F(LockStateControllerTest, LegacyNotLoggedIn) { |
| 410 Initialize(true, LoginStatus::NOT_LOGGED_IN); | 415 Initialize(true, LoginStatus::NOT_LOGGED_IN); |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 // When we hear that the process is exiting but we haven't had a chance to | 804 // When we hear that the process is exiting but we haven't had a chance to |
| 800 // display an animation, we should just blank the screen. | 805 // display an animation, we should just blank the screen. |
| 801 TEST_F(LockStateControllerTest, ShutdownWithoutButton) { | 806 TEST_F(LockStateControllerTest, ShutdownWithoutButton) { |
| 802 Initialize(false, LoginStatus::USER); | 807 Initialize(false, LoginStatus::USER); |
| 803 lock_state_controller_->OnAppTerminating(); | 808 lock_state_controller_->OnAppTerminating(); |
| 804 | 809 |
| 805 EXPECT_TRUE(test_animator_->AreContainersAnimated( | 810 EXPECT_TRUE(test_animator_->AreContainersAnimated( |
| 806 SessionStateAnimator::kAllNonRootContainersMask, | 811 SessionStateAnimator::kAllNonRootContainersMask, |
| 807 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 812 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| 808 GenerateMouseMoveEvent(); | 813 GenerateMouseMoveEvent(); |
| 809 EXPECT_FALSE(cursor_visible()); | 814 // TODO: CursorManager not created in mash. http://crbug.com/631103. |
| 815 if (!WmShell::Get()->IsRunningInMash()) |
| 816 EXPECT_FALSE(cursor_visible()); |
| 810 } | 817 } |
| 811 | 818 |
| 812 // Test that we display the fast-close animation and shut down when we get an | 819 // Test that we display the fast-close animation and shut down when we get an |
| 813 // outside request to shut down (e.g. from the login or lock screen). | 820 // outside request to shut down (e.g. from the login or lock screen). |
| 814 TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) { | 821 TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) { |
| 815 Initialize(false, LoginStatus::NOT_LOGGED_IN); | 822 Initialize(false, LoginStatus::NOT_LOGGED_IN); |
| 816 | 823 |
| 817 lock_state_controller_->RequestShutdown(); | 824 lock_state_controller_->RequestShutdown(); |
| 818 | 825 |
| 819 ExpectShutdownAnimationStarted(); | 826 ExpectShutdownAnimationStarted(); |
| 820 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | 827 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 821 | 828 |
| 822 GenerateMouseMoveEvent(); | 829 GenerateMouseMoveEvent(); |
| 823 EXPECT_FALSE(cursor_visible()); | 830 // TODO: CursorManager not created in mash. http://crbug.com/631103. |
| 831 if (!WmShell::Get()->IsRunningInMash()) |
| 832 EXPECT_FALSE(cursor_visible()); |
| 824 | 833 |
| 825 EXPECT_EQ(0, NumShutdownRequests()); | 834 EXPECT_EQ(0, NumShutdownRequests()); |
| 826 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 835 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 827 test_api_->trigger_real_shutdown_timeout(); | 836 test_api_->trigger_real_shutdown_timeout(); |
| 828 EXPECT_EQ(1, NumShutdownRequests()); | 837 EXPECT_EQ(1, NumShutdownRequests()); |
| 829 } | 838 } |
| 830 | 839 |
| 831 TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) { | 840 TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) { |
| 832 Initialize(false, LoginStatus::USER); | 841 Initialize(false, LoginStatus::USER); |
| 833 | 842 |
| 834 SystemLocks(); | 843 SystemLocks(); |
| 835 | 844 |
| 836 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | 845 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 837 ExpectPostLockAnimationFinished(); | 846 ExpectPostLockAnimationFinished(); |
| 838 | 847 |
| 839 lock_state_controller_->RequestShutdown(); | 848 lock_state_controller_->RequestShutdown(); |
| 840 | 849 |
| 841 ExpectShutdownAnimationStarted(); | 850 ExpectShutdownAnimationStarted(); |
| 842 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | 851 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 843 | 852 |
| 844 GenerateMouseMoveEvent(); | 853 GenerateMouseMoveEvent(); |
| 845 EXPECT_FALSE(cursor_visible()); | 854 // TODO: CursorManager not created in mash. http://crbug.com/631103. |
| 855 if (!WmShell::Get()->IsRunningInMash()) |
| 856 EXPECT_FALSE(cursor_visible()); |
| 846 | 857 |
| 847 EXPECT_EQ(0, NumShutdownRequests()); | 858 EXPECT_EQ(0, NumShutdownRequests()); |
| 848 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 859 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 849 test_api_->trigger_real_shutdown_timeout(); | 860 test_api_->trigger_real_shutdown_timeout(); |
| 850 EXPECT_EQ(1, NumShutdownRequests()); | 861 EXPECT_EQ(1, NumShutdownRequests()); |
| 851 } | 862 } |
| 852 | 863 |
| 853 TEST_F(LockStateControllerTest, RequestAndCancelShutdownFromLockScreen) { | 864 TEST_F(LockStateControllerTest, RequestAndCancelShutdownFromLockScreen) { |
| 854 Initialize(false, LoginStatus::USER); | 865 Initialize(false, LoginStatus::USER); |
| 855 | 866 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 ExpectRestoringWallpaperVisibility(); | 1023 ExpectRestoringWallpaperVisibility(); |
| 1013 | 1024 |
| 1014 Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | 1025 Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); |
| 1015 | 1026 |
| 1016 ExpectUnlockAfterUIDestroyedAnimationFinished(); | 1027 ExpectUnlockAfterUIDestroyedAnimationFinished(); |
| 1017 | 1028 |
| 1018 ExpectUnlockedState(); | 1029 ExpectUnlockedState(); |
| 1019 } | 1030 } |
| 1020 | 1031 |
| 1021 TEST_F(LockStateControllerTest, Screenshot) { | 1032 TEST_F(LockStateControllerTest, Screenshot) { |
| 1033 // TODO: fails because of no screenshot in mash. http://crbug.com/698033. |
| 1034 if (WmShell::Get()->IsRunningInMash()) |
| 1035 return; |
| 1036 |
| 1022 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); | 1037 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); |
| 1023 delegate->set_can_take_screenshot(true); | 1038 delegate->set_can_take_screenshot(true); |
| 1024 | 1039 |
| 1025 EnableMaximizeMode(false); | 1040 EnableMaximizeMode(false); |
| 1026 | 1041 |
| 1027 // Screenshot handling should not be active when not in maximize mode. | 1042 // Screenshot handling should not be active when not in maximize mode. |
| 1028 ASSERT_EQ(0, delegate->handle_take_screenshot_count()); | 1043 ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1029 PressVolumeDown(); | 1044 PressVolumeDown(); |
| 1030 PressPowerButton(); | 1045 PressPowerButton(); |
| 1031 ReleasePowerButton(); | 1046 ReleasePowerButton(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1059 ASSERT_EQ(0, delegate->handle_take_screenshot_count()); | 1074 ASSERT_EQ(0, delegate->handle_take_screenshot_count()); |
| 1060 PressVolumeDown(); | 1075 PressVolumeDown(); |
| 1061 PressPowerButton(); | 1076 PressPowerButton(); |
| 1062 ReleasePowerButton(); | 1077 ReleasePowerButton(); |
| 1063 ReleaseVolumeDown(); | 1078 ReleaseVolumeDown(); |
| 1064 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); | 1079 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); |
| 1065 } | 1080 } |
| 1066 | 1081 |
| 1067 } // namespace test | 1082 } // namespace test |
| 1068 } // namespace ash | 1083 } // namespace ash |
| OLD | NEW |