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

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: Rebase. 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
« 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
(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 radius,
21 float pressure) {
22 return ui::TouchEvent(type,
23 gfx::PointF(x, y),
24 0,
25 id,
26 base::TimeDelta::FromMilliseconds(0),
27 radius,
28 radius,
29 0,
30 pressure);
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.
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(1, event.GetActionIndex());
122 EXPECT_EQ(2U, event.GetPointerCount());
123
124 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
125 event.OnTouch(release2);
126 event.CleanupRemovedTouchPoints(release2);
127 EXPECT_EQ(0, event.GetActionIndex());
128 EXPECT_EQ(1U, event.GetPointerCount());
129
130 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]);
131 event.OnTouch(release0);
132 event.CleanupRemovedTouchPoints(release0);
133 EXPECT_EQ(0U, event.GetPointerCount());
134 }
135
136 TEST(MotionEventAuraTest, PointerLocations) {
137 // Test that location information is stored correctly.
138 MotionEventAura event;
139
140 int ids[] = {15, 13};
141 float x;
142 float y;
143 float r;
144 float p;
145
146 x = 14.4f;
147 y = 17.3f;
148 r = 25.7f;
149 p = 48.2f;
150 TouchEvent press0 = TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, r, p);
151 event.OnTouch(press0);
152
153 EXPECT_EQ(1U, event.GetPointerCount());
154 EXPECT_FLOAT_EQ(x, event.GetX(0));
155 EXPECT_FLOAT_EQ(y, event.GetY(0));
156 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(0) / 2);
157 EXPECT_FLOAT_EQ(p, event.GetPressure(0));
158
159 x = 17.8f;
160 y = 12.1f;
161 r = 21.2f;
162 p = 18.4f;
163 TouchEvent press1 = TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, r, p);
164 event.OnTouch(press1);
165
166 EXPECT_EQ(2U, event.GetPointerCount());
167 EXPECT_FLOAT_EQ(x, event.GetX(1));
168 EXPECT_FLOAT_EQ(y, event.GetY(1));
169 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(1) / 2);
170 EXPECT_FLOAT_EQ(p, event.GetPressure(1));
171
172 // Test cloning of pointer location information.
173 scoped_ptr<MotionEvent> clone = event.Clone();
174 EXPECT_EQ(2U, clone->GetPointerCount());
175 EXPECT_FLOAT_EQ(x, clone->GetX(1));
176 EXPECT_FLOAT_EQ(y, clone->GetY(1));
177 EXPECT_FLOAT_EQ(r, clone->GetTouchMajor(1) / 2);
178 EXPECT_FLOAT_EQ(p, clone->GetPressure(1));
179
180 x = 27.9f;
181 y = 22.3f;
182 r = 7.6f;
183 p = 82.1f;
184 TouchEvent move1 = TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, r, p);
185 event.OnTouch(move1);
186
187 EXPECT_FLOAT_EQ(x, event.GetX(1));
188 EXPECT_FLOAT_EQ(y, event.GetY(1));
189 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(1) / 2);
190 EXPECT_FLOAT_EQ(p, event.GetPressure(1));
191
192
193 x = 34.6f;
194 y = 23.8f;
195 r = 12.9f;
196 p = 14.2f;
197 TouchEvent move0 = TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, r, p);
198 event.OnTouch(move0);
199
200 EXPECT_FLOAT_EQ(x, event.GetX(0));
201 EXPECT_FLOAT_EQ(y, event.GetY(0));
202 EXPECT_FLOAT_EQ(r, event.GetTouchMajor(0) / 2);
203 EXPECT_FLOAT_EQ(p, event.GetPressure(0));
204 }
205
206 TEST(MotionEventAuraTest, Timestamps) {
207 // Test that timestamp information is stored and converted correctly.
208 MotionEventAura event;
209 int ids[] = {7, 13};
210 int times_in_ms[] = {59436, 60263, 82175};
211
212 TouchEvent press0 = TouchWithTime(
213 ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]);
214 event.OnTouch(press0);
215 EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime());
216
217 TouchEvent press1 = TouchWithTime(
218 ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]);
219 event.OnTouch(press1);
220 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime());
221
222 TouchEvent move0 = TouchWithTime(
223 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]);
224 event.OnTouch(move0);
225 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime());
226
227 // Test cloning of timestamp information.
228 scoped_ptr<MotionEvent> clone = event.Clone();
229 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime());
230 }
231
232 TEST(MotionEventAuraTest, CachedAction) {
233 // Test that the cached action and cached action index are correct.
234 int ids[] = {4, 6};
235 MotionEventAura event;
236
237 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
238 event.OnTouch(press0);
239 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction());
240 EXPECT_EQ(1U, event.GetPointerCount());
241
242 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
243 event.OnTouch(press1);
244 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
245 EXPECT_EQ(1, event.GetActionIndex());
246 EXPECT_EQ(2U, event.GetPointerCount());
247
248 // Test cloning of CachedAction information.
249 scoped_ptr<MotionEvent> clone = event.Clone();
250 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction());
251 EXPECT_EQ(1, clone->GetActionIndex());
252
253 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]);
254 event.OnTouch(move0);
255 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction());
256 EXPECT_EQ(2U, event.GetPointerCount());
257
258 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
259 event.OnTouch(release0);
260 EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction());
261 EXPECT_EQ(2U, event.GetPointerCount());
262 event.CleanupRemovedTouchPoints(release0);
263 EXPECT_EQ(1U, event.GetPointerCount());
264
265 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
266 event.OnTouch(release1);
267 EXPECT_EQ(MotionEvent::ACTION_UP, event.GetAction());
268 EXPECT_EQ(1U, event.GetPointerCount());
269 event.CleanupRemovedTouchPoints(release1);
270 EXPECT_EQ(0U, event.GetPointerCount());
271 }
272
273 TEST(MotionEventAuraTest, Cancel) {
274 int ids[] = {4, 6};
275 MotionEventAura event;
276
277 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
278 event.OnTouch(press0);
279 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction());
280 EXPECT_EQ(1U, event.GetPointerCount());
281
282 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
283 event.OnTouch(press1);
284 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
285 EXPECT_EQ(1, event.GetActionIndex());
286 EXPECT_EQ(2U, event.GetPointerCount());
287
288 scoped_ptr<MotionEvent> cancel = event.Cancel();
289 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction());
290 EXPECT_EQ(2U, static_cast<MotionEventAura*>(cancel.get())->GetPointerCount());
291 }
292
293 } // 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