| 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" |
| 11 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
| 12 #include "ui/events/gestures/motion_event_aura.h" | 12 #include "ui/events/gestures/motion_event_aura.h" |
| 13 #include "ui/events/test/motion_event_test_utils.h" | 13 #include "ui/events/test/motion_event_test_utils.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 ui::TouchEvent TouchWithType(ui::EventType type, int id) { | 17 ui::TouchEvent TouchWithType(ui::EventType type, int id) { |
| 18 return ui::TouchEvent( | 18 return ui::TouchEvent(type, gfx::Point(0, 0), id, |
| 19 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(0)); | 19 base::TimeDelta::FromMilliseconds(0)); |
| 20 } | 20 } |
| 21 | 21 |
| 22 ui::TouchEvent TouchWithPosition(ui::EventType type, | 22 ui::TouchEvent TouchWithPosition(ui::EventType type, |
| 23 int id, | 23 int id, |
| 24 float x, | 24 float x, |
| 25 float y, | 25 float y, |
| 26 float raw_x, | 26 float raw_x, |
| 27 float raw_y) { | 27 float raw_y) { |
| 28 ui::TouchEvent event(type, | 28 ui::TouchEvent event(type, gfx::Point(), 0, id, |
| 29 gfx::PointF(x, y), | 29 base::TimeDelta::FromMilliseconds(0), 0, 0, 0, 0); |
| 30 0, | 30 event.set_location_f(gfx::PointF(x, y)); |
| 31 id, | 31 event.set_root_location_f(gfx::PointF(raw_x, raw_y)); |
| 32 base::TimeDelta::FromMilliseconds(0), | |
| 33 0, | |
| 34 0, | |
| 35 0, | |
| 36 0); | |
| 37 event.set_root_location(gfx::PointF(raw_x, raw_y)); | |
| 38 return event; | 32 return event; |
| 39 } | 33 } |
| 40 | 34 |
| 41 ui::TouchEvent TouchWithTapParams(ui::EventType type, | 35 ui::TouchEvent TouchWithTapParams(ui::EventType type, |
| 42 int id, | 36 int id, |
| 43 float radius_x, | 37 float radius_x, |
| 44 float radius_y, | 38 float radius_y, |
| 45 float rotation_angle, | 39 float rotation_angle, |
| 46 float pressure) { | 40 float pressure) { |
| 47 ui::TouchEvent event(type, | 41 ui::TouchEvent event(type, gfx::Point(1, 1), 0, id, |
| 48 gfx::PointF(1, 1), | 42 base::TimeDelta::FromMilliseconds(0), radius_x, radius_y, |
| 49 0, | 43 rotation_angle, pressure); |
| 50 id, | |
| 51 base::TimeDelta::FromMilliseconds(0), | |
| 52 radius_x, | |
| 53 radius_y, | |
| 54 rotation_angle, | |
| 55 pressure); | |
| 56 event.set_root_location(gfx::PointF(1, 1)); | |
| 57 return event; | 44 return event; |
| 58 } | 45 } |
| 59 | 46 |
| 60 ui::TouchEvent TouchWithTime(ui::EventType type, int id, int ms) { | 47 ui::TouchEvent TouchWithTime(ui::EventType type, int id, int ms) { |
| 61 return ui::TouchEvent( | 48 return ui::TouchEvent(type, gfx::Point(0, 0), id, |
| 62 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(ms)); | 49 base::TimeDelta::FromMilliseconds(ms)); |
| 63 } | 50 } |
| 64 | 51 |
| 65 base::TimeTicks MsToTicks(int ms) { | 52 base::TimeTicks MsToTicks(int ms) { |
| 66 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); | 53 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); |
| 67 } | 54 } |
| 68 | 55 |
| 69 } // namespace | 56 } // namespace |
| 70 | 57 |
| 71 namespace ui { | 58 namespace ui { |
| 72 | 59 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 EXPECT_TRUE(event.OnTouch(press0)); | 340 EXPECT_TRUE(event.OnTouch(press0)); |
| 354 EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime()); | 341 EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime()); |
| 355 | 342 |
| 356 TouchEvent press1 = TouchWithTime( | 343 TouchEvent press1 = TouchWithTime( |
| 357 ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]); | 344 ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]); |
| 358 EXPECT_TRUE(event.OnTouch(press1)); | 345 EXPECT_TRUE(event.OnTouch(press1)); |
| 359 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime()); | 346 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime()); |
| 360 | 347 |
| 361 TouchEvent move0 = TouchWithTime( | 348 TouchEvent move0 = TouchWithTime( |
| 362 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]); | 349 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]); |
| 363 move0.set_location(gfx::PointF(12, 21)); | 350 move0.set_location(gfx::Point(12, 21)); |
| 364 EXPECT_TRUE(event.OnTouch(move0)); | 351 EXPECT_TRUE(event.OnTouch(move0)); |
| 365 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime()); | 352 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime()); |
| 366 | 353 |
| 367 // Test cloning of timestamp information. | 354 // Test cloning of timestamp information. |
| 368 scoped_ptr<MotionEvent> clone = event.Clone(); | 355 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 369 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime()); | 356 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime()); |
| 370 } | 357 } |
| 371 | 358 |
| 372 TEST(MotionEventAuraTest, CachedAction) { | 359 TEST(MotionEventAuraTest, CachedAction) { |
| 373 // Test that the cached action and cached action index are correct. | 360 // Test that the cached action and cached action index are correct. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 384 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 371 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
| 385 EXPECT_EQ(1, event.GetActionIndex()); | 372 EXPECT_EQ(1, event.GetActionIndex()); |
| 386 EXPECT_EQ(2U, event.GetPointerCount()); | 373 EXPECT_EQ(2U, event.GetPointerCount()); |
| 387 | 374 |
| 388 // Test cloning of CachedAction information. | 375 // Test cloning of CachedAction information. |
| 389 scoped_ptr<MotionEvent> clone = event.Clone(); | 376 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 390 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction()); | 377 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction()); |
| 391 EXPECT_EQ(1, clone->GetActionIndex()); | 378 EXPECT_EQ(1, clone->GetActionIndex()); |
| 392 | 379 |
| 393 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]); | 380 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]); |
| 394 move0.set_location(gfx::PointF(10, 12)); | 381 move0.set_location(gfx::Point(10, 12)); |
| 395 EXPECT_TRUE(event.OnTouch(move0)); | 382 EXPECT_TRUE(event.OnTouch(move0)); |
| 396 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction()); | 383 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction()); |
| 397 EXPECT_EQ(2U, event.GetPointerCount()); | 384 EXPECT_EQ(2U, event.GetPointerCount()); |
| 398 | 385 |
| 399 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 386 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| 400 EXPECT_TRUE(event.OnTouch(release0)); | 387 EXPECT_TRUE(event.OnTouch(release0)); |
| 401 EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction()); | 388 EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction()); |
| 402 EXPECT_EQ(2U, event.GetPointerCount()); | 389 EXPECT_EQ(2U, event.GetPointerCount()); |
| 403 event.CleanupRemovedTouchPoints(release0); | 390 event.CleanupRemovedTouchPoints(release0); |
| 404 EXPECT_EQ(1U, event.GetPointerCount()); | 391 EXPECT_EQ(1U, event.GetPointerCount()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 int id = i + kIdOffset; | 517 int id = i + kIdOffset; |
| 531 TouchEvent release = TouchWithType(ET_TOUCH_RELEASED, id); | 518 TouchEvent release = TouchWithType(ET_TOUCH_RELEASED, id); |
| 532 if (i < MotionEvent::MAX_TOUCH_POINT_COUNT) | 519 if (i < MotionEvent::MAX_TOUCH_POINT_COUNT) |
| 533 EXPECT_TRUE(event.OnTouch(release)); | 520 EXPECT_TRUE(event.OnTouch(release)); |
| 534 else | 521 else |
| 535 EXPECT_FALSE(event.OnTouch(release)); | 522 EXPECT_FALSE(event.OnTouch(release)); |
| 536 } | 523 } |
| 537 } | 524 } |
| 538 | 525 |
| 539 } // namespace ui | 526 } // namespace ui |
| OLD | NEW |