diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 02:42:25 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 02:42:25 +0000 |
commit | 4fc24a6e5fad3b0a2b4d6bc511755bff4225b0ae (patch) | |
tree | 064d4020d8494aec2986f45ef810598b21107f8a | |
parent | d42e5cb5b3617391ecc2b0627a459b7a42ba9aea (diff) | |
download | chromium_src-4fc24a6e5fad3b0a2b4d6bc511755bff4225b0ae.zip chromium_src-4fc24a6e5fad3b0a2b4d6bc511755bff4225b0ae.tar.gz chromium_src-4fc24a6e5fad3b0a2b4d6bc511755bff4225b0ae.tar.bz2 |
chromeos/aura: Handle power button on unofficial hardware.
Most official Chrome OS hardware reports power button
releases correctly, but on standard x86 systems, we'll always
receive a button up event just after the button down. This
change adds a chromeos_legacy_power_button gyp flag; when
set, we lock the screen or shut down immediately when the
button is pressed instead of providing interactive
animations.
BUG=109209
TEST=added tests; also did manual testing
Review URL: http://codereview.chromium.org/9110044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116993 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/wm/power_button_controller.cc | 18 | ||||
-rw-r--r-- | ash/wm/power_button_controller_unittest.cc | 75 | ||||
-rw-r--r-- | build/common.gypi | 7 |
3 files changed, 100 insertions, 0 deletions
diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc index 2c720db..f18c1e0 100644 --- a/ash/wm/power_button_controller.cc +++ b/ash/wm/power_button_controller.cc @@ -340,6 +340,7 @@ void PowerButtonController::OnLockStateChange(bool locked) { lock_timer_.Stop(); lock_fail_timer_.Stop(); +#if !defined(CHROMEOS_LEGACY_POWER_BUTTON) if (power_button_down_) { lock_to_shutdown_timer_.Stop(); lock_to_shutdown_timer_.Start( @@ -347,6 +348,7 @@ void PowerButtonController::OnLockStateChange(bool locked) { base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), this, &PowerButtonController::OnLockToShutdownTimeout); } +#endif } else { StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_RESTORE); @@ -372,6 +374,21 @@ void PowerButtonController::OnPowerButtonEvent( if (shutting_down_) return; +#if defined(CHROMEOS_LEGACY_POWER_BUTTON) + // If power button releases won't get reported correctly because we're not + // running on official hardware, just lock the screen or shut down + // immediately. + if (down) { + ShowBackgroundLayer(); + if (logged_in_as_non_guest_ && !locked_) { + StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, + ANIMATION_SLOW_CLOSE); + OnLockTimeout(); + } else { + OnShutdownTimeout(); + } + } +#else if (down) { // If we already have a pending request to lock the screen, wait. if (lock_fail_timer_.IsRunning()) @@ -401,6 +418,7 @@ void PowerButtonController::OnPowerButtonEvent( shutdown_timer_.Stop(); lock_to_shutdown_timer_.Stop(); } +#endif } void PowerButtonController::OnLockButtonEvent( diff --git a/ash/wm/power_button_controller_unittest.cc b/ash/wm/power_button_controller_unittest.cc index 78ced33..658ed98 100644 --- a/ash/wm/power_button_controller_unittest.cc +++ b/ash/wm/power_button_controller_unittest.cc @@ -61,6 +61,80 @@ class PowerButtonControllerTest : public AuraShellTestBase { DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); }; +#if defined(CHROMEOS_LEGACY_POWER_BUTTON) +// Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't +// correctly report power button releases. We should lock immediately the first +// time the button is pressed and shut down when it's pressed from the locked +// state. +TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { + controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); + controller_->OnLockStateChange(false); + + // We should request that the screen be locked immediately after seeing the + // power button get pressed. + controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); + EXPECT_TRUE( + test_api_->ContainerGroupIsAnimated( + PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, + PowerButtonController::ANIMATION_SLOW_CLOSE)); + EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); + EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running()); + EXPECT_FALSE(test_api_->lock_timer_is_running()); + EXPECT_EQ(1, delegate_->num_lock_requests()); + + // Notify that we locked successfully. + controller_->OnStartingLock(); + EXPECT_TRUE( + test_api_->ContainerGroupIsAnimated( + PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, + PowerButtonController::ANIMATION_FAST_CLOSE)); + EXPECT_TRUE( + test_api_->ContainerGroupIsAnimated( + PowerButtonController::SCREEN_LOCKER_CONTAINERS, + PowerButtonController::ANIMATION_HIDE)); + + // Notify that the lock window is visible. We should make it fade in. + controller_->OnLockStateChange(true); + EXPECT_TRUE( + test_api_->ContainerGroupIsAnimated( + PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, + PowerButtonController::ANIMATION_FADE_IN)); + + // We shouldn't progress towards the shutdown state, however. + EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); + EXPECT_FALSE(test_api_->shutdown_timer_is_running()); + controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); + + // Hold the button again and check that we start shutting down. + controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); + EXPECT_EQ(0, delegate_->num_shutdown_requests()); + EXPECT_TRUE( + test_api_->ContainerGroupIsAnimated( + PowerButtonController::ALL_CONTAINERS, + PowerButtonController::ANIMATION_FAST_CLOSE)); + EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); + test_api_->trigger_real_shutdown_timeout(); + EXPECT_EQ(1, delegate_->num_shutdown_requests()); +} + +// Test that we start shutting down immediately if the power button is pressed +// while we're not logged in on an unofficial system. +TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { + controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); + controller_->OnLockStateChange(false); + controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); + EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); +} + +// Test that we start shutting down immediately if the power button is pressed +// while we're logged in as a guest on an unofficial system. +TEST_F(PowerButtonControllerTest, LegacyGuest) { + controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/); + controller_->OnLockStateChange(false); + controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); + EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); +} +#else // When we hold the power button while the user isn't logged in, we should shut // down the machine directly. TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { @@ -364,6 +438,7 @@ TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); EXPECT_FALSE(test_api_->lock_timer_is_running()); } +#endif } // namespace test } // namespace ash diff --git a/build/common.gypi b/build/common.gypi index 0aade78..9c1d9db 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -655,6 +655,10 @@ # Disable Dart by default. 'enable_dart%': 0, + # (Most) Chrome OS hardware reports ACPI power button releases correctly. + # Standard hardware reports releases immediately after presses. + 'chromeos_legacy_power_button%': 0, + 'conditions': [ # Used to disable Native Client at compile time, for platforms where it # isn't supported (ARM) @@ -1059,6 +1063,9 @@ ['chromeos==1', { 'defines': ['OS_CHROMEOS=1'], }], + ['chromeos_legacy_power_button==1', { + 'defines': ['CHROMEOS_LEGACY_POWER_BUTTON=1'], + }], ['use_virtual_keyboard==1', { 'defines': ['USE_VIRTUAL_KEYBOARD=1'], }], |