power_button_controller_test_api.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/system/power/power_button_controller_test_api.h"
  5. #include "ash/system/power/power_button_display_controller.h"
  6. #include "ash/system/power/power_button_menu_screen_view.h"
  7. #include "ash/system/power/power_button_menu_view.h"
  8. #include "ash/system/power/power_button_screenshot_controller.h"
  9. #include "base/time/default_tick_clock.h"
  10. #include "ui/gfx/geometry/rect.h"
  11. #include "ui/views/widget/widget.h"
  12. namespace ash {
  13. PowerButtonControllerTestApi::PowerButtonControllerTestApi(
  14. PowerButtonController* controller)
  15. : controller_(controller) {}
  16. PowerButtonControllerTestApi::~PowerButtonControllerTestApi() = default;
  17. bool PowerButtonControllerTestApi::PreShutdownTimerIsRunning() const {
  18. return controller_->pre_shutdown_timer_.IsRunning();
  19. }
  20. bool PowerButtonControllerTestApi::TriggerPreShutdownTimeout() {
  21. if (!controller_->pre_shutdown_timer_.IsRunning())
  22. return false;
  23. controller_->pre_shutdown_timer_.FireNow();
  24. return true;
  25. }
  26. bool PowerButtonControllerTestApi::PowerButtonMenuTimerIsRunning() const {
  27. return controller_->power_button_menu_timer_.IsRunning();
  28. }
  29. bool PowerButtonControllerTestApi::TriggerPowerButtonMenuTimeout() {
  30. if (!controller_->power_button_menu_timer_.IsRunning())
  31. return false;
  32. controller_->power_button_menu_timer_.FireNow();
  33. return true;
  34. }
  35. void PowerButtonControllerTestApi::SendKeyEvent(ui::KeyEvent* event) {
  36. controller_->display_controller_->OnKeyEvent(event);
  37. }
  38. gfx::Rect PowerButtonControllerTestApi::GetMenuBoundsInScreen() const {
  39. return IsMenuOpened() ? GetPowerButtonMenuView()->GetBoundsInScreen()
  40. : gfx::Rect();
  41. }
  42. PowerButtonMenuView* PowerButtonControllerTestApi::GetPowerButtonMenuView()
  43. const {
  44. return IsMenuOpened() ? static_cast<PowerButtonMenuScreenView*>(
  45. controller_->menu_widget_->GetContentsView())
  46. ->power_button_menu_view()
  47. : nullptr;
  48. }
  49. bool PowerButtonControllerTestApi::IsMenuOpened() const {
  50. return controller_->IsMenuOpened();
  51. }
  52. bool PowerButtonControllerTestApi::MenuHasSignOutItem() const {
  53. return IsMenuOpened() && GetPowerButtonMenuView()->sign_out_item_for_test();
  54. }
  55. bool PowerButtonControllerTestApi::MenuHasLockScreenItem() const {
  56. return IsMenuOpened() &&
  57. GetPowerButtonMenuView()->lock_screen_item_for_test();
  58. }
  59. bool PowerButtonControllerTestApi::MenuHasFeedbackItem() const {
  60. return IsMenuOpened() && GetPowerButtonMenuView()->feedback_item_for_test();
  61. }
  62. PowerButtonScreenshotController*
  63. PowerButtonControllerTestApi::GetScreenshotController() {
  64. return controller_->screenshot_controller_.get();
  65. }
  66. void PowerButtonControllerTestApi::SetPowerButtonType(
  67. PowerButtonController::ButtonType button_type) {
  68. controller_->button_type_ = button_type;
  69. }
  70. void PowerButtonControllerTestApi::SetTickClock(
  71. const base::TickClock* tick_clock) {
  72. DCHECK(tick_clock);
  73. controller_->tick_clock_ = tick_clock;
  74. controller_->display_controller_ =
  75. std::make_unique<PowerButtonDisplayController>(
  76. controller_->backlights_forced_off_setter_, controller_->tick_clock_);
  77. }
  78. void PowerButtonControllerTestApi::SetShowMenuAnimationDone(
  79. bool show_menu_animation_done) {
  80. controller_->show_menu_animation_done_ = show_menu_animation_done;
  81. }
  82. bool PowerButtonControllerTestApi::ShowMenuAnimationDone() const {
  83. return controller_->show_menu_animation_done_;
  84. }
  85. } // namespace ash