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

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

Issue 251543003: Unified Gesture Recognizer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address jdduke comments. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/events/event.h"
7 #include "ui/events/gestures/motion_event_aura.h"
8
9 namespace {
10
11 ui::TouchEvent TouchWithType(ui::EventType type, int id) {
12 return ui::TouchEvent(
13 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(0));
14 }
15
16 ui::TouchEvent TouchWithPosition(ui::EventType type,
17 int id,
18 float x,
19 float y,
20 float r,
jdduke (slow) 2014/05/05 16:57:09 For my sanity could you use full names for r(adius
tdresser 2014/05/05 17:45:14 Done, though I haven't changed |PointerLocations|.
21 float p) {
22 return ui::TouchEvent(type,
23 gfx::PointF(x, y),
24 0,
25 id,
26 base::TimeDelta::FromMilliseconds(0),
27 r,
28 r,
29 0,
30 p);
31 }
32
33 ui::TouchEvent TouchWithTime(ui::EventType type, int id, int ms) {
34 return ui::TouchEvent(
35 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(ms));
36 }
37
38 base::TimeTicks MsToTicks(int ms) {
39 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms);
40 }
41
42 } // namespace
43
44 namespace ui {
45
46 TEST(MotionEventAuraTest, PointerCountAndIds) {
47 // Test that |PointerCount()| returns the correct number of pointers, and ids
48 // are assigned correctly.
49 int ids[] = {4, 6, 1};
50
51 MotionEventAura event;
52 EXPECT_EQ(0U, event.GetPointerCount());
53
54 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
55 event.OnTouch(press0);
56 EXPECT_EQ(1U, event.GetPointerCount());
57
58 EXPECT_EQ(ids[0], event.GetPointerId(0));
59
60 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
61 event.OnTouch(press1);
62 EXPECT_EQ(2U, event.GetPointerCount());
63
64 EXPECT_EQ(ids[0], event.GetPointerId(0));
65 EXPECT_EQ(ids[1], event.GetPointerId(1));
66
67 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]);
68 event.OnTouch(press2);
69 EXPECT_EQ(3U, event.GetPointerCount());
70
71 EXPECT_EQ(ids[0], event.GetPointerId(0));
72 EXPECT_EQ(ids[1], event.GetPointerId(1));
73 EXPECT_EQ(ids[2], event.GetPointerId(2));
74
75 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
76 event.OnTouch(release1);
77 event.CleanupRemovedTouchPoints(release1);
78 EXPECT_EQ(2U, event.GetPointerCount());
79
80 EXPECT_EQ(ids[0], event.GetPointerId(0));
81 EXPECT_EQ(ids[2], event.GetPointerId(1));
82
83 // Test cloning of pointer count and id information.
84 scoped_ptr<MotionEvent> clone = event.Clone();
85 EXPECT_EQ(2U, clone->GetPointerCount());
86 EXPECT_EQ(ids[0], clone->GetPointerId(0));
87 EXPECT_EQ(ids[2], clone->GetPointerId(1));
88
89 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
90 event.OnTouch(release0);
91 event.CleanupRemovedTouchPoints(release0);
92 EXPECT_EQ(1U, event.GetPointerCount());
93
94 EXPECT_EQ(ids[2], event.GetPointerId(0));
95
96 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]);
97 event.OnTouch(release2);
98 event.CleanupRemovedTouchPoints(release2);
99 EXPECT_EQ(0U, event.GetPointerCount());
100 }
101
102 TEST(MotionEventAuraTest, GetActionIndexAfterRemoval) {
103 // Test that |GetActionIndex()| returns the correct index when points have
104 // been removed.
jdduke (slow) 2014/05/05 16:57:09 Hmm, I don't see any |GetActionIndex()| calls in t
tdresser 2014/05/05 17:45:14 Done.
105 int ids[] = {4, 6, 9};
106
107 MotionEventAura event;
108 EXPECT_EQ(0U, event.GetPointerCount());
109
110 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
111 event.OnTouch(press0);
112 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
113 event.OnTouch(press1);
114 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]);
115 event.OnTouch(press2);
116 EXPECT_EQ(3U, event.GetPointerCount());
117
118 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
119 event.OnTouch(release1);
120 event.CleanupRemovedTouchPoints(release1);
121 EXPECT_EQ(2U, event.GetPointerCount());
122
123 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]);
124 event.OnTouch(release2);
125 event.CleanupRemovedTouchPoints(release2);
126 EXPECT_EQ(1U, event.GetPointerCount());
127
128 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
129 event.OnTouch(release0);
130 event.CleanupRemovedTouchPoints(release0);
131 EXPECT_EQ(0U, event.GetPointerCount());
132 }
133
134 TEST(MotionEventAuraTest, PointerLocations) {
135 // Test that location information is stored correctly.
136 MotionEventAura event;
137
138 int ids[] = {15, 13};
139 float x;
140 float y;
141 float r;
142 float p;
143
144 x = 14.4f;
145 y = 17.3f;
146 r = 25.7f;
147 p = 48.2f;
148 TouchEvent press0 = TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, r, p);
149 event.OnTouch(press0);
150
151 EXPECT_EQ(1U, event.GetPointerCount());
152 EXPECT_FLOAT_EQ(x, event.GetX(0));
153 EXPECT_FLOAT_EQ(y, event.GetY(0));
154 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(0) / 2);
155 EXPECT_FLOAT_EQ(p, event.GetPressure(0));
156
157 x = 17.8f;
158 y = 12.1f;
159 r = 21.2f;
160 p = 18.4f;
161 TouchEvent press1 = TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, r, p);
162 event.OnTouch(press1);
163
164 EXPECT_EQ(2U, event.GetPointerCount());
165 EXPECT_FLOAT_EQ(x, event.GetX(1));
166 EXPECT_FLOAT_EQ(y, event.GetY(1));
167 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(1) / 2);
168 EXPECT_FLOAT_EQ(p, event.GetPressure(1));
169
170 // Test cloning of pointer location information.
171 scoped_ptr<MotionEvent> clone = event.Clone();
172 EXPECT_EQ(2U, clone->GetPointerCount());
173 EXPECT_FLOAT_EQ(x, clone->GetX(1));
174 EXPECT_FLOAT_EQ(y, clone->GetY(1));
175 EXPECT_FLOAT_EQ(r, clone->GetTouchMajor(1) / 2);
176 EXPECT_FLOAT_EQ(p, clone->GetPressure(1));
177
178 x = 27.9f;
179 y = 22.3f;
180 r = 7.6f;
181 p = 82.1f;
182 TouchEvent move1 = TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, r, p);
183 event.OnTouch(move1);
184
185 EXPECT_FLOAT_EQ(x, event.GetX(1));
186 EXPECT_FLOAT_EQ(y, event.GetY(1));
187 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(1) / 2);
188 EXPECT_FLOAT_EQ(p, event.GetPressure(1));
189
190
191 x = 34.6f;
192 y = 23.8f;
193 r = 12.9f;
194 p = 14.2f;
195 TouchEvent move0 = TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, r, p);
196 event.OnTouch(move0);
197
198 EXPECT_FLOAT_EQ(x, event.GetX(0));
199 EXPECT_FLOAT_EQ(y, event.GetY(0));
200 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(0) / 2);
201 EXPECT_FLOAT_EQ(p, event.GetPressure(0));
202 }
203
204 TEST(MotionEventAuraTest, Timestamps) {
205 // Test that timestamp information is stored and converted correctly.
206 MotionEventAura event;
207 int ids[] = {7, 13};
208 int times_in_ms[] = {59436, 60263, 82175};
209
210 TouchEvent press0 = TouchWithTime(
211 ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]);
212 event.OnTouch(press0);
213 EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime());
214
215 TouchEvent press1 = TouchWithTime(
216 ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]);
217 event.OnTouch(press1);
218 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime());
219
220 TouchEvent move0 = TouchWithTime(
221 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]);
222 event.OnTouch(move0);
223 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime());
224
225 // Test cloning of timestamp information.
226 scoped_ptr<MotionEvent> clone = event.Clone();
227 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime());
228 }
229
230 TEST(MotionEventAuraTest, CachedAction) {
231 // Test that the cached action and cached action index are correct.
232 int ids[] = {4, 6};
233 MotionEventAura event;
234
235 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
236 event.OnTouch(press0);
237 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction());
238 EXPECT_EQ(1U, event.GetPointerCount());
239
240 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
241 event.OnTouch(press1);
242 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
243 EXPECT_EQ(1, event.GetActionIndex());
244 EXPECT_EQ(2U, event.GetPointerCount());
245
246 // Test cloning of CachedAction information.
247 scoped_ptr<MotionEvent> clone = event.Clone();
248 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction());
249 EXPECT_EQ(1, clone->GetActionIndex());
250
251 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]);
252 event.OnTouch(move0);
253 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction());
254 EXPECT_EQ(2U, event.GetPointerCount());
255
256 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
257 event.OnTouch(release0);
258 EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction());
259 EXPECT_EQ(2U, event.GetPointerCount());
260 event.CleanupRemovedTouchPoints(release0);
261 EXPECT_EQ(1U, event.GetPointerCount());
262
263 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
264 event.OnTouch(release1);
265 EXPECT_EQ(MotionEvent::ACTION_UP, event.GetAction());
266 EXPECT_EQ(1U, event.GetPointerCount());
267 event.CleanupRemovedTouchPoints(release1);
268 EXPECT_EQ(0U, event.GetPointerCount());
269 }
270
271 TEST(MotionEventAuraTest, Cancel) {
272 int ids[] = {4, 6};
273 MotionEventAura event;
274
275 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
276 event.OnTouch(press0);
277 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction());
278 EXPECT_EQ(1U, event.GetPointerCount());
279
280 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
281 event.OnTouch(press1);
282 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
283 EXPECT_EQ(1, event.GetActionIndex());
284 EXPECT_EQ(2U, event.GetPointerCount());
285
286 scoped_ptr<MotionEvent> clone = event.Cancel();
jdduke (slow) 2014/05/05 16:57:09 Nit: Maybe rename clone to cancel?
tdresser 2014/05/05 17:45:14 Done.
287 EXPECT_EQ(MotionEvent::ACTION_CANCEL, clone->GetAction());
288 EXPECT_EQ(2U, static_cast<MotionEventAura*>(clone.get())->GetPointerCount());
289 }
290
291 } // 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