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

Unified Diff: content/browser/renderer_host/input/touch_disposition_gesture_filter_unittest.cc

Issue 156783006: Consuming a touch move prevents only the next scroll update. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up error handling and tests. Created 6 years, 10 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: content/browser/renderer_host/input/touch_disposition_gesture_filter_unittest.cc
diff --git a/content/browser/renderer_host/input/touch_disposition_gesture_filter_unittest.cc b/content/browser/renderer_host/input/touch_disposition_gesture_filter_unittest.cc
index e537bdb16c1d6608582197419d1d82f86931c45f..49a4bc0538716dc5b87d731f047b9384a16168e2 100644
--- a/content/browser/renderer_host/input/touch_disposition_gesture_filter_unittest.cc
+++ b/content/browser/renderer_host/input/touch_disposition_gesture_filter_unittest.cc
@@ -211,18 +211,24 @@ TEST_F(TouchDispositionGestureFilterTest, BasicGestures) {
// Multiple gestures can be queued for a single event.
PushGesture(WebInputEvent::GestureFlingStart);
PushGesture(WebInputEvent::GestureFlingCancel);
- MoveTouchPoint(0, 1, 1);
+ ReleaseTouchPoint(0);
EXPECT_FALSE(GesturesSent());
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart,
WebInputEvent::GestureFlingCancel),
GetAndResetSentGestures()));
+}
+TEST_F(TouchDispositionGestureFilterTest, BasicGesturesConsumed) {
// A consumed touch's gesture should not be sent.
+ PushGesture(WebInputEvent::GestureScrollBegin);
+ PressTouchPoint(1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
PushGesture(WebInputEvent::GestureFlingStart);
PushGesture(WebInputEvent::GestureFlingCancel);
ReleaseTouchPoint(0);
- EXPECT_FALSE(GesturesSent());
SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_FALSE(GesturesSent());
}
@@ -243,8 +249,65 @@ TEST_F(TouchDispositionGestureFilterTest, ConsumedThenNotConsumed) {
// Even if the subsequent touch had no consumer, continue dropping gestures.
PushGesture(WebInputEvent::GestureFlingStart);
ReleaseTouchPoint(0);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
+ EXPECT_FALSE(GesturesSent());
+}
+
+TEST_F(TouchDispositionGestureFilterTest, NotConsumedThenConsumed) {
+ // A not consumed touch's gesture should be sent.
+ PushGesture(WebInputEvent::GestureScrollBegin);
+ PressTouchPoint(1, 1);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
+ GetAndResetSentGestures()));
+
+ // A newly consumed gesture should not be sent.
+ PushGesture(WebInputEvent::GesturePinchBegin);
+ PressTouchPoint(10, 10);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_FALSE(GesturesSent());
+
+ // And subsequent non-consumed pinch updates should not be sent.
+ PushGesture(WebInputEvent::GestureScrollUpdate);
+ PushGesture(WebInputEvent::GesturePinchUpdate);
+ MoveTouchPoint(0, 2, 2);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollUpdate),
+ GetAndResetSentGestures()));
+
+ // End events dispatched only when their start events were.
+ PushGesture(WebInputEvent::GesturePinchEnd);
+ ReleaseTouchPoint(1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ PushGesture(WebInputEvent::GestureScrollEnd);
+ ReleaseTouchPoint(0);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollEnd),
+ GetAndResetSentGestures()));
+}
+
+TEST_F(TouchDispositionGestureFilterTest, ScrollAlternatelyConsumed) {
+ // A consumed touch's gesture should not be sent.
+ PushGesture(WebInputEvent::GestureScrollBegin);
+ PressTouchPoint(1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
+ GetAndResetSentGestures()));
+
+ for (size_t i = 0; i < 3; ++i) {
+ PushGesture(WebInputEvent::GestureScrollUpdate);
+ MoveTouchPoint(0, 2, 2);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ PushGesture(WebInputEvent::GestureScrollUpdate);
+ MoveTouchPoint(0, 3, 3);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollUpdate),
+ GetAndResetSentGestures()));
+ }
}
TEST_F(TouchDispositionGestureFilterTest, NotConsumedThenNoConsumer) {
@@ -263,11 +326,155 @@ TEST_F(TouchDispositionGestureFilterTest, NotConsumedThenNoConsumer) {
EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin),
GetAndResetSentGestures()));
- // If the subsequent touch is consumed, then the remaining gesture sequence
- // should be dropped, regardless of subsequent touch ack disposition.
+ // End events should be dispatched when their start events were, independent
+ // of the ack state.
+ PushGesture(WebInputEvent::GesturePinchEnd);
+ ReleaseTouchPoint(1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchEnd),
+ GetAndResetSentGestures()));
+
+ PushGesture(WebInputEvent::GestureScrollEnd);
+ ReleaseTouchPoint(0);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollEnd),
+ GetAndResetSentGestures()));
+}
+
+TEST_F(TouchDispositionGestureFilterTest, EndingEventsSent) {
+ PushGesture(WebInputEvent::GestureScrollBegin);
+ PressTouchPoint(1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
+ GetAndResetSentGestures()));
+
+ PushGesture(WebInputEvent::GesturePinchBegin);
+ PressTouchPoint(2, 2);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin),
+ GetAndResetSentGestures()));
+
+ // Consuming the touchend event can't suppress the match end gesture.
+ PushGesture(WebInputEvent::GesturePinchEnd);
+ ReleaseTouchPoint(1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchEnd),
+ GetAndResetSentGestures()));
+
+ // But other events in the same packet are still suppressed.
+ PushGesture(WebInputEvent::GestureScrollUpdate);
+ PushGesture(WebInputEvent::GestureScrollEnd);
+ ReleaseTouchPoint(0);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollEnd),
+ GetAndResetSentGestures()));
+
+ // GestureScrollEnd and GestureFlingStart behave the same in this regard.
+ PushGesture(WebInputEvent::GestureScrollBegin);
+ PressTouchPoint(1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
+ GetAndResetSentGestures()));
+
+ PushGesture(WebInputEvent::GestureFlingStart);
+ ReleaseTouchPoint(0);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart),
+ GetAndResetSentGestures()));
+}
+
+TEST_F(TouchDispositionGestureFilterTest, EndingEventsNotSent) {
+ // Consuming a begin event ensures no end events are sent.
+ PushGesture(WebInputEvent::GestureScrollBegin);
+ PressTouchPoint(1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ PushGesture(WebInputEvent::GesturePinchBegin);
+ PressTouchPoint(2, 2);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ PushGesture(WebInputEvent::GesturePinchEnd);
+ ReleaseTouchPoint(1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ PushGesture(WebInputEvent::GestureScrollEnd);
+ ReleaseTouchPoint(0);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+}
+
+TEST_F(TouchDispositionGestureFilterTest, UpdateEventsSuppressedPerEvent) {
+ PushGesture(WebInputEvent::GestureScrollBegin);
+ PressTouchPoint(1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
+ GetAndResetSentGestures()));
+
+ // Consuming a single scroll or pinch update should suppress only that event.
+ PushGesture(WebInputEvent::GestureScrollUpdate);
+ MoveTouchPoint(0, 2, 2);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ PushGesture(WebInputEvent::GesturePinchBegin);
+ PressTouchPoint(2, 2);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin),
+ GetAndResetSentGestures()));
+
+ PushGesture(WebInputEvent::GesturePinchUpdate);
+ MoveTouchPoint(1, 2, 3);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ // Subsequent updates should not be affected.
PushGesture(WebInputEvent::GestureScrollUpdate);
+ MoveTouchPoint(0, 4, 4);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollUpdate),
+ GetAndResetSentGestures()));
+
PushGesture(WebInputEvent::GesturePinchUpdate);
+ MoveTouchPoint(0, 4, 5);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchUpdate),
+ GetAndResetSentGestures()));
+
+ PushGesture(WebInputEvent::GesturePinchEnd);
+ ReleaseTouchPoint(1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchEnd),
+ GetAndResetSentGestures()));
+
+ PushGesture(WebInputEvent::GestureScrollEnd);
+ ReleaseTouchPoint(0);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollEnd),
+ GetAndResetSentGestures()));
+}
+
+TEST_F(TouchDispositionGestureFilterTest, UpdateEventsDependOnBeginEvents) {
+ PushGesture(WebInputEvent::GestureScrollBegin);
+ PressTouchPoint(1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ // Independent packets are never sent when the global state is to drop.
+ PushGesture(WebInputEvent::GestureScrollUpdate);
MoveTouchPoint(0, 2, 2);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ PushGesture(WebInputEvent::GesturePinchBegin);
+ PressTouchPoint(2, 2);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_FALSE(GesturesSent());
+
+ PushGesture(WebInputEvent::GesturePinchUpdate);
+ MoveTouchPoint(1, 2, 3);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_FALSE(GesturesSent());
@@ -278,19 +485,19 @@ TEST_F(TouchDispositionGestureFilterTest, NotConsumedThenNoConsumer) {
PushGesture(WebInputEvent::GestureScrollEnd);
ReleaseTouchPoint(0);
- SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_FALSE(GesturesSent());
}
TEST_F(TouchDispositionGestureFilterTest, MultipleTouchSequences) {
// Queue two touch-to-gestures sequences.
- PushGesture(WebInputEvent::GestureFlingStart);
+ PushGesture(WebInputEvent::GestureTapDown);
PressTouchPoint(1, 1);
- PushGesture(WebInputEvent::GestureFlingCancel);
+ PushGesture(WebInputEvent::GestureTap);
ReleaseTouchPoint(0);
- PushGesture(WebInputEvent::GestureFlingStart);
+ PushGesture(WebInputEvent::GestureScrollBegin);
PressTouchPoint(1, 1);
- PushGesture(WebInputEvent::GestureFlingCancel);
+ PushGesture(WebInputEvent::GestureScrollEnd);
ReleaseTouchPoint(0);
// The first gesture sequence should not be allowed.
@@ -301,15 +508,18 @@ TEST_F(TouchDispositionGestureFilterTest, MultipleTouchSequences) {
// The subsequent sequence should "reset" allowance.
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
- EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart,
- WebInputEvent::GestureFlingCancel),
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin,
+ WebInputEvent::GestureScrollEnd),
GetAndResetSentGestures()));
}
TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnNewTouchSequence) {
// Simulate a fling.
+ PushGesture(WebInputEvent::GestureScrollBegin);
PressTouchPoint(1, 1);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
+ GetAndResetSentGestures()));
PushGesture(WebInputEvent::GestureFlingStart);
ReleaseTouchPoint(0);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
@@ -318,10 +528,12 @@ TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnNewTouchSequence) {
// A new touch seqeuence should cancel the outstanding fling.
PressTouchPoint(1, 1);
- ReleaseTouchPoint(0);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingCancel),
GetAndResetSentGestures()));
+ ReleaseTouchPoint(0);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
+ EXPECT_FALSE(GesturesSent());
}
TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnScrollBegin) {
@@ -347,19 +559,24 @@ TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnScrollBegin) {
TEST_F(TouchDispositionGestureFilterTest, FlingNotCancelledIfGFCEventReceived) {
// Simulate a fling that is started then cancelled.
- PushGesture(WebInputEvent::GestureFlingStart);
+ PushGesture(WebInputEvent::GestureScrollBegin);
PressTouchPoint(1, 1);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
+ PushGesture(WebInputEvent::GestureFlingStart);
+ MoveTouchPoint(0, 1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
PushGesture(WebInputEvent::GestureFlingCancel);
ReleaseTouchPoint(0);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
- EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart,
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin,
+ WebInputEvent::GestureFlingStart,
WebInputEvent::GestureFlingCancel),
GetAndResetSentGestures()));
// A new touch sequence will not inject a GestureFlingCancel, as the fling
// has already been cancelled.
PressTouchPoint(1, 1);
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
ReleaseTouchPoint(0);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_FALSE(GesturesSent());
@@ -468,12 +685,12 @@ TEST_F(TouchDispositionGestureFilterTest, SpuriousAcksIgnored) {
PushGesture(WebInputEvent::GestureScrollBegin);
PressTouchPoint(1, 1);
- PushGesture(WebInputEvent::GestureScrollEnd);
- ReleaseTouchPoint(0);
+ PushGesture(WebInputEvent::GestureScrollUpdate);
+ MoveTouchPoint(0, 3,3);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin,
- WebInputEvent::GestureScrollEnd),
+ WebInputEvent::GestureScrollUpdate),
GetAndResetSentGestures()));
// Even if all packets have been dispatched, the filter may not be empty as
@@ -504,4 +721,42 @@ TEST_F(TouchDispositionGestureFilterTest, PacketsWithInvalidOrderIgnored) {
EXPECT_TRUE(IsEmpty());
}
+TEST_F(TouchDispositionGestureFilterTest, EmptyWhenSequenceHasEnded) {
+ // An unconsumed touch's gesture should be sent.
+ PushGesture(WebInputEvent::GestureTapDown);
+ PressTouchPoint(1, 1);
+ EXPECT_FALSE(GesturesSent());
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapDown),
+ GetAndResetSentGestures()));
+
+ PushGesture(WebInputEvent::GestureTap);
+ ReleaseTouchPoint(0);
+ EXPECT_FALSE(GesturesSent());
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTap),
+ GetAndResetSentGestures()));
+
+ EXPECT_TRUE(IsEmpty());
+}
+
+TEST_F(TouchDispositionGestureFilterTest, ConsumedTouchCancel) {
+ // An unconsumed touch's gesture should be sent.
+ PushGesture(WebInputEvent::GestureTapDown);
+ PressTouchPoint(1, 1);
+ EXPECT_FALSE(GesturesSent());
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapDown),
+ GetAndResetSentGestures()));
+
+ PushGesture(WebInputEvent::GestureTapCancel);
+ PushGesture(WebInputEvent::GestureScrollEnd);
+ CancelTouchPoint(0);
+ EXPECT_FALSE(GesturesSent());
+ SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
+ EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapCancel,
+ WebInputEvent::GestureScrollEnd),
+ GetAndResetSentGestures()));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698