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

Unified Diff: ui/events/gesture_detection/motion_event_generic_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: Rebase 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 side-by-side diff with in-line comments
Download patch
Index: ui/events/gesture_detection/motion_event_generic_unittest.cc
diff --git a/ui/events/gesture_detection/motion_event_generic_unittest.cc b/ui/events/gesture_detection/motion_event_generic_unittest.cc
index f1aa2937deb664807cce49ac7fa00fad9249ecbd..eb8470489951581840c31e076f27735c62848f1c 100644
--- a/ui/events/gesture_detection/motion_event_generic_unittest.cc
+++ b/ui/events/gesture_detection/motion_event_generic_unittest.cc
@@ -16,12 +16,12 @@ TEST(MotionEventGenericTest, Basic) {
EXPECT_EQ(0U, event.GetHistorySize());
EXPECT_EQ(event_time, event.GetEventTime());
- event.PushPointer(PointerProperties(8.3f, 4.7f));
+ event.PushPointer(PointerProperties(8.3f, 4.7f, 0.9f));
ASSERT_EQ(2U, event.GetPointerCount());
EXPECT_EQ(8.3f, event.GetX(1));
EXPECT_EQ(4.7f, event.GetY(1));
- event.PushPointer(PointerProperties(2.3f, -3.7f));
+ event.PushPointer(PointerProperties(2.3f, -3.7f, 5.8f));
ASSERT_EQ(3U, event.GetPointerCount());
EXPECT_EQ(2.3f, event.GetX(2));
EXPECT_EQ(-3.7f, event.GetY(2));
@@ -44,31 +44,78 @@ TEST(MotionEventGenericTest, Basic) {
event.set_action_index(1);
EXPECT_EQ(1, event.GetActionIndex());
+
+ event.set_action(MotionEvent::ACTION_MOVE);
+ EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction());
+
+ PointerProperties historical_pointer0(1.2f, 2.4f, 1.f);
+ PointerProperties historical_pointer1(2.4f, 4.8f, 2.f);
+ PointerProperties historical_pointer2(4.8f, 9.6f, 3.f);
+ MotionEventGeneric historical_event(
+ MotionEvent::ACTION_MOVE,
+ event_time - base::TimeDelta::FromMilliseconds(5),
+ historical_pointer0);
+ historical_event.PushPointer(historical_pointer1);
+ historical_event.PushPointer(historical_pointer2);
+
+ event.PushHistoricalEvent(historical_event.Clone());
+ EXPECT_EQ(1U, event.GetHistorySize());
+ EXPECT_EQ(event_time - base::TimeDelta::FromMilliseconds(5),
+ event.GetHistoricalEventTime(0));
+ EXPECT_EQ(1.2f, event.GetHistoricalX(0, 0));
+ EXPECT_EQ(2.4f, event.GetHistoricalY(0, 0));
+ EXPECT_EQ(1.f, event.GetHistoricalTouchMajor(0, 0));
+ EXPECT_EQ(2.4f, event.GetHistoricalX(1, 0));
+ EXPECT_EQ(4.8f, event.GetHistoricalY(1, 0));
+ EXPECT_EQ(2.f, event.GetHistoricalTouchMajor(1, 0));
+ EXPECT_EQ(4.8f, event.GetHistoricalX(2, 0));
+ EXPECT_EQ(9.6f, event.GetHistoricalY(2, 0));
+ EXPECT_EQ(3.f, event.GetHistoricalTouchMajor(2, 0));
}
TEST(MotionEventGenericTest, Clone) {
MotionEventGeneric event(MotionEvent::ACTION_DOWN,
base::TimeTicks::Now(),
- PointerProperties(8.3f, 4.7f));
+ PointerProperties(8.3f, 4.7f, 2.f));
event.set_id(1);
event.set_button_state(MotionEvent::BUTTON_PRIMARY);
scoped_ptr<MotionEvent> clone = event.Clone();
ASSERT_TRUE(clone);
- EXPECT_EQ(event, *clone);
+ EXPECT_EQ(event.ToString(), clone->ToString());
+}
+
+TEST(MotionEventGenericTest, CloneWithHistory) {
+ base::TimeTicks event_time = base::TimeTicks::Now();
+ base::TimeTicks historical_event_time =
+ event_time - base::TimeDelta::FromMilliseconds(5);
+
+ PointerProperties pointer(8.3f, 4.7f, 10.1f);
+ MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer);
+
+ PointerProperties historical_pointer(3.4f, -4.3f, 11.5);
+ scoped_ptr<MotionEvent> historical_event(new MotionEventGeneric(
+ MotionEvent::ACTION_MOVE, historical_event_time, historical_pointer));
+
+ event.PushHistoricalEvent(historical_event.Pass());
+ EXPECT_EQ(1U, event.GetHistorySize());
+
+ scoped_ptr<MotionEvent> clone = event.Clone();
+ ASSERT_TRUE(clone);
+ EXPECT_EQ(event.ToString(), clone->ToString());
}
TEST(MotionEventGenericTest, Cancel) {
MotionEventGeneric event(MotionEvent::ACTION_UP,
base::TimeTicks::Now(),
- PointerProperties(8.7f, 4.3f));
+ PointerProperties(8.7f, 4.3f, 1.f));
event.set_id(2);
event.set_button_state(MotionEvent::BUTTON_SECONDARY);
scoped_ptr<MotionEvent> cancel = event.Cancel();
event.set_action(MotionEvent::ACTION_CANCEL);
ASSERT_TRUE(cancel);
- EXPECT_EQ(event, *cancel);
+ EXPECT_EQ(event.ToString(), cancel->ToString());
tdresser 2014/10/20 15:19:15 Is this ToString method just to make debugging fai
jdduke (slow) 2014/10/21 22:19:58 Yeah, good call. I factored out operator<< and ope
}
TEST(MotionEventGenericTest, FindPointerIndexOfId) {
@@ -98,4 +145,49 @@ TEST(MotionEventGenericTest, FindPointerIndexOfId) {
EXPECT_EQ(-1, event2.FindPointerIndexOfId(2));
}
+TEST(MotionEventGenericTest, ToString) {
+ base::TimeTicks event_time = base::TimeTicks::Now();
+ base::TimeTicks historical_event_time0 =
+ event_time - base::TimeDelta::FromMilliseconds(10);
+ base::TimeTicks historical_event_time1 =
+ event_time - base::TimeDelta::FromMilliseconds(5);
+
+ PointerProperties pointer0(1, 2, 3);
+ pointer0.id = 7;
+ pointer0.pressure = 10;
+ pointer0.touch_minor = 15;
+ pointer0.touch_major = 20;
+ pointer0.orientation = 1;
+
+ PointerProperties pointer1(4, 5, 6);
+ pointer1.id = 3;
+ pointer0.pressure = 25;
+ pointer0.touch_minor = 30;
+ pointer0.touch_major = 35;
+ pointer0.orientation = -1;
+
+ MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer0);
+ event.PushPointer(pointer1);
+
+ pointer0.x += 50;
+ pointer1.x -= 50;
+ scoped_ptr<MotionEventGeneric> historical_event0(new MotionEventGeneric(
+ MotionEvent::ACTION_MOVE, historical_event_time0, pointer0));
+ historical_event0->PushPointer(pointer1);
+
+ pointer0.x += 100;
+ pointer1.x -= 100;
+ scoped_ptr<MotionEventGeneric> historical_event1(new MotionEventGeneric(
+ MotionEvent::ACTION_MOVE, historical_event_time1, pointer0));
+ historical_event1->PushPointer(pointer1);
+
+ event.PushHistoricalEvent(historical_event0.PassAs<MotionEvent>());
+ event.PushHistoricalEvent(historical_event1.PassAs<MotionEvent>());
+ ASSERT_EQ(2U, event.GetHistorySize());
+ ASSERT_EQ(2U, event.GetPointerCount());
+ std::string event_string = event.ToString();
+ EXPECT_FALSE(event_string.empty());
+ EXPECT_EQ(event_string, event.ToString());
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698