1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101

ash / system / power / power_button_controller_test_api.h [blame]

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_POWER_POWER_BUTTON_CONTROLLER_TEST_API_H_
#define ASH_SYSTEM_POWER_POWER_BUTTON_CONTROLLER_TEST_API_H_

#include "ash/system/power/power_button_controller.h"
#include "base/memory/raw_ptr.h"

namespace base {
class TickClock;
}  // namespace base

namespace ui {
class KeyEvent;
}  // namespace ui

namespace gfx {
class Rect;
}  // namespace gfx

namespace ash {
class PowerButtonMenuView;
class PowerButtonScreenshotController;

// Helper class used by tests to access PowerButtonController's internal state.
class PowerButtonControllerTestApi {
 public:
  explicit PowerButtonControllerTestApi(PowerButtonController* controller);

  PowerButtonControllerTestApi(const PowerButtonControllerTestApi&) = delete;
  PowerButtonControllerTestApi& operator=(const PowerButtonControllerTestApi&) =
      delete;

  ~PowerButtonControllerTestApi();

  // Returns true when |controller_->pre_shutdown_timer_| is running.
  bool PreShutdownTimerIsRunning() const;

  // If |controller_->pre_shutdown_timer_| is running, stops it, runs its task,
  // and returns true. Otherwise, returns false.
  [[nodiscard]] bool TriggerPreShutdownTimeout();

  // Returns true when |power_button_menu_timer_| is running.
  bool PowerButtonMenuTimerIsRunning() const;

  // If |controller_->power_button_menu_timer_| is running, stops it, runs its
  // task, and returns true. Otherwise, returns false.
  [[nodiscard]] bool TriggerPowerButtonMenuTimeout();

  // Sends |event| to |controller_->display_controller_|.
  void SendKeyEvent(ui::KeyEvent* event);

  // Gets the bounds of the menu view in screen.
  gfx::Rect GetMenuBoundsInScreen() const;

  // Gets the PowerButtonMenuView of the |controller_|'s menu, which is used by
  // GetMenuBoundsInScreen.
  PowerButtonMenuView* GetPowerButtonMenuView() const;

  // Gets the layer associated with the `controller_`'s menu background
  // (a `PowerButtonMenuBackgroundView`).
  ui::Layer* GetPowerButtonMenuBackgroundLayer() const;

  // True if the menu is opened.
  bool IsMenuOpened() const;

  // True if |controller_|'s menu has a power off item.
  bool MenuHasPowerOffItem() const;

  // True if |controller_|'s menu has a sign out item.
  bool MenuHasSignOutItem() const;

  // True if |controller_|'s menu has a lock screen item.
  bool MenuHasLockScreenItem() const;

  // True if |controller_|'s menu has a capture mode item.
  bool MenuHasCaptureModeItem() const;

  // True if |controller_|'s menu has a feedback item.
  bool MenuHasFeedbackItem() const;

  PowerButtonScreenshotController* GetScreenshotController();

  void SetPowerButtonType(PowerButtonController::ButtonType button_type);

  void SetTickClock(const base::TickClock* tick_clock);

  void SetShowMenuAnimationDone(bool show_menu_animation_done);

  // Gets |show_menu_animation_done_| of |controller_|.
  bool ShowMenuAnimationDone() const;

 private:
  raw_ptr<PowerButtonController, DanglingUntriaged> controller_;  // Not owned.
};

}  // namespace ash

#endif  // ASH_SYSTEM_POWER_POWER_BUTTON_CONTROLLER_TEST_API_H_