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

Side by Side Diff: ui/events/gesture_detection/motion_event_buffer_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: Nasty bug fix 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 #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 13 matching lines...) Expand all
34 #define EXPECT_EVENT_HISTORY_EQ(A, I, B) \ 34 #define EXPECT_EVENT_HISTORY_EQ(A, I, B) \
35 { \ 35 { \
36 SCOPED_TRACE(testing::Message()); \ 36 SCOPED_TRACE(testing::Message()); \
37 ExpectEqualsHistoryIndex((A), (I), (B)); \ 37 ExpectEqualsHistoryIndex((A), (I), (B)); \
38 } 38 }
39 39
40 class MotionEventBufferTest : public testing::Test, 40 class MotionEventBufferTest : public testing::Test,
41 public MotionEventBufferClient { 41 public MotionEventBufferClient {
42 public: 42 public:
43 MotionEventBufferTest() : needs_flush_(false) {} 43 MotionEventBufferTest() : needs_flush_(false) {}
44 virtual ~MotionEventBufferTest() {} 44 ~MotionEventBufferTest() override {}
45 45
46 // MotionEventBufferClient implementation. 46 // MotionEventBufferClient implementation.
47 virtual void ForwardMotionEvent(const MotionEvent& event) override { 47 void ForwardMotionEvent(const MotionEvent& event) override {
48 forwarded_events_.push_back(event.Clone().release()); 48 forwarded_events_.push_back(event.Clone().release());
49 } 49 }
50 50
51 virtual void SetNeedsFlush() override { needs_flush_ = true; } 51 void SetNeedsFlush() override { needs_flush_ = true; }
52 52
53 bool GetAndResetNeedsFlush() { 53 bool GetAndResetNeedsFlush() {
54 bool needs_flush = needs_flush_; 54 bool needs_flush = needs_flush_;
55 needs_flush_ = false; 55 needs_flush_ = false;
56 return needs_flush; 56 return needs_flush;
57 } 57 }
58 58
59 ScopedVector<MotionEvent> GetAndResetForwardedEvents() { 59 ScopedVector<MotionEvent> GetAndResetForwardedEvents() {
60 ScopedVector<MotionEvent> forwarded_events; 60 ScopedVector<MotionEvent> forwarded_events;
61 forwarded_events.swap(forwarded_events_); 61 forwarded_events.swap(forwarded_events_);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // The flushed event should only include the latest move event. 337 // The flushed event should only include the latest move event.
338 buffer.Flush(event_time); 338 buffer.Flush(event_time);
339 ScopedVector<MotionEvent> events = GetAndResetForwardedEvents(); 339 ScopedVector<MotionEvent> events = GetAndResetForwardedEvents();
340 ASSERT_EQ(3U, events.size()); 340 ASSERT_EQ(3U, events.size());
341 EXPECT_EVENT_EQ(move2, *events.back()); 341 EXPECT_EVENT_EQ(move2, *events.back());
342 EXPECT_FALSE(GetAndResetNeedsFlush()); 342 EXPECT_FALSE(GetAndResetNeedsFlush());
343 343
344 event_time += base::TimeDelta::FromMilliseconds(5); 344 event_time += base::TimeDelta::FromMilliseconds(5);
345 345
346 // Events with different pointer ids should not combine. 346 // Events with different pointer ids should not combine.
347 PointerProperties pointer0(5.f, 5.f); 347 PointerProperties pointer0(5.f, 5.f, 1.f);
348 pointer0.id = 1; 348 pointer0.id = 1;
349 PointerProperties pointer1(10.f, 10.f); 349 PointerProperties pointer1(10.f, 10.f, 2.f);
350 pointer1.id = 2; 350 pointer1.id = 2;
351 MotionEventGeneric move3(MotionEvent::ACTION_MOVE, event_time, pointer0); 351 MotionEventGeneric move3(MotionEvent::ACTION_MOVE, event_time, pointer0);
352 move3.PushPointer(pointer1); 352 move3.PushPointer(pointer1);
353 buffer.OnMotionEvent(move3); 353 buffer.OnMotionEvent(move3);
354 ASSERT_FALSE(GetLastEvent()); 354 ASSERT_FALSE(GetLastEvent());
355 EXPECT_TRUE(GetAndResetNeedsFlush()); 355 EXPECT_TRUE(GetAndResetNeedsFlush());
356 356
357 MotionEventGeneric move4(MotionEvent::ACTION_MOVE, event_time, pointer0); 357 MotionEventGeneric move4(MotionEvent::ACTION_MOVE, event_time, pointer0);
358 pointer1.id = 7; 358 pointer1.id = 7;
359 move4.PushPointer(pointer1); 359 move4.PushPointer(pointer1);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 buffer.Flush(flush_time); 400 buffer.Flush(flush_time);
401 EXPECT_FALSE(GetAndResetNeedsFlush()); 401 EXPECT_FALSE(GetAndResetNeedsFlush());
402 ASSERT_TRUE(GetLastEvent()); 402 ASSERT_TRUE(GetLastEvent());
403 EXPECT_EVENT_EQ(move, *GetLastEvent()); 403 EXPECT_EVENT_EQ(move, *GetLastEvent());
404 } 404 }
405 405
406 TEST_F(MotionEventBufferTest, OutOfOrderPointersBuffered) { 406 TEST_F(MotionEventBufferTest, OutOfOrderPointersBuffered) {
407 base::TimeTicks event_time = base::TimeTicks::Now(); 407 base::TimeTicks event_time = base::TimeTicks::Now();
408 MotionEventBuffer buffer(this, true); 408 MotionEventBuffer buffer(this, true);
409 409
410 PointerProperties p0(1.f, 2.f); 410 PointerProperties p0(1.f, 2.f, 3.f);
411 p0.id = 1; 411 p0.id = 1;
412 PointerProperties p1(2.f, 1.f); 412 PointerProperties p1(2.f, 1.f, 0.5f);
413 p1.id = 2; 413 p1.id = 2;
414 414
415 MotionEventGeneric move0(MotionEvent::ACTION_MOVE, event_time, p0); 415 MotionEventGeneric move0(MotionEvent::ACTION_MOVE, event_time, p0);
416 move0.PushPointer(p1); 416 move0.PushPointer(p1);
417 buffer.OnMotionEvent(move0); 417 buffer.OnMotionEvent(move0);
418 EXPECT_TRUE(GetAndResetNeedsFlush()); 418 EXPECT_TRUE(GetAndResetNeedsFlush());
419 ASSERT_FALSE(GetLastEvent()); 419 ASSERT_FALSE(GetLastEvent());
420 420
421 event_time += base::TimeDelta::FromMilliseconds(5); 421 event_time += base::TimeDelta::FromMilliseconds(5);
422 422
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 TEST_F(MotionEventBufferTest, Resampling150to60) { 862 TEST_F(MotionEventBufferTest, Resampling150to60) {
863 base::TimeDelta flush_time_delta = 863 base::TimeDelta flush_time_delta =
864 base::TimeDelta::FromMillisecondsD(1000. / 60.); 864 base::TimeDelta::FromMillisecondsD(1000. / 60.);
865 base::TimeDelta event_time_delta = 865 base::TimeDelta event_time_delta =
866 base::TimeDelta::FromMillisecondsD(1000. / 150.); 866 base::TimeDelta::FromMillisecondsD(1000. / 150.);
867 867
868 RunResample(flush_time_delta, event_time_delta); 868 RunResample(flush_time_delta, event_time_delta);
869 } 869 }
870 870
871 } // namespace ui 871 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/motion_event_buffer.cc ('k') | ui/events/gesture_detection/motion_event_generic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698