| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system/chromeos/power/tablet_power_button_controller.h" | 5 #include "ash/system/chromeos/power/tablet_power_button_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 TEST_F(TabletPowerButtonControllerTest, LockScreenIfRequired) { | 133 TEST_F(TabletPowerButtonControllerTest, LockScreenIfRequired) { |
| 134 Initialize(LoginStatus::USER); | 134 Initialize(LoginStatus::USER); |
| 135 SetShouldLockScreenAutomatically(true); | 135 SetShouldLockScreenAutomatically(true); |
| 136 EXPECT_FALSE(GetLockedState()); | 136 EXPECT_FALSE(GetLockedState()); |
| 137 | 137 |
| 138 // On User logged in status, power-button-press-release should lock screen if | 138 // On User logged in status, power-button-press-release should lock screen if |
| 139 // automatic screen-locking was requested. | 139 // automatic screen-locking was requested. |
| 140 PressPowerButton(); | 140 PressPowerButton(); |
| 141 ReleasePowerButton(); | 141 ReleasePowerButton(); |
| 142 EXPECT_TRUE(test_api_->LockScreenTimerIsRunning()); | |
| 143 EXPECT_FALSE(GetLockedState()); | |
| 144 test_api_->TriggerLockScreenTimeout(); | |
| 145 EXPECT_TRUE(GetLockedState()); | 142 EXPECT_TRUE(GetLockedState()); |
| 146 | 143 |
| 147 // On locked state, power-button-press-release should do nothing. | 144 // On locked state, power-button-press-release should do nothing. |
| 148 PressPowerButton(); | 145 PressPowerButton(); |
| 149 ReleasePowerButton(); | 146 ReleasePowerButton(); |
| 150 EXPECT_FALSE(test_api_->LockScreenTimerIsRunning()); | |
| 151 EXPECT_TRUE(GetLockedState()); | 147 EXPECT_TRUE(GetLockedState()); |
| 152 | 148 |
| 153 // Unlock the sceen. | 149 // Unlock the sceen. |
| 154 UnlockScreen(); | 150 UnlockScreen(); |
| 155 ASSERT_FALSE(GetLockedState()); | 151 ASSERT_FALSE(GetLockedState()); |
| 156 | 152 |
| 157 // power-button-press-release should not lock the screen if automatic | 153 // power-button-press-release should not lock the screen if automatic |
| 158 // screen-locking wasn't requested. | 154 // screen-locking wasn't requested. |
| 159 SetShouldLockScreenAutomatically(false); | 155 SetShouldLockScreenAutomatically(false); |
| 160 PressPowerButton(); | 156 PressPowerButton(); |
| 161 ReleasePowerButton(); | 157 ReleasePowerButton(); |
| 162 EXPECT_FALSE(test_api_->LockScreenTimerIsRunning()); | |
| 163 EXPECT_FALSE(GetLockedState()); | 158 EXPECT_FALSE(GetLockedState()); |
| 164 } | 159 } |
| 165 | 160 |
| 166 // Tests when display is on, quickly tapping power button two times, screen is | |
| 167 // not locked. | |
| 168 TEST_F(TabletPowerButtonControllerTest, LockScreenGracePeriodTest) { | |
| 169 Initialize(LoginStatus::USER); | |
| 170 SetShouldLockScreenAutomatically(true); | |
| 171 EXPECT_FALSE(GetLockedState()); | |
| 172 | |
| 173 PressPowerButton(); | |
| 174 ReleasePowerButton(); | |
| 175 power_manager_client_->SendBrightnessChanged(0, false); | |
| 176 EXPECT_TRUE(test_api_->LockScreenTimerIsRunning()); | |
| 177 PressPowerButton(); | |
| 178 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
| 179 EXPECT_FALSE(test_api_->LockScreenTimerIsRunning()); | |
| 180 ReleasePowerButton(); | |
| 181 EXPECT_FALSE(test_api_->LockScreenTimerIsRunning()); | |
| 182 EXPECT_FALSE(GetLockedState()); | |
| 183 } | |
| 184 | |
| 185 // Tests that shutdown animation is not started if the power button is released | 161 // Tests that shutdown animation is not started if the power button is released |
| 186 // quickly. | 162 // quickly. |
| 187 TEST_F(TabletPowerButtonControllerTest, | 163 TEST_F(TabletPowerButtonControllerTest, |
| 188 ReleasePowerButtonBeforeStartingShutdownAnimation) { | 164 ReleasePowerButtonBeforeStartingShutdownAnimation) { |
| 189 PressPowerButton(); | 165 PressPowerButton(); |
| 190 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | 166 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); |
| 191 EXPECT_FALSE(GetBacklightsForcedOff()); | 167 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 192 ReleasePowerButton(); | 168 ReleasePowerButton(); |
| 193 power_manager_client_->SendBrightnessChanged(0, false); | 169 power_manager_client_->SendBrightnessChanged(0, false); |
| 194 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | 170 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 tablet_controller_->OnMaximizeModeEnded(); | 434 tablet_controller_->OnMaximizeModeEnded(); |
| 459 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); | 435 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); |
| 460 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(4500)); | 436 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(4500)); |
| 461 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | 437 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); |
| 462 EXPECT_FALSE(GetLockedState()); | 438 EXPECT_FALSE(GetLockedState()); |
| 463 EXPECT_FALSE(GetBacklightsForcedOff()); | 439 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 464 } | 440 } |
| 465 | 441 |
| 466 } // namespace test | 442 } // namespace test |
| 467 } // namespace ash | 443 } // namespace ash |
| OLD | NEW |