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

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

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