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

Unified Diff: ui/events/gesture_detection/gesture_provider_unittest.cc

Issue 306483003: Prepare for Unified Gesture Recognizer landing in Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable UGR. Created 6 years, 7 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/gesture_provider_unittest.cc
diff --git a/ui/events/gesture_detection/gesture_provider_unittest.cc b/ui/events/gesture_detection/gesture_provider_unittest.cc
index 12870a92a22db4cd5f0171cda5092d33718c4c95..7df65066924fba222ec6faa335f0a08e6d1b189e 100644
--- a/ui/events/gesture_detection/gesture_provider_unittest.cc
+++ b/ui/events/gesture_detection/gesture_provider_unittest.cc
@@ -74,6 +74,30 @@ class GestureProviderTest : public testing::Test, public GestureProviderClient {
return MockMotionEvent(action, event_time, x0, y0, x1, y1);
}
+ static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
+ MotionEvent::Action action,
+ float x0,
+ float y0,
+ float x1,
+ float y1,
+ float x2,
+ float y2) {
+ return MockMotionEvent(action, event_time, x0, y0, x1, y1, x2, y2);
+ }
+
+ static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
jdduke (slow) 2014/05/28 16:26:00 Hmm, I don't actually see where the 4 pointer case
tdresser 2014/05/29 14:26:21 Oh goodness, you're right. I was using 4 for the b
+ MotionEvent::Action action,
+ float x0,
+ float y0,
+ float x1,
+ float y1,
+ float x2,
+ float y2,
+ float x3,
+ float y3) {
+ return MockMotionEvent(action, event_time, x0, y0, x1, y1, x2, y2, x3, y3);
+ }
+
static MockMotionEvent ObtainMotionEvent(
base::TimeTicks event_time,
MotionEvent::Action action,
@@ -98,8 +122,20 @@ class GestureProviderTest : public testing::Test, public GestureProviderClient {
positions[1].y(),
positions[2].x(),
positions[2].y());
+ case 4:
+ return MockMotionEvent(action,
+ event_time,
+ positions[0].x(),
+ positions[0].y(),
+ positions[1].x(),
+ positions[1].y(),
+ positions[2].x(),
+ positions[2].y(),
+ positions[3].x(),
+ positions[3].y());
+
default:
- CHECK(false) << "MockMotionEvent only supports 1-3 pointers";
+ CHECK(false) << "MockMotionEvent only supports 1-4 pointers";
return MockMotionEvent();
}
}
@@ -1389,6 +1425,10 @@ TEST_F(GestureProviderTest, PinchZoom) {
EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
+
+ EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x);
+ EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y);
+
EXPECT_EQ(
gfx::RectF(kFakeCoordX - kMockTouchRadius,
kFakeCoordY - kMockTouchRadius,
@@ -1679,84 +1719,154 @@ TEST_F(GestureProviderTest, GestureBeginAndEnd) {
EXPECT_EQ(0U, GetReceivedGestureCount());
MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
+ ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
event.pointer_count = 1;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type);
EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
EXPECT_EQ(2U, GetReceivedGestureCount());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius,
- kFakeCoordY - kMockTouchRadius,
+ EXPECT_EQ(1, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(1, GetMostRecentGestureEvent().y);
+ EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
+ 1 - kMockTouchRadius,
kMockTouchRadius * 2,
kMockTouchRadius * 2),
GetMostRecentGestureEvent().details.bounding_box());
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN);
+ event = ObtainMotionEvent(
+ event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2);
event.pointer_count = 2;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
EXPECT_EQ(3U, GetReceivedGestureCount());
EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(2, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(2, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN);
+ event = ObtainMotionEvent(
+ event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3);
event.pointer_count = 3;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
EXPECT_EQ(4U, GetReceivedGestureCount());
EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(3, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(3, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP);
+ event = ObtainMotionEvent(
+ event_time, MotionEvent::ACTION_POINTER_UP, 1, 1, 2, 2, 3, 3);
event.pointer_count = 2;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
EXPECT_EQ(5U, GetReceivedGestureCount());
EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(1, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(1, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN);
+ event = ObtainMotionEvent(
+ event_time, MotionEvent::ACTION_POINTER_DOWN, 2, 2, 3, 3, 4, 4);
event.pointer_count = 3;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
EXPECT_EQ(6U, GetReceivedGestureCount());
EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(4, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(4, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP);
+ event = ObtainMotionEvent(
+ event_time, MotionEvent::ACTION_POINTER_UP, 2, 2, 3, 3, 4, 4);
event.pointer_count = 2;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
EXPECT_EQ(7U, GetReceivedGestureCount());
EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(2, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(2, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP);
+ event =
+ ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP, 3, 3, 4, 4);
event.pointer_count = 1;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
EXPECT_EQ(8U, GetReceivedGestureCount());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(3, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(3, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
+
+ event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 4, 4);
event.pointer_count = 1;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
EXPECT_EQ(9U, GetReceivedGestureCount());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(4, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(4, GetMostRecentGestureEvent().y);
+}
+
+// Verify that gesture begin and gesture end events are dispatched correctly
+// when an ACTION_CANCEL is received.
+TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) {
+ EnableBeginEndTypes();
+ base::TimeTicks event_time = base::TimeTicks::Now();
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
+ EXPECT_EQ(0U, GetReceivedGestureCount());
+ MockMotionEvent event =
+ ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
event.pointer_count = 1;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(9).type);
+ EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type);
EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(11U, GetReceivedGestureCount());
+ EXPECT_EQ(2U, GetReceivedGestureCount());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
+ 1 - kMockTouchRadius,
+ kMockTouchRadius * 2,
+ kMockTouchRadius * 2),
+ GetMostRecentGestureEvent().details.bounding_box());
+ EXPECT_EQ(1, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(1, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL);
- event.pointer_count = 1;
+ event = ObtainMotionEvent(
+ event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2);
+ event.pointer_count = 2;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
- EXPECT_EQ(12U, GetReceivedGestureCount());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
-}
+ EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
+ EXPECT_EQ(3U, GetReceivedGestureCount());
+ EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(2, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(2, GetMostRecentGestureEvent().y);
+
+ event = ObtainMotionEvent(
+ event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3);
+ event.pointer_count = 3;
+ EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
+ EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
+ EXPECT_EQ(4U, GetReceivedGestureCount());
+ EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
+ EXPECT_EQ(3, GetMostRecentGestureEvent().x);
+ EXPECT_EQ(3, GetMostRecentGestureEvent().y);
+
+ event = ObtainMotionEvent(
+ event_time, MotionEvent::ACTION_CANCEL, 1, 1, 2, 2, 3, 3);
+ event.pointer_count = 3;
+ EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
+ EXPECT_EQ(7U, GetReceivedGestureCount());
+ EXPECT_EQ(3, GetReceivedGesture(4).details.touch_points());
+ EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(4).details.type());
+ EXPECT_EQ(2, GetReceivedGesture(5).details.touch_points());
+ EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(5).details.type());
+ EXPECT_EQ(1, GetReceivedGesture(6).details.touch_points());
+ EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(6).details.type());
+ EXPECT_EQ(1, GetReceivedGesture(4).x);
+ EXPECT_EQ(1, GetReceivedGesture(4).y);
+ EXPECT_EQ(2, GetReceivedGesture(5).x);
+ EXPECT_EQ(2, GetReceivedGesture(5).y);
+ EXPECT_EQ(3, GetReceivedGesture(6).x);
+ EXPECT_EQ(3, GetReceivedGesture(6).y);
+}
// Test a simple two finger tap
TEST_F(GestureProviderTest, TwoFingerTap) {

Powered by Google App Engine
This is Rietveld 408576698