Index: content/public/android/javatests/src/org/chromium/content/browser/ContentViewGestureHandlerTest.java |
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewGestureHandlerTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewGestureHandlerTest.java |
index e18171b0ac5478c611c03b299824dcb5a00c5982..9f2aaca07f08f879c8405bdfe67e605522478478 100644 |
--- a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewGestureHandlerTest.java |
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewGestureHandlerTest.java |
@@ -11,18 +11,14 @@ import android.test.InstrumentationTestCase; |
import android.test.suitebuilder.annotation.SmallTest; |
import android.util.Log; |
import android.view.MotionEvent; |
-import android.view.MotionEvent.PointerCoords; |
-import android.view.MotionEvent.PointerProperties; |
import android.view.ViewConfiguration; |
import org.chromium.base.test.util.Feature; |
-import org.chromium.base.test.util.ScalableTimeout; |
import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegate; |
import org.chromium.content.browser.third_party.GestureDetector; |
import java.util.ArrayList; |
import java.util.concurrent.CountDownLatch; |
-import java.util.concurrent.TimeUnit; |
/** |
* Test suite for ContentViewGestureHandler. |
@@ -37,7 +33,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
private MockGestureDetector mMockGestureDetector; |
private MockZoomManager mMockZoomManager; |
private ContentViewGestureHandler mGestureHandler; |
- private LongPressDetector mLongPressDetector; |
static class MockListener extends GestureDetector.SimpleOnGestureListener { |
MotionEvent mLastLongPress; |
@@ -62,7 +57,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
public void onShowPress(MotionEvent e) { |
mLastShowPress = MotionEvent.obtain(e); |
mShowPressCalled.countDown(); |
- Log.e("Overscroll", "OnShowPress"); |
} |
@Override |
@@ -103,20 +97,17 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
} |
static class MockMotionEventDelegate implements MotionEventDelegate { |
- private ContentViewGestureHandler mSynchronousConfirmTarget; |
- private int mSynchronousConfirmAckResult; |
- |
public int mLastTouchAction; |
public int mLastGestureType; |
public int mTotalSentGestureCount; |
@Override |
- public boolean sendTouchEvent(long timeMs, int action, TouchPoint[] pts) { |
+ public void onTouchEventHandlingBegin(long timeMs, int action, TouchPoint[] pts) { |
mLastTouchAction = action; |
- if (mSynchronousConfirmTarget != null) { |
- mSynchronousConfirmTarget.confirmTouchEvent(mSynchronousConfirmAckResult); |
- } |
- return true; |
+ } |
+ |
+ @Override |
+ public void onTouchEventHandlingEnd() { |
} |
@Override |
@@ -126,32 +117,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
mTotalSentGestureCount++; |
return true; |
} |
- |
- @Override |
- public void sendSingleTapUMA(int type) { |
- // Not implemented. |
- } |
- |
- @Override |
- public void sendActionAfterDoubleTapUMA(int type, |
- boolean clickDelayEnabled) { |
- // Not implemented. |
- } |
- |
- @Override |
- public void invokeZoomPicker() { |
- // Not implemented. |
- } |
- |
- public void enableSynchronousConfirmTouchEvent( |
- ContentViewGestureHandler handler, int ackResult) { |
- mSynchronousConfirmTarget = handler; |
- mSynchronousConfirmAckResult = ackResult; |
- } |
- |
- public void disableSynchronousConfirmTouchEvent() { |
- mSynchronousConfirmTarget = null; |
- } |
} |
static class MockZoomManager extends ZoomManager { |
@@ -190,10 +155,7 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mMockMotionEventDelegate, |
mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
- mGestureHandler.setTestDependencies( |
- mLongPressDetector, mMockGestureDetector, mMockListener); |
+ mGestureHandler.setTestDependencies(mMockGestureDetector, mMockListener); |
TouchPoint.initializeConstantsForTesting(); |
} |
@@ -212,301 +174,14 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
assertFalse(mGestureHandler.onTouchEvent(event)); |
assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEvent != null); |
- assertTrue("Should have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 10); |
- mLongPressDetector.cancelLongPressIfNeeded(event); |
- assertTrue("Should not have a pending LONG_PRESS", !mLongPressDetector.hasPendingMessage()); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
// Synchronous, no need to wait. |
assertTrue("Should have a single tap", mMockListener.mLastSingleTap != null); |
} |
/** |
- * Verify that when a touch event handler is registered the touch events are queued |
- * and sent in order. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testFlingOnTouchHandler() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertTrue("Should not have a pending gesture", mMockGestureDetector.mLastEvent == null); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("We should have coalesced move events into one" |
- , 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 15, MotionEvent.ACTION_UP, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals(MotionEvent.ACTION_MOVE, |
- mGestureHandler.peekFirstInPendingMotionEventsForTesting().getActionMasked()); |
- assertFalse("Pending LONG_PRESS should have been canceled", |
- mLongPressDetector.hasPendingMessage()); |
- |
- mGestureHandler.confirmTouchEvent(ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals(MotionEvent.ACTION_UP, |
- mGestureHandler.peekFirstInPendingMotionEventsForTesting().getActionMasked()); |
- |
- mGestureHandler.confirmTouchEvent(ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Synchronous, no need to wait. |
- assertTrue("Should not have a fling", mMockListener.mLastFling1 == null); |
- assertTrue("Should not have a long press", mMockListener.mLastLongPress == null); |
- } |
- |
- /** |
- * Verify that after a touch event handlers starts handling a gesture, even though some event |
- * in the middle of the gesture returns with NOT_CONSUMED, we don't send that to the gesture |
- * detector to avoid falling to a faulty state. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testFlingOnTouchHandlerWithOneEventNotConsumed() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertTrue("Should not have a pending gesture", mMockGestureDetector.mLastEvent == null); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("We should have coalesced move events into one" |
- , 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 15, MotionEvent.ACTION_UP, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals(MotionEvent.ACTION_MOVE, |
- mGestureHandler.peekFirstInPendingMotionEventsForTesting().getActionMasked()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals(MotionEvent.ACTION_UP, |
- mGestureHandler.peekFirstInPendingMotionEventsForTesting().getActionMasked()); |
- assertTrue("Even though the last event was not consumed by JavaScript," + |
- "it shouldn't have been sent to the Gesture Detector", |
- mMockGestureDetector.mLastEvent == null); |
- |
- mGestureHandler.confirmTouchEvent(ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Synchronous, no need to wait. |
- assertTrue("Should not have a fling", mMockListener.mLastFling1 == null); |
- assertTrue("Should not have a long press", mMockListener.mLastLongPress == null); |
- } |
- |
- /** |
- * Verify that when a registered touch event handler return NO_CONSUMER_EXISTS for down event |
- * all queue is drained until next down. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testDrainWithFlingAndClickOutofTouchHandler() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- mGestureHandler = new ContentViewGestureHandler( |
- getInstrumentation().getTargetContext(), new MockMotionEventDelegate(), |
- mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 15, MotionEvent.ACTION_UP, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = motionEvent(MotionEvent.ACTION_DOWN, eventTime + 20, eventTime + 20); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(4, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 20, MotionEvent.ACTION_UP, |
- FAKE_COORD_X, FAKE_COORD_Y, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(5, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
- assertEquals("The queue should have been drained until first down since no consumer exists", |
- 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals(MotionEvent.ACTION_DOWN, |
- mGestureHandler.peekFirstInPendingMotionEventsForTesting().getActionMasked()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
- assertEquals("The queue should have been drained", |
- 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- } |
- |
- /** |
- * Verify that when a touch event handler is registered the touch events stop getting queued |
- * after we received INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testFlingOutOfTouchHandler() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertTrue("Should not have a pending gesture", mMockGestureDetector.mLastEvent == null); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("The down touch event should have been sent to the Gesture Detector", |
- event.getEventTime(), mMockGestureDetector.mLastEvent.getEventTime()); |
- assertEquals("The down touch event should have been sent to the Gesture Detector", |
- MotionEvent.ACTION_DOWN, mMockGestureDetector.mLastEvent.getActionMasked()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("Motion events should be going to the Gesture Detector directly", |
- event.getEventTime(), mMockGestureDetector.mLastEvent.getEventTime()); |
- assertEquals("Motion events should be going to the Gesture Detector directly", |
- MotionEvent.ACTION_MOVE, mMockGestureDetector.mLastEvent.getActionMasked()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_UP, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("Motion events should be going to the Gesture Detector directly", |
- event.getEventTime(), mMockGestureDetector.mLastEvent.getEventTime()); |
- assertEquals("Motion events should be going to the Gesture Detector directly", |
- MotionEvent.ACTION_UP, mMockGestureDetector.mLastEvent.getActionMasked()); |
- |
- // Synchronous, no need to wait. |
- assertTrue("Should have a fling", mMockListener.mLastFling1 != null); |
- assertTrue("Should not have a long press", mMockListener.mLastLongPress == null); |
- } |
- |
- /** |
- * Verifies that a single tap doesn't cause a long press event to be sent. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testNoLongPressIsSentForSingleTapOutOfTouchHandler() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertTrue("Should not have a pending gesture", mMockGestureDetector.mLastEvent == null); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- |
- event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 5); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("The down touch event should have been sent to the Gesture Detector", |
- event.getDownTime(), mMockGestureDetector.mLastEvent.getEventTime()); |
- assertEquals("The next event should be ACTION_UP", |
- MotionEvent.ACTION_UP, |
- mGestureHandler.peekFirstInPendingMotionEventsForTesting().getActionMasked()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("The up touch event should have been sent to the Gesture Detector", |
- event.getEventTime(), mMockGestureDetector.mLastEvent.getEventTime()); |
- |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- } |
- |
- /** |
* Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). |
* @throws Exception |
*/ |
@@ -520,13 +195,10 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
assertFalse(mGestureHandler.onTouchEvent(event)); |
assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEvent != null); |
- assertTrue("Should have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
event = MotionEvent.obtain( |
downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- mLongPressDetector.cancelLongPressIfNeeded(event); |
- assertTrue("Should not have a pending LONG_PRESS", !mLongPressDetector.hasPendingMessage()); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
event = MotionEvent.obtain( |
@@ -750,9 +422,7 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
new GestureRecordingMotionEventDelegate(); |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
- mGestureHandler.setTestDependencies(mLongPressDetector, null, null); |
+ mGestureHandler.setTestDependencies(null, null); |
MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, time, time); |
mGestureHandler.onTouchEvent(event); |
@@ -764,9 +434,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
assertEquals("Only showPressedState and tapDown should have been sent", |
2, mockDelegate.mGestureTypeList.size()); |
- mLongPressDetector.startLongPressTimerIfNeeded(event); |
- mLongPressDetector.sendLongPressGestureForTest(); |
- |
assertEquals("Only should have sent only LONG_PRESS event", |
3, mockDelegate.mGestureTypeList.size()); |
assertEquals("Should have a long press event next", |
@@ -797,13 +464,10 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
new GestureRecordingMotionEventDelegate(); |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
mGestureHandler.sendShowPressedStateGestureForTesting(); |
@@ -857,12 +521,9 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
new GestureRecordingMotionEventDelegate(); |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
mGestureHandler.sendShowPressedStateGestureForTesting(); |
assertEquals("GESTURE_SHOW_PRESSED_STATE should have been sent", |
@@ -939,12 +600,9 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
new GestureRecordingMotionEventDelegate(); |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, downTime1); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
mGestureHandler.sendShowPressedStateGestureForTesting(); |
assertEquals("GESTURE_SHOW_PRESSED_STATE should have been sent", |
@@ -1075,8 +733,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
new GestureRecordingMotionEventDelegate(); |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, downTime1); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
@@ -1286,8 +942,11 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
private final ArrayList<Long> mGestureTimeList = new ArrayList<Long>(); |
@Override |
- public boolean sendTouchEvent(long timeMs, int action, TouchPoint[] pts) { |
- return true; |
+ public void onTouchEventHandlingBegin(long timeMs, int action, TouchPoint[] pts) { |
+ } |
+ |
+ @Override |
+ public void onTouchEventHandlingEnd() { |
} |
@Override |
@@ -1304,22 +963,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
return true; |
} |
- @Override |
- public void sendSingleTapUMA(int type) { |
- // Not implemented. |
- } |
- |
- @Override |
- public void sendActionAfterDoubleTapUMA(int type, |
- boolean clickDelayEnabled) { |
- // Not implemented. |
- } |
- |
- @Override |
- public void invokeZoomPicker() { |
- // Not implemented. |
- } |
- |
public GestureEvent getMostRecentGestureEvent() { |
return mMostRecentGestureEvent; |
} |
@@ -1435,11 +1078,9 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
new GestureRecordingMotionEventDelegate(); |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mLongPressDetector = mGestureHandler.getLongPressDetector(); |
MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertTrue("Should have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
event = MotionEvent.obtain( |
downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
@@ -1448,7 +1089,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertTrue("Should not have a pending LONG_PRESS", !mLongPressDetector.hasPendingMessage()); |
// No LONG_TAP because LONG_PRESS timer is cancelled. |
assertFalse("No LONG_PRESS should be sent", |
@@ -1460,48 +1100,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
} |
/** |
- * Verifies that when hasTouchEventHandlers changes while in a gesture, that the pending |
- * queue does not grow continually. |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testHasTouchEventHandlersChangesInGesture() { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- mGestureHandler = new ContentViewGestureHandler( |
- getInstrumentation().getTargetContext(), new MockMotionEventDelegate(), |
- mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 15, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 15, FAKE_COORD_Y * 15, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- } |
- |
- /** |
* Verify that LONG_TAP is triggered after LongPress followed by an UP. |
* |
* @throws Exception |
@@ -1516,13 +1114,9 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
new GestureRecordingMotionEventDelegate(); |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mLongPressDetector = mGestureHandler.getLongPressDetector(); |
MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertTrue("Should have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- |
- mLongPressDetector.sendLongPressGestureForTest(); |
assertEquals("A LONG_PRESS gesture should have been sent", |
ContentViewGestureHandler.GESTURE_LONG_PRESS, |
@@ -1574,164 +1168,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
assertEquals(-scrollDelta, extraParams.getInt(ContentViewGestureHandler.DISTANCE_Y)); |
} |
- /** |
- * Verify that touch moves are deferred if they are within the touch slop region |
- * and the touch sequence is not being consumed. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testTouchMoveWithinTouchSlopDeferred() throws Exception { |
- Context context = getInstrumentation().getTargetContext(); |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- final int scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
- final int lessThanSlopScrollDelta = scaledTouchSlop / 2; |
- final int greaterThanSlopScrollDelta = scaledTouchSlop * 2; |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("The touch down should have been forwarded", |
- TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLastTouchAction); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X, FAKE_COORD_Y + lessThanSlopScrollDelta, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals("The less-than-slop touch move should not have been forwarded", |
- TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLastTouchAction); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X, FAKE_COORD_Y + greaterThanSlopScrollDelta, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("The touch move should have been forwarded", |
- TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.mLastTouchAction); |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- } |
- |
- /** |
- * Verify that touch moves are not deferred even if they are within the touch slop region |
- * when the touch sequence is being consumed. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testTouchMoveWithinTouchSlopNotDeferredIfJavascriptConsumingGesture() |
- throws Exception { |
- Context context = getInstrumentation().getTargetContext(); |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- final int scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
- final int lessThanSlopScrollDelta = scaledTouchSlop / 2; |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("The touch down should have been forwarded", |
- TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLastTouchAction); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X, FAKE_COORD_Y + lessThanSlopScrollDelta, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals("The less-than-slop touch move should have been forwarded", |
- TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.mLastTouchAction); |
- } |
- |
- |
- /** |
- * Verify that touch moves are not deferred when the MotionEvent has multiple active pointers. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testTouchMoveNotDeferredWithMultiplePointers() |
- throws Exception { |
- Context context = getInstrumentation().getTargetContext(); |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- final int scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
- final int lessThanSlopScrollDelta = scaledTouchSlop / 2; |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- final int secondaryCoordX = FAKE_COORD_X + 10 * scaledTouchSlop; |
- final int secondaryCoordY = FAKE_COORD_Y + 10 * scaledTouchSlop; |
- |
- PointerProperties pp0 = new PointerProperties(); |
- pp0.id = 0; |
- pp0.toolType = MotionEvent.TOOL_TYPE_FINGER; |
- PointerProperties pp1 = new PointerProperties(); |
- pp1.id = 1; |
- pp1.toolType = MotionEvent.TOOL_TYPE_FINGER; |
- |
- PointerCoords pc0 = new PointerCoords(); |
- pc0.x = FAKE_COORD_X; |
- pc0.y = FAKE_COORD_Y; |
- pc0.pressure = 1; |
- pc0.size = 1; |
- PointerCoords pc1 = new PointerCoords(); |
- pc1.x = secondaryCoordX; |
- pc1.y = secondaryCoordY; |
- pc1.pressure = 1; |
- pc1.size = 1; |
- |
- MotionEvent event = MotionEvent.obtain( |
- eventTime, eventTime, MotionEvent.ACTION_DOWN, |
- 1, new PointerProperties[] { pp0 }, new PointerCoords[] { pc0 }, |
- 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("The touch down should have been forwarded", |
- TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLastTouchAction); |
- |
- event = MotionEvent.obtain( |
- eventTime, eventTime, MotionEvent.ACTION_POINTER_DOWN, |
- 2, new PointerProperties[] { pp0, pp1 }, new PointerCoords[] { pc0, pc1 }, |
- 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("The secondary touch down should have been forwarded", |
- TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLastTouchAction); |
- |
- pc1.x = secondaryCoordX + lessThanSlopScrollDelta; |
- pc1.y = secondaryCoordY + lessThanSlopScrollDelta; |
- |
- event = MotionEvent.obtain( |
- eventTime, eventTime, MotionEvent.ACTION_MOVE, |
- 2, new PointerProperties[] { pp0, pp1 }, new PointerCoords[] { pc0, pc1 }, |
- 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("The secondary touch move should have been forwarded", |
- TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.mLastTouchAction); |
- } |
- |
private static void sendLastScrollByEvent(ContentViewGestureHandler handler) { |
final long downTime = SystemClock.uptimeMillis(); |
final long eventTime = SystemClock.uptimeMillis(); |
@@ -1927,133 +1363,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
} |
/** |
- * Verify that touch move events are properly coalesced. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testTouchMoveCoalescing() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- mGestureHandler.confirmTouchEvent(ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals(TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLastTouchAction); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.hasPendingMessage()); |
- assertEquals("Initial move events should offered to javascript and added to the queue", |
- 1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals(TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.mLastTouchAction); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("Move events already sent to javascript should not be coalesced", |
- 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 15, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 15, FAKE_COORD_Y * 15, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("Similar pending move events should be coalesced", |
- 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- PointerProperties pp1 = new PointerProperties(); |
- pp1.id = 0; |
- pp1.toolType = MotionEvent.TOOL_TYPE_FINGER; |
- PointerProperties pp2 = new PointerProperties(); |
- pp2.id = 1; |
- pp2.toolType = MotionEvent.TOOL_TYPE_FINGER; |
- PointerProperties[] properties = new PointerProperties[] { pp1, pp2 }; |
- |
- PointerCoords pc1 = new PointerCoords(); |
- pc1.x = FAKE_COORD_X * 10; |
- pc1.y = FAKE_COORD_Y * 10; |
- pc1.pressure = 1; |
- pc1.size = 1; |
- PointerCoords pc2 = new PointerCoords(); |
- pc2.x = FAKE_COORD_X * 15; |
- pc2.y = FAKE_COORD_Y * 15; |
- pc2.pressure = 1; |
- pc2.size = 1; |
- PointerCoords[] coords = new PointerCoords[] { pc1, pc2 }; |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 20, MotionEvent.ACTION_MOVE, |
- 2, properties, coords, 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("Move events with different pointer counts should not be coalesced", |
- 3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 25, MotionEvent.ACTION_MOVE, |
- 2, properties, coords, 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("Move events with similar pointer counts should be coalesced", |
- 3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals("Move events should not be coalesced with other events", |
- 4, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- } |
- |
- /** |
- * Verify that synchronous confirmTouchEvent() calls made from the MotionEventDelegate behave |
- * properly. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testSynchronousConfirmTouchEvent() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- mMockMotionEventDelegate.disableSynchronousConfirmTouchEvent(); |
- |
- // Queue an asynchronously handled event. |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Queue another event; this will remain in the queue until the first event is confirmed. |
- event = MotionEvent.obtain( |
- downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Enable synchronous event confirmation upon dispatch. |
- mMockMotionEventDelegate.enableSynchronousConfirmTouchEvent( |
- mGestureHandler, ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- |
- // Confirm the original event; this should dispatch the second event and confirm it |
- // synchronously. |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals(TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.mLastTouchAction); |
- |
- // Adding events to any empty queue will trigger synchronous dispatch and confirmation. |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- } |
- |
- /** |
* Verify that no double tap gestures are created if the gesture handler is |
* told to disable double tap gesture detection (according to the logic in |
* ContentViewCore.onRenderCoordinatesUpdated). |
@@ -2196,8 +1505,6 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
new GestureRecordingMotionEventDelegate(); |
mGestureHandler = new ContentViewGestureHandler( |
getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mLongPressDetector = new LongPressDetector( |
- getInstrumentation().getTargetContext(), mGestureHandler); |
// Start a double-tap drag gesture. |
MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, downTime1); |
@@ -2296,271 +1603,4 @@ public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
mockDelegate.mGestureTypeList.contains( |
ContentViewGestureHandler.GESTURE_PINCH_END)); |
} |
- |
- /** |
- * Verify that a secondary pointer press with no consumer does not interfere |
- * with Javascript touch handling. |
- * |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testSecondaryPointerWithNoConsumer() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- // Queue a primary pointer press, a secondary pointer press and release, |
- // and a primary pointer move. |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = motionEvent(MotionEvent.ACTION_POINTER_DOWN, downTime, eventTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = motionEvent(MotionEvent.ACTION_POINTER_UP, downTime, eventTime + 10); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 15, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(4, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Simulate preventDefault from Javascript, forcing all touch events to Javascript |
- // for the current sequence. |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
- assertEquals("Even if the secondary pointer has no consumer, continue sending events", |
- 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
- assertEquals("Even if the secondary pointer has no consumer, continue sending events", |
- 1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- assertEquals("No gestures should result from the Javascript-consumed sequence", |
- 0, mMockMotionEventDelegate.mTotalSentGestureCount); |
- } |
- |
- /** |
- * Verify that multiple touch sequences in the queue are handled properly when |
- * the Javascript response is different for each. |
- * |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testMultiplyEnqueuedTouches() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- mGestureHandler.updateDoubleTapSupport(false); |
- |
- // Queue a tap sequence. |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 5); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Queue a scroll sequence. |
- event = motionEvent(MotionEvent.ACTION_DOWN, downTime + 10, downTime + 10); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = MotionEvent.obtain( |
- downTime + 10, eventTime + 15, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertFalse(mGestureHandler.isNativeScrolling()); |
- assertEquals(4, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = motionEvent(MotionEvent.ACTION_UP, downTime + 10, downTime + 20); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- assertEquals(5, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Consume the first gesture. |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals(4, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Don't consume the second gesture; it should be fed to the gesture detector. |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertEquals("The down touch event should have been sent to the gesture detector", |
- MotionEvent.ACTION_DOWN, mMockGestureDetector.mLastEvent.getActionMasked()); |
- assertFalse(mGestureHandler.isNativeScrolling()); |
- |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals("The move touch event should have been sent to the gesture detector", |
- MotionEvent.ACTION_MOVE, mMockGestureDetector.mLastEvent.getActionMasked()); |
- } |
- |
- /** |
- * Verify that only complete gestures are forwarded to Javascript if we receive |
- * a touch handler notification. |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testOnlyCompleteGesturesForwardedToTouchHandler() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- mGestureHandler.hasTouchEventHandlers(false); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- mGestureHandler.onTouchEvent(event); |
- assertEquals("Initial down events should not be sent to Javascript without a touch handler", |
- 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEvent != null); |
- mMockGestureDetector.mLastEvent = null; |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
- mGestureHandler.onTouchEvent(event); |
- assertEquals("A move event should only be offered to javascript if the down was offered", |
- 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEvent != null); |
- |
- event = motionEvent(MotionEvent.ACTION_POINTER_DOWN, downTime, eventTime + 10); |
- mGestureHandler.onTouchEvent(event); |
- assertEquals("A pointer event should only be offered to Javascript if the down was offered", |
- 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- // Ensure that redundant notifications have no effect. |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- event = motionEvent(MotionEvent.ACTION_POINTER_UP, downTime, eventTime + 15); |
- mGestureHandler.onTouchEvent(event); |
- assertEquals("A pointer event should only be offered to Javascript if the down was offered", |
- 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 20); |
- mGestureHandler.onTouchEvent(event); |
- assertEquals("A pointer event should only be offered to Javascript if the down was offered", |
- 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- |
- event = motionEvent(MotionEvent.ACTION_DOWN, downTime + 25, downTime + 25); |
- mGestureHandler.onTouchEvent(event); |
- assertEquals("A down event should be offered to Javascript with a registered touch handler", |
- 1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); |
- } |
- |
- /** |
- * Verify that no timeout-based gestures are triggered after a touch event |
- * is consumed. In particular, LONG_PRESS and SHOW_PRESS should not fire |
- * if TouchStart went unconsumed, but subsequent TouchMoves are consumed. |
- * |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testNoTimeoutGestureAfterTouchConsumed() throws Exception { |
- getInstrumentation().runOnMainSync(new Runnable() { |
- @Override |
- public void run() { |
- setUp(); |
- |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, eventTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertTrue("Should have a pending LONG_PRESS", |
- mLongPressDetector.hasPendingMessage()); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X, FAKE_COORD_Y + 200, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertFalse("Should not have a pending LONG_PRESS", |
- mLongPressDetector.hasPendingMessage()); |
- } |
- }); |
- assertFalse(mMockListener.mShowPressCalled.await( |
- ScalableTimeout.ScaleTimeout(ViewConfiguration.getTapTimeout() + 10), |
- TimeUnit.MILLISECONDS)); |
- assertFalse(mMockListener.mLongPressCalled.await( |
- ScalableTimeout.ScaleTimeout(ViewConfiguration.getLongPressTimeout() + 10), |
- TimeUnit.MILLISECONDS)); |
- } |
- |
- /** |
- * Verify that a TAP_DOWN will be followed by a TAP_CANCEL if the first |
- * touch is unconsumed, but the subsequent touch is consumed. |
- * |
- * @throws Exception |
- */ |
- @SmallTest |
- @Feature({"Gestures"}) |
- public void testTapCancelledAfterTouchConsumed() throws Exception { |
- final long downTime = SystemClock.uptimeMillis(); |
- final long eventTime = SystemClock.uptimeMillis(); |
- |
- GestureRecordingMotionEventDelegate mockDelegate = |
- new GestureRecordingMotionEventDelegate(); |
- mGestureHandler = new ContentViewGestureHandler( |
- getInstrumentation().getTargetContext(), mockDelegate, mMockZoomManager); |
- mGestureHandler.hasTouchEventHandlers(true); |
- |
- MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals("A TAP_DOWN gesture should have been sent", |
- ContentViewGestureHandler.GESTURE_TAP_DOWN, |
- mockDelegate.mMostRecentGestureEvent.mType); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X, FAKE_COORD_Y + 200, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); |
- assertEquals("A TAP_CANCEL gesture should have been sent", |
- ContentViewGestureHandler.GESTURE_TAP_CANCEL, |
- mockDelegate.mMostRecentGestureEvent.mType); |
- |
- event = MotionEvent.obtain( |
- downTime, eventTime + 15, MotionEvent.ACTION_MOVE, |
- FAKE_COORD_X, FAKE_COORD_Y + 400, 0); |
- assertTrue(mGestureHandler.onTouchEvent(event)); |
- mGestureHandler.confirmTouchEvent( |
- ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
- assertEquals("No further gestures should be sent", |
- ContentViewGestureHandler.GESTURE_TAP_CANCEL, |
- mockDelegate.mMostRecentGestureEvent.mType); |
- } |
} |