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

Side by Side Diff: ui/events/gestures/motion_event_aura_unittest.cc

Issue 494833003: Completed webkit radiusX, radiusY and rotationAngle handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES
tdresser 2014/08/27 18:31:35 #include <cmath>
mustaq 2014/08/27 20:51:08 Done.
7
5 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/events/event.h" 9 #include "ui/events/event.h"
7 #include "ui/events/gestures/motion_event_aura.h" 10 #include "ui/events/gestures/motion_event_aura.h"
8 11
9 namespace { 12 namespace {
10 13
11 ui::TouchEvent TouchWithType(ui::EventType type, int id) { 14 ui::TouchEvent TouchWithType(ui::EventType type, int id) {
12 return ui::TouchEvent( 15 return ui::TouchEvent(
13 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(0)); 16 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(0));
14 } 17 }
15 18
16 ui::TouchEvent TouchWithPosition(ui::EventType type, 19 ui::TouchEvent TouchWithPosition(ui::EventType type,
17 int id, 20 int id,
18 float x, 21 float x,
19 float y, 22 float y,
20 float raw_x, 23 float raw_x,
21 float raw_y, 24 float raw_y) {
22 float radius,
23 float pressure) {
24 ui::TouchEvent event(type, 25 ui::TouchEvent event(type,
25 gfx::PointF(x, y), 26 gfx::PointF(x, y),
26 0, 27 0,
27 id, 28 id,
28 base::TimeDelta::FromMilliseconds(0), 29 base::TimeDelta::FromMilliseconds(0),
29 radius,
30 radius,
31 0, 30 0,
31 0,
32 0,
33 0);
34 event.set_root_location(gfx::PointF(raw_x, raw_y));
35 return event;
36 }
37
38 ui::TouchEvent TouchWithTapParams(ui::EventType type,
39 int id,
40 float radius_x,
41 float radius_y,
42 float rotation_angle,
43 float pressure) {
44 ui::TouchEvent event(type,
45 gfx::PointF(1, 1),
46 0,
47 id,
48 base::TimeDelta::FromMilliseconds(0),
49 radius_x,
50 radius_y,
51 rotation_angle,
32 pressure); 52 pressure);
33 event.set_root_location(gfx::PointF(raw_x, raw_y)); 53 event.set_root_location(gfx::PointF(1, 1));
34 return event; 54 return event;
35 } 55 }
36 56
37 ui::TouchEvent TouchWithTime(ui::EventType type, int id, int ms) { 57 ui::TouchEvent TouchWithTime(ui::EventType type, int id, int ms) {
38 return ui::TouchEvent( 58 return ui::TouchEvent(
39 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(ms)); 59 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(ms));
40 } 60 }
41 61
42 base::TimeTicks MsToTicks(int ms) { 62 base::TimeTicks MsToTicks(int ms) {
43 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); 63 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 98
79 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); 99 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
80 event.OnTouch(release1); 100 event.OnTouch(release1);
81 event.CleanupRemovedTouchPoints(release1); 101 event.CleanupRemovedTouchPoints(release1);
82 EXPECT_EQ(2U, event.GetPointerCount()); 102 EXPECT_EQ(2U, event.GetPointerCount());
83 103
84 EXPECT_EQ(ids[0], event.GetPointerId(0)); 104 EXPECT_EQ(ids[0], event.GetPointerId(0));
85 EXPECT_EQ(ids[2], event.GetPointerId(1)); 105 EXPECT_EQ(ids[2], event.GetPointerId(1));
86 106
87 // Test cloning of pointer count and id information. 107 // Test cloning of pointer count and id information.
108 // TODO(mustaq): Make a separate clone test
88 scoped_ptr<MotionEvent> clone = event.Clone(); 109 scoped_ptr<MotionEvent> clone = event.Clone();
89 EXPECT_EQ(2U, clone->GetPointerCount()); 110 EXPECT_EQ(2U, clone->GetPointerCount());
90 EXPECT_EQ(ids[0], clone->GetPointerId(0)); 111 EXPECT_EQ(ids[0], clone->GetPointerId(0));
91 EXPECT_EQ(ids[2], clone->GetPointerId(1)); 112 EXPECT_EQ(ids[2], clone->GetPointerId(1));
92 113
93 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); 114 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
94 event.OnTouch(release0); 115 event.OnTouch(release0);
95 event.CleanupRemovedTouchPoints(release0); 116 event.CleanupRemovedTouchPoints(release0);
96 EXPECT_EQ(1U, event.GetPointerCount()); 117 EXPECT_EQ(1U, event.GetPointerCount());
97 118
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 MotionEventAura event; 163 MotionEventAura event;
143 164
144 const float kRawOffsetX = 11.1f; 165 const float kRawOffsetX = 11.1f;
145 const float kRawOffsetY = 13.3f; 166 const float kRawOffsetY = 13.3f;
146 167
147 int ids[] = {15, 13}; 168 int ids[] = {15, 13};
148 float x; 169 float x;
149 float y; 170 float y;
150 float raw_x; 171 float raw_x;
151 float raw_y; 172 float raw_y;
152 float r;
153 float p;
154 173
155 x = 14.4f; 174 x = 14.4f;
156 y = 17.3f; 175 y = 17.3f;
157 raw_x = x + kRawOffsetX; 176 raw_x = x + kRawOffsetX;
158 raw_y = y + kRawOffsetY; 177 raw_y = y + kRawOffsetY;
159 r = 25.7f;
160 p = 48.2f;
161 TouchEvent press0 = 178 TouchEvent press0 =
162 TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, raw_x, raw_y, r, p); 179 TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, raw_x, raw_y);
163 event.OnTouch(press0); 180 event.OnTouch(press0);
164 181
165 EXPECT_EQ(1U, event.GetPointerCount()); 182 EXPECT_EQ(1U, event.GetPointerCount());
166 EXPECT_FLOAT_EQ(x, event.GetX(0)); 183 EXPECT_FLOAT_EQ(x, event.GetX(0));
167 EXPECT_FLOAT_EQ(y, event.GetY(0)); 184 EXPECT_FLOAT_EQ(y, event.GetY(0));
168 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); 185 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0));
169 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); 186 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0));
170 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(0) / 2);
171 EXPECT_FLOAT_EQ(p, event.GetPressure(0));
172 187
173 x = 17.8f; 188 x = 17.8f;
174 y = 12.1f; 189 y = 12.1f;
175 raw_x = x + kRawOffsetX; 190 raw_x = x + kRawOffsetX;
176 raw_y = y + kRawOffsetY; 191 raw_y = y + kRawOffsetY;
177 r = 21.2f;
178 p = 18.4f;
179 TouchEvent press1 = 192 TouchEvent press1 =
180 TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, raw_x, raw_y, r, p); 193 TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, raw_x, raw_y);
181 event.OnTouch(press1); 194 event.OnTouch(press1);
182 195
183 EXPECT_EQ(2U, event.GetPointerCount()); 196 EXPECT_EQ(2U, event.GetPointerCount());
184 EXPECT_FLOAT_EQ(x, event.GetX(1)); 197 EXPECT_FLOAT_EQ(x, event.GetX(1));
185 EXPECT_FLOAT_EQ(y, event.GetY(1)); 198 EXPECT_FLOAT_EQ(y, event.GetY(1));
186 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); 199 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1));
187 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); 200 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1));
188 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(1) / 2);
189 EXPECT_FLOAT_EQ(p, event.GetPressure(1));
190 201
191 // Test cloning of pointer location information. 202 // Test cloning of pointer location information.
192 scoped_ptr<MotionEvent> clone = event.Clone(); 203 scoped_ptr<MotionEvent> clone = event.Clone();
193 EXPECT_EQ(2U, clone->GetPointerCount()); 204 {
194 EXPECT_FLOAT_EQ(x, clone->GetX(1)); 205 const MotionEventAura* raw_clone_aura =
195 EXPECT_FLOAT_EQ(y, clone->GetY(1)); 206 static_cast<MotionEventAura*>(clone.get());
196 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); 207 EXPECT_EQ(2U, raw_clone_aura->GetPointerCount());
197 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); 208 EXPECT_FLOAT_EQ(x, raw_clone_aura->GetX(1));
198 EXPECT_FLOAT_EQ(r, clone->GetTouchMajor(1) / 2); 209 EXPECT_FLOAT_EQ(y, raw_clone_aura->GetY(1));
199 EXPECT_FLOAT_EQ(p, clone->GetPressure(1)); 210 EXPECT_FLOAT_EQ(raw_x, raw_clone_aura->GetRawX(1));
211 EXPECT_FLOAT_EQ(raw_y, raw_clone_aura->GetRawY(1));
212 }
200 213
201 x = 27.9f; 214 x = 27.9f;
202 y = 22.3f; 215 y = 22.3f;
203 raw_x = x + kRawOffsetX; 216 raw_x = x + kRawOffsetX;
204 raw_y = y + kRawOffsetY; 217 raw_y = y + kRawOffsetY;
205 r = 7.6f;
206 p = 82.1f;
207 TouchEvent move1 = 218 TouchEvent move1 =
208 TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, raw_x, raw_y, r, p); 219 TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, raw_x, raw_y);
209 event.OnTouch(move1); 220 event.OnTouch(move1);
210 221
211 EXPECT_FLOAT_EQ(x, event.GetX(1)); 222 EXPECT_FLOAT_EQ(x, event.GetX(1));
212 EXPECT_FLOAT_EQ(y, event.GetY(1)); 223 EXPECT_FLOAT_EQ(y, event.GetY(1));
213 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); 224 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1));
214 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); 225 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1));
215 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(1) / 2);
216 EXPECT_FLOAT_EQ(p, event.GetPressure(1));
217 226
218 x = 34.6f; 227 x = 34.6f;
219 y = 23.8f; 228 y = 23.8f;
220 raw_x = x + kRawOffsetX; 229 raw_x = x + kRawOffsetX;
221 raw_y = y + kRawOffsetY; 230 raw_y = y + kRawOffsetY;
222 r = 12.9f;
223 p = 14.2f;
224 TouchEvent move0 = 231 TouchEvent move0 =
225 TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, raw_x, raw_y, r, p); 232 TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, raw_x, raw_y);
226 event.OnTouch(move0); 233 event.OnTouch(move0);
227 234
228 EXPECT_FLOAT_EQ(x, event.GetX(0)); 235 EXPECT_FLOAT_EQ(x, event.GetX(0));
229 EXPECT_FLOAT_EQ(y, event.GetY(0)); 236 EXPECT_FLOAT_EQ(y, event.GetY(0));
230 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); 237 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0));
231 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); 238 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0));
232 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(0) / 2); 239 }
233 EXPECT_FLOAT_EQ(p, event.GetPressure(0)); 240
241 TEST(MotionEventAuraTest, TapParams) {
242 // Test that touch params are stored correctly.
243 MotionEventAura event;
244
245 int ids[] = {15, 13};
246
247 float radius_x;
248 float radius_y;
249 float rotation_angle;
250 float pressure;
251
252 radius_x = 123.45f;
253 radius_y = 67.89f;
254 rotation_angle = 23.f; // Any positive acute angle
255 pressure = 0.123f;
256 TouchEvent press0 = TouchWithTapParams(
257 ET_TOUCH_PRESSED, ids[0], radius_x, radius_y, rotation_angle, pressure);
258 event.OnTouch(press0);
259
260 EXPECT_EQ(1U, event.GetPointerCount());
261 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMajor(0) / 2);
262 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMinor(0) / 2);
263 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(0) * 180 / M_PI);
264 EXPECT_FLOAT_EQ(pressure, event.GetPressure(0));
265
266 radius_x = 67.89f;
267 radius_y = 123.45f;
268 rotation_angle = 46.f; // Any positive acute angle
269 pressure = 0.456f;
270 TouchEvent press1 = TouchWithTapParams(
271 ET_TOUCH_PRESSED, ids[1], radius_x, radius_y, rotation_angle, pressure);
272 event.OnTouch(press1);
273
274 EXPECT_EQ(2U, event.GetPointerCount());
275 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2);
276 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2);
277 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI + 90);
278 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1));
279
280 // Test cloning of tap params
281 scoped_ptr<MotionEvent> clone = event.Clone();
282 {
283 const MotionEventAura* raw_clone_aura =
284 static_cast<MotionEventAura*>(clone.get());
285 EXPECT_EQ(2U, raw_clone_aura->GetPointerCount());
286 EXPECT_FLOAT_EQ(radius_y, raw_clone_aura->GetTouchMajor(1) / 2);
287 EXPECT_FLOAT_EQ(radius_x, raw_clone_aura->GetTouchMinor(1) / 2);
288 EXPECT_FLOAT_EQ(
289 rotation_angle, raw_clone_aura->GetOrientation(1) * 180 / M_PI + 90);
290 EXPECT_FLOAT_EQ(pressure, raw_clone_aura->GetPressure(1));
291 }
292
293 radius_x = 76.98f;
294 radius_y = 321.54f;
295 rotation_angle = 64.f; // Any positive acute angle
296 pressure = 0.654f;
297 TouchEvent move1 = TouchWithTapParams(
298 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure);
299 event.OnTouch(move1);
300
301 EXPECT_EQ(2U, event.GetPointerCount());
302 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2);
303 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2);
304 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI + 90);
305 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1));
234 } 306 }
235 307
236 TEST(MotionEventAuraTest, Timestamps) { 308 TEST(MotionEventAuraTest, Timestamps) {
237 // Test that timestamp information is stored and converted correctly. 309 // Test that timestamp information is stored and converted correctly.
238 MotionEventAura event; 310 MotionEventAura event;
239 int ids[] = {7, 13}; 311 int ids[] = {7, 13};
240 int times_in_ms[] = {59436, 60263, 82175}; 312 int times_in_ms[] = {59436, 60263, 82175};
241 313
242 TouchEvent press0 = TouchWithTime( 314 TouchEvent press0 = TouchWithTime(
243 ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]); 315 ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 397
326 // For now, all pointers have an unknown tool type. 398 // For now, all pointers have an unknown tool type.
327 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source 399 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source
328 // touch type, crbug.com/404128. 400 // touch type, crbug.com/404128.
329 event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7)); 401 event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7));
330 ASSERT_EQ(1U, event.GetPointerCount()); 402 ASSERT_EQ(1U, event.GetPointerCount());
331 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0)); 403 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0));
332 } 404 }
333 405
334 } // namespace ui 406 } // namespace ui
OLDNEW
« ui/events/gestures/motion_event_aura.cc ('K') | « ui/events/gestures/motion_event_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698