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
  102
  103
  104
  105
  106
  107
  108
  109

ash / wm / tablet_mode / tablet_mode_controller_test_api.h [blame]

// Copyright 2018 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_WM_TABLET_MODE_TABLET_MODE_CONTROLLER_TEST_API_H_
#define ASH_WM_TABLET_MODE_TABLET_MODE_CONTROLLER_TEST_API_H_

#include <memory>

#include "ash/wm/tablet_mode/internal_input_devices_event_blocker.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/memory/raw_ptr.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"

namespace ash {

class InternalInputDevicesEventBlocker;
class TabletModeController;
class TabletModeWindowManager;

// Use the api in this class to test TabletModeController.
class TabletModeControllerTestApi {
 public:
  static constexpr float kDegreesToRadians = 3.1415926f / 180.0f;

  TabletModeControllerTestApi();

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

  ~TabletModeControllerTestApi();

  // Enters or exits tablet mode. Use these instead when stuff such as tray
  // visibilty depends on the event blocker instead of the actual tablet mode.
  void EnterTabletMode();
  void LeaveTabletMode();

  // Called to attach an external mouse/touchpad. If we're currently in tablet
  // mode, tablet mode will be ended because of this.
  void AttachExternalMouse();
  void AttachBluetoothMouse(device::MockBluetoothAdapter* bluetooth_adapter);
  void AttachExternalTouchpad();

  // Called in association with the above to remove all mice/touchpads.
  void DetachAllMice();
  void DetachAllTouchpads();

  void TriggerLidUpdate(const gfx::Vector3dF& lid);
  void TriggerBaseAndLidUpdate(const gfx::Vector3dF& base,
                               const gfx::Vector3dF& lid);

  void OpenLidToAngle(float degrees);
  void HoldDeviceVertical();
  void OpenLid();
  void CloseLid();
  void SetTabletMode(bool on);

  // Called to simulate the device suspend and resume.
  void SuspendImminent();
  void SuspendDone(base::TimeDelta sleep_duration);

  // Sets the event blocker on the tablet mode controller.
  void set_event_blocker(
      std::unique_ptr<InternalInputDevicesEventBlocker> blocker) {
    tablet_mode_controller_->event_blocker_ = std::move(blocker);
  }

  TabletModeWindowManager* tablet_mode_window_manager() {
    return tablet_mode_controller_->tablet_mode_window_manager_.get();
  }

  // Set the TickClock. This is only to be used by tests that need to
  // artificially and deterministically control the current time.
  // This does not take the ownership of the tick_clock. |tick_clock| must
  // outlive the TabletModeController instance.
  void set_tick_clock(const base::TickClock* tick_clock) {
    DCHECK(tick_clock);
    tablet_mode_controller_->tick_clock_ = tick_clock;
  }
  const base::TickClock* tick_clock() {
    return tablet_mode_controller_->tick_clock_;
  }

  bool CanUseUnstableLidAngle() const {
    return tablet_mode_controller_->CanUseUnstableLidAngle();
  }

  bool AreEventsBlocked() const {
    return tablet_mode_controller_->AreInternalInputDeviceEventsBlocked();
  }

  bool IsScreenshotShown() const {
    return !!tablet_mode_controller_->screenshot_layer_;
  }

  bool IsInPhysicalTabletState() const {
    return tablet_mode_controller_->is_in_tablet_physical_state();
  }

  float GetLidAngle() const { return tablet_mode_controller_->lid_angle(); }

 private:
  raw_ptr<TabletModeController> tablet_mode_controller_;
};

}  // namespace ash

#endif  // ASH_WM_TABLET_MODE_TABLET_MODE_CONTROLLER_TEST_API_H_