| 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 "ui/events/gesture_detection/motion_event_generic.h" |
| 9 |
| 8 #include <cmath> | 10 #include <cmath> |
| 11 #include <utility> |
| 9 | 12 |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 12 #include "ui/events/gesture_detection/motion_event_generic.h" | |
| 13 #include "ui/events/test/motion_event_test_utils.h" | 15 #include "ui/events/test/motion_event_test_utils.h" |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 16 | 18 |
| 17 TEST(MotionEventGenericTest, Basic) { | 19 TEST(MotionEventGenericTest, Basic) { |
| 18 base::TimeTicks event_time = base::TimeTicks::Now(); | 20 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 19 MotionEventGeneric event( | 21 MotionEventGeneric event( |
| 20 MotionEvent::ACTION_DOWN, event_time, PointerProperties()); | 22 MotionEvent::ACTION_DOWN, event_time, PointerProperties()); |
| 21 EXPECT_EQ(1U, event.GetPointerCount()); | 23 EXPECT_EQ(1U, event.GetPointerCount()); |
| 22 EXPECT_EQ(0U, event.GetHistorySize()); | 24 EXPECT_EQ(0U, event.GetHistorySize()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 base::TimeTicks historical_event_time = | 102 base::TimeTicks historical_event_time = |
| 101 event_time - base::TimeDelta::FromMilliseconds(5); | 103 event_time - base::TimeDelta::FromMilliseconds(5); |
| 102 | 104 |
| 103 PointerProperties pointer(8.3f, 4.7f, 10.1f); | 105 PointerProperties pointer(8.3f, 4.7f, 10.1f); |
| 104 MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer); | 106 MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer); |
| 105 | 107 |
| 106 PointerProperties historical_pointer(3.4f, -4.3f, 11.5); | 108 PointerProperties historical_pointer(3.4f, -4.3f, 11.5); |
| 107 scoped_ptr<MotionEvent> historical_event(new MotionEventGeneric( | 109 scoped_ptr<MotionEvent> historical_event(new MotionEventGeneric( |
| 108 MotionEvent::ACTION_MOVE, historical_event_time, historical_pointer)); | 110 MotionEvent::ACTION_MOVE, historical_event_time, historical_pointer)); |
| 109 | 111 |
| 110 event.PushHistoricalEvent(historical_event.Pass()); | 112 event.PushHistoricalEvent(std::move(historical_event)); |
| 111 EXPECT_EQ(1U, event.GetHistorySize()); | 113 EXPECT_EQ(1U, event.GetHistorySize()); |
| 112 | 114 |
| 113 scoped_ptr<MotionEvent> clone = event.Clone(); | 115 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 114 ASSERT_TRUE(clone); | 116 ASSERT_TRUE(clone); |
| 115 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); | 117 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 116 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 118 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 117 } | 119 } |
| 118 | 120 |
| 119 TEST(MotionEventGenericTest, Cancel) { | 121 TEST(MotionEventGenericTest, Cancel) { |
| 120 MotionEventGeneric event(MotionEvent::ACTION_UP, | 122 MotionEventGeneric event(MotionEvent::ACTION_UP, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 scoped_ptr<MotionEventGeneric> historical_event0(new MotionEventGeneric( | 256 scoped_ptr<MotionEventGeneric> historical_event0(new MotionEventGeneric( |
| 255 MotionEvent::ACTION_MOVE, historical_event_time0, pointer0)); | 257 MotionEvent::ACTION_MOVE, historical_event_time0, pointer0)); |
| 256 historical_event0->PushPointer(pointer1); | 258 historical_event0->PushPointer(pointer1); |
| 257 | 259 |
| 258 pointer0.x += 100; | 260 pointer0.x += 100; |
| 259 pointer1.x -= 100; | 261 pointer1.x -= 100; |
| 260 scoped_ptr<MotionEventGeneric> historical_event1(new MotionEventGeneric( | 262 scoped_ptr<MotionEventGeneric> historical_event1(new MotionEventGeneric( |
| 261 MotionEvent::ACTION_MOVE, historical_event_time1, pointer0)); | 263 MotionEvent::ACTION_MOVE, historical_event_time1, pointer0)); |
| 262 historical_event1->PushPointer(pointer1); | 264 historical_event1->PushPointer(pointer1); |
| 263 | 265 |
| 264 event.PushHistoricalEvent(historical_event0.Pass()); | 266 event.PushHistoricalEvent(std::move(historical_event0)); |
| 265 event.PushHistoricalEvent(historical_event1.Pass()); | 267 event.PushHistoricalEvent(std::move(historical_event1)); |
| 266 ASSERT_EQ(2U, event.GetHistorySize()); | 268 ASSERT_EQ(2U, event.GetHistorySize()); |
| 267 ASSERT_EQ(2U, event.GetPointerCount()); | 269 ASSERT_EQ(2U, event.GetPointerCount()); |
| 268 | 270 |
| 269 // Do a basic smoke exercise of event stringification to ensure things don't | 271 // Do a basic smoke exercise of event stringification to ensure things don't |
| 270 // explode in the process. | 272 // explode in the process. |
| 271 std::string event_string = test::ToString(event); | 273 std::string event_string = test::ToString(event); |
| 272 EXPECT_FALSE(event_string.empty()); | 274 EXPECT_FALSE(event_string.empty()); |
| 273 } | 275 } |
| 274 | 276 |
| 275 } // namespace ui | 277 } // namespace ui |
| OLD | NEW |