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

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

Issue 502993004: Remove abstract Clone and Cancel methods from MotionEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 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. 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // been removed. 131 // been removed.
132 int ids[] = {4, 6, 9}; 132 int ids[] = {4, 6, 9};
133 133
134 MotionEventAura event; 134 MotionEventAura event;
135 EXPECT_EQ(0U, event.GetPointerCount()); 135 EXPECT_EQ(0U, event.GetPointerCount());
136 136
137 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); 137 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
138 event.OnTouch(press0); 138 event.OnTouch(press0);
139 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); 139 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
140 event.OnTouch(press1); 140 event.OnTouch(press1);
141 EXPECT_EQ(1, event.GetActionIndex());
141 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); 142 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]);
142 event.OnTouch(press2); 143 event.OnTouch(press2);
144 EXPECT_EQ(2, event.GetActionIndex());
143 EXPECT_EQ(3U, event.GetPointerCount()); 145 EXPECT_EQ(3U, event.GetPointerCount());
144 146
145 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); 147 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
146 event.OnTouch(release1); 148 event.OnTouch(release1);
149 EXPECT_EQ(1, event.GetActionIndex());
147 event.CleanupRemovedTouchPoints(release1); 150 event.CleanupRemovedTouchPoints(release1);
148 EXPECT_EQ(1, event.GetActionIndex());
149 EXPECT_EQ(2U, event.GetPointerCount()); 151 EXPECT_EQ(2U, event.GetPointerCount());
150 152
151 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); 153 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
152 event.OnTouch(release2); 154 event.OnTouch(release2);
155 EXPECT_EQ(0, event.GetActionIndex());
153 event.CleanupRemovedTouchPoints(release2); 156 event.CleanupRemovedTouchPoints(release2);
154 EXPECT_EQ(0, event.GetActionIndex());
155 EXPECT_EQ(1U, event.GetPointerCount()); 157 EXPECT_EQ(1U, event.GetPointerCount());
156 158
157 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); 159 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]);
158 event.OnTouch(release0); 160 event.OnTouch(release0);
159 event.CleanupRemovedTouchPoints(release0); 161 event.CleanupRemovedTouchPoints(release0);
160 EXPECT_EQ(0U, event.GetPointerCount()); 162 EXPECT_EQ(0U, event.GetPointerCount());
161 } 163 }
162 164
163 TEST(MotionEventAuraTest, PointerLocations) { 165 TEST(MotionEventAuraTest, PointerLocations) {
164 // Test that location information is stored correctly. 166 // Test that location information is stored correctly.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 199
198 EXPECT_EQ(2U, event.GetPointerCount()); 200 EXPECT_EQ(2U, event.GetPointerCount());
199 EXPECT_FLOAT_EQ(x, event.GetX(1)); 201 EXPECT_FLOAT_EQ(x, event.GetX(1));
200 EXPECT_FLOAT_EQ(y, event.GetY(1)); 202 EXPECT_FLOAT_EQ(y, event.GetY(1));
201 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); 203 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1));
202 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); 204 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1));
203 205
204 // Test cloning of pointer location information. 206 // Test cloning of pointer location information.
205 scoped_ptr<MotionEvent> clone = event.Clone(); 207 scoped_ptr<MotionEvent> clone = event.Clone();
206 { 208 {
207 const MotionEventAura* raw_clone_aura = 209 EXPECT_EQ(2U, clone->GetPointerCount());
208 static_cast<MotionEventAura*>(clone.get()); 210 EXPECT_FLOAT_EQ(x, clone->GetX(1));
209 EXPECT_EQ(2U, raw_clone_aura->GetPointerCount()); 211 EXPECT_FLOAT_EQ(y, clone->GetY(1));
210 EXPECT_FLOAT_EQ(x, raw_clone_aura->GetX(1)); 212 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1));
211 EXPECT_FLOAT_EQ(y, raw_clone_aura->GetY(1)); 213 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1));
212 EXPECT_FLOAT_EQ(raw_x, raw_clone_aura->GetRawX(1));
213 EXPECT_FLOAT_EQ(raw_y, raw_clone_aura->GetRawY(1));
214 } 214 }
215 215
216 x = 27.9f; 216 x = 27.9f;
217 y = 22.3f; 217 y = 22.3f;
218 raw_x = x + kRawOffsetX; 218 raw_x = x + kRawOffsetX;
219 raw_y = y + kRawOffsetY; 219 raw_y = y + kRawOffsetY;
220 TouchEvent move1 = 220 TouchEvent move1 =
221 TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, raw_x, raw_y); 221 TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, raw_x, raw_y);
222 event.OnTouch(move1); 222 event.OnTouch(move1);
223 223
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 275
276 EXPECT_EQ(2U, event.GetPointerCount()); 276 EXPECT_EQ(2U, event.GetPointerCount());
277 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); 277 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2);
278 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); 278 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2);
279 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); 279 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI);
280 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); 280 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1));
281 281
282 // Test cloning of tap params 282 // Test cloning of tap params
283 scoped_ptr<MotionEvent> clone = event.Clone(); 283 scoped_ptr<MotionEvent> clone = event.Clone();
284 { 284 {
285 const MotionEventAura* raw_clone_aura = 285 EXPECT_EQ(2U, clone->GetPointerCount());
286 static_cast<MotionEventAura*>(clone.get()); 286 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2);
287 EXPECT_EQ(2U, raw_clone_aura->GetPointerCount()); 287 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2);
288 EXPECT_FLOAT_EQ(radius_y, raw_clone_aura->GetTouchMajor(1) / 2); 288 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI);
289 EXPECT_FLOAT_EQ(radius_x, raw_clone_aura->GetTouchMinor(1) / 2); 289 EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1));
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 } 290 }
294 291
295 radius_x = 76.98f; 292 radius_x = 76.98f;
296 radius_y = 321.54f; 293 radius_y = 321.54f;
297 rotation_angle = 64.f; 294 rotation_angle = 64.f;
298 pressure = 0.654f; 295 pressure = 0.654f;
299 TouchEvent move1 = TouchWithTapParams( 296 TouchEvent move1 = TouchWithTapParams(
300 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure); 297 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure);
301 event.OnTouch(move1); 298 event.OnTouch(move1);
302 299
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 EXPECT_EQ(1U, event.GetPointerCount()); 381 EXPECT_EQ(1U, event.GetPointerCount());
385 382
386 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); 383 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
387 event.OnTouch(press1); 384 event.OnTouch(press1);
388 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); 385 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
389 EXPECT_EQ(1, event.GetActionIndex()); 386 EXPECT_EQ(1, event.GetActionIndex());
390 EXPECT_EQ(2U, event.GetPointerCount()); 387 EXPECT_EQ(2U, event.GetPointerCount());
391 388
392 scoped_ptr<MotionEvent> cancel = event.Cancel(); 389 scoped_ptr<MotionEvent> cancel = event.Cancel();
393 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); 390 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction());
394 EXPECT_EQ(2U, static_cast<MotionEventAura*>(cancel.get())->GetPointerCount()); 391 EXPECT_EQ(2U, cancel->GetPointerCount());
395 } 392 }
396 393
397 TEST(MotionEventAuraTest, ToolType) { 394 TEST(MotionEventAuraTest, ToolType) {
398 MotionEventAura event; 395 MotionEventAura event;
399 396
400 // For now, all pointers have an unknown tool type. 397 // For now, all pointers have an unknown tool type.
401 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source 398 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source
402 // touch type, crbug.com/404128. 399 // touch type, crbug.com/404128.
403 event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7)); 400 event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7));
404 ASSERT_EQ(1U, event.GetPointerCount()); 401 ASSERT_EQ(1U, event.GetPointerCount());
405 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0)); 402 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0));
406 } 403 }
407 404
408 TEST(MotionEventAuraTest, Flags) { 405 TEST(MotionEventAuraTest, Flags) {
409 int ids[] = {7, 11}; 406 int ids[] = {7, 11};
410 MotionEventAura event; 407 MotionEventAura event;
411 408
412 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); 409 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
413 press0.set_flags(EF_CONTROL_DOWN); 410 press0.set_flags(EF_CONTROL_DOWN);
414 event.OnTouch(press0); 411 event.OnTouch(press0);
415 EXPECT_EQ(EF_CONTROL_DOWN, event.GetFlags()); 412 EXPECT_EQ(EF_CONTROL_DOWN, event.GetFlags());
416 413
417 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); 414 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
418 press1.set_flags(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN); 415 press1.set_flags(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN);
419 event.OnTouch(press1); 416 event.OnTouch(press1);
420 EXPECT_EQ(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN, event.GetFlags()); 417 EXPECT_EQ(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN, event.GetFlags());
421 } 418 }
422 419
423 } // namespace ui 420 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698