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(); |
142 EXPECT_TRUE(GetLockedState()); | 145 EXPECT_TRUE(GetLockedState()); |
143 | 146 |
144 // On locked state, power-button-press-release should do nothing. | 147 // On locked state, power-button-press-release should do nothing. |
145 PressPowerButton(); | 148 PressPowerButton(); |
146 ReleasePowerButton(); | 149 ReleasePowerButton(); |
| 150 EXPECT_FALSE(test_api_->LockScreenTimerIsRunning()); |
147 EXPECT_TRUE(GetLockedState()); | 151 EXPECT_TRUE(GetLockedState()); |
148 | 152 |
149 // Unlock the sceen. | 153 // Unlock the sceen. |
150 UnlockScreen(); | 154 UnlockScreen(); |
151 ASSERT_FALSE(GetLockedState()); | 155 ASSERT_FALSE(GetLockedState()); |
152 | 156 |
153 // power-button-press-release should not lock the screen if automatic | 157 // power-button-press-release should not lock the screen if automatic |
154 // screen-locking wasn't requested. | 158 // screen-locking wasn't requested. |
155 SetShouldLockScreenAutomatically(false); | 159 SetShouldLockScreenAutomatically(false); |
156 PressPowerButton(); | 160 PressPowerButton(); |
157 ReleasePowerButton(); | 161 ReleasePowerButton(); |
| 162 EXPECT_FALSE(test_api_->LockScreenTimerIsRunning()); |
158 EXPECT_FALSE(GetLockedState()); | 163 EXPECT_FALSE(GetLockedState()); |
159 } | 164 } |
160 | 165 |
| 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 |
161 // Tests that shutdown animation is not started if the power button is released | 185 // Tests that shutdown animation is not started if the power button is released |
162 // quickly. | 186 // quickly. |
163 TEST_F(TabletPowerButtonControllerTest, | 187 TEST_F(TabletPowerButtonControllerTest, |
164 ReleasePowerButtonBeforeStartingShutdownAnimation) { | 188 ReleasePowerButtonBeforeStartingShutdownAnimation) { |
165 PressPowerButton(); | 189 PressPowerButton(); |
166 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | 190 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); |
167 EXPECT_FALSE(GetBacklightsForcedOff()); | 191 EXPECT_FALSE(GetBacklightsForcedOff()); |
168 ReleasePowerButton(); | 192 ReleasePowerButton(); |
169 power_manager_client_->SendBrightnessChanged(0, false); | 193 power_manager_client_->SendBrightnessChanged(0, false); |
170 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | 194 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 tablet_controller_->OnMaximizeModeEnded(); | 458 tablet_controller_->OnMaximizeModeEnded(); |
435 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); | 459 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); |
436 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(4500)); | 460 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(4500)); |
437 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | 461 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); |
438 EXPECT_FALSE(GetLockedState()); | 462 EXPECT_FALSE(GetLockedState()); |
439 EXPECT_FALSE(GetBacklightsForcedOff()); | 463 EXPECT_FALSE(GetBacklightsForcedOff()); |
440 } | 464 } |
441 | 465 |
442 } // namespace test | 466 } // namespace test |
443 } // namespace ash | 467 } // namespace ash |
OLD | NEW |