| 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" |
| 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
| 15 #include "ash/test/lock_state_controller_test_api.h" | 15 #include "ash/test/lock_state_controller_test_api.h" |
| 16 #include "ash/test/test_shell_delegate.h" |
| 16 #include "ash/wm/lock_state_controller.h" | 17 #include "ash/wm/lock_state_controller.h" |
| 17 #include "ash/wm/power_button_controller.h" | 18 #include "ash/wm/power_button_controller.h" |
| 18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 19 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
| 20 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 21 #include "base/test/simple_test_tick_clock.h" | 22 #include "base/test/simple_test_tick_clock.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "chromeos/dbus/fake_power_manager_client.h" | 24 #include "chromeos/dbus/fake_power_manager_client.h" |
| 24 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
| 25 #include "ui/events/test/event_generator.h" | 26 #include "ui/events/test/event_generator.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 54 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 55 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 55 switches::kAshEnableTabletPowerButton); | 56 switches::kAshEnableTabletPowerButton); |
| 56 AshTestBase::SetUp(); | 57 AshTestBase::SetUp(); |
| 57 | 58 |
| 58 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); | 59 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); |
| 59 tablet_controller_ = Shell::GetInstance() | 60 tablet_controller_ = Shell::GetInstance() |
| 60 ->power_button_controller() | 61 ->power_button_controller() |
| 61 ->tablet_power_button_controller_for_test(); | 62 ->tablet_power_button_controller_for_test(); |
| 62 test_api_ = base::MakeUnique<TabletPowerButtonController::TestApi>( | 63 test_api_ = base::MakeUnique<TabletPowerButtonController::TestApi>( |
| 63 tablet_controller_); | 64 tablet_controller_); |
| 65 shell_delegate_ = |
| 66 static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); |
| 64 generator_ = &AshTestBase::GetEventGenerator(); | 67 generator_ = &AshTestBase::GetEventGenerator(); |
| 65 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | 68 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 66 EXPECT_FALSE(GetBacklightsForcedOff()); | 69 EXPECT_FALSE(GetBacklightsForcedOff()); |
| 67 } | 70 } |
| 68 | 71 |
| 69 void TearDown() override { | 72 void TearDown() override { |
| 70 generator_ = nullptr; | 73 generator_ = nullptr; |
| 71 AshTestBase::TearDown(); | 74 AshTestBase::TearDown(); |
| 72 chromeos::DBusThreadManager::Shutdown(); | 75 chromeos::DBusThreadManager::Shutdown(); |
| 73 } | 76 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 base::RunLoop().RunUntilIdle(); | 111 base::RunLoop().RunUntilIdle(); |
| 109 return forced_off; | 112 return forced_off; |
| 110 } | 113 } |
| 111 | 114 |
| 112 // Ownership is passed on to chromeos::DBusThreadManager. | 115 // Ownership is passed on to chromeos::DBusThreadManager. |
| 113 chromeos::FakePowerManagerClient* power_manager_client_; | 116 chromeos::FakePowerManagerClient* power_manager_client_; |
| 114 | 117 |
| 115 LockStateController* lock_state_controller_; // Not owned. | 118 LockStateController* lock_state_controller_; // Not owned. |
| 116 TabletPowerButtonController* tablet_controller_; // Not owned. | 119 TabletPowerButtonController* tablet_controller_; // Not owned. |
| 117 std::unique_ptr<TabletPowerButtonController::TestApi> test_api_; | 120 std::unique_ptr<TabletPowerButtonController::TestApi> test_api_; |
| 121 TestShellDelegate* shell_delegate_; // Not owned. |
| 118 ui::test::EventGenerator* generator_ = nullptr; | 122 ui::test::EventGenerator* generator_ = nullptr; |
| 119 | 123 |
| 120 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonControllerTest); | 124 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonControllerTest); |
| 121 }; | 125 }; |
| 122 | 126 |
| 123 TEST_F(TabletPowerButtonControllerTest, LockScreenIfRequired) { | 127 TEST_F(TabletPowerButtonControllerTest, LockScreenIfRequired) { |
| 124 Initialize(LoginStatus::USER); | 128 Initialize(LoginStatus::USER); |
| 125 SetShouldLockScreenAutomatically(true); | 129 SetShouldLockScreenAutomatically(true); |
| 126 EXPECT_FALSE(GetLockedState()); | 130 EXPECT_FALSE(GetLockedState()); |
| 127 | 131 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 PressPowerButton(); | 320 PressPowerButton(); |
| 317 tablet_controller_->OnKeyEvent(&power_key_pressed); | 321 tablet_controller_->OnKeyEvent(&power_key_pressed); |
| 318 tablet_controller_->OnKeyEvent(&power_key_pressed); | 322 tablet_controller_->OnKeyEvent(&power_key_pressed); |
| 319 tablet_controller_->OnKeyEvent(&power_key_pressed); | 323 tablet_controller_->OnKeyEvent(&power_key_pressed); |
| 320 ReleasePowerButton(); | 324 ReleasePowerButton(); |
| 321 tablet_controller_->OnKeyEvent(&power_key_released); | 325 tablet_controller_->OnKeyEvent(&power_key_released); |
| 322 tablet_controller_->OnKeyEvent(&power_key_released); | 326 tablet_controller_->OnKeyEvent(&power_key_released); |
| 323 EXPECT_EQ(1, power_manager_client_->num_set_backlights_forced_off_calls()); | 327 EXPECT_EQ(1, power_manager_client_->num_set_backlights_forced_off_calls()); |
| 324 } | 328 } |
| 325 | 329 |
| 330 // Tests that under (1) tablet power button pressed/released, (2) keyboard/mouse |
| 331 // events on laptop mode when screen is off, requesting/stopping backlights |
| 332 // forced off should also try to toggle touch screen. |
| 333 TEST_F(TabletPowerButtonControllerTest, ToggleTouchScreen) { |
| 334 // Tests tablet power button. |
| 335 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabled()); |
| 336 PressPowerButton(); |
| 337 ReleasePowerButton(); |
| 338 power_manager_client_->SendBrightnessChanged(0, false); |
| 339 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabled()); |
| 340 |
| 341 PressPowerButton(); |
| 342 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 343 ReleasePowerButton(); |
| 344 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabled()); |
| 345 |
| 346 // KeyEvent on laptop mode when screen is off. |
| 347 PressPowerButton(); |
| 348 ReleasePowerButton(); |
| 349 power_manager_client_->SendBrightnessChanged(0, false); |
| 350 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 351 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabled()); |
| 352 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); |
| 353 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 354 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabled()); |
| 355 |
| 356 // MouseEvent on laptop mode when screen is off. |
| 357 PressPowerButton(); |
| 358 ReleasePowerButton(); |
| 359 power_manager_client_->SendBrightnessChanged(0, false); |
| 360 EXPECT_TRUE(GetBacklightsForcedOff()); |
| 361 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabled()); |
| 362 generator_->MoveMouseBy(1, 1); |
| 363 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); |
| 364 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabled()); |
| 365 } |
| 366 |
| 326 } // namespace test | 367 } // namespace test |
| 327 } // namespace ash | 368 } // namespace ash |
| OLD | NEW |