1 // Copyright 2018 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 #include "chrome/browser/vr/platform_controller_for_testing.h"
6 #include "base/time/time.h"
7 #include "chrome/browser/vr/model/controller_model.h"
8 #include "ui/gfx/geometry/point_f.h"
9 
10 namespace vr {
11 
PlatformControllerForTesting(ControllerModel * prev_model,ControllerModel * cur_model,base::TimeTicks last_touchpad_timestamp)12 PlatformControllerForTesting::PlatformControllerForTesting(
13     ControllerModel* prev_model,
14     ControllerModel* cur_model,
15     base::TimeTicks last_touchpad_timestamp)
16     : prev_model_(prev_model),
17       cur_model_(cur_model),
18       last_touchpad_timestamp_(last_touchpad_timestamp) {}
19 
IsButtonDown(PlatformController::ButtonType type) const20 bool PlatformControllerForTesting::IsButtonDown(
21     PlatformController::ButtonType type) const {
22   switch (type) {
23     case PlatformController::ButtonType::kButtonMenu:
24       return cur_model_->app_button_state ==
25              ControllerModel::ButtonState::kDown;
26     case PlatformController::ButtonType::kButtonSelect:
27       return cur_model_->touchpad_button_state ==
28              ControllerModel::ButtonState::kDown;
29     default:
30       return false;
31   }
32 }
33 
ButtonUpHappened(PlatformController::ButtonType type) const34 bool PlatformControllerForTesting::ButtonUpHappened(
35     PlatformController::ButtonType type) const {
36   switch (type) {
37     case PlatformController::ButtonType::kButtonMenu:
38       return (cur_model_->app_button_state ==
39                   ControllerModel::ButtonState::kUp &&
40               cur_model_->app_button_state != prev_model_->app_button_state);
41     case PlatformController::ButtonType::kButtonSelect:
42       return (cur_model_->touchpad_button_state ==
43                   ControllerModel::ButtonState::kUp &&
44               cur_model_->touchpad_button_state !=
45                   prev_model_->touchpad_button_state);
46     default:
47       return false;
48   }
49 }
50 
ButtonDownHappened(PlatformController::ButtonType type) const51 bool PlatformControllerForTesting::ButtonDownHappened(
52     PlatformController::ButtonType type) const {
53   switch (type) {
54     case PlatformController::ButtonType::kButtonMenu:
55       return (cur_model_->app_button_state ==
56                   ControllerModel::ButtonState::kDown &&
57               cur_model_->app_button_state != prev_model_->app_button_state);
58     case PlatformController::ButtonType::kButtonSelect:
59       return (cur_model_->touchpad_button_state ==
60                   ControllerModel::ButtonState::kDown &&
61               cur_model_->touchpad_button_state !=
62                   prev_model_->touchpad_button_state);
63     default:
64       return false;
65   }
66 }
67 
IsTouchingTrackpad() const68 bool PlatformControllerForTesting::IsTouchingTrackpad() const {
69   return cur_model_->touching_touchpad;
70 }
71 
GetPositionInTrackpad() const72 gfx::PointF PlatformControllerForTesting::GetPositionInTrackpad() const {
73   return cur_model_->touchpad_touch_position;
74 }
75 
GetLastOrientationTimestamp() const76 base::TimeTicks PlatformControllerForTesting::GetLastOrientationTimestamp()
77     const {
78   return cur_model_->last_orientation_timestamp;
79 }
80 
GetLastTouchTimestamp() const81 base::TimeTicks PlatformControllerForTesting::GetLastTouchTimestamp() const {
82   return last_touchpad_timestamp_;
83 }
84 
GetLastButtonTimestamp() const85 base::TimeTicks PlatformControllerForTesting::GetLastButtonTimestamp() const {
86   return cur_model_->last_button_timestamp;
87 }
88 
GetHandedness() const89 ControllerModel::Handedness PlatformControllerForTesting::GetHandedness()
90     const {
91   return ControllerModel::Handedness::kRightHanded;
92 }
93 
GetRecentered() const94 bool PlatformControllerForTesting::GetRecentered() const {
95   return false;
96 }
97 
GetBatteryLevel() const98 int PlatformControllerForTesting::GetBatteryLevel() const {
99   return 100;
100 }
101 
102 }  // namespace vr
103