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 5 #ifndef ASH_SYSTEM_POWER_POWER_BUTTON_CONTROLLER_TEST_API_H_ 6 #define ASH_SYSTEM_POWER_POWER_BUTTON_CONTROLLER_TEST_API_H_ 7 8 #include "ash/system/power/power_button_controller.h" 9 #include "base/compiler_specific.h" 10 #include "base/macros.h" 11 12 namespace base { 13 class TickClock; 14 } // namespace base 15 16 namespace ui { 17 class KeyEvent; 18 } // namespace ui 19 20 namespace gfx { 21 class Rect; 22 } // namespace gfx 23 24 namespace ash { 25 class PowerButtonMenuView; 26 class PowerButtonScreenshotController; 27 28 // Helper class used by tests to access PowerButtonController's internal state. 29 class PowerButtonControllerTestApi { 30 public: 31 explicit PowerButtonControllerTestApi(PowerButtonController* controller); 32 ~PowerButtonControllerTestApi(); 33 34 // Returns true when |controller_->pre_shutdown_timer_| is running. 35 bool PreShutdownTimerIsRunning() const; 36 37 // If |controller_->pre_shutdown_timer_| is running, stops it, runs its task, 38 // and returns true. Otherwise, returns false. 39 bool TriggerPreShutdownTimeout() WARN_UNUSED_RESULT; 40 41 // Returns true when |power_button_menu_timer_| is running. 42 bool PowerButtonMenuTimerIsRunning() const; 43 44 // If |controller_->power_button_menu_timer_| is running, stops it, runs its 45 // task, and returns true. Otherwise, returns false. 46 bool TriggerPowerButtonMenuTimeout() WARN_UNUSED_RESULT; 47 48 // Sends |event| to |controller_->display_controller_|. 49 void SendKeyEvent(ui::KeyEvent* event); 50 51 // Gets the bounds of the menu view in screen. 52 gfx::Rect GetMenuBoundsInScreen() const; 53 54 // Gets the PowerButtonMenuView of the |controller_|'s menu, which is used by 55 // GetMenuBoundsInScreen. 56 PowerButtonMenuView* GetPowerButtonMenuView() const; 57 58 // True if the menu is opened. 59 bool IsMenuOpened() const; 60 61 // True if |controller_|'s menu has a sign out item. 62 bool MenuHasSignOutItem() const; 63 64 // True if |controller_|'s menu has a lock screen item. 65 bool MenuHasLockScreenItem() const; 66 67 // True if |controller_|'s menu has a feedback item. 68 bool MenuHasFeedbackItem() const; 69 70 PowerButtonScreenshotController* GetScreenshotController(); 71 72 void SetPowerButtonType(PowerButtonController::ButtonType button_type); 73 74 void SetTickClock(const base::TickClock* tick_clock); 75 76 void SetShowMenuAnimationDone(bool show_menu_animation_done); 77 78 // Gets |show_menu_animation_done_| of |controller_|. 79 bool ShowMenuAnimationDone() const; 80 81 private: 82 PowerButtonController* controller_; // Not owned. 83 84 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTestApi); 85 }; 86 87 } // namespace ash 88 89 #endif // ASH_SYSTEM_POWER_POWER_BUTTON_CONTROLLER_TEST_API_H_ 90