Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1197)

Side by Side Diff: remoting/client/plugin/touch_input_scaler_unittest.cc

Issue 1228333004: Move code that doesn't depend on PPAPI out of remoting/client/plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/client/plugin/touch_input_scaler.cc ('k') | remoting/client/touch_input_scaler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "remoting/client/plugin/touch_input_scaler.h"
6
7 #include <cmath>
8
9 #include "remoting/protocol/protocol_mock_objects.h"
10 #include "remoting/protocol/test_event_matchers.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using ::testing::_;
15 using ::testing::AllOf;
16 using ::testing::PrintToString;
17
18 namespace remoting {
19
20 using protocol::MockInputStub;
21 using protocol::TouchEvent;
22 using protocol::TouchEventPoint;
23 using protocol::test::EqualsTouchPointCoordinates;
24 using protocol::test::EqualsTouchPointRadii;
25
26 namespace {
27
28 const float kDefaultRadius = 30.0f;
29 const float kDefaultXCoord = 1.0f;
30 const float kDefaultYCoord = 1.0f;
31
32 struct PointInfo {
33 PointInfo(float x, float y)
34 : PointInfo(x, y, kDefaultRadius, kDefaultRadius) {}
35 PointInfo(float x, float y, float radius_x, float radius_y)
36 : x(x), y(y), radius_x(radius_x), radius_y(radius_y) {}
37
38 float x;
39 float y;
40 float radius_x;
41 float radius_y;
42 };
43
44 const PointInfo kDefaultPointInfo = {kDefaultXCoord,
45 kDefaultYCoord,
46 kDefaultRadius,
47 kDefaultRadius};
48
49 } // namespace
50
51 class TouchInputScalerTest : public ::testing::Test {
52 protected:
53 TouchInputScalerTest() : touch_input_scaler_(&mock_stub_) {}
54
55 void AddInputCoordinate(const PointInfo& point_info) {
56 point_infos_.push_back(point_info);
57 }
58
59 void AddDefaultTestPoint() { point_infos_.push_back(kDefaultPointInfo); }
60
61 void InjectTestTouchEvent() {
62 TouchEvent e;
63 e.set_event_type(TouchEvent::TOUCH_POINT_MOVE);
64
65 uint32_t id = 1;
66 for (const PointInfo& point_info : point_infos_) {
67 TouchEventPoint* point = e.add_touch_points();
68 point->set_id(id++);
69 point->set_x(point_info.x);
70 point->set_y(point_info.y);
71 point->set_radius_x(point_info.radius_x);
72 point->set_radius_y(point_info.radius_y);
73 }
74
75 touch_input_scaler_.InjectTouchEvent(e);
76 }
77
78 void SetInputDimensions(int width, int height) {
79 touch_input_scaler_.set_input_size(webrtc::DesktopSize(width, height));
80 }
81
82 void SetOutputDimensions(int width, int height) {
83 touch_input_scaler_.set_output_size(webrtc::DesktopSize(width, height));
84 }
85
86 MockInputStub mock_stub_;
87 TouchInputScaler touch_input_scaler_;
88
89 private:
90 std::vector<PointInfo> point_infos_;
91
92 DISALLOW_COPY_AND_ASSIGN(TouchInputScalerTest);
93 };
94
95 // TouchInputFilter require both input and output dimensions.
96 // These test verify that no events are forwarded to the next InputStub if
97 // either dimensions are not set or 0.
98 TEST_F(TouchInputScalerTest, NoDimensionsSet) {
99 AddDefaultTestPoint();
100 EXPECT_CALL(mock_stub_, InjectTouchEvent(_)).Times(0);
101 InjectTestTouchEvent();
102 }
103
104 TEST_F(TouchInputScalerTest, BothDimensionsZero) {
105 SetInputDimensions(0, 0);
106 SetOutputDimensions(0, 0);
107 AddDefaultTestPoint();
108 EXPECT_CALL(mock_stub_, InjectTouchEvent(_)).Times(0);
109 InjectTestTouchEvent();
110 }
111
112 TEST_F(TouchInputScalerTest, SetOnlyInputDimensions) {
113 SetInputDimensions(50, 60);
114 AddDefaultTestPoint();
115 EXPECT_CALL(mock_stub_, InjectTouchEvent(_)).Times(0);
116 InjectTestTouchEvent();
117 }
118
119 TEST_F(TouchInputScalerTest, SetOnlyOutputDimensions) {
120 SetOutputDimensions(50, 60);
121 AddDefaultTestPoint();
122 EXPECT_CALL(mock_stub_, InjectTouchEvent(_)).Times(0);
123 InjectTestTouchEvent();
124 }
125
126 // The x,y coordinate fall in the desktop size.
127 TEST_F(TouchInputScalerTest, NoClampingNoScaling) {
128 SetInputDimensions(50, 60);
129 SetOutputDimensions(50, 60);
130
131 AddInputCoordinate({10.0f, 15.0f});
132 TouchEvent expected_out;
133 TouchEventPoint* point = expected_out.add_touch_points();
134 point->set_x(10.0f);
135 point->set_y(15.0f);
136
137 EXPECT_CALL(mock_stub_,
138 InjectTouchEvent(EqualsTouchPointCoordinates(expected_out)));
139 InjectTestTouchEvent();
140 }
141
142 // Make sure clamping works.
143 TEST_F(TouchInputScalerTest, ClampingNoScaling) {
144 SetInputDimensions(50, 60);
145 SetOutputDimensions(50, 60);
146
147 // Note that this could happen if touch started in the chromoting window but
148 // the finger moved off the windows.
149 AddInputCoordinate({-1.0f, 1.0f});
150 TouchEvent expected_out;
151 TouchEventPoint* point = expected_out.add_touch_points();
152 point->set_x(0.0f);
153 point->set_y(1.0f);
154
155 EXPECT_CALL(mock_stub_,
156 InjectTouchEvent(EqualsTouchPointCoordinates(expected_out)));
157 InjectTestTouchEvent();
158 }
159
160 TEST_F(TouchInputScalerTest, ClampingMultiplePointsNoScaling) {
161 SetInputDimensions(50, 60);
162 SetOutputDimensions(50, 60);
163
164 AddInputCoordinate({-1.0f, 1.0f}); // Fall off left.
165 TouchEvent expected_out;
166 TouchEventPoint* point = expected_out.add_touch_points();
167 point->set_x(0.0f);
168 point->set_y(1.0f);
169
170 AddInputCoordinate({100.0f, 1.0f}); // Fall off right.
171 point = expected_out.add_touch_points();
172 point->set_x(49.0f);
173 point->set_y(1.0f);
174
175 AddInputCoordinate({20.0f, 15.0f}); // Should not be clamped.
176 point = expected_out.add_touch_points();
177 point->set_x(20.0f);
178 point->set_y(15.0f);
179
180 AddInputCoordinate({3.0f, -1.0f}); // Fall off above.
181 point = expected_out.add_touch_points();
182 point->set_x(3.0f);
183 point->set_y(0.0f);
184
185 AddInputCoordinate({10.0f, 200.0f}); // Fall off below.
186 point = expected_out.add_touch_points();
187 point->set_x(10.0f);
188 point->set_y(59.0f);
189
190 EXPECT_CALL(mock_stub_,
191 InjectTouchEvent(EqualsTouchPointCoordinates(expected_out)));
192 InjectTestTouchEvent();
193 }
194
195 // Verify up-scaling works. All coordinates should fall inside the output
196 // dimensions after scaling.
197 TEST_F(TouchInputScalerTest, UpScalingNoClamping) {
198 SetInputDimensions(20, 20);
199 SetOutputDimensions(40, 40);
200
201 AddInputCoordinate({1.0f, 1.0f});
202 TouchEvent expected_out;
203 TouchEventPoint* point = expected_out.add_touch_points();
204 point->set_x(2.0f);
205 point->set_y(2.0f);
206
207 AddInputCoordinate({1.2f, 4.2f});
208 point = expected_out.add_touch_points();
209 point->set_x(2.4f);
210 point->set_y(8.4f);
211
212 EXPECT_CALL(mock_stub_,
213 InjectTouchEvent(EqualsTouchPointCoordinates(expected_out)));
214 InjectTestTouchEvent();
215 }
216
217 // Verify up-scaling works with clamping.
218 TEST_F(TouchInputScalerTest, UpScalingWithClamping) {
219 SetInputDimensions(20, 20);
220 SetOutputDimensions(40, 40);
221
222 AddInputCoordinate({25.0f, 25.0f});
223 TouchEvent expected_out;
224 TouchEventPoint* point = expected_out.add_touch_points();
225 point->set_x(39.0f);
226 point->set_y(39.0f);
227
228 EXPECT_CALL(mock_stub_,
229 InjectTouchEvent(EqualsTouchPointCoordinates(expected_out)));
230 InjectTestTouchEvent();
231 }
232
233 // Verify down scaling works. All coordinates should fall inside the output
234 // dimensions after scaling.
235 TEST_F(TouchInputScalerTest, DownScalingNoClamping) {
236 SetInputDimensions(40, 40);
237 SetOutputDimensions(20, 20);
238
239 AddInputCoordinate({2.0f, 2.0f});
240 TouchEvent expected_out;
241 TouchEventPoint* point = expected_out.add_touch_points();
242 point->set_x(1.0f);
243 point->set_y(1.0f);
244
245 AddInputCoordinate({6.0f, 3.0f});
246 point = expected_out.add_touch_points();
247 point->set_x(3.0);
248 point->set_y(1.5f);
249
250 EXPECT_CALL(mock_stub_,
251 InjectTouchEvent(EqualsTouchPointCoordinates(expected_out)));
252 InjectTestTouchEvent();
253 }
254
255 // Verify down scaling works with clamping.
256 TEST_F(TouchInputScalerTest, DownScalingWithClamping) {
257 SetInputDimensions(40, 40);
258 SetOutputDimensions(20, 20);
259
260 AddInputCoordinate({-20.0f, 10.0f});
261 TouchEvent expected_out;
262 TouchEventPoint* point = expected_out.add_touch_points();
263 point->set_x(0.0f);
264 point->set_y(5.0f);
265
266 AddInputCoordinate({10.0f, -20.0f});
267 point = expected_out.add_touch_points();
268 point->set_x(5.0f);
269 point->set_y(0.0f);
270
271 AddInputCoordinate({6.0f, 80.0f});
272 point = expected_out.add_touch_points();
273 point->set_x(3.0f);
274 point->set_y(19.0f);
275
276 AddInputCoordinate({80.0f, 6.0f});
277 point = expected_out.add_touch_points();
278 point->set_x(19.0f);
279 point->set_y(3.0f);
280
281 EXPECT_CALL(mock_stub_,
282 InjectTouchEvent(EqualsTouchPointCoordinates(expected_out)));
283 InjectTestTouchEvent();
284 }
285
286 // Verify that the radii are up-scaled.
287 TEST_F(TouchInputScalerTest, UpScaleRadii) {
288 SetInputDimensions(20, 20);
289 SetOutputDimensions(40, 40);
290
291 AddInputCoordinate({0.0f, 0.0f, 1.0f, 2.0f});
292 TouchEvent expected_out;
293 TouchEventPoint* point = expected_out.add_touch_points();
294 point->set_radius_x(2.0f);
295 point->set_radius_y(4.0f);
296
297 EXPECT_CALL(mock_stub_,
298 InjectTouchEvent(EqualsTouchPointRadii(expected_out)));
299 InjectTestTouchEvent();
300 }
301
302 // Verify that the radii are down-scaled.
303 TEST_F(TouchInputScalerTest, DownScaleRadii) {
304 SetInputDimensions(20, 20);
305 SetOutputDimensions(10, 10);
306
307 AddInputCoordinate({0.0f, 0.0f, 5.0f, 4.0f});
308 TouchEvent expected_out;
309 TouchEventPoint* point = expected_out.add_touch_points();
310 point->set_radius_x(2.5f);
311 point->set_radius_y(2.0f);
312
313 EXPECT_CALL(mock_stub_,
314 InjectTouchEvent(EqualsTouchPointRadii(expected_out)));
315 InjectTestTouchEvent();
316 }
317
318 // Verify that up-scaling with clamping works for x,y coordinates and radii all
319 // work together.
320 TEST_F(TouchInputScalerTest, UpScaleCoordinatesAndRadii) {
321 SetInputDimensions(20, 20);
322 SetOutputDimensions(40, 40);
323
324 AddInputCoordinate({5.0f, 12.0f, 3.0f, 2.0f});
325 TouchEvent expected_out;
326 TouchEventPoint* point = expected_out.add_touch_points();
327 point->set_x(10.0f);
328 point->set_y(24.0f);
329 point->set_radius_x(6.0f);
330 point->set_radius_y(4.0f);
331
332 // Make sure clamping and scaling all work.
333 AddInputCoordinate({22.0f, -1.0f, 8.0f, 3.0f});
334 point = expected_out.add_touch_points();
335 point->set_x(39.0f);
336 point->set_y(0.0f);
337 point->set_radius_x(16.0f);
338 point->set_radius_y(6.0f);
339
340 EXPECT_CALL(mock_stub_,
341 InjectTouchEvent(AllOf(EqualsTouchPointCoordinates(expected_out),
342 EqualsTouchPointRadii(expected_out))));
343 InjectTestTouchEvent();
344 }
345
346 // Verify that down-scaling with clamping works for x,y coordinates and radii
347 // all work together.
348 TEST_F(TouchInputScalerTest, DownScaleCoordinatesAndRadii) {
349 SetInputDimensions(60, 60);
350 SetOutputDimensions(20, 20);
351
352 AddInputCoordinate({50.0f, 24.0f, 10.0f, 9.0f});
353 TouchEvent expected_out;
354 TouchEventPoint* point = expected_out.add_touch_points();
355 point->set_x(16.666f);
356 point->set_y(8.0f);
357 point->set_radius_x(3.333f);
358 point->set_radius_y(3.0f);
359
360 // Make sure clamping and scaling all work.
361 AddInputCoordinate({70.0f, 82.0f, 8.0f, 3.0f});
362 point = expected_out.add_touch_points();
363 point->set_x(19.0f);
364 point->set_y(19.0f);
365 point->set_radius_x(2.666f);
366 point->set_radius_y(1.0f);
367
368 EXPECT_CALL(mock_stub_,
369 InjectTouchEvent(AllOf(EqualsTouchPointCoordinates(expected_out),
370 EqualsTouchPointRadii(expected_out))));
371 InjectTestTouchEvent();
372 }
373
374 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/touch_input_scaler.cc ('k') | remoting/client/touch_input_scaler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698