19
19
#include "src/server/input/android/android_pointer_controller.h"
21
#include "mir_test_doubles/mock_viewable_area.h"
21
#include "mir_test_doubles/mock_input_region.h"
22
22
#include "mir_test/event_factory.h"
23
23
#include "mir_test/fake_shared.h"
30
30
namespace mi = mir::input;
31
31
namespace mia = mi::android;
32
32
namespace mis = mi::synthesis;
33
namespace mg = mir::graphics;
34
33
namespace geom = mir::geometry;
35
34
namespace mt = mir::test;
36
35
namespace mtd = mir::test::doubles;
49
controller = std::make_shared<mia::PointerController>(mt::fake_shared(viewable_area));
48
controller = std::make_shared<mia::PointerController>(mt::fake_shared(input_region));
52
mtd::MockViewableArea viewable_area;
51
mtd::MockInputRegion input_region;
53
52
std::shared_ptr<mia::PointerController> controller;
70
69
static const float stored_x = 100;
71
70
static const float stored_y = 200;
71
geom::Point stored{stored_x, stored_y};
73
EXPECT_CALL(viewable_area, view_area()).WillOnce(Return(default_view_area));
73
EXPECT_CALL(input_region, confine(stored));
75
75
controller->setPosition(stored_x, stored_y);
86
86
using namespace ::testing;
88
EXPECT_CALL(viewable_area, view_area()).Times(2)
89
.WillRepeatedly(Return(default_view_area));
91
88
static const float start_x = 100;
92
89
static const float start_y = 100;
93
90
static const float dx = 100;
94
91
static const float dy = 50;
92
geom::Point start{start_x, start_y};
93
geom::Point moved{start_x + dx, start_y + dy};
95
EXPECT_CALL(input_region, confine(start));
96
EXPECT_CALL(input_region, confine(moved));
96
98
controller->setPosition(start_x, start_y);
97
99
controller->move(dx, dy);
106
108
TEST_F(AndroidPointerControllerSetup, returns_bounds_of_view_area)
108
110
using namespace ::testing;
109
EXPECT_CALL(viewable_area, view_area()).WillOnce(Return(default_view_area));
111
EXPECT_CALL(input_region, bounding_rectangle())
112
.WillOnce(Return(default_view_area));
111
114
float controller_min_x, controller_min_y, controller_max_x, controller_max_y;
112
115
controller->getBounds(&controller_min_x, &controller_min_y,
122
125
EXPECT_EQ(controller_max_x, area_max_x);
123
126
EXPECT_EQ(controller_max_y, area_max_y);
126
TEST_F(AndroidPointerControllerSetup, clips_to_view_area)
128
using namespace ::testing;
130
float min_x_bound = default_view_area.top_left.x.as_float();
131
float min_y_bound = default_view_area.top_left.x.as_float();
132
float max_x_bound = min_x_bound + default_view_area.size.width.as_float();
133
float max_y_bound = min_y_bound + default_view_area.size.height.as_float();
135
static const float invalid_lower_bound_x = min_x_bound - 1;
136
static const float invalid_lower_bound_y = min_y_bound - 1;
137
static const float invalid_upper_bound_x = max_x_bound + 1;
138
static const float invalid_upper_bound_y = max_y_bound + 1;
140
EXPECT_CALL(viewable_area, view_area()).Times(4).WillRepeatedly(Return(default_view_area));
142
float bounded_x, bounded_y;
144
controller->setPosition(invalid_lower_bound_x, 0);
145
controller->getPosition(&bounded_x, &bounded_y);
146
EXPECT_EQ(min_x_bound, bounded_x);
148
controller->setPosition(0, invalid_lower_bound_y);
149
controller->getPosition(&bounded_x, &bounded_y);
150
EXPECT_EQ(min_y_bound, bounded_y);
152
controller->setPosition(invalid_upper_bound_x, 0);
153
controller->getPosition(&bounded_x, &bounded_y);
154
EXPECT_EQ(max_x_bound, bounded_x);
156
controller->setPosition(0, invalid_upper_bound_y);
157
controller->getPosition(&bounded_x, &bounded_y);
158
EXPECT_EQ(max_y_bound, bounded_y);