| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Tests that shutdown animation is not started if the power button is released | 150 // Tests that shutdown animation is not started if the power button is released |
| 151 // quickly. | 151 // quickly. |
| 152 TEST_F(TabletPowerButtonControllerTest, | 152 TEST_F(TabletPowerButtonControllerTest, |
| 153 ReleasePowerButtonBeforeStartingShutdownAnimation) { | 153 ReleasePowerButtonBeforeStartingShutdownAnimation) { |
| 154 PressPowerButton(); | 154 PressPowerButton(); |
| 155 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | 155 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); |
| 156 EXPECT_FALSE(GetBacklightsForcedOff()); | 156 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 157 ReleasePowerButton(); | 157 ReleasePowerButton(); |
| 158 power_manager_client_->SendBrightnessChanged(0, true); | 158 power_manager_client_->SendBrightnessChanged(0, false); |
| 159 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | 159 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); |
| 160 EXPECT_TRUE(GetBacklightsForcedOff()); | 160 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 161 | 161 |
| 162 PressPowerButton(); | 162 PressPowerButton(); |
| 163 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, true); | 163 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 164 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | 164 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); |
| 165 EXPECT_FALSE(GetBacklightsForcedOff()); | 165 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 166 ReleasePowerButton(); | 166 ReleasePowerButton(); |
| 167 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | 167 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); |
| 168 EXPECT_FALSE(GetBacklightsForcedOff()); | 168 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Tests that the shutdown animation is started when the power button is | 171 // Tests that the shutdown animation is started when the power button is |
| 172 // released after the timer fires. | 172 // released after the timer fires. |
| 173 TEST_F(TabletPowerButtonControllerTest, | 173 TEST_F(TabletPowerButtonControllerTest, |
| 174 ReleasePowerButtonDuringShutdownAnimation) { | 174 ReleasePowerButtonDuringShutdownAnimation) { |
| 175 // Initializes LockStateControllerTestApi to observe shutdown animation timer. | 175 // Initializes LockStateControllerTestApi to observe shutdown animation timer. |
| 176 std::unique_ptr<LockStateControllerTestApi> lock_state_test_api = | 176 std::unique_ptr<LockStateControllerTestApi> lock_state_test_api = |
| 177 base::MakeUnique<LockStateControllerTestApi>(lock_state_controller_); | 177 base::MakeUnique<LockStateControllerTestApi>(lock_state_controller_); |
| 178 | 178 |
| 179 PressPowerButton(); | 179 PressPowerButton(); |
| 180 test_api_->TriggerShutdownTimeout(); | 180 test_api_->TriggerShutdownTimeout(); |
| 181 EXPECT_TRUE(lock_state_test_api->shutdown_timer_is_running()); | 181 EXPECT_TRUE(lock_state_test_api->shutdown_timer_is_running()); |
| 182 ReleasePowerButton(); | 182 ReleasePowerButton(); |
| 183 EXPECT_FALSE(lock_state_test_api->shutdown_timer_is_running()); | 183 EXPECT_FALSE(lock_state_test_api->shutdown_timer_is_running()); |
| 184 EXPECT_FALSE(GetBacklightsForcedOff()); | 184 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 185 | 185 |
| 186 // Test again when backlights is forced off. | 186 // Test again when backlights is forced off. |
| 187 PressPowerButton(); | 187 PressPowerButton(); |
| 188 ReleasePowerButton(); | 188 ReleasePowerButton(); |
| 189 power_manager_client_->SendBrightnessChanged(0, true); | 189 power_manager_client_->SendBrightnessChanged(0, false); |
| 190 EXPECT_TRUE(GetBacklightsForcedOff()); | 190 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 191 | 191 |
| 192 PressPowerButton(); | 192 PressPowerButton(); |
| 193 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, true); | 193 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 194 EXPECT_FALSE(GetBacklightsForcedOff()); | 194 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 195 test_api_->TriggerShutdownTimeout(); | 195 test_api_->TriggerShutdownTimeout(); |
| 196 EXPECT_TRUE(lock_state_test_api->shutdown_timer_is_running()); | 196 EXPECT_TRUE(lock_state_test_api->shutdown_timer_is_running()); |
| 197 ReleasePowerButton(); | 197 ReleasePowerButton(); |
| 198 EXPECT_FALSE(lock_state_test_api->shutdown_timer_is_running()); | 198 EXPECT_FALSE(lock_state_test_api->shutdown_timer_is_running()); |
| 199 EXPECT_FALSE(GetBacklightsForcedOff()); | 199 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Tests tapping power button when screen is idle off. | 202 // Tests tapping power button when screen is idle off. |
| 203 TEST_F(TabletPowerButtonControllerTest, TappingPowerButtonWhenScreenIsIdleOff) { | 203 TEST_F(TabletPowerButtonControllerTest, TappingPowerButtonWhenScreenIsIdleOff) { |
| 204 power_manager_client_->SendBrightnessChanged(0, false); | 204 power_manager_client_->SendBrightnessChanged(0, false); |
| 205 PressPowerButton(); | 205 PressPowerButton(); |
| 206 EXPECT_FALSE(GetBacklightsForcedOff()); | 206 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 207 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, true); | 207 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 208 ReleasePowerButton(); | 208 ReleasePowerButton(); |
| 209 EXPECT_FALSE(GetBacklightsForcedOff()); | 209 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Tests tapping power button when device is suspended. | 212 // Tests tapping power button when device is suspended. |
| 213 TEST_F(TabletPowerButtonControllerTest, TappingPowerButtonWhenSuspended) { | 213 TEST_F(TabletPowerButtonControllerTest, TappingPowerButtonWhenSuspended) { |
| 214 base::SimpleTestTickClock* tick_clock = new base::SimpleTestTickClock; | 214 base::SimpleTestTickClock* tick_clock = new base::SimpleTestTickClock; |
| 215 // |tick_clock| owned by |tablet_controller_|. | 215 // |tick_clock| owned by |tablet_controller_|. |
| 216 tablet_controller_->SetTickClockForTesting( | 216 tablet_controller_->SetTickClockForTesting( |
| 217 std::unique_ptr<base::TickClock>(tick_clock)); | 217 std::unique_ptr<base::TickClock>(tick_clock)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 238 } | 238 } |
| 239 | 239 |
| 240 // For convertible device working on laptop mode, tests keyboard/mouse event | 240 // For convertible device working on laptop mode, tests keyboard/mouse event |
| 241 // when screen is off. | 241 // when screen is off. |
| 242 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnLaptopMode) { | 242 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnLaptopMode) { |
| 243 EnableMaximizeMode(false); | 243 EnableMaximizeMode(false); |
| 244 | 244 |
| 245 // KeyEvent should SetBacklightsForcedOff(false). | 245 // KeyEvent should SetBacklightsForcedOff(false). |
| 246 PressPowerButton(); | 246 PressPowerButton(); |
| 247 ReleasePowerButton(); | 247 ReleasePowerButton(); |
| 248 power_manager_client_->SendBrightnessChanged(0, true); | 248 power_manager_client_->SendBrightnessChanged(0, false); |
| 249 EXPECT_TRUE(GetBacklightsForcedOff()); | 249 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 250 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); | 250 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); |
| 251 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, true); | 251 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 252 EXPECT_FALSE(GetBacklightsForcedOff()); | 252 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 253 | 253 |
| 254 // Regular mouse event should SetBacklightsForcedOff(false). | 254 // Regular mouse event should SetBacklightsForcedOff(false). |
| 255 PressPowerButton(); | 255 PressPowerButton(); |
| 256 ReleasePowerButton(); | 256 ReleasePowerButton(); |
| 257 power_manager_client_->SendBrightnessChanged(0, true); | 257 power_manager_client_->SendBrightnessChanged(0, false); |
| 258 EXPECT_TRUE(GetBacklightsForcedOff()); | 258 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 259 generator_->MoveMouseBy(1, 1); | 259 generator_->MoveMouseBy(1, 1); |
| 260 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, true); | 260 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 261 EXPECT_FALSE(GetBacklightsForcedOff()); | 261 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 262 | 262 |
| 263 // Synthesized mouse event should not SetBacklightsForcedOff(false). | 263 // Synthesized mouse event should not SetBacklightsForcedOff(false). |
| 264 PressPowerButton(); | 264 PressPowerButton(); |
| 265 ReleasePowerButton(); | 265 ReleasePowerButton(); |
| 266 power_manager_client_->SendBrightnessChanged(0, true); | 266 power_manager_client_->SendBrightnessChanged(0, false); |
| 267 EXPECT_TRUE(GetBacklightsForcedOff()); | 267 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 268 generator_->set_flags(ui::EF_IS_SYNTHESIZED); | 268 generator_->set_flags(ui::EF_IS_SYNTHESIZED); |
| 269 generator_->MoveMouseBy(1, 1); | 269 generator_->MoveMouseBy(1, 1); |
| 270 generator_->set_flags(ui::EF_NONE); | 270 generator_->set_flags(ui::EF_NONE); |
| 271 EXPECT_TRUE(GetBacklightsForcedOff()); | 271 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 272 | 272 |
| 273 // Stylus mouse event should not SetBacklightsForcedOff(false). | 273 // Stylus mouse event should not SetBacklightsForcedOff(false). |
| 274 EXPECT_TRUE(GetBacklightsForcedOff()); | 274 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 275 generator_->EnterPenPointerMode(); | 275 generator_->EnterPenPointerMode(); |
| 276 generator_->MoveMouseBy(1, 1); | 276 generator_->MoveMouseBy(1, 1); |
| 277 EXPECT_TRUE(GetBacklightsForcedOff()); | 277 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 278 generator_->ExitPenPointerMode(); | 278 generator_->ExitPenPointerMode(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 // For convertible device working on tablet mode, keyboard/mouse event should | 281 // For convertible device working on tablet mode, keyboard/mouse event should |
| 282 // not SetBacklightsForcedOff(false) when screen is off. | 282 // not SetBacklightsForcedOff(false) when screen is off. |
| 283 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnMaximizeMode) { | 283 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnMaximizeMode) { |
| 284 EnableMaximizeMode(true); | 284 EnableMaximizeMode(true); |
| 285 | 285 |
| 286 PressPowerButton(); | 286 PressPowerButton(); |
| 287 ReleasePowerButton(); | 287 ReleasePowerButton(); |
| 288 power_manager_client_->SendBrightnessChanged(0, true); | 288 power_manager_client_->SendBrightnessChanged(0, false); |
| 289 EXPECT_TRUE(GetBacklightsForcedOff()); | 289 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 290 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); | 290 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); |
| 291 EXPECT_TRUE(GetBacklightsForcedOff()); | 291 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 292 | 292 |
| 293 generator_->MoveMouseBy(1, 1); | 293 generator_->MoveMouseBy(1, 1); |
| 294 EXPECT_TRUE(GetBacklightsForcedOff()); | 294 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 295 | 295 |
| 296 generator_->EnterPenPointerMode(); | 296 generator_->EnterPenPointerMode(); |
| 297 generator_->MoveMouseBy(1, 1); | 297 generator_->MoveMouseBy(1, 1); |
| 298 EXPECT_TRUE(GetBacklightsForcedOff()); | 298 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 299 generator_->ExitPenPointerMode(); | 299 generator_->ExitPenPointerMode(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 } // namespace test | 302 } // namespace test |
| 303 } // namespace ash | 303 } // namespace ash |
| OLD | NEW |