| 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(type, gfx::Point(0, 0), id, | 18 return ui::TouchEvent(type, gfx::Point(0, 0), id, base::TimeTicks()); |
| 19 base::TimeDelta::FromMilliseconds(0)); | |
| 20 } | 19 } |
| 21 | 20 |
| 22 ui::TouchEvent TouchWithPosition(ui::EventType type, | 21 ui::TouchEvent TouchWithPosition(ui::EventType type, |
| 23 int id, | 22 int id, |
| 24 float x, | 23 float x, |
| 25 float y, | 24 float y, |
| 26 float raw_x, | 25 float raw_x, |
| 27 float raw_y) { | 26 float raw_y) { |
| 28 ui::TouchEvent event(type, gfx::Point(), 0, id, | 27 ui::TouchEvent event(type, gfx::Point(), 0, id, base::TimeTicks(), 0, 0, 0, |
| 29 base::TimeDelta::FromMilliseconds(0), 0, 0, 0, 0); | 28 0); |
| 30 event.set_location_f(gfx::PointF(x, y)); | 29 event.set_location_f(gfx::PointF(x, y)); |
| 31 event.set_root_location_f(gfx::PointF(raw_x, raw_y)); | 30 event.set_root_location_f(gfx::PointF(raw_x, raw_y)); |
| 32 return event; | 31 return event; |
| 33 } | 32 } |
| 34 | 33 |
| 35 ui::TouchEvent TouchWithTapParams(ui::EventType type, | 34 ui::TouchEvent TouchWithTapParams(ui::EventType type, |
| 36 int id, | 35 int id, |
| 37 float radius_x, | 36 float radius_x, |
| 38 float radius_y, | 37 float radius_y, |
| 39 float rotation_angle, | 38 float rotation_angle, |
| 40 float pressure) { | 39 float pressure) { |
| 41 ui::TouchEvent event(type, gfx::Point(1, 1), 0, id, | 40 ui::TouchEvent event(type, gfx::Point(1, 1), 0, id, base::TimeTicks(), |
| 42 base::TimeDelta::FromMilliseconds(0), radius_x, radius_y, | 41 radius_x, radius_y, rotation_angle, pressure); |
| 43 rotation_angle, pressure); | |
| 44 return event; | 42 return event; |
| 45 } | 43 } |
| 46 | 44 |
| 47 ui::TouchEvent TouchWithTime(ui::EventType type, int id, int ms) { | |
| 48 return ui::TouchEvent(type, gfx::Point(0, 0), id, | |
| 49 base::TimeDelta::FromMilliseconds(ms)); | |
| 50 } | |
| 51 | |
| 52 base::TimeTicks MsToTicks(int ms) { | 45 base::TimeTicks MsToTicks(int ms) { |
| 53 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); | 46 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); |
| 54 } | 47 } |
| 55 | 48 |
| 49 ui::TouchEvent TouchWithTime(ui::EventType type, int id, int ms) { |
| 50 return ui::TouchEvent(type, gfx::Point(0, 0), id, MsToTicks(ms)); |
| 51 } |
| 52 |
| 56 } // namespace | 53 } // namespace |
| 57 | 54 |
| 58 namespace ui { | 55 namespace ui { |
| 59 | 56 |
| 60 TEST(MotionEventAuraTest, PointerCountAndIds) { | 57 TEST(MotionEventAuraTest, PointerCountAndIds) { |
| 61 // Test that |PointerCount()| returns the correct number of pointers, and ids | 58 // Test that |PointerCount()| returns the correct number of pointers, and ids |
| 62 // are assigned correctly. | 59 // are assigned correctly. |
| 63 int ids[] = {4, 6, 1}; | 60 int ids[] = {4, 6, 1}; |
| 64 | 61 |
| 65 MotionEventAura event; | 62 MotionEventAura event; |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 int id = i + kIdOffset; | 523 int id = i + kIdOffset; |
| 527 TouchEvent release = TouchWithType(ET_TOUCH_RELEASED, id); | 524 TouchEvent release = TouchWithType(ET_TOUCH_RELEASED, id); |
| 528 if (i < MotionEvent::MAX_TOUCH_POINT_COUNT) | 525 if (i < MotionEvent::MAX_TOUCH_POINT_COUNT) |
| 529 EXPECT_TRUE(event.OnTouch(release)); | 526 EXPECT_TRUE(event.OnTouch(release)); |
| 530 else | 527 else |
| 531 EXPECT_FALSE(event.OnTouch(release)); | 528 EXPECT_FALSE(event.OnTouch(release)); |
| 532 } | 529 } |
| 533 } | 530 } |
| 534 | 531 |
| 535 } // namespace ui | 532 } // namespace ui |
| OLD | NEW |