| 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 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/events/gesture_detection/motion_event_buffer.h" | 9 #include "ui/events/gesture_detection/motion_event_buffer.h" |
| 10 #include "ui/events/test/mock_motion_event.h" | 10 #include "ui/events/test/motion_event_test_utils.h" |
| 11 | 11 |
| 12 using base::TimeDelta; | 12 using base::TimeDelta; |
| 13 using base::TimeTicks; | 13 using base::TimeTicks; |
| 14 using ui::test::MockMotionEvent; | 14 using ui::test::MockMotionEvent; |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 | 17 |
| 18 const int kSmallDeltaMs = 1; | 18 const int kSmallDeltaMs = 1; |
| 19 const int kLargeDeltaMs = 50; | 19 const int kLargeDeltaMs = 50; |
| 20 const int kResampleDeltaMs = 5; | 20 const int kResampleDeltaMs = 5; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return base::TimeDelta::FromMilliseconds(kSmallDeltaMs); | 74 return base::TimeDelta::FromMilliseconds(kSmallDeltaMs); |
| 75 } | 75 } |
| 76 | 76 |
| 77 static base::TimeDelta ResampleDelta() { | 77 static base::TimeDelta ResampleDelta() { |
| 78 return base::TimeDelta::FromMilliseconds(kResampleDeltaMs); | 78 return base::TimeDelta::FromMilliseconds(kResampleDeltaMs); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static void ExpectEqualsImpl(const MotionEvent& a, | 81 static void ExpectEqualsImpl(const MotionEvent& a, |
| 82 const MotionEvent& b, | 82 const MotionEvent& b, |
| 83 bool ignore_history) { | 83 bool ignore_history) { |
| 84 EXPECT_EQ(a.GetId(), b.GetId()); | |
| 85 EXPECT_EQ(a.GetAction(), b.GetAction()); | 84 EXPECT_EQ(a.GetAction(), b.GetAction()); |
| 86 EXPECT_EQ(a.GetActionIndex(), b.GetActionIndex()); | 85 if (a.GetAction() == MotionEvent::ACTION_POINTER_DOWN || |
| 86 a.GetAction() == MotionEvent::ACTION_POINTER_UP) { |
| 87 EXPECT_EQ(a.GetActionIndex(), b.GetActionIndex()); |
| 88 } |
| 87 EXPECT_EQ(a.GetButtonState(), b.GetButtonState()); | 89 EXPECT_EQ(a.GetButtonState(), b.GetButtonState()); |
| 88 EXPECT_EQ(a.GetEventTime(), b.GetEventTime()); | 90 EXPECT_EQ(a.GetEventTime(), b.GetEventTime()); |
| 89 | 91 |
| 90 ASSERT_EQ(a.GetPointerCount(), b.GetPointerCount()); | 92 ASSERT_EQ(a.GetPointerCount(), b.GetPointerCount()); |
| 91 for (size_t i = 0; i < a.GetPointerCount(); ++i) { | 93 for (size_t i = 0; i < a.GetPointerCount(); ++i) { |
| 92 int bi = b.FindPointerIndexOfId(a.GetPointerId(i)); | 94 int bi = b.FindPointerIndexOfId(a.GetPointerId(i)); |
| 93 ASSERT_NE(bi, -1); | 95 ASSERT_NE(bi, -1); |
| 94 EXPECT_EQ(a.GetX(i), b.GetX(bi)); | 96 EXPECT_EQ(a.GetX(i), b.GetX(bi)); |
| 95 EXPECT_EQ(a.GetY(i), b.GetY(bi)); | 97 EXPECT_EQ(a.GetY(i), b.GetY(bi)); |
| 96 EXPECT_EQ(a.GetRawX(i), b.GetRawX(bi)); | 98 EXPECT_EQ(a.GetRawX(i), b.GetRawX(bi)); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // The flushed event should only include the latest move event. | 339 // The flushed event should only include the latest move event. |
| 338 buffer.Flush(event_time); | 340 buffer.Flush(event_time); |
| 339 ScopedVector<MotionEvent> events = GetAndResetForwardedEvents(); | 341 ScopedVector<MotionEvent> events = GetAndResetForwardedEvents(); |
| 340 ASSERT_EQ(3U, events.size()); | 342 ASSERT_EQ(3U, events.size()); |
| 341 EXPECT_EVENT_EQ(move2, *events.back()); | 343 EXPECT_EVENT_EQ(move2, *events.back()); |
| 342 EXPECT_FALSE(GetAndResetNeedsFlush()); | 344 EXPECT_FALSE(GetAndResetNeedsFlush()); |
| 343 | 345 |
| 344 event_time += base::TimeDelta::FromMilliseconds(5); | 346 event_time += base::TimeDelta::FromMilliseconds(5); |
| 345 | 347 |
| 346 // Events with different pointer ids should not combine. | 348 // Events with different pointer ids should not combine. |
| 347 PointerProperties pointer0(5.f, 5.f); | 349 PointerProperties pointer0(5.f, 5.f, 1.f); |
| 348 pointer0.id = 1; | 350 pointer0.id = 1; |
| 349 PointerProperties pointer1(10.f, 10.f); | 351 PointerProperties pointer1(10.f, 10.f, 2.f); |
| 350 pointer1.id = 2; | 352 pointer1.id = 2; |
| 351 MotionEventGeneric move3(MotionEvent::ACTION_MOVE, event_time, pointer0); | 353 MotionEventGeneric move3(MotionEvent::ACTION_MOVE, event_time, pointer0); |
| 352 move3.PushPointer(pointer1); | 354 move3.PushPointer(pointer1); |
| 353 buffer.OnMotionEvent(move3); | 355 buffer.OnMotionEvent(move3); |
| 354 ASSERT_FALSE(GetLastEvent()); | 356 ASSERT_FALSE(GetLastEvent()); |
| 355 EXPECT_TRUE(GetAndResetNeedsFlush()); | 357 EXPECT_TRUE(GetAndResetNeedsFlush()); |
| 356 | 358 |
| 357 MotionEventGeneric move4(MotionEvent::ACTION_MOVE, event_time, pointer0); | 359 MotionEventGeneric move4(MotionEvent::ACTION_MOVE, event_time, pointer0); |
| 358 pointer1.id = 7; | 360 pointer1.id = 7; |
| 359 move4.PushPointer(pointer1); | 361 move4.PushPointer(pointer1); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 buffer.Flush(flush_time); | 402 buffer.Flush(flush_time); |
| 401 EXPECT_FALSE(GetAndResetNeedsFlush()); | 403 EXPECT_FALSE(GetAndResetNeedsFlush()); |
| 402 ASSERT_TRUE(GetLastEvent()); | 404 ASSERT_TRUE(GetLastEvent()); |
| 403 EXPECT_EVENT_EQ(move, *GetLastEvent()); | 405 EXPECT_EVENT_EQ(move, *GetLastEvent()); |
| 404 } | 406 } |
| 405 | 407 |
| 406 TEST_F(MotionEventBufferTest, OutOfOrderPointersBuffered) { | 408 TEST_F(MotionEventBufferTest, OutOfOrderPointersBuffered) { |
| 407 base::TimeTicks event_time = base::TimeTicks::Now(); | 409 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 408 MotionEventBuffer buffer(this, true); | 410 MotionEventBuffer buffer(this, true); |
| 409 | 411 |
| 410 PointerProperties p0(1.f, 2.f); | 412 PointerProperties p0(1.f, 2.f, 3.f); |
| 411 p0.id = 1; | 413 p0.id = 1; |
| 412 PointerProperties p1(2.f, 1.f); | 414 PointerProperties p1(2.f, 1.f, 0.5f); |
| 413 p1.id = 2; | 415 p1.id = 2; |
| 414 | 416 |
| 415 MotionEventGeneric move0(MotionEvent::ACTION_MOVE, event_time, p0); | 417 MotionEventGeneric move0(MotionEvent::ACTION_MOVE, event_time, p0); |
| 416 move0.PushPointer(p1); | 418 move0.PushPointer(p1); |
| 417 buffer.OnMotionEvent(move0); | 419 buffer.OnMotionEvent(move0); |
| 418 EXPECT_TRUE(GetAndResetNeedsFlush()); | 420 EXPECT_TRUE(GetAndResetNeedsFlush()); |
| 419 ASSERT_FALSE(GetLastEvent()); | 421 ASSERT_FALSE(GetLastEvent()); |
| 420 | 422 |
| 421 event_time += base::TimeDelta::FromMilliseconds(5); | 423 event_time += base::TimeDelta::FromMilliseconds(5); |
| 422 | 424 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 TEST_F(MotionEventBufferTest, Resampling150to60) { | 864 TEST_F(MotionEventBufferTest, Resampling150to60) { |
| 863 base::TimeDelta flush_time_delta = | 865 base::TimeDelta flush_time_delta = |
| 864 base::TimeDelta::FromMillisecondsD(1000. / 60.); | 866 base::TimeDelta::FromMillisecondsD(1000. / 60.); |
| 865 base::TimeDelta event_time_delta = | 867 base::TimeDelta event_time_delta = |
| 866 base::TimeDelta::FromMillisecondsD(1000. / 150.); | 868 base::TimeDelta::FromMillisecondsD(1000. / 150.); |
| 867 | 869 |
| 868 RunResample(flush_time_delta, event_time_delta); | 870 RunResample(flush_time_delta, event_time_delta); |
| 869 } | 871 } |
| 870 | 872 |
| 871 } // namespace ui | 873 } // namespace ui |
| OLD | NEW |