OLD | NEW |
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. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 TEST(MotionEventAuraTest, PointerCountAndIds) { | 73 TEST(MotionEventAuraTest, PointerCountAndIds) { |
74 // Test that |PointerCount()| returns the correct number of pointers, and ids | 74 // Test that |PointerCount()| returns the correct number of pointers, and ids |
75 // are assigned correctly. | 75 // are assigned correctly. |
76 int ids[] = {4, 6, 1}; | 76 int ids[] = {4, 6, 1}; |
77 | 77 |
78 MotionEventAura event; | 78 MotionEventAura event; |
79 EXPECT_EQ(0U, event.GetPointerCount()); | 79 EXPECT_EQ(0U, event.GetPointerCount()); |
80 | 80 |
81 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 81 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
82 event.OnTouch(press0); | 82 EXPECT_TRUE(event.OnTouch(press0)); |
83 EXPECT_EQ(1U, event.GetPointerCount()); | 83 EXPECT_EQ(1U, event.GetPointerCount()); |
84 | 84 |
85 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 85 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
86 | 86 |
87 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 87 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
88 event.OnTouch(press1); | 88 EXPECT_TRUE(event.OnTouch(press1)); |
89 EXPECT_EQ(2U, event.GetPointerCount()); | 89 EXPECT_EQ(2U, event.GetPointerCount()); |
90 | 90 |
91 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 91 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
92 EXPECT_EQ(ids[1], event.GetPointerId(1)); | 92 EXPECT_EQ(ids[1], event.GetPointerId(1)); |
93 | 93 |
94 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); | 94 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); |
95 event.OnTouch(press2); | 95 EXPECT_TRUE(event.OnTouch(press2)); |
96 EXPECT_EQ(3U, event.GetPointerCount()); | 96 EXPECT_EQ(3U, event.GetPointerCount()); |
97 | 97 |
98 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 98 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
99 EXPECT_EQ(ids[1], event.GetPointerId(1)); | 99 EXPECT_EQ(ids[1], event.GetPointerId(1)); |
100 EXPECT_EQ(ids[2], event.GetPointerId(2)); | 100 EXPECT_EQ(ids[2], event.GetPointerId(2)); |
101 | 101 |
102 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); | 102 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); |
103 event.OnTouch(release1); | 103 EXPECT_TRUE(event.OnTouch(release1)); |
104 event.CleanupRemovedTouchPoints(release1); | 104 event.CleanupRemovedTouchPoints(release1); |
105 EXPECT_EQ(2U, event.GetPointerCount()); | 105 EXPECT_EQ(2U, event.GetPointerCount()); |
106 | 106 |
107 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 107 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
108 EXPECT_EQ(ids[2], event.GetPointerId(1)); | 108 EXPECT_EQ(ids[2], event.GetPointerId(1)); |
109 | 109 |
110 // Test cloning of pointer count and id information. | 110 // Test cloning of pointer count and id information. |
111 // TODO(mustaq): Make a separate clone test | 111 // TODO(mustaq): Make a separate clone test |
112 scoped_ptr<MotionEvent> clone = event.Clone(); | 112 scoped_ptr<MotionEvent> clone = event.Clone(); |
113 EXPECT_EQ(2U, clone->GetPointerCount()); | 113 EXPECT_EQ(2U, clone->GetPointerCount()); |
114 EXPECT_EQ(ids[0], clone->GetPointerId(0)); | 114 EXPECT_EQ(ids[0], clone->GetPointerId(0)); |
115 EXPECT_EQ(ids[2], clone->GetPointerId(1)); | 115 EXPECT_EQ(ids[2], clone->GetPointerId(1)); |
116 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 116 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
117 | 117 |
118 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 118 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
119 event.OnTouch(release0); | 119 EXPECT_TRUE(event.OnTouch(release0)); |
120 event.CleanupRemovedTouchPoints(release0); | 120 event.CleanupRemovedTouchPoints(release0); |
121 EXPECT_EQ(1U, event.GetPointerCount()); | 121 EXPECT_EQ(1U, event.GetPointerCount()); |
122 | 122 |
123 EXPECT_EQ(ids[2], event.GetPointerId(0)); | 123 EXPECT_EQ(ids[2], event.GetPointerId(0)); |
124 | 124 |
125 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); | 125 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); |
126 event.OnTouch(release2); | 126 EXPECT_TRUE(event.OnTouch(release2)); |
127 event.CleanupRemovedTouchPoints(release2); | 127 event.CleanupRemovedTouchPoints(release2); |
128 EXPECT_EQ(0U, event.GetPointerCount()); | 128 EXPECT_EQ(0U, event.GetPointerCount()); |
129 } | 129 } |
130 | 130 |
131 TEST(MotionEventAuraTest, GetActionIndexAfterRemoval) { | 131 TEST(MotionEventAuraTest, GetActionIndexAfterRemoval) { |
132 // Test that |GetActionIndex()| returns the correct index when points have | 132 // Test that |GetActionIndex()| returns the correct index when points have |
133 // been removed. | 133 // been removed. |
134 int ids[] = {4, 6, 9}; | 134 int ids[] = {4, 6, 9}; |
135 | 135 |
136 MotionEventAura event; | 136 MotionEventAura event; |
137 EXPECT_EQ(0U, event.GetPointerCount()); | 137 EXPECT_EQ(0U, event.GetPointerCount()); |
138 | 138 |
139 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 139 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
140 event.OnTouch(press0); | 140 EXPECT_TRUE(event.OnTouch(press0)); |
141 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 141 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
142 event.OnTouch(press1); | 142 EXPECT_TRUE(event.OnTouch(press1)); |
143 EXPECT_EQ(1, event.GetActionIndex()); | 143 EXPECT_EQ(1, event.GetActionIndex()); |
144 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); | 144 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); |
145 event.OnTouch(press2); | 145 EXPECT_TRUE(event.OnTouch(press2)); |
146 EXPECT_EQ(2, event.GetActionIndex()); | 146 EXPECT_EQ(2, event.GetActionIndex()); |
147 EXPECT_EQ(3U, event.GetPointerCount()); | 147 EXPECT_EQ(3U, event.GetPointerCount()); |
148 | 148 |
149 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); | 149 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); |
150 event.OnTouch(release1); | 150 EXPECT_TRUE(event.OnTouch(release1)); |
151 EXPECT_EQ(1, event.GetActionIndex()); | 151 EXPECT_EQ(1, event.GetActionIndex()); |
152 event.CleanupRemovedTouchPoints(release1); | 152 event.CleanupRemovedTouchPoints(release1); |
153 EXPECT_EQ(2U, event.GetPointerCount()); | 153 EXPECT_EQ(2U, event.GetPointerCount()); |
154 | 154 |
155 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 155 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
156 event.OnTouch(release2); | 156 EXPECT_TRUE(event.OnTouch(release2)); |
157 EXPECT_EQ(0, event.GetActionIndex()); | 157 EXPECT_EQ(0, event.GetActionIndex()); |
158 event.CleanupRemovedTouchPoints(release2); | 158 event.CleanupRemovedTouchPoints(release2); |
159 EXPECT_EQ(1U, event.GetPointerCount()); | 159 EXPECT_EQ(1U, event.GetPointerCount()); |
160 | 160 |
161 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); | 161 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); |
162 event.OnTouch(release0); | 162 EXPECT_TRUE(event.OnTouch(release0)); |
163 event.CleanupRemovedTouchPoints(release0); | 163 event.CleanupRemovedTouchPoints(release0); |
164 EXPECT_EQ(0U, event.GetPointerCount()); | 164 EXPECT_EQ(0U, event.GetPointerCount()); |
165 } | 165 } |
166 | 166 |
167 TEST(MotionEventAuraTest, PointerLocations) { | 167 TEST(MotionEventAuraTest, PointerLocations) { |
168 // Test that location information is stored correctly. | 168 // Test that location information is stored correctly. |
169 MotionEventAura event; | 169 MotionEventAura event; |
170 | 170 |
171 const float kRawOffsetX = 11.1f; | 171 const float kRawOffsetX = 11.1f; |
172 const float kRawOffsetY = 13.3f; | 172 const float kRawOffsetY = 13.3f; |
173 | 173 |
174 int ids[] = {15, 13}; | 174 int ids[] = {15, 13}; |
175 float x; | 175 float x; |
176 float y; | 176 float y; |
177 float raw_x; | 177 float raw_x; |
178 float raw_y; | 178 float raw_y; |
179 | 179 |
180 x = 14.4f; | 180 x = 14.4f; |
181 y = 17.3f; | 181 y = 17.3f; |
182 raw_x = x + kRawOffsetX; | 182 raw_x = x + kRawOffsetX; |
183 raw_y = y + kRawOffsetY; | 183 raw_y = y + kRawOffsetY; |
184 TouchEvent press0 = | 184 TouchEvent press0 = |
185 TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, raw_x, raw_y); | 185 TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, raw_x, raw_y); |
186 event.OnTouch(press0); | 186 EXPECT_TRUE(event.OnTouch(press0)); |
187 | 187 |
188 EXPECT_EQ(1U, event.GetPointerCount()); | 188 EXPECT_EQ(1U, event.GetPointerCount()); |
189 EXPECT_FLOAT_EQ(x, event.GetX(0)); | 189 EXPECT_FLOAT_EQ(x, event.GetX(0)); |
190 EXPECT_FLOAT_EQ(y, event.GetY(0)); | 190 EXPECT_FLOAT_EQ(y, event.GetY(0)); |
191 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); | 191 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); |
192 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); | 192 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); |
193 | 193 |
194 x = 17.8f; | 194 x = 17.8f; |
195 y = 12.1f; | 195 y = 12.1f; |
196 raw_x = x + kRawOffsetX; | 196 raw_x = x + kRawOffsetX; |
197 raw_y = y + kRawOffsetY; | 197 raw_y = y + kRawOffsetY; |
198 TouchEvent press1 = | 198 TouchEvent press1 = |
199 TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, raw_x, raw_y); | 199 TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, raw_x, raw_y); |
200 event.OnTouch(press1); | 200 EXPECT_TRUE(event.OnTouch(press1)); |
201 | 201 |
202 EXPECT_EQ(2U, event.GetPointerCount()); | 202 EXPECT_EQ(2U, event.GetPointerCount()); |
203 EXPECT_FLOAT_EQ(x, event.GetX(1)); | 203 EXPECT_FLOAT_EQ(x, event.GetX(1)); |
204 EXPECT_FLOAT_EQ(y, event.GetY(1)); | 204 EXPECT_FLOAT_EQ(y, event.GetY(1)); |
205 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); | 205 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); |
206 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); | 206 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); |
207 | 207 |
208 // Test cloning of pointer location information. | 208 // Test cloning of pointer location information. |
209 scoped_ptr<MotionEvent> clone = event.Clone(); | 209 scoped_ptr<MotionEvent> clone = event.Clone(); |
210 { | 210 { |
211 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 211 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
212 EXPECT_EQ(2U, clone->GetPointerCount()); | 212 EXPECT_EQ(2U, clone->GetPointerCount()); |
213 EXPECT_FLOAT_EQ(x, clone->GetX(1)); | 213 EXPECT_FLOAT_EQ(x, clone->GetX(1)); |
214 EXPECT_FLOAT_EQ(y, clone->GetY(1)); | 214 EXPECT_FLOAT_EQ(y, clone->GetY(1)); |
215 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); | 215 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); |
216 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); | 216 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); |
217 } | 217 } |
218 | 218 |
219 x = 27.9f; | 219 x = 27.9f; |
220 y = 22.3f; | 220 y = 22.3f; |
221 raw_x = x + kRawOffsetX; | 221 raw_x = x + kRawOffsetX; |
222 raw_y = y + kRawOffsetY; | 222 raw_y = y + kRawOffsetY; |
223 TouchEvent move1 = | 223 TouchEvent move1 = |
224 TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, raw_x, raw_y); | 224 TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, raw_x, raw_y); |
225 event.OnTouch(move1); | 225 EXPECT_TRUE(event.OnTouch(move1)); |
226 | 226 |
227 EXPECT_FLOAT_EQ(x, event.GetX(1)); | 227 EXPECT_FLOAT_EQ(x, event.GetX(1)); |
228 EXPECT_FLOAT_EQ(y, event.GetY(1)); | 228 EXPECT_FLOAT_EQ(y, event.GetY(1)); |
229 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); | 229 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); |
230 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); | 230 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); |
231 | 231 |
232 x = 34.6f; | 232 x = 34.6f; |
233 y = 23.8f; | 233 y = 23.8f; |
234 raw_x = x + kRawOffsetX; | 234 raw_x = x + kRawOffsetX; |
235 raw_y = y + kRawOffsetY; | 235 raw_y = y + kRawOffsetY; |
236 TouchEvent move0 = | 236 TouchEvent move0 = |
237 TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, raw_x, raw_y); | 237 TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, raw_x, raw_y); |
238 event.OnTouch(move0); | 238 EXPECT_TRUE(event.OnTouch(move0)); |
239 | 239 |
240 EXPECT_FLOAT_EQ(x, event.GetX(0)); | 240 EXPECT_FLOAT_EQ(x, event.GetX(0)); |
241 EXPECT_FLOAT_EQ(y, event.GetY(0)); | 241 EXPECT_FLOAT_EQ(y, event.GetY(0)); |
242 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); | 242 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); |
243 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); | 243 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); |
244 } | 244 } |
245 | 245 |
246 TEST(MotionEventAuraTest, TapParams) { | 246 TEST(MotionEventAuraTest, TapParams) { |
247 // Test that touch params are stored correctly. | 247 // Test that touch params are stored correctly. |
248 MotionEventAura event; | 248 MotionEventAura event; |
249 | 249 |
250 int ids[] = {15, 13}; | 250 int ids[] = {15, 13}; |
251 | 251 |
252 float radius_x; | 252 float radius_x; |
253 float radius_y; | 253 float radius_y; |
254 float rotation_angle; | 254 float rotation_angle; |
255 float pressure; | 255 float pressure; |
256 | 256 |
257 radius_x = 123.45f; | 257 radius_x = 123.45f; |
258 radius_y = 67.89f; | 258 radius_y = 67.89f; |
259 rotation_angle = 23.f; | 259 rotation_angle = 23.f; |
260 pressure = 0.123f; | 260 pressure = 0.123f; |
261 TouchEvent press0 = TouchWithTapParams( | 261 TouchEvent press0 = TouchWithTapParams( |
262 ET_TOUCH_PRESSED, ids[0], radius_x, radius_y, rotation_angle, pressure); | 262 ET_TOUCH_PRESSED, ids[0], radius_x, radius_y, rotation_angle, pressure); |
263 event.OnTouch(press0); | 263 EXPECT_TRUE(event.OnTouch(press0)); |
264 | 264 |
265 EXPECT_EQ(1U, event.GetPointerCount()); | 265 EXPECT_EQ(1U, event.GetPointerCount()); |
266 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMajor(0) / 2); | 266 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMajor(0) / 2); |
267 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMinor(0) / 2); | 267 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMinor(0) / 2); |
268 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(0) * 180 / M_PI + 90); | 268 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(0) * 180 / M_PI + 90); |
269 EXPECT_FLOAT_EQ(pressure, event.GetPressure(0)); | 269 EXPECT_FLOAT_EQ(pressure, event.GetPressure(0)); |
270 | 270 |
271 radius_x = 67.89f; | 271 radius_x = 67.89f; |
272 radius_y = 123.45f; | 272 radius_y = 123.45f; |
273 rotation_angle = 46.f; | 273 rotation_angle = 46.f; |
274 pressure = 0.456f; | 274 pressure = 0.456f; |
275 TouchEvent press1 = TouchWithTapParams( | 275 TouchEvent press1 = TouchWithTapParams( |
276 ET_TOUCH_PRESSED, ids[1], radius_x, radius_y, rotation_angle, pressure); | 276 ET_TOUCH_PRESSED, ids[1], radius_x, radius_y, rotation_angle, pressure); |
277 event.OnTouch(press1); | 277 EXPECT_TRUE(event.OnTouch(press1)); |
278 | 278 |
279 EXPECT_EQ(2U, event.GetPointerCount()); | 279 EXPECT_EQ(2U, event.GetPointerCount()); |
280 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); | 280 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); |
281 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); | 281 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); |
282 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); | 282 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); |
283 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); | 283 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); |
284 | 284 |
285 // Test cloning of tap params | 285 // Test cloning of tap params |
286 scoped_ptr<MotionEvent> clone = event.Clone(); | 286 scoped_ptr<MotionEvent> clone = event.Clone(); |
287 { | 287 { |
288 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 288 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
289 EXPECT_EQ(2U, clone->GetPointerCount()); | 289 EXPECT_EQ(2U, clone->GetPointerCount()); |
290 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); | 290 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); |
291 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); | 291 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); |
292 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); | 292 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); |
293 EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); | 293 EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); |
294 } | 294 } |
295 | 295 |
296 radius_x = 76.98f; | 296 radius_x = 76.98f; |
297 radius_y = 321.54f; | 297 radius_y = 321.54f; |
298 rotation_angle = 64.f; | 298 rotation_angle = 64.f; |
299 pressure = 0.654f; | 299 pressure = 0.654f; |
300 TouchEvent move1 = TouchWithTapParams( | 300 TouchEvent move1 = TouchWithTapParams( |
301 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure); | 301 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure); |
302 event.OnTouch(move1); | 302 move1.set_location(gfx::Point(20, 21)); |
| 303 EXPECT_TRUE(event.OnTouch(move1)); |
303 | 304 |
304 EXPECT_EQ(2U, event.GetPointerCount()); | 305 EXPECT_EQ(2U, event.GetPointerCount()); |
305 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); | 306 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); |
306 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); | 307 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); |
307 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); | 308 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); |
308 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); | 309 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); |
309 } | 310 } |
310 | 311 |
311 TEST(MotionEventAuraTest, Timestamps) { | 312 TEST(MotionEventAuraTest, Timestamps) { |
312 // Test that timestamp information is stored and converted correctly. | 313 // Test that timestamp information is stored and converted correctly. |
313 MotionEventAura event; | 314 MotionEventAura event; |
314 int ids[] = {7, 13}; | 315 int ids[] = {7, 13}; |
315 int times_in_ms[] = {59436, 60263, 82175}; | 316 int times_in_ms[] = {59436, 60263, 82175}; |
316 | 317 |
317 TouchEvent press0 = TouchWithTime( | 318 TouchEvent press0 = TouchWithTime( |
318 ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]); | 319 ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]); |
319 event.OnTouch(press0); | 320 EXPECT_TRUE(event.OnTouch(press0)); |
320 EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime()); | 321 EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime()); |
321 | 322 |
322 TouchEvent press1 = TouchWithTime( | 323 TouchEvent press1 = TouchWithTime( |
323 ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]); | 324 ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]); |
324 event.OnTouch(press1); | 325 EXPECT_TRUE(event.OnTouch(press1)); |
325 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime()); | 326 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime()); |
326 | 327 |
327 TouchEvent move0 = TouchWithTime( | 328 TouchEvent move0 = TouchWithTime( |
328 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]); | 329 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]); |
329 event.OnTouch(move0); | 330 move0.set_location(gfx::PointF(12, 21)); |
| 331 EXPECT_TRUE(event.OnTouch(move0)); |
330 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime()); | 332 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime()); |
331 | 333 |
332 // Test cloning of timestamp information. | 334 // Test cloning of timestamp information. |
333 scoped_ptr<MotionEvent> clone = event.Clone(); | 335 scoped_ptr<MotionEvent> clone = event.Clone(); |
334 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime()); | 336 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime()); |
335 } | 337 } |
336 | 338 |
337 TEST(MotionEventAuraTest, CachedAction) { | 339 TEST(MotionEventAuraTest, CachedAction) { |
338 // Test that the cached action and cached action index are correct. | 340 // Test that the cached action and cached action index are correct. |
339 int ids[] = {4, 6}; | 341 int ids[] = {4, 6}; |
340 MotionEventAura event; | 342 MotionEventAura event; |
341 | 343 |
342 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 344 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
343 event.OnTouch(press0); | 345 EXPECT_TRUE(event.OnTouch(press0)); |
344 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); | 346 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); |
345 EXPECT_EQ(1U, event.GetPointerCount()); | 347 EXPECT_EQ(1U, event.GetPointerCount()); |
346 | 348 |
347 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 349 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
348 event.OnTouch(press1); | 350 EXPECT_TRUE(event.OnTouch(press1)); |
349 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 351 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
350 EXPECT_EQ(1, event.GetActionIndex()); | 352 EXPECT_EQ(1, event.GetActionIndex()); |
351 EXPECT_EQ(2U, event.GetPointerCount()); | 353 EXPECT_EQ(2U, event.GetPointerCount()); |
352 | 354 |
353 // Test cloning of CachedAction information. | 355 // Test cloning of CachedAction information. |
354 scoped_ptr<MotionEvent> clone = event.Clone(); | 356 scoped_ptr<MotionEvent> clone = event.Clone(); |
355 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction()); | 357 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction()); |
356 EXPECT_EQ(1, clone->GetActionIndex()); | 358 EXPECT_EQ(1, clone->GetActionIndex()); |
357 | 359 |
358 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]); | 360 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]); |
359 event.OnTouch(move0); | 361 move0.set_location(gfx::PointF(10, 12)); |
| 362 EXPECT_TRUE(event.OnTouch(move0)); |
360 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction()); | 363 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction()); |
361 EXPECT_EQ(2U, event.GetPointerCount()); | 364 EXPECT_EQ(2U, event.GetPointerCount()); |
362 | 365 |
363 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 366 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
364 event.OnTouch(release0); | 367 EXPECT_TRUE(event.OnTouch(release0)); |
365 EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction()); | 368 EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction()); |
366 EXPECT_EQ(2U, event.GetPointerCount()); | 369 EXPECT_EQ(2U, event.GetPointerCount()); |
367 event.CleanupRemovedTouchPoints(release0); | 370 event.CleanupRemovedTouchPoints(release0); |
368 EXPECT_EQ(1U, event.GetPointerCount()); | 371 EXPECT_EQ(1U, event.GetPointerCount()); |
369 | 372 |
370 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); | 373 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); |
371 event.OnTouch(release1); | 374 EXPECT_TRUE(event.OnTouch(release1)); |
372 EXPECT_EQ(MotionEvent::ACTION_UP, event.GetAction()); | 375 EXPECT_EQ(MotionEvent::ACTION_UP, event.GetAction()); |
373 EXPECT_EQ(1U, event.GetPointerCount()); | 376 EXPECT_EQ(1U, event.GetPointerCount()); |
374 event.CleanupRemovedTouchPoints(release1); | 377 event.CleanupRemovedTouchPoints(release1); |
375 EXPECT_EQ(0U, event.GetPointerCount()); | 378 EXPECT_EQ(0U, event.GetPointerCount()); |
376 } | 379 } |
377 | 380 |
378 TEST(MotionEventAuraTest, Cancel) { | 381 TEST(MotionEventAuraTest, Cancel) { |
379 int ids[] = {4, 6}; | 382 int ids[] = {4, 6}; |
380 MotionEventAura event; | 383 MotionEventAura event; |
381 | 384 |
382 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 385 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
383 event.OnTouch(press0); | 386 EXPECT_TRUE(event.OnTouch(press0)); |
384 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); | 387 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); |
385 EXPECT_EQ(1U, event.GetPointerCount()); | 388 EXPECT_EQ(1U, event.GetPointerCount()); |
386 | 389 |
387 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 390 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
388 event.OnTouch(press1); | 391 EXPECT_TRUE(event.OnTouch(press1)); |
389 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 392 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
390 EXPECT_EQ(1, event.GetActionIndex()); | 393 EXPECT_EQ(1, event.GetActionIndex()); |
391 EXPECT_EQ(2U, event.GetPointerCount()); | 394 EXPECT_EQ(2U, event.GetPointerCount()); |
392 | 395 |
393 scoped_ptr<MotionEvent> cancel = event.Cancel(); | 396 scoped_ptr<MotionEvent> cancel = event.Cancel(); |
394 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); | 397 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); |
395 EXPECT_EQ(2U, cancel->GetPointerCount()); | 398 EXPECT_EQ(2U, cancel->GetPointerCount()); |
396 } | 399 } |
397 | 400 |
398 TEST(MotionEventAuraTest, ToolType) { | 401 TEST(MotionEventAuraTest, ToolType) { |
399 MotionEventAura event; | 402 MotionEventAura event; |
400 | 403 |
401 // For now, all pointers have an unknown tool type. | 404 // For now, all pointers have an unknown tool type. |
402 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source | 405 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source |
403 // touch type, crbug.com/404128. | 406 // touch type, crbug.com/404128. |
404 event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7)); | 407 EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7))); |
405 ASSERT_EQ(1U, event.GetPointerCount()); | 408 ASSERT_EQ(1U, event.GetPointerCount()); |
406 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0)); | 409 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0)); |
407 } | 410 } |
408 | 411 |
409 TEST(MotionEventAuraTest, Flags) { | 412 TEST(MotionEventAuraTest, Flags) { |
410 int ids[] = {7, 11}; | 413 int ids[] = {7, 11}; |
411 MotionEventAura event; | 414 MotionEventAura event; |
412 | 415 |
413 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 416 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
414 press0.set_flags(EF_CONTROL_DOWN); | 417 press0.set_flags(EF_CONTROL_DOWN); |
415 event.OnTouch(press0); | 418 EXPECT_TRUE(event.OnTouch(press0)); |
416 EXPECT_EQ(EF_CONTROL_DOWN, event.GetFlags()); | 419 EXPECT_EQ(EF_CONTROL_DOWN, event.GetFlags()); |
417 | 420 |
418 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 421 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
419 press1.set_flags(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN); | 422 press1.set_flags(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN); |
420 event.OnTouch(press1); | 423 EXPECT_TRUE(event.OnTouch(press1)); |
421 EXPECT_EQ(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN, event.GetFlags()); | 424 EXPECT_EQ(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN, event.GetFlags()); |
422 } | 425 } |
423 | 426 |
| 427 // Once crbug.com/446852 is fixed, we should ignore redundant presses. |
| 428 TEST(MotionEventAuraTest, DoesntIgnoreRedundantPresses) { |
| 429 int id = 7; |
| 430 MotionEventAura event; |
| 431 EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, id))); |
| 432 EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, id))); |
| 433 } |
| 434 |
| 435 TEST(MotionEventAuraTest, IgnoresEventsWithoutPress) { |
| 436 int id = 7; |
| 437 MotionEventAura event; |
| 438 EXPECT_FALSE(event.OnTouch(TouchWithType(ET_TOUCH_MOVED, id))); |
| 439 } |
| 440 |
| 441 TEST(MotionEventAuraTest, IgnoresStationaryMoves) { |
| 442 int id = 7; |
| 443 MotionEventAura event; |
| 444 EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, id))); |
| 445 TouchEvent move0 = TouchWithPosition(ET_TOUCH_PRESSED, id, 10, 20, 10, 20); |
| 446 EXPECT_TRUE(event.OnTouch(move0)); |
| 447 |
| 448 TouchEvent move1 = TouchWithPosition(ET_TOUCH_MOVED, id, 11, 21, 11, 21); |
| 449 EXPECT_TRUE(event.OnTouch(move1)); |
| 450 EXPECT_FALSE(event.OnTouch(move1)); |
| 451 } |
| 452 |
424 } // namespace ui | 453 } // namespace ui |
OLD | NEW |