| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Bundle; | 8 import android.os.Bundle; |
| 9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
| 10 import android.test.InstrumentationTestCase; | 10 import android.test.InstrumentationTestCase; |
| 11 import android.test.suitebuilder.annotation.SmallTest; | 11 import android.test.suitebuilder.annotation.SmallTest; |
| 12 import android.util.Log; | 12 import android.util.Log; |
| 13 import android.view.MotionEvent; | 13 import android.view.MotionEvent; |
| 14 import android.view.MotionEvent.PointerCoords; | |
| 15 import android.view.MotionEvent.PointerProperties; | |
| 16 import android.view.ViewConfiguration; | 14 import android.view.ViewConfiguration; |
| 17 | 15 |
| 18 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
| 19 import org.chromium.base.test.util.ScalableTimeout; | |
| 20 import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegat
e; | 17 import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegat
e; |
| 21 import org.chromium.content.browser.third_party.GestureDetector; | 18 import org.chromium.content.browser.third_party.GestureDetector; |
| 22 | 19 |
| 23 import java.util.ArrayList; | 20 import java.util.ArrayList; |
| 24 import java.util.concurrent.CountDownLatch; | 21 import java.util.concurrent.CountDownLatch; |
| 25 import java.util.concurrent.TimeUnit; | |
| 26 | 22 |
| 27 /** | 23 /** |
| 28 * Test suite for ContentViewGestureHandler. | 24 * Test suite for ContentViewGestureHandler. |
| 29 */ | 25 */ |
| 30 public class ContentViewGestureHandlerTest extends InstrumentationTestCase { | 26 public class ContentViewGestureHandlerTest extends InstrumentationTestCase { |
| 31 private static final int FAKE_COORD_X = 42; | 27 private static final int FAKE_COORD_X = 42; |
| 32 private static final int FAKE_COORD_Y = 24; | 28 private static final int FAKE_COORD_Y = 24; |
| 33 | 29 |
| 34 private static final String TAG = "ContentViewGestureHandler"; | 30 private static final String TAG = "ContentViewGestureHandler"; |
| 35 private MockListener mMockListener; | 31 private MockListener mMockListener; |
| 36 private MockMotionEventDelegate mMockMotionEventDelegate; | 32 private MockMotionEventDelegate mMockMotionEventDelegate; |
| 37 private MockGestureDetector mMockGestureDetector; | 33 private MockGestureDetector mMockGestureDetector; |
| 38 private MockZoomManager mMockZoomManager; | 34 private MockZoomManager mMockZoomManager; |
| 39 private ContentViewGestureHandler mGestureHandler; | 35 private ContentViewGestureHandler mGestureHandler; |
| 40 private LongPressDetector mLongPressDetector; | |
| 41 | 36 |
| 42 static class MockListener extends GestureDetector.SimpleOnGestureListener { | 37 static class MockListener extends GestureDetector.SimpleOnGestureListener { |
| 43 MotionEvent mLastLongPress; | 38 MotionEvent mLastLongPress; |
| 44 MotionEvent mLastShowPress; | 39 MotionEvent mLastShowPress; |
| 45 MotionEvent mLastSingleTap; | 40 MotionEvent mLastSingleTap; |
| 46 MotionEvent mLastFling1; | 41 MotionEvent mLastFling1; |
| 47 CountDownLatch mLongPressCalled; | 42 CountDownLatch mLongPressCalled; |
| 48 CountDownLatch mShowPressCalled; | 43 CountDownLatch mShowPressCalled; |
| 49 | 44 |
| 50 public MockListener() { | 45 public MockListener() { |
| 51 mLongPressCalled = new CountDownLatch(1); | 46 mLongPressCalled = new CountDownLatch(1); |
| 52 mShowPressCalled = new CountDownLatch(1); | 47 mShowPressCalled = new CountDownLatch(1); |
| 53 } | 48 } |
| 54 | 49 |
| 55 @Override | 50 @Override |
| 56 public void onLongPress(MotionEvent e) { | 51 public void onLongPress(MotionEvent e) { |
| 57 mLastLongPress = MotionEvent.obtain(e); | 52 mLastLongPress = MotionEvent.obtain(e); |
| 58 mLongPressCalled.countDown(); | 53 mLongPressCalled.countDown(); |
| 59 } | 54 } |
| 60 | 55 |
| 61 @Override | 56 @Override |
| 62 public void onShowPress(MotionEvent e) { | 57 public void onShowPress(MotionEvent e) { |
| 63 mLastShowPress = MotionEvent.obtain(e); | 58 mLastShowPress = MotionEvent.obtain(e); |
| 64 mShowPressCalled.countDown(); | 59 mShowPressCalled.countDown(); |
| 65 Log.e("Overscroll", "OnShowPress"); | |
| 66 } | 60 } |
| 67 | 61 |
| 68 @Override | 62 @Override |
| 69 public boolean onSingleTapConfirmed(MotionEvent e) { | 63 public boolean onSingleTapConfirmed(MotionEvent e) { |
| 70 mLastSingleTap = e; | 64 mLastSingleTap = e; |
| 71 return true; | 65 return true; |
| 72 } | 66 } |
| 73 | 67 |
| 74 @Override | 68 @Override |
| 75 public boolean onSingleTapUp(MotionEvent e) { | 69 public boolean onSingleTapUp(MotionEvent e) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 96 } | 90 } |
| 97 | 91 |
| 98 @Override | 92 @Override |
| 99 public boolean onTouchEvent(MotionEvent ev) { | 93 public boolean onTouchEvent(MotionEvent ev) { |
| 100 mLastEvent = MotionEvent.obtain(ev); | 94 mLastEvent = MotionEvent.obtain(ev); |
| 101 return super.onTouchEvent(ev); | 95 return super.onTouchEvent(ev); |
| 102 } | 96 } |
| 103 } | 97 } |
| 104 | 98 |
| 105 static class MockMotionEventDelegate implements MotionEventDelegate { | 99 static class MockMotionEventDelegate implements MotionEventDelegate { |
| 106 private ContentViewGestureHandler mSynchronousConfirmTarget; | |
| 107 private int mSynchronousConfirmAckResult; | |
| 108 | |
| 109 public int mLastTouchAction; | 100 public int mLastTouchAction; |
| 110 public int mLastGestureType; | 101 public int mLastGestureType; |
| 111 public int mTotalSentGestureCount; | 102 public int mTotalSentGestureCount; |
| 112 | 103 |
| 113 @Override | 104 @Override |
| 114 public boolean sendTouchEvent(long timeMs, int action, TouchPoint[] pts)
{ | 105 public void onTouchEventHandlingBegin(long timeMs, int action, TouchPoin
t[] pts) { |
| 115 mLastTouchAction = action; | 106 mLastTouchAction = action; |
| 116 if (mSynchronousConfirmTarget != null) { | |
| 117 mSynchronousConfirmTarget.confirmTouchEvent(mSynchronousConfirmA
ckResult); | |
| 118 } | |
| 119 return true; | |
| 120 } | 107 } |
| 121 | 108 |
| 122 @Override | 109 @Override |
| 110 public void onTouchEventHandlingEnd() { |
| 111 } |
| 112 |
| 113 @Override |
| 123 public boolean sendGesture(int type, long timeMs, int x, int y, Bundle e
xtraParams) { | 114 public boolean sendGesture(int type, long timeMs, int x, int y, Bundle e
xtraParams) { |
| 124 Log.i(TAG,"Gesture event received with type id " + type); | 115 Log.i(TAG,"Gesture event received with type id " + type); |
| 125 mLastGestureType = type; | 116 mLastGestureType = type; |
| 126 mTotalSentGestureCount++; | 117 mTotalSentGestureCount++; |
| 127 return true; | 118 return true; |
| 128 } | 119 } |
| 129 | |
| 130 @Override | |
| 131 public void sendSingleTapUMA(int type) { | |
| 132 // Not implemented. | |
| 133 } | |
| 134 | |
| 135 @Override | |
| 136 public void sendActionAfterDoubleTapUMA(int type, | |
| 137 boolean clickDelayEnabled) { | |
| 138 // Not implemented. | |
| 139 } | |
| 140 | |
| 141 @Override | |
| 142 public void invokeZoomPicker() { | |
| 143 // Not implemented. | |
| 144 } | |
| 145 | |
| 146 public void enableSynchronousConfirmTouchEvent( | |
| 147 ContentViewGestureHandler handler, int ackResult) { | |
| 148 mSynchronousConfirmTarget = handler; | |
| 149 mSynchronousConfirmAckResult = ackResult; | |
| 150 } | |
| 151 | |
| 152 public void disableSynchronousConfirmTouchEvent() { | |
| 153 mSynchronousConfirmTarget = null; | |
| 154 } | |
| 155 } | 120 } |
| 156 | 121 |
| 157 static class MockZoomManager extends ZoomManager { | 122 static class MockZoomManager extends ZoomManager { |
| 158 private ContentViewGestureHandler mHandlerForMoveEvents; | 123 private ContentViewGestureHandler mHandlerForMoveEvents; |
| 159 | 124 |
| 160 MockZoomManager(Context context, ContentViewCore contentViewCore) { | 125 MockZoomManager(Context context, ContentViewCore contentViewCore) { |
| 161 super(context, contentViewCore); | 126 super(context, contentViewCore); |
| 162 } | 127 } |
| 163 | 128 |
| 164 public void pinchOnMoveEvents(ContentViewGestureHandler handler) { | 129 public void pinchOnMoveEvents(ContentViewGestureHandler handler) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 183 @Override | 148 @Override |
| 184 public void setUp() { | 149 public void setUp() { |
| 185 mMockListener = new MockListener(); | 150 mMockListener = new MockListener(); |
| 186 mMockGestureDetector = new MockGestureDetector( | 151 mMockGestureDetector = new MockGestureDetector( |
| 187 getInstrumentation().getTargetContext(), mMockListener); | 152 getInstrumentation().getTargetContext(), mMockListener); |
| 188 mMockMotionEventDelegate = new MockMotionEventDelegate(); | 153 mMockMotionEventDelegate = new MockMotionEventDelegate(); |
| 189 mMockZoomManager = new MockZoomManager(getInstrumentation().getTargetCon
text(), null); | 154 mMockZoomManager = new MockZoomManager(getInstrumentation().getTargetCon
text(), null); |
| 190 mGestureHandler = new ContentViewGestureHandler( | 155 mGestureHandler = new ContentViewGestureHandler( |
| 191 getInstrumentation().getTargetContext(), mMockMotionEventDelegat
e, | 156 getInstrumentation().getTargetContext(), mMockMotionEventDelegat
e, |
| 192 mMockZoomManager); | 157 mMockZoomManager); |
| 193 mLongPressDetector = new LongPressDetector( | 158 mGestureHandler.setTestDependencies(mMockGestureDetector, mMockListener)
; |
| 194 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 195 mGestureHandler.setTestDependencies( | |
| 196 mLongPressDetector, mMockGestureDetector, mMockListener); | |
| 197 TouchPoint.initializeConstantsForTesting(); | 159 TouchPoint.initializeConstantsForTesting(); |
| 198 } | 160 } |
| 199 | 161 |
| 200 /** | 162 /** |
| 201 * Verify that a DOWN followed shortly by an UP will trigger a single tap. | 163 * Verify that a DOWN followed shortly by an UP will trigger a single tap. |
| 202 * | 164 * |
| 203 * @throws Exception | 165 * @throws Exception |
| 204 */ | 166 */ |
| 205 @SmallTest | 167 @SmallTest |
| 206 @Feature({"Gestures"}) | 168 @Feature({"Gestures"}) |
| 207 public void testGestureSingleClick() throws Exception { | 169 public void testGestureSingleClick() throws Exception { |
| 208 final long downTime = SystemClock.uptimeMillis(); | 170 final long downTime = SystemClock.uptimeMillis(); |
| 209 final long eventTime = SystemClock.uptimeMillis(); | 171 final long eventTime = SystemClock.uptimeMillis(); |
| 210 | 172 |
| 211 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | 173 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); |
| 212 | 174 |
| 213 assertFalse(mGestureHandler.onTouchEvent(event)); | 175 assertFalse(mGestureHandler.onTouchEvent(event)); |
| 214 assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEv
ent != null); | 176 assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEv
ent != null); |
| 215 assertTrue("Should have a pending LONG_PRESS", mLongPressDetector.hasPen
dingMessage()); | |
| 216 | 177 |
| 217 event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 10); | 178 event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 10); |
| 218 mLongPressDetector.cancelLongPressIfNeeded(event); | |
| 219 assertTrue("Should not have a pending LONG_PRESS", !mLongPressDetector.h
asPendingMessage()); | |
| 220 assertTrue(mGestureHandler.onTouchEvent(event)); | 179 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 221 // Synchronous, no need to wait. | 180 // Synchronous, no need to wait. |
| 222 assertTrue("Should have a single tap", mMockListener.mLastSingleTap != n
ull); | 181 assertTrue("Should have a single tap", mMockListener.mLastSingleTap != n
ull); |
| 223 } | 182 } |
| 224 | 183 |
| 225 /** | 184 /** |
| 226 * Verify that when a touch event handler is registered the touch events are
queued | |
| 227 * and sent in order. | |
| 228 * @throws Exception | |
| 229 */ | |
| 230 @SmallTest | |
| 231 @Feature({"Gestures"}) | |
| 232 public void testFlingOnTouchHandler() throws Exception { | |
| 233 final long downTime = SystemClock.uptimeMillis(); | |
| 234 final long eventTime = SystemClock.uptimeMillis(); | |
| 235 | |
| 236 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 237 | |
| 238 mGestureHandler.hasTouchEventHandlers(true); | |
| 239 | |
| 240 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 241 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 242 assertTrue("Should not have a pending gesture", mMockGestureDetector.mLa
stEvent == null); | |
| 243 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 244 | |
| 245 event = MotionEvent.obtain( | |
| 246 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | |
| 247 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 248 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 249 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 250 | |
| 251 event = MotionEvent.obtain( | |
| 252 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 253 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 254 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 255 assertEquals("We should have coalesced move events into one" | |
| 256 , 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting())
; | |
| 257 | |
| 258 event = MotionEvent.obtain( | |
| 259 downTime, eventTime + 15, MotionEvent.ACTION_UP, | |
| 260 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 261 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 262 assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 263 | |
| 264 mGestureHandler.confirmTouchEvent( | |
| 265 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 266 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 267 assertEquals(MotionEvent.ACTION_MOVE, | |
| 268 mGestureHandler.peekFirstInPendingMotionEventsForTesting().getAc
tionMasked()); | |
| 269 assertFalse("Pending LONG_PRESS should have been canceled", | |
| 270 mLongPressDetector.hasPendingMessage()); | |
| 271 | |
| 272 mGestureHandler.confirmTouchEvent(ContentViewGestureHandler.INPUT_EVENT_
ACK_STATE_CONSUMED); | |
| 273 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 274 assertEquals(MotionEvent.ACTION_UP, | |
| 275 mGestureHandler.peekFirstInPendingMotionEventsForTesting().getAc
tionMasked()); | |
| 276 | |
| 277 mGestureHandler.confirmTouchEvent(ContentViewGestureHandler.INPUT_EVENT_
ACK_STATE_CONSUMED); | |
| 278 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 279 | |
| 280 // Synchronous, no need to wait. | |
| 281 assertTrue("Should not have a fling", mMockListener.mLastFling1 == null)
; | |
| 282 assertTrue("Should not have a long press", mMockListener.mLastLongPress
== null); | |
| 283 } | |
| 284 | |
| 285 /** | |
| 286 * Verify that after a touch event handlers starts handling a gesture, even
though some event | |
| 287 * in the middle of the gesture returns with NOT_CONSUMED, we don't send tha
t to the gesture | |
| 288 * detector to avoid falling to a faulty state. | |
| 289 * @throws Exception | |
| 290 */ | |
| 291 @SmallTest | |
| 292 @Feature({"Gestures"}) | |
| 293 public void testFlingOnTouchHandlerWithOneEventNotConsumed() throws Exceptio
n { | |
| 294 final long downTime = SystemClock.uptimeMillis(); | |
| 295 final long eventTime = SystemClock.uptimeMillis(); | |
| 296 | |
| 297 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 298 | |
| 299 mGestureHandler.hasTouchEventHandlers(true); | |
| 300 | |
| 301 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 302 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 303 assertTrue("Should not have a pending gesture", mMockGestureDetector.mLa
stEvent == null); | |
| 304 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 305 | |
| 306 event = MotionEvent.obtain( | |
| 307 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | |
| 308 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 309 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 310 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 311 | |
| 312 event = MotionEvent.obtain( | |
| 313 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 314 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 315 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 316 assertEquals("We should have coalesced move events into one" | |
| 317 , 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting())
; | |
| 318 | |
| 319 event = MotionEvent.obtain( | |
| 320 downTime, eventTime + 15, MotionEvent.ACTION_UP, | |
| 321 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 322 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 323 assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 324 | |
| 325 mGestureHandler.confirmTouchEvent( | |
| 326 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 327 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 328 assertEquals(MotionEvent.ACTION_MOVE, | |
| 329 mGestureHandler.peekFirstInPendingMotionEventsForTesting().getAc
tionMasked()); | |
| 330 | |
| 331 mGestureHandler.confirmTouchEvent( | |
| 332 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 333 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 334 assertEquals(MotionEvent.ACTION_UP, | |
| 335 mGestureHandler.peekFirstInPendingMotionEventsForTesting().getAc
tionMasked()); | |
| 336 assertTrue("Even though the last event was not consumed by JavaScript,"
+ | |
| 337 "it shouldn't have been sent to the Gesture Detector", | |
| 338 mMockGestureDetector.mLastEvent == null); | |
| 339 | |
| 340 mGestureHandler.confirmTouchEvent(ContentViewGestureHandler.INPUT_EVENT_
ACK_STATE_CONSUMED); | |
| 341 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 342 | |
| 343 // Synchronous, no need to wait. | |
| 344 assertTrue("Should not have a fling", mMockListener.mLastFling1 == null)
; | |
| 345 assertTrue("Should not have a long press", mMockListener.mLastLongPress
== null); | |
| 346 } | |
| 347 | |
| 348 /** | |
| 349 * Verify that when a registered touch event handler return NO_CONSUMER_EXIS
TS for down event | |
| 350 * all queue is drained until next down. | |
| 351 * @throws Exception | |
| 352 */ | |
| 353 @SmallTest | |
| 354 @Feature({"Gestures"}) | |
| 355 public void testDrainWithFlingAndClickOutofTouchHandler() throws Exception { | |
| 356 final long downTime = SystemClock.uptimeMillis(); | |
| 357 final long eventTime = SystemClock.uptimeMillis(); | |
| 358 | |
| 359 mGestureHandler = new ContentViewGestureHandler( | |
| 360 getInstrumentation().getTargetContext(), new MockMotionEventDele
gate(), | |
| 361 mMockZoomManager); | |
| 362 mLongPressDetector = new LongPressDetector( | |
| 363 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 364 | |
| 365 mGestureHandler.hasTouchEventHandlers(true); | |
| 366 | |
| 367 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 368 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 369 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 370 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 371 | |
| 372 event = MotionEvent.obtain( | |
| 373 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | |
| 374 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 375 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 376 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 377 | |
| 378 event = MotionEvent.obtain( | |
| 379 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 380 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 381 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 382 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 383 | |
| 384 event = MotionEvent.obtain( | |
| 385 downTime, eventTime + 15, MotionEvent.ACTION_UP, | |
| 386 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 387 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 388 assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 389 | |
| 390 event = motionEvent(MotionEvent.ACTION_DOWN, eventTime + 20, eventTime +
20); | |
| 391 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 392 assertEquals(4, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 393 | |
| 394 event = MotionEvent.obtain( | |
| 395 downTime, eventTime + 20, MotionEvent.ACTION_UP, | |
| 396 FAKE_COORD_X, FAKE_COORD_Y, 0); | |
| 397 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 398 assertEquals(5, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 399 | |
| 400 mGestureHandler.confirmTouchEvent( | |
| 401 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXIS
TS); | |
| 402 assertEquals("The queue should have been drained until first down since
no consumer exists", | |
| 403 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 404 assertEquals(MotionEvent.ACTION_DOWN, | |
| 405 mGestureHandler.peekFirstInPendingMotionEventsForTesting().getAc
tionMasked()); | |
| 406 | |
| 407 mGestureHandler.confirmTouchEvent( | |
| 408 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXIS
TS); | |
| 409 assertEquals("The queue should have been drained", | |
| 410 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 411 } | |
| 412 | |
| 413 /** | |
| 414 * Verify that when a touch event handler is registered the touch events sto
p getting queued | |
| 415 * after we received INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS. | |
| 416 * @throws Exception | |
| 417 */ | |
| 418 @SmallTest | |
| 419 @Feature({"Gestures"}) | |
| 420 public void testFlingOutOfTouchHandler() throws Exception { | |
| 421 final long downTime = SystemClock.uptimeMillis(); | |
| 422 final long eventTime = SystemClock.uptimeMillis(); | |
| 423 | |
| 424 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 425 | |
| 426 mGestureHandler.hasTouchEventHandlers(true); | |
| 427 | |
| 428 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 429 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 430 assertTrue("Should not have a pending gesture", mMockGestureDetector.mLa
stEvent == null); | |
| 431 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 432 | |
| 433 mGestureHandler.confirmTouchEvent( | |
| 434 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXIS
TS); | |
| 435 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 436 assertEquals("The down touch event should have been sent to the Gesture
Detector", | |
| 437 event.getEventTime(), mMockGestureDetector.mLastEvent.getEventTi
me()); | |
| 438 assertEquals("The down touch event should have been sent to the Gesture
Detector", | |
| 439 MotionEvent.ACTION_DOWN, mMockGestureDetector.mLastEvent.getActi
onMasked()); | |
| 440 | |
| 441 event = MotionEvent.obtain( | |
| 442 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | |
| 443 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 444 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 445 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 446 assertEquals("Motion events should be going to the Gesture Detector dire
ctly", | |
| 447 event.getEventTime(), mMockGestureDetector.mLastEvent.getEventTi
me()); | |
| 448 assertEquals("Motion events should be going to the Gesture Detector dire
ctly", | |
| 449 MotionEvent.ACTION_MOVE, mMockGestureDetector.mLastEvent.getActi
onMasked()); | |
| 450 | |
| 451 event = MotionEvent.obtain( | |
| 452 downTime, eventTime + 10, MotionEvent.ACTION_UP, | |
| 453 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 454 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 455 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 456 assertEquals("Motion events should be going to the Gesture Detector dire
ctly", | |
| 457 event.getEventTime(), mMockGestureDetector.mLastEvent.getEventTi
me()); | |
| 458 assertEquals("Motion events should be going to the Gesture Detector dire
ctly", | |
| 459 MotionEvent.ACTION_UP, mMockGestureDetector.mLastEvent.getAction
Masked()); | |
| 460 | |
| 461 // Synchronous, no need to wait. | |
| 462 assertTrue("Should have a fling", mMockListener.mLastFling1 != null); | |
| 463 assertTrue("Should not have a long press", mMockListener.mLastLongPress
== null); | |
| 464 } | |
| 465 | |
| 466 /** | |
| 467 * Verifies that a single tap doesn't cause a long press event to be sent. | |
| 468 * @throws Exception | |
| 469 */ | |
| 470 @SmallTest | |
| 471 @Feature({"Gestures"}) | |
| 472 public void testNoLongPressIsSentForSingleTapOutOfTouchHandler() throws Exce
ption { | |
| 473 final long downTime = SystemClock.uptimeMillis(); | |
| 474 final long eventTime = SystemClock.uptimeMillis(); | |
| 475 | |
| 476 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 477 | |
| 478 mGestureHandler.hasTouchEventHandlers(true); | |
| 479 | |
| 480 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 481 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 482 assertTrue("Should not have a pending gesture", mMockGestureDetector.mLa
stEvent == null); | |
| 483 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 484 | |
| 485 event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 5); | |
| 486 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 487 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 488 | |
| 489 mGestureHandler.confirmTouchEvent( | |
| 490 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 491 | |
| 492 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 493 assertEquals("The down touch event should have been sent to the Gesture
Detector", | |
| 494 event.getDownTime(), mMockGestureDetector.mLastEvent.getEventTim
e()); | |
| 495 assertEquals("The next event should be ACTION_UP", | |
| 496 MotionEvent.ACTION_UP, | |
| 497 mGestureHandler.peekFirstInPendingMotionEventsForTesting().getAc
tionMasked()); | |
| 498 | |
| 499 mGestureHandler.confirmTouchEvent( | |
| 500 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 501 | |
| 502 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 503 assertEquals("The up touch event should have been sent to the Gesture De
tector", | |
| 504 event.getEventTime(), mMockGestureDetector.mLastEvent.getEventTi
me()); | |
| 505 | |
| 506 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 507 } | |
| 508 | |
| 509 /** | |
| 510 * Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). | 185 * Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). |
| 511 * @throws Exception | 186 * @throws Exception |
| 512 */ | 187 */ |
| 513 @SmallTest | 188 @SmallTest |
| 514 @Feature({"Gestures"}) | 189 @Feature({"Gestures"}) |
| 515 public void testGestureFlingAndCancelLongClick() throws Exception { | 190 public void testGestureFlingAndCancelLongClick() throws Exception { |
| 516 final long downTime = SystemClock.uptimeMillis(); | 191 final long downTime = SystemClock.uptimeMillis(); |
| 517 final long eventTime = SystemClock.uptimeMillis(); | 192 final long eventTime = SystemClock.uptimeMillis(); |
| 518 | 193 |
| 519 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | 194 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); |
| 520 | 195 |
| 521 assertFalse(mGestureHandler.onTouchEvent(event)); | 196 assertFalse(mGestureHandler.onTouchEvent(event)); |
| 522 assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEv
ent != null); | 197 assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEv
ent != null); |
| 523 assertTrue("Should have a pending LONG_PRESS", mLongPressDetector.hasPen
dingMessage()); | |
| 524 | 198 |
| 525 event = MotionEvent.obtain( | 199 event = MotionEvent.obtain( |
| 526 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | 200 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
| 527 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | 201 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
| 528 mLongPressDetector.cancelLongPressIfNeeded(event); | |
| 529 assertTrue("Should not have a pending LONG_PRESS", !mLongPressDetector.h
asPendingMessage()); | |
| 530 assertTrue(mGestureHandler.onTouchEvent(event)); | 202 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 531 | 203 |
| 532 event = MotionEvent.obtain( | 204 event = MotionEvent.obtain( |
| 533 downTime, eventTime + 10, MotionEvent.ACTION_UP, | 205 downTime, eventTime + 10, MotionEvent.ACTION_UP, |
| 534 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | 206 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
| 535 assertTrue(mGestureHandler.onTouchEvent(event)); | 207 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 536 | 208 |
| 537 // Synchronous, no need to wait. | 209 // Synchronous, no need to wait. |
| 538 assertTrue("Should have a fling", mMockListener.mLastFling1 != null); | 210 assertTrue("Should have a fling", mMockListener.mLastFling1 != null); |
| 539 assertTrue("Should not have a long press", mMockListener.mLastLongPress
== null); | 211 assertTrue("Should not have a long press", mMockListener.mLastLongPress
== null); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 * @throws Exception | 415 * @throws Exception |
| 744 */ | 416 */ |
| 745 @SmallTest | 417 @SmallTest |
| 746 @Feature({"Gestures"}) | 418 @Feature({"Gestures"}) |
| 747 public void testShowPressCancelOnWindowFocusLost() throws Exception { | 419 public void testShowPressCancelOnWindowFocusLost() throws Exception { |
| 748 final long time = SystemClock.uptimeMillis(); | 420 final long time = SystemClock.uptimeMillis(); |
| 749 GestureRecordingMotionEventDelegate mockDelegate = | 421 GestureRecordingMotionEventDelegate mockDelegate = |
| 750 new GestureRecordingMotionEventDelegate(); | 422 new GestureRecordingMotionEventDelegate(); |
| 751 mGestureHandler = new ContentViewGestureHandler( | 423 mGestureHandler = new ContentViewGestureHandler( |
| 752 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | 424 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); |
| 753 mLongPressDetector = new LongPressDetector( | 425 mGestureHandler.setTestDependencies(null, null); |
| 754 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 755 mGestureHandler.setTestDependencies(mLongPressDetector, null, null); | |
| 756 | 426 |
| 757 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, time, time); | 427 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, time, time); |
| 758 mGestureHandler.onTouchEvent(event); | 428 mGestureHandler.onTouchEvent(event); |
| 759 | 429 |
| 760 mGestureHandler.sendShowPressedStateGestureForTesting(); | 430 mGestureHandler.sendShowPressedStateGestureForTesting(); |
| 761 assertEquals("A show pressed state event should have been sent", | 431 assertEquals("A show pressed state event should have been sent", |
| 762 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, | 432 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, |
| 763 mockDelegate.mMostRecentGestureEvent.mType); | 433 mockDelegate.mMostRecentGestureEvent.mType); |
| 764 assertEquals("Only showPressedState and tapDown should have been sent", | 434 assertEquals("Only showPressedState and tapDown should have been sent", |
| 765 2, mockDelegate.mGestureTypeList.size()); | 435 2, mockDelegate.mGestureTypeList.size()); |
| 766 | 436 |
| 767 mLongPressDetector.startLongPressTimerIfNeeded(event); | |
| 768 mLongPressDetector.sendLongPressGestureForTest(); | |
| 769 | |
| 770 assertEquals("Only should have sent only LONG_PRESS event", | 437 assertEquals("Only should have sent only LONG_PRESS event", |
| 771 3, mockDelegate.mGestureTypeList.size()); | 438 3, mockDelegate.mGestureTypeList.size()); |
| 772 assertEquals("Should have a long press event next", | 439 assertEquals("Should have a long press event next", |
| 773 ContentViewGestureHandler.GESTURE_LONG_PRESS, | 440 ContentViewGestureHandler.GESTURE_LONG_PRESS, |
| 774 mockDelegate.mGestureTypeList.get(2).intValue()); | 441 mockDelegate.mGestureTypeList.get(2).intValue()); |
| 775 | 442 |
| 776 // The long press triggers window focus loss by opening a context menu | 443 // The long press triggers window focus loss by opening a context menu |
| 777 mGestureHandler.onWindowFocusLost(); | 444 mGestureHandler.onWindowFocusLost(); |
| 778 | 445 |
| 779 assertEquals("Only should have sent only GESTURE_TAP_CANCEL event", | 446 assertEquals("Only should have sent only GESTURE_TAP_CANCEL event", |
| (...skipping 10 matching lines...) Expand all Loading... |
| 790 @SmallTest | 457 @SmallTest |
| 791 @Feature({"Gestures"}) | 458 @Feature({"Gestures"}) |
| 792 public void testShowPressCancelWhenScrollBegins() throws Exception { | 459 public void testShowPressCancelWhenScrollBegins() throws Exception { |
| 793 final long downTime = SystemClock.uptimeMillis(); | 460 final long downTime = SystemClock.uptimeMillis(); |
| 794 final long eventTime = SystemClock.uptimeMillis(); | 461 final long eventTime = SystemClock.uptimeMillis(); |
| 795 | 462 |
| 796 GestureRecordingMotionEventDelegate mockDelegate = | 463 GestureRecordingMotionEventDelegate mockDelegate = |
| 797 new GestureRecordingMotionEventDelegate(); | 464 new GestureRecordingMotionEventDelegate(); |
| 798 mGestureHandler = new ContentViewGestureHandler( | 465 mGestureHandler = new ContentViewGestureHandler( |
| 799 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | 466 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); |
| 800 mLongPressDetector = new LongPressDetector( | |
| 801 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 802 | 467 |
| 803 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | 468 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); |
| 804 | 469 |
| 805 assertTrue(mGestureHandler.onTouchEvent(event)); | 470 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 806 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 807 | 471 |
| 808 mGestureHandler.sendShowPressedStateGestureForTesting(); | 472 mGestureHandler.sendShowPressedStateGestureForTesting(); |
| 809 | 473 |
| 810 assertEquals("A show pressed state event should have been sent", | 474 assertEquals("A show pressed state event should have been sent", |
| 811 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, | 475 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, |
| 812 mockDelegate.mMostRecentGestureEvent.mType); | 476 mockDelegate.mMostRecentGestureEvent.mType); |
| 813 assertEquals("Only tapDown and showPressedState should have been sent", | 477 assertEquals("Only tapDown and showPressedState should have been sent", |
| 814 2, mockDelegate.mGestureTypeList.size()); | 478 2, mockDelegate.mGestureTypeList.size()); |
| 815 | 479 |
| 816 event = MotionEvent.obtain( | 480 event = MotionEvent.obtain( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 @SmallTest | 514 @SmallTest |
| 851 @Feature({"Gestures"}) | 515 @Feature({"Gestures"}) |
| 852 public void testDoubleTap() throws Exception { | 516 public void testDoubleTap() throws Exception { |
| 853 final long downTime = SystemClock.uptimeMillis(); | 517 final long downTime = SystemClock.uptimeMillis(); |
| 854 final long eventTime = SystemClock.uptimeMillis(); | 518 final long eventTime = SystemClock.uptimeMillis(); |
| 855 | 519 |
| 856 GestureRecordingMotionEventDelegate mockDelegate = | 520 GestureRecordingMotionEventDelegate mockDelegate = |
| 857 new GestureRecordingMotionEventDelegate(); | 521 new GestureRecordingMotionEventDelegate(); |
| 858 mGestureHandler = new ContentViewGestureHandler( | 522 mGestureHandler = new ContentViewGestureHandler( |
| 859 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | 523 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); |
| 860 mLongPressDetector = new LongPressDetector( | |
| 861 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 862 | 524 |
| 863 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | 525 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); |
| 864 assertTrue(mGestureHandler.onTouchEvent(event)); | 526 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 865 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 866 | 527 |
| 867 mGestureHandler.sendShowPressedStateGestureForTesting(); | 528 mGestureHandler.sendShowPressedStateGestureForTesting(); |
| 868 assertEquals("GESTURE_SHOW_PRESSED_STATE should have been sent", | 529 assertEquals("GESTURE_SHOW_PRESSED_STATE should have been sent", |
| 869 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, | 530 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, |
| 870 mockDelegate.mMostRecentGestureEvent.mType); | 531 mockDelegate.mMostRecentGestureEvent.mType); |
| 871 assertEquals("Only GESTURE_TAP_DOWN and GESTURE_SHOW_PRESSED_STATE shoul
d have been sent", | 532 assertEquals("Only GESTURE_TAP_DOWN and GESTURE_SHOW_PRESSED_STATE shoul
d have been sent", |
| 872 2, mockDelegate.mGestureTypeList.size()); | 533 2, mockDelegate.mGestureTypeList.size()); |
| 873 | 534 |
| 874 event = MotionEvent.obtain( | 535 event = MotionEvent.obtain( |
| 875 downTime, eventTime + 5, MotionEvent.ACTION_UP, | 536 downTime, eventTime + 5, MotionEvent.ACTION_UP, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 @SmallTest | 593 @SmallTest |
| 933 @Feature({"Gestures"}) | 594 @Feature({"Gestures"}) |
| 934 public void testDoubleTapDragZoom() throws Exception { | 595 public void testDoubleTapDragZoom() throws Exception { |
| 935 final long downTime1 = SystemClock.uptimeMillis(); | 596 final long downTime1 = SystemClock.uptimeMillis(); |
| 936 final long downTime2 = downTime1 + 100; | 597 final long downTime2 = downTime1 + 100; |
| 937 | 598 |
| 938 GestureRecordingMotionEventDelegate mockDelegate = | 599 GestureRecordingMotionEventDelegate mockDelegate = |
| 939 new GestureRecordingMotionEventDelegate(); | 600 new GestureRecordingMotionEventDelegate(); |
| 940 mGestureHandler = new ContentViewGestureHandler( | 601 mGestureHandler = new ContentViewGestureHandler( |
| 941 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | 602 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); |
| 942 mLongPressDetector = new LongPressDetector( | |
| 943 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 944 | 603 |
| 945 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, down
Time1); | 604 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, down
Time1); |
| 946 assertTrue(mGestureHandler.onTouchEvent(event)); | 605 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 947 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 948 | 606 |
| 949 mGestureHandler.sendShowPressedStateGestureForTesting(); | 607 mGestureHandler.sendShowPressedStateGestureForTesting(); |
| 950 assertEquals("GESTURE_SHOW_PRESSED_STATE should have been sent", | 608 assertEquals("GESTURE_SHOW_PRESSED_STATE should have been sent", |
| 951 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, | 609 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, |
| 952 mockDelegate.mMostRecentGestureEvent.mType); | 610 mockDelegate.mMostRecentGestureEvent.mType); |
| 953 assertEquals("Only GESTURE_TAP_DOWN and GESTURE_SHOW_PRESSED_STATE shoul
d have been sent", | 611 assertEquals("Only GESTURE_TAP_DOWN and GESTURE_SHOW_PRESSED_STATE shoul
d have been sent", |
| 954 2, mockDelegate.mGestureTypeList.size()); | 612 2, mockDelegate.mGestureTypeList.size()); |
| 955 | 613 |
| 956 | 614 |
| 957 event = MotionEvent.obtain( | 615 event = MotionEvent.obtain( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 @SmallTest | 726 @SmallTest |
| 1069 @Feature({"Gestures"}) | 727 @Feature({"Gestures"}) |
| 1070 public void testDoubleTapDragZoomCancelledOnSecondaryPointerDown() throws Ex
ception { | 728 public void testDoubleTapDragZoomCancelledOnSecondaryPointerDown() throws Ex
ception { |
| 1071 final long downTime1 = SystemClock.uptimeMillis(); | 729 final long downTime1 = SystemClock.uptimeMillis(); |
| 1072 final long downTime2 = downTime1 + 100; | 730 final long downTime2 = downTime1 + 100; |
| 1073 | 731 |
| 1074 GestureRecordingMotionEventDelegate mockDelegate = | 732 GestureRecordingMotionEventDelegate mockDelegate = |
| 1075 new GestureRecordingMotionEventDelegate(); | 733 new GestureRecordingMotionEventDelegate(); |
| 1076 mGestureHandler = new ContentViewGestureHandler( | 734 mGestureHandler = new ContentViewGestureHandler( |
| 1077 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | 735 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); |
| 1078 mLongPressDetector = new LongPressDetector( | |
| 1079 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 1080 | 736 |
| 1081 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, down
Time1); | 737 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, down
Time1); |
| 1082 assertTrue(mGestureHandler.onTouchEvent(event)); | 738 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 1083 | 739 |
| 1084 mGestureHandler.sendShowPressedStateGestureForTesting(); | 740 mGestureHandler.sendShowPressedStateGestureForTesting(); |
| 1085 assertEquals("GESTURE_SHOW_PRESSED_STATE should have been sent", | 741 assertEquals("GESTURE_SHOW_PRESSED_STATE should have been sent", |
| 1086 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, | 742 ContentViewGestureHandler.GESTURE_SHOW_PRESSED_STATE, |
| 1087 mockDelegate.mMostRecentGestureEvent.mType); | 743 mockDelegate.mMostRecentGestureEvent.mType); |
| 1088 assertEquals("Only GESTURE_TAP_DOWN and GESTURE_SHOW_PRESSED_STATE shoul
d have been sent", | 744 assertEquals("Only GESTURE_TAP_DOWN and GESTURE_SHOW_PRESSED_STATE shoul
d have been sent", |
| 1089 2, mockDelegate.mGestureTypeList.size()); | 745 2, mockDelegate.mGestureTypeList.size()); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 public Bundle getExtraParams() { | 935 public Bundle getExtraParams() { |
| 1280 return mExtraParams; | 936 return mExtraParams; |
| 1281 } | 937 } |
| 1282 } | 938 } |
| 1283 private GestureEvent mMostRecentGestureEvent; | 939 private GestureEvent mMostRecentGestureEvent; |
| 1284 private GestureEvent mActiveScrollStartEvent; | 940 private GestureEvent mActiveScrollStartEvent; |
| 1285 private final ArrayList<Integer> mGestureTypeList = new ArrayList<Intege
r>(); | 941 private final ArrayList<Integer> mGestureTypeList = new ArrayList<Intege
r>(); |
| 1286 private final ArrayList<Long> mGestureTimeList = new ArrayList<Long>(); | 942 private final ArrayList<Long> mGestureTimeList = new ArrayList<Long>(); |
| 1287 | 943 |
| 1288 @Override | 944 @Override |
| 1289 public boolean sendTouchEvent(long timeMs, int action, TouchPoint[] pts)
{ | 945 public void onTouchEventHandlingBegin(long timeMs, int action, TouchPoin
t[] pts) { |
| 1290 return true; | |
| 1291 } | 946 } |
| 1292 | 947 |
| 1293 @Override | 948 @Override |
| 949 public void onTouchEventHandlingEnd() { |
| 950 } |
| 951 |
| 952 @Override |
| 1294 public boolean sendGesture(int type, long timeMs, int x, int y, Bundle e
xtraParams) { | 953 public boolean sendGesture(int type, long timeMs, int x, int y, Bundle e
xtraParams) { |
| 1295 Log.i(TAG, "Gesture event received with type id " + type); | 954 Log.i(TAG, "Gesture event received with type id " + type); |
| 1296 mMostRecentGestureEvent = new GestureEvent(type, timeMs, x, y, extra
Params); | 955 mMostRecentGestureEvent = new GestureEvent(type, timeMs, x, y, extra
Params); |
| 1297 mGestureTypeList.add(mMostRecentGestureEvent.mType); | 956 mGestureTypeList.add(mMostRecentGestureEvent.mType); |
| 1298 mGestureTimeList.add(timeMs); | 957 mGestureTimeList.add(timeMs); |
| 1299 if (type == ContentViewGestureHandler.GESTURE_SCROLL_START) | 958 if (type == ContentViewGestureHandler.GESTURE_SCROLL_START) |
| 1300 mActiveScrollStartEvent = mMostRecentGestureEvent; | 959 mActiveScrollStartEvent = mMostRecentGestureEvent; |
| 1301 else if (type == ContentViewGestureHandler.GESTURE_SCROLL_END || | 960 else if (type == ContentViewGestureHandler.GESTURE_SCROLL_END || |
| 1302 type == ContentViewGestureHandler.GESTURE_FLING_CANCEL) | 961 type == ContentViewGestureHandler.GESTURE_FLING_CANCEL) |
| 1303 mActiveScrollStartEvent = null; | 962 mActiveScrollStartEvent = null; |
| 1304 return true; | 963 return true; |
| 1305 } | 964 } |
| 1306 | 965 |
| 1307 @Override | |
| 1308 public void sendSingleTapUMA(int type) { | |
| 1309 // Not implemented. | |
| 1310 } | |
| 1311 | |
| 1312 @Override | |
| 1313 public void sendActionAfterDoubleTapUMA(int type, | |
| 1314 boolean clickDelayEnabled) { | |
| 1315 // Not implemented. | |
| 1316 } | |
| 1317 | |
| 1318 @Override | |
| 1319 public void invokeZoomPicker() { | |
| 1320 // Not implemented. | |
| 1321 } | |
| 1322 | |
| 1323 public GestureEvent getMostRecentGestureEvent() { | 966 public GestureEvent getMostRecentGestureEvent() { |
| 1324 return mMostRecentGestureEvent; | 967 return mMostRecentGestureEvent; |
| 1325 } | 968 } |
| 1326 | 969 |
| 1327 public GestureEvent getActiveScrollStartEvent() { | 970 public GestureEvent getActiveScrollStartEvent() { |
| 1328 return mActiveScrollStartEvent; | 971 return mActiveScrollStartEvent; |
| 1329 } | 972 } |
| 1330 } | 973 } |
| 1331 | 974 |
| 1332 /** | 975 /** |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 @SmallTest | 1071 @SmallTest |
| 1429 @Feature({"Gestures"}) | 1072 @Feature({"Gestures"}) |
| 1430 public void testLongPressAndTapCancelWhenScrollBegins() throws Exception { | 1073 public void testLongPressAndTapCancelWhenScrollBegins() throws Exception { |
| 1431 final long downTime = SystemClock.uptimeMillis(); | 1074 final long downTime = SystemClock.uptimeMillis(); |
| 1432 final long eventTime = SystemClock.uptimeMillis(); | 1075 final long eventTime = SystemClock.uptimeMillis(); |
| 1433 | 1076 |
| 1434 GestureRecordingMotionEventDelegate mockDelegate = | 1077 GestureRecordingMotionEventDelegate mockDelegate = |
| 1435 new GestureRecordingMotionEventDelegate(); | 1078 new GestureRecordingMotionEventDelegate(); |
| 1436 mGestureHandler = new ContentViewGestureHandler( | 1079 mGestureHandler = new ContentViewGestureHandler( |
| 1437 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | 1080 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); |
| 1438 mLongPressDetector = mGestureHandler.getLongPressDetector(); | |
| 1439 | 1081 |
| 1440 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | 1082 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); |
| 1441 assertTrue(mGestureHandler.onTouchEvent(event)); | 1083 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 1442 assertTrue("Should have a pending LONG_PRESS", mLongPressDetector.hasPen
dingMessage()); | |
| 1443 event = MotionEvent.obtain( | 1084 event = MotionEvent.obtain( |
| 1444 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | 1085 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, |
| 1445 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | 1086 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); |
| 1446 assertTrue(mGestureHandler.onTouchEvent(event)); | 1087 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 1447 event = MotionEvent.obtain( | 1088 event = MotionEvent.obtain( |
| 1448 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | 1089 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
| 1449 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | 1090 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
| 1450 assertTrue(mGestureHandler.onTouchEvent(event)); | 1091 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 1451 assertTrue("Should not have a pending LONG_PRESS", !mLongPressDetector.h
asPendingMessage()); | |
| 1452 | 1092 |
| 1453 // No LONG_TAP because LONG_PRESS timer is cancelled. | 1093 // No LONG_TAP because LONG_PRESS timer is cancelled. |
| 1454 assertFalse("No LONG_PRESS should be sent", | 1094 assertFalse("No LONG_PRESS should be sent", |
| 1455 mockDelegate.mGestureTypeList.contains( | 1095 mockDelegate.mGestureTypeList.contains( |
| 1456 ContentViewGestureHandler.GESTURE_LONG_PRESS)); | 1096 ContentViewGestureHandler.GESTURE_LONG_PRESS)); |
| 1457 assertFalse("No LONG_TAP should be sent", | 1097 assertFalse("No LONG_TAP should be sent", |
| 1458 mockDelegate.mGestureTypeList.contains( | 1098 mockDelegate.mGestureTypeList.contains( |
| 1459 ContentViewGestureHandler.GESTURE_LONG_TAP)); | 1099 ContentViewGestureHandler.GESTURE_LONG_TAP)); |
| 1460 } | 1100 } |
| 1461 | 1101 |
| 1462 /** | 1102 /** |
| 1463 * Verifies that when hasTouchEventHandlers changes while in a gesture, that
the pending | |
| 1464 * queue does not grow continually. | |
| 1465 */ | |
| 1466 @SmallTest | |
| 1467 @Feature({"Gestures"}) | |
| 1468 public void testHasTouchEventHandlersChangesInGesture() { | |
| 1469 final long downTime = SystemClock.uptimeMillis(); | |
| 1470 final long eventTime = SystemClock.uptimeMillis(); | |
| 1471 | |
| 1472 mGestureHandler = new ContentViewGestureHandler( | |
| 1473 getInstrumentation().getTargetContext(), new MockMotionEventDele
gate(), | |
| 1474 mMockZoomManager); | |
| 1475 mLongPressDetector = new LongPressDetector( | |
| 1476 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 1477 | |
| 1478 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 1479 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1480 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1481 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 1482 | |
| 1483 event = MotionEvent.obtain( | |
| 1484 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | |
| 1485 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 1486 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1487 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1488 | |
| 1489 mGestureHandler.hasTouchEventHandlers(true); | |
| 1490 | |
| 1491 event = MotionEvent.obtain( | |
| 1492 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 1493 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 1494 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1495 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1496 | |
| 1497 event = MotionEvent.obtain( | |
| 1498 downTime, eventTime + 15, MotionEvent.ACTION_MOVE, | |
| 1499 FAKE_COORD_X * 15, FAKE_COORD_Y * 15, 0); | |
| 1500 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1501 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1502 } | |
| 1503 | |
| 1504 /** | |
| 1505 * Verify that LONG_TAP is triggered after LongPress followed by an UP. | 1103 * Verify that LONG_TAP is triggered after LongPress followed by an UP. |
| 1506 * | 1104 * |
| 1507 * @throws Exception | 1105 * @throws Exception |
| 1508 */ | 1106 */ |
| 1509 @SmallTest | 1107 @SmallTest |
| 1510 @Feature({"Gestures"}) | 1108 @Feature({"Gestures"}) |
| 1511 public void testGestureLongTap() throws Exception { | 1109 public void testGestureLongTap() throws Exception { |
| 1512 final long downTime = SystemClock.uptimeMillis(); | 1110 final long downTime = SystemClock.uptimeMillis(); |
| 1513 final long eventTime = SystemClock.uptimeMillis(); | 1111 final long eventTime = SystemClock.uptimeMillis(); |
| 1514 | 1112 |
| 1515 GestureRecordingMotionEventDelegate mockDelegate = | 1113 GestureRecordingMotionEventDelegate mockDelegate = |
| 1516 new GestureRecordingMotionEventDelegate(); | 1114 new GestureRecordingMotionEventDelegate(); |
| 1517 mGestureHandler = new ContentViewGestureHandler( | 1115 mGestureHandler = new ContentViewGestureHandler( |
| 1518 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | 1116 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); |
| 1519 mLongPressDetector = mGestureHandler.getLongPressDetector(); | |
| 1520 | 1117 |
| 1521 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | 1118 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); |
| 1522 assertTrue(mGestureHandler.onTouchEvent(event)); | 1119 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 1523 assertTrue("Should have a pending LONG_PRESS", mLongPressDetector.hasPen
dingMessage()); | |
| 1524 | |
| 1525 mLongPressDetector.sendLongPressGestureForTest(); | |
| 1526 | 1120 |
| 1527 assertEquals("A LONG_PRESS gesture should have been sent", | 1121 assertEquals("A LONG_PRESS gesture should have been sent", |
| 1528 ContentViewGestureHandler.GESTURE_LONG_PRESS, | 1122 ContentViewGestureHandler.GESTURE_LONG_PRESS, |
| 1529 mockDelegate.mMostRecentGestureEvent.mType); | 1123 mockDelegate.mMostRecentGestureEvent.mType); |
| 1530 | 1124 |
| 1531 event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 1000); | 1125 event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 1000); |
| 1532 assertTrue(mGestureHandler.onTouchEvent(event)); | 1126 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 1533 assertEquals("A LONG_TAP gesture should have been sent", | 1127 assertEquals("A LONG_TAP gesture should have been sent", |
| 1534 ContentViewGestureHandler.GESTURE_LONG_TAP, | 1128 ContentViewGestureHandler.GESTURE_LONG_TAP, |
| 1535 mockDelegate.mMostRecentGestureEvent.mType); | 1129 mockDelegate.mMostRecentGestureEvent.mType); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 mockDelegate.mMostRecentGestureEvent.mType); | 1161 mockDelegate.mMostRecentGestureEvent.mType); |
| 1568 | 1162 |
| 1569 GestureRecordingMotionEventDelegate.GestureEvent gestureEvent = | 1163 GestureRecordingMotionEventDelegate.GestureEvent gestureEvent = |
| 1570 mockDelegate.getMostRecentGestureEvent(); | 1164 mockDelegate.getMostRecentGestureEvent(); |
| 1571 assertNotNull(gestureEvent); | 1165 assertNotNull(gestureEvent); |
| 1572 Bundle extraParams = gestureEvent.getExtraParams(); | 1166 Bundle extraParams = gestureEvent.getExtraParams(); |
| 1573 assertEquals(0, extraParams.getInt(ContentViewGestureHandler.DISTANCE_X)
); | 1167 assertEquals(0, extraParams.getInt(ContentViewGestureHandler.DISTANCE_X)
); |
| 1574 assertEquals(-scrollDelta, extraParams.getInt(ContentViewGestureHandler.
DISTANCE_Y)); | 1168 assertEquals(-scrollDelta, extraParams.getInt(ContentViewGestureHandler.
DISTANCE_Y)); |
| 1575 } | 1169 } |
| 1576 | 1170 |
| 1577 /** | |
| 1578 * Verify that touch moves are deferred if they are within the touch slop re
gion | |
| 1579 * and the touch sequence is not being consumed. | |
| 1580 * @throws Exception | |
| 1581 */ | |
| 1582 @SmallTest | |
| 1583 @Feature({"Gestures"}) | |
| 1584 public void testTouchMoveWithinTouchSlopDeferred() throws Exception { | |
| 1585 Context context = getInstrumentation().getTargetContext(); | |
| 1586 final long downTime = SystemClock.uptimeMillis(); | |
| 1587 final long eventTime = SystemClock.uptimeMillis(); | |
| 1588 final int scaledTouchSlop = ViewConfiguration.get(context).getScaledTouc
hSlop(); | |
| 1589 final int lessThanSlopScrollDelta = scaledTouchSlop / 2; | |
| 1590 final int greaterThanSlopScrollDelta = scaledTouchSlop * 2; | |
| 1591 | |
| 1592 mGestureHandler.hasTouchEventHandlers(true); | |
| 1593 | |
| 1594 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 1595 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1596 assertEquals("The touch down should have been forwarded", | |
| 1597 TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLas
tTouchAction); | |
| 1598 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1599 | |
| 1600 event = MotionEvent.obtain( | |
| 1601 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 1602 FAKE_COORD_X, FAKE_COORD_Y + lessThanSlopScrollDelta, 0); | |
| 1603 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1604 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1605 | |
| 1606 mGestureHandler.confirmTouchEvent( | |
| 1607 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1608 assertEquals("The less-than-slop touch move should not have been forward
ed", | |
| 1609 TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLas
tTouchAction); | |
| 1610 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1611 | |
| 1612 event = MotionEvent.obtain( | |
| 1613 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 1614 FAKE_COORD_X, FAKE_COORD_Y + greaterThanSlopScrollDelta, 0); | |
| 1615 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1616 assertEquals("The touch move should have been forwarded", | |
| 1617 TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.mLast
TouchAction); | |
| 1618 mGestureHandler.confirmTouchEvent( | |
| 1619 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1620 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1621 } | |
| 1622 | |
| 1623 /** | |
| 1624 * Verify that touch moves are not deferred even if they are within the touc
h slop region | |
| 1625 * when the touch sequence is being consumed. | |
| 1626 * @throws Exception | |
| 1627 */ | |
| 1628 @SmallTest | |
| 1629 @Feature({"Gestures"}) | |
| 1630 public void testTouchMoveWithinTouchSlopNotDeferredIfJavascriptConsumingGest
ure() | |
| 1631 throws Exception { | |
| 1632 Context context = getInstrumentation().getTargetContext(); | |
| 1633 final long downTime = SystemClock.uptimeMillis(); | |
| 1634 final long eventTime = SystemClock.uptimeMillis(); | |
| 1635 final int scaledTouchSlop = ViewConfiguration.get(context).getScaledTouc
hSlop(); | |
| 1636 final int lessThanSlopScrollDelta = scaledTouchSlop / 2; | |
| 1637 | |
| 1638 mGestureHandler.hasTouchEventHandlers(true); | |
| 1639 | |
| 1640 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 1641 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1642 assertEquals("The touch down should have been forwarded", | |
| 1643 TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLas
tTouchAction); | |
| 1644 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1645 | |
| 1646 event = MotionEvent.obtain( | |
| 1647 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 1648 FAKE_COORD_X, FAKE_COORD_Y + lessThanSlopScrollDelta, 0); | |
| 1649 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1650 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1651 | |
| 1652 mGestureHandler.confirmTouchEvent( | |
| 1653 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 1654 assertEquals("The less-than-slop touch move should have been forwarded", | |
| 1655 TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.mLast
TouchAction); | |
| 1656 } | |
| 1657 | |
| 1658 | |
| 1659 /** | |
| 1660 * Verify that touch moves are not deferred when the MotionEvent has multipl
e active pointers. | |
| 1661 * @throws Exception | |
| 1662 */ | |
| 1663 @SmallTest | |
| 1664 @Feature({"Gestures"}) | |
| 1665 public void testTouchMoveNotDeferredWithMultiplePointers() | |
| 1666 throws Exception { | |
| 1667 Context context = getInstrumentation().getTargetContext(); | |
| 1668 final long downTime = SystemClock.uptimeMillis(); | |
| 1669 final long eventTime = SystemClock.uptimeMillis(); | |
| 1670 final int scaledTouchSlop = ViewConfiguration.get(context).getScaledTouc
hSlop(); | |
| 1671 final int lessThanSlopScrollDelta = scaledTouchSlop / 2; | |
| 1672 | |
| 1673 mGestureHandler.hasTouchEventHandlers(true); | |
| 1674 | |
| 1675 final int secondaryCoordX = FAKE_COORD_X + 10 * scaledTouchSlop; | |
| 1676 final int secondaryCoordY = FAKE_COORD_Y + 10 * scaledTouchSlop; | |
| 1677 | |
| 1678 PointerProperties pp0 = new PointerProperties(); | |
| 1679 pp0.id = 0; | |
| 1680 pp0.toolType = MotionEvent.TOOL_TYPE_FINGER; | |
| 1681 PointerProperties pp1 = new PointerProperties(); | |
| 1682 pp1.id = 1; | |
| 1683 pp1.toolType = MotionEvent.TOOL_TYPE_FINGER; | |
| 1684 | |
| 1685 PointerCoords pc0 = new PointerCoords(); | |
| 1686 pc0.x = FAKE_COORD_X; | |
| 1687 pc0.y = FAKE_COORD_Y; | |
| 1688 pc0.pressure = 1; | |
| 1689 pc0.size = 1; | |
| 1690 PointerCoords pc1 = new PointerCoords(); | |
| 1691 pc1.x = secondaryCoordX; | |
| 1692 pc1.y = secondaryCoordY; | |
| 1693 pc1.pressure = 1; | |
| 1694 pc1.size = 1; | |
| 1695 | |
| 1696 MotionEvent event = MotionEvent.obtain( | |
| 1697 eventTime, eventTime, MotionEvent.ACTION_DOWN, | |
| 1698 1, new PointerProperties[] { pp0 }, new PointerCoords[] { pc0 }, | |
| 1699 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); | |
| 1700 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1701 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1702 assertEquals("The touch down should have been forwarded", | |
| 1703 TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLas
tTouchAction); | |
| 1704 | |
| 1705 event = MotionEvent.obtain( | |
| 1706 eventTime, eventTime, MotionEvent.ACTION_POINTER_DOWN, | |
| 1707 2, new PointerProperties[] { pp0, pp1 }, new PointerCoords[] { p
c0, pc1 }, | |
| 1708 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); | |
| 1709 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1710 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1711 | |
| 1712 mGestureHandler.confirmTouchEvent( | |
| 1713 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1714 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1715 assertEquals("The secondary touch down should have been forwarded", | |
| 1716 TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate.mLas
tTouchAction); | |
| 1717 | |
| 1718 pc1.x = secondaryCoordX + lessThanSlopScrollDelta; | |
| 1719 pc1.y = secondaryCoordY + lessThanSlopScrollDelta; | |
| 1720 | |
| 1721 event = MotionEvent.obtain( | |
| 1722 eventTime, eventTime, MotionEvent.ACTION_MOVE, | |
| 1723 2, new PointerProperties[] { pp0, pp1 }, new PointerCoords[] { p
c0, pc1 }, | |
| 1724 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); | |
| 1725 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1726 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1727 | |
| 1728 mGestureHandler.confirmTouchEvent( | |
| 1729 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1730 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 1731 assertEquals("The secondary touch move should have been forwarded", | |
| 1732 TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.mLast
TouchAction); | |
| 1733 } | |
| 1734 | |
| 1735 private static void sendLastScrollByEvent(ContentViewGestureHandler handler)
{ | 1171 private static void sendLastScrollByEvent(ContentViewGestureHandler handler)
{ |
| 1736 final long downTime = SystemClock.uptimeMillis(); | 1172 final long downTime = SystemClock.uptimeMillis(); |
| 1737 final long eventTime = SystemClock.uptimeMillis(); | 1173 final long eventTime = SystemClock.uptimeMillis(); |
| 1738 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | 1174 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); |
| 1739 assertTrue(handler.onTouchEvent(event)); | 1175 assertTrue(handler.onTouchEvent(event)); |
| 1740 event = MotionEvent.obtain( | 1176 event = MotionEvent.obtain( |
| 1741 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | 1177 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, |
| 1742 FAKE_COORD_X, FAKE_COORD_Y + 30, 0); | 1178 FAKE_COORD_X, FAKE_COORD_Y + 30, 0); |
| 1743 assertTrue(handler.onTouchEvent(event)); | 1179 assertTrue(handler.onTouchEvent(event)); |
| 1744 } | 1180 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 assertTrue(mockDelegate.mGestureTypeList.contains( | 1356 assertTrue(mockDelegate.mGestureTypeList.contains( |
| 1921 ContentViewGestureHandler.GESTURE_SCROLL_START)); | 1357 ContentViewGestureHandler.GESTURE_SCROLL_START)); |
| 1922 assertTrue(mockDelegate.mGestureTypeList.contains( | 1358 assertTrue(mockDelegate.mGestureTypeList.contains( |
| 1923 ContentViewGestureHandler.GESTURE_TAP_CANCEL)); | 1359 ContentViewGestureHandler.GESTURE_TAP_CANCEL)); |
| 1924 assertFalse("A scroll should terminate the tap down.", | 1360 assertFalse("A scroll should terminate the tap down.", |
| 1925 mGestureHandler.needsTapEndingEventForTesting()); | 1361 mGestureHandler.needsTapEndingEventForTesting()); |
| 1926 assertFalse(mGestureHandler.needsTapEndingEventForTesting()); | 1362 assertFalse(mGestureHandler.needsTapEndingEventForTesting()); |
| 1927 } | 1363 } |
| 1928 | 1364 |
| 1929 /** | 1365 /** |
| 1930 * Verify that touch move events are properly coalesced. | |
| 1931 * @throws Exception | |
| 1932 */ | |
| 1933 @SmallTest | |
| 1934 @Feature({"Gestures"}) | |
| 1935 public void testTouchMoveCoalescing() throws Exception { | |
| 1936 final long downTime = SystemClock.uptimeMillis(); | |
| 1937 final long eventTime = SystemClock.uptimeMillis(); | |
| 1938 | |
| 1939 mGestureHandler.hasTouchEventHandlers(true); | |
| 1940 | |
| 1941 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 1942 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1943 mGestureHandler.confirmTouchEvent(ContentViewGestureHandler.INPUT_EVENT_
ACK_STATE_CONSUMED); | |
| 1944 assertEquals(TouchPoint.TOUCH_EVENT_TYPE_START, mMockMotionEventDelegate
.mLastTouchAction); | |
| 1945 | |
| 1946 event = MotionEvent.obtain( | |
| 1947 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | |
| 1948 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 1949 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1950 assertFalse("Should not have a pending LONG_PRESS", mLongPressDetector.h
asPendingMessage()); | |
| 1951 assertEquals("Initial move events should offered to javascript and added
to the queue", | |
| 1952 1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 1953 assertEquals(TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.
mLastTouchAction); | |
| 1954 | |
| 1955 event = MotionEvent.obtain( | |
| 1956 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 1957 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 1958 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1959 assertEquals("Move events already sent to javascript should not be coale
sced", | |
| 1960 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 1961 | |
| 1962 event = MotionEvent.obtain( | |
| 1963 downTime, eventTime + 15, MotionEvent.ACTION_MOVE, | |
| 1964 FAKE_COORD_X * 15, FAKE_COORD_Y * 15, 0); | |
| 1965 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1966 assertEquals("Similar pending move events should be coalesced", | |
| 1967 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 1968 | |
| 1969 PointerProperties pp1 = new PointerProperties(); | |
| 1970 pp1.id = 0; | |
| 1971 pp1.toolType = MotionEvent.TOOL_TYPE_FINGER; | |
| 1972 PointerProperties pp2 = new PointerProperties(); | |
| 1973 pp2.id = 1; | |
| 1974 pp2.toolType = MotionEvent.TOOL_TYPE_FINGER; | |
| 1975 PointerProperties[] properties = new PointerProperties[] { pp1, pp2 }; | |
| 1976 | |
| 1977 PointerCoords pc1 = new PointerCoords(); | |
| 1978 pc1.x = FAKE_COORD_X * 10; | |
| 1979 pc1.y = FAKE_COORD_Y * 10; | |
| 1980 pc1.pressure = 1; | |
| 1981 pc1.size = 1; | |
| 1982 PointerCoords pc2 = new PointerCoords(); | |
| 1983 pc2.x = FAKE_COORD_X * 15; | |
| 1984 pc2.y = FAKE_COORD_Y * 15; | |
| 1985 pc2.pressure = 1; | |
| 1986 pc2.size = 1; | |
| 1987 PointerCoords[] coords = new PointerCoords[] { pc1, pc2 }; | |
| 1988 | |
| 1989 event = MotionEvent.obtain( | |
| 1990 downTime, eventTime + 20, MotionEvent.ACTION_MOVE, | |
| 1991 2, properties, coords, 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); | |
| 1992 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 1993 assertEquals("Move events with different pointer counts should not be co
alesced", | |
| 1994 3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 1995 | |
| 1996 event = MotionEvent.obtain( | |
| 1997 downTime, eventTime + 25, MotionEvent.ACTION_MOVE, | |
| 1998 2, properties, coords, 0, 0, 1.0f, 1.0f, 0, 0, 0, 0); | |
| 1999 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2000 assertEquals("Move events with similar pointer counts should be coalesce
d", | |
| 2001 3, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2002 | |
| 2003 event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downTime); | |
| 2004 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2005 assertEquals("Move events should not be coalesced with other events", | |
| 2006 4, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2007 } | |
| 2008 | |
| 2009 /** | |
| 2010 * Verify that synchronous confirmTouchEvent() calls made from the MotionEve
ntDelegate behave | |
| 2011 * properly. | |
| 2012 * @throws Exception | |
| 2013 */ | |
| 2014 @SmallTest | |
| 2015 @Feature({"Gestures"}) | |
| 2016 public void testSynchronousConfirmTouchEvent() throws Exception { | |
| 2017 final long downTime = SystemClock.uptimeMillis(); | |
| 2018 final long eventTime = SystemClock.uptimeMillis(); | |
| 2019 | |
| 2020 mGestureHandler.hasTouchEventHandlers(true); | |
| 2021 | |
| 2022 mMockMotionEventDelegate.disableSynchronousConfirmTouchEvent(); | |
| 2023 | |
| 2024 // Queue an asynchronously handled event. | |
| 2025 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 2026 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2027 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2028 | |
| 2029 // Queue another event; this will remain in the queue until the first ev
ent is confirmed. | |
| 2030 event = MotionEvent.obtain( | |
| 2031 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | |
| 2032 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | |
| 2033 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2034 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2035 | |
| 2036 // Enable synchronous event confirmation upon dispatch. | |
| 2037 mMockMotionEventDelegate.enableSynchronousConfirmTouchEvent( | |
| 2038 mGestureHandler, ContentViewGestureHandler.INPUT_EVENT_ACK_STATE
_CONSUMED); | |
| 2039 | |
| 2040 // Confirm the original event; this should dispatch the second event and
confirm it | |
| 2041 // synchronously. | |
| 2042 mGestureHandler.confirmTouchEvent( | |
| 2043 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2044 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2045 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2046 assertEquals(TouchPoint.TOUCH_EVENT_TYPE_MOVE, mMockMotionEventDelegate.
mLastTouchAction); | |
| 2047 | |
| 2048 // Adding events to any empty queue will trigger synchronous dispatch an
d confirmation. | |
| 2049 event = MotionEvent.obtain( | |
| 2050 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 2051 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 2052 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2053 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2054 } | |
| 2055 | |
| 2056 /** | |
| 2057 * Verify that no double tap gestures are created if the gesture handler is | 1366 * Verify that no double tap gestures are created if the gesture handler is |
| 2058 * told to disable double tap gesture detection (according to the logic in | 1367 * told to disable double tap gesture detection (according to the logic in |
| 2059 * ContentViewCore.onRenderCoordinatesUpdated). | 1368 * ContentViewCore.onRenderCoordinatesUpdated). |
| 2060 * @throws Exception | 1369 * @throws Exception |
| 2061 */ | 1370 */ |
| 2062 @SmallTest | 1371 @SmallTest |
| 2063 @Feature({"Gestures"}) | 1372 @Feature({"Gestures"}) |
| 2064 public void testNoDoubleTapWhenDoubleTapDisabled() throws Exception { | 1373 public void testNoDoubleTapWhenDoubleTapDisabled() throws Exception { |
| 2065 final long downTime = SystemClock.uptimeMillis(); | 1374 final long downTime = SystemClock.uptimeMillis(); |
| 2066 final long eventTime = SystemClock.uptimeMillis(); | 1375 final long eventTime = SystemClock.uptimeMillis(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2189 @SmallTest | 1498 @SmallTest |
| 2190 @Feature({"Gestures"}) | 1499 @Feature({"Gestures"}) |
| 2191 public void testFixedPageScaleDuringDoubleTapDragZoom() throws Exception { | 1500 public void testFixedPageScaleDuringDoubleTapDragZoom() throws Exception { |
| 2192 long downTime1 = SystemClock.uptimeMillis(); | 1501 long downTime1 = SystemClock.uptimeMillis(); |
| 2193 long downTime2 = downTime1 + 100; | 1502 long downTime2 = downTime1 + 100; |
| 2194 | 1503 |
| 2195 GestureRecordingMotionEventDelegate mockDelegate = | 1504 GestureRecordingMotionEventDelegate mockDelegate = |
| 2196 new GestureRecordingMotionEventDelegate(); | 1505 new GestureRecordingMotionEventDelegate(); |
| 2197 mGestureHandler = new ContentViewGestureHandler( | 1506 mGestureHandler = new ContentViewGestureHandler( |
| 2198 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | 1507 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); |
| 2199 mLongPressDetector = new LongPressDetector( | |
| 2200 getInstrumentation().getTargetContext(), mGestureHandler); | |
| 2201 | 1508 |
| 2202 // Start a double-tap drag gesture. | 1509 // Start a double-tap drag gesture. |
| 2203 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, down
Time1); | 1510 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime1, down
Time1); |
| 2204 assertTrue(mGestureHandler.onTouchEvent(event)); | 1511 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 2205 mGestureHandler.sendShowPressedStateGestureForTesting(); | 1512 mGestureHandler.sendShowPressedStateGestureForTesting(); |
| 2206 event = MotionEvent.obtain( | 1513 event = MotionEvent.obtain( |
| 2207 downTime1, downTime1 + 5, MotionEvent.ACTION_UP, | 1514 downTime1, downTime1 + 5, MotionEvent.ACTION_UP, |
| 2208 FAKE_COORD_X, FAKE_COORD_Y, 0); | 1515 FAKE_COORD_X, FAKE_COORD_Y, 0); |
| 2209 mGestureHandler.onTouchEvent(event); | 1516 mGestureHandler.onTouchEvent(event); |
| 2210 event = MotionEvent.obtain( | 1517 event = MotionEvent.obtain( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2289 mockDelegate.mGestureTypeList.contains( | 1596 mockDelegate.mGestureTypeList.contains( |
| 2290 ContentViewGestureHandler.GESTURE_PINCH_BY)); | 1597 ContentViewGestureHandler.GESTURE_PINCH_BY)); |
| 2291 event = MotionEvent.obtain( | 1598 event = MotionEvent.obtain( |
| 2292 downTime2, downTime2 + 15, MotionEvent.ACTION_UP, | 1599 downTime2, downTime2 + 15, MotionEvent.ACTION_UP, |
| 2293 FAKE_COORD_X, FAKE_COORD_Y + 200, 0); | 1600 FAKE_COORD_X, FAKE_COORD_Y + 200, 0); |
| 2294 assertTrue(mGestureHandler.onTouchEvent(event)); | 1601 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 2295 assertFalse("GESTURE_PINCH_END should not have been sent", | 1602 assertFalse("GESTURE_PINCH_END should not have been sent", |
| 2296 mockDelegate.mGestureTypeList.contains( | 1603 mockDelegate.mGestureTypeList.contains( |
| 2297 ContentViewGestureHandler.GESTURE_PINCH_END)); | 1604 ContentViewGestureHandler.GESTURE_PINCH_END)); |
| 2298 } | 1605 } |
| 2299 | |
| 2300 /** | |
| 2301 * Verify that a secondary pointer press with no consumer does not interfere | |
| 2302 * with Javascript touch handling. | |
| 2303 * | |
| 2304 * @throws Exception | |
| 2305 */ | |
| 2306 @SmallTest | |
| 2307 @Feature({"Gestures"}) | |
| 2308 public void testSecondaryPointerWithNoConsumer() throws Exception { | |
| 2309 final long downTime = SystemClock.uptimeMillis(); | |
| 2310 final long eventTime = SystemClock.uptimeMillis(); | |
| 2311 | |
| 2312 mGestureHandler.hasTouchEventHandlers(true); | |
| 2313 | |
| 2314 // Queue a primary pointer press, a secondary pointer press and release, | |
| 2315 // and a primary pointer move. | |
| 2316 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 2317 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2318 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2319 | |
| 2320 event = motionEvent(MotionEvent.ACTION_POINTER_DOWN, downTime, eventTime
); | |
| 2321 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2322 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2323 | |
| 2324 event = motionEvent(MotionEvent.ACTION_POINTER_UP, downTime, eventTime +
10); | |
| 2325 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2326 assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2327 | |
| 2328 event = MotionEvent.obtain( | |
| 2329 downTime, eventTime + 15, MotionEvent.ACTION_MOVE, | |
| 2330 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 2331 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2332 assertEquals(4, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2333 | |
| 2334 // Simulate preventDefault from Javascript, forcing all touch events to
Javascript | |
| 2335 // for the current sequence. | |
| 2336 mGestureHandler.confirmTouchEvent( | |
| 2337 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2338 assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2339 | |
| 2340 mGestureHandler.confirmTouchEvent( | |
| 2341 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXIS
TS); | |
| 2342 assertEquals("Even if the secondary pointer has no consumer, continue se
nding events", | |
| 2343 2, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2344 | |
| 2345 mGestureHandler.confirmTouchEvent( | |
| 2346 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXIS
TS); | |
| 2347 assertEquals("Even if the secondary pointer has no consumer, continue se
nding events", | |
| 2348 1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2349 | |
| 2350 mGestureHandler.confirmTouchEvent( | |
| 2351 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2352 assertEquals(0, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2353 | |
| 2354 assertEquals("No gestures should result from the Javascript-consumed seq
uence", | |
| 2355 0, mMockMotionEventDelegate.mTotalSentGestureCount); | |
| 2356 } | |
| 2357 | |
| 2358 /** | |
| 2359 * Verify that multiple touch sequences in the queue are handled properly wh
en | |
| 2360 * the Javascript response is different for each. | |
| 2361 * | |
| 2362 * @throws Exception | |
| 2363 */ | |
| 2364 @SmallTest | |
| 2365 @Feature({"Gestures"}) | |
| 2366 public void testMultiplyEnqueuedTouches() throws Exception { | |
| 2367 final long downTime = SystemClock.uptimeMillis(); | |
| 2368 final long eventTime = SystemClock.uptimeMillis(); | |
| 2369 | |
| 2370 mGestureHandler.hasTouchEventHandlers(true); | |
| 2371 mGestureHandler.updateDoubleTapSupport(false); | |
| 2372 | |
| 2373 // Queue a tap sequence. | |
| 2374 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 2375 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2376 assertEquals(1, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2377 | |
| 2378 event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 5); | |
| 2379 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2380 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2381 | |
| 2382 // Queue a scroll sequence. | |
| 2383 event = motionEvent(MotionEvent.ACTION_DOWN, downTime + 10, downTime + 1
0); | |
| 2384 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2385 assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2386 | |
| 2387 event = MotionEvent.obtain( | |
| 2388 downTime + 10, eventTime + 15, MotionEvent.ACTION_MOVE, | |
| 2389 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 2390 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2391 assertFalse(mGestureHandler.isNativeScrolling()); | |
| 2392 assertEquals(4, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2393 | |
| 2394 event = motionEvent(MotionEvent.ACTION_UP, downTime + 10, downTime + 20)
; | |
| 2395 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2396 assertEquals(5, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2397 | |
| 2398 // Consume the first gesture. | |
| 2399 mGestureHandler.confirmTouchEvent( | |
| 2400 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2401 assertEquals(4, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2402 | |
| 2403 mGestureHandler.confirmTouchEvent( | |
| 2404 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2405 assertEquals(3, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2406 | |
| 2407 // Don't consume the second gesture; it should be fed to the gesture det
ector. | |
| 2408 mGestureHandler.confirmTouchEvent( | |
| 2409 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2410 assertEquals(2, mGestureHandler.getNumberOfPendingMotionEventsForTesting
()); | |
| 2411 assertEquals("The down touch event should have been sent to the gesture
detector", | |
| 2412 MotionEvent.ACTION_DOWN, mMockGestureDetector.mLastEvent.getActi
onMasked()); | |
| 2413 assertFalse(mGestureHandler.isNativeScrolling()); | |
| 2414 | |
| 2415 mGestureHandler.confirmTouchEvent( | |
| 2416 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2417 assertEquals("The move touch event should have been sent to the gesture
detector", | |
| 2418 MotionEvent.ACTION_MOVE, mMockGestureDetector.mLastEvent.getActi
onMasked()); | |
| 2419 } | |
| 2420 | |
| 2421 /** | |
| 2422 * Verify that only complete gestures are forwarded to Javascript if we rece
ive | |
| 2423 * a touch handler notification. | |
| 2424 * @throws Exception | |
| 2425 */ | |
| 2426 @SmallTest | |
| 2427 @Feature({"Gestures"}) | |
| 2428 public void testOnlyCompleteGesturesForwardedToTouchHandler() throws Excepti
on { | |
| 2429 final long downTime = SystemClock.uptimeMillis(); | |
| 2430 final long eventTime = SystemClock.uptimeMillis(); | |
| 2431 | |
| 2432 mGestureHandler.hasTouchEventHandlers(false); | |
| 2433 | |
| 2434 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 2435 mGestureHandler.onTouchEvent(event); | |
| 2436 assertEquals("Initial down events should not be sent to Javascript witho
ut a touch handler", | |
| 2437 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2438 assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEv
ent != null); | |
| 2439 mMockGestureDetector.mLastEvent = null; | |
| 2440 | |
| 2441 mGestureHandler.hasTouchEventHandlers(true); | |
| 2442 | |
| 2443 event = MotionEvent.obtain( | |
| 2444 downTime, eventTime + 5, MotionEvent.ACTION_MOVE, | |
| 2445 FAKE_COORD_X * 5, FAKE_COORD_Y * 5, 0); | |
| 2446 mGestureHandler.onTouchEvent(event); | |
| 2447 assertEquals("A move event should only be offered to javascript if the d
own was offered", | |
| 2448 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2449 assertTrue("Should have a pending gesture", mMockGestureDetector.mLastEv
ent != null); | |
| 2450 | |
| 2451 event = motionEvent(MotionEvent.ACTION_POINTER_DOWN, downTime, eventTime
+ 10); | |
| 2452 mGestureHandler.onTouchEvent(event); | |
| 2453 assertEquals("A pointer event should only be offered to Javascript if th
e down was offered", | |
| 2454 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2455 | |
| 2456 // Ensure that redundant notifications have no effect. | |
| 2457 mGestureHandler.hasTouchEventHandlers(true); | |
| 2458 | |
| 2459 event = motionEvent(MotionEvent.ACTION_POINTER_UP, downTime, eventTime +
15); | |
| 2460 mGestureHandler.onTouchEvent(event); | |
| 2461 assertEquals("A pointer event should only be offered to Javascript if th
e down was offered", | |
| 2462 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2463 | |
| 2464 event = motionEvent(MotionEvent.ACTION_UP, downTime, eventTime + 20); | |
| 2465 mGestureHandler.onTouchEvent(event); | |
| 2466 assertEquals("A pointer event should only be offered to Javascript if th
e down was offered", | |
| 2467 0, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2468 | |
| 2469 event = motionEvent(MotionEvent.ACTION_DOWN, downTime + 25, downTime + 2
5); | |
| 2470 mGestureHandler.onTouchEvent(event); | |
| 2471 assertEquals("A down event should be offered to Javascript with a regist
ered touch handler", | |
| 2472 1, mGestureHandler.getNumberOfPendingMotionEventsForTesting()); | |
| 2473 } | |
| 2474 | |
| 2475 /** | |
| 2476 * Verify that no timeout-based gestures are triggered after a touch event | |
| 2477 * is consumed. In particular, LONG_PRESS and SHOW_PRESS should not fire | |
| 2478 * if TouchStart went unconsumed, but subsequent TouchMoves are consumed. | |
| 2479 * | |
| 2480 * @throws Exception | |
| 2481 */ | |
| 2482 @SmallTest | |
| 2483 @Feature({"Gestures"}) | |
| 2484 public void testNoTimeoutGestureAfterTouchConsumed() throws Exception { | |
| 2485 getInstrumentation().runOnMainSync(new Runnable() { | |
| 2486 @Override | |
| 2487 public void run() { | |
| 2488 setUp(); | |
| 2489 | |
| 2490 final long downTime = SystemClock.uptimeMillis(); | |
| 2491 final long eventTime = SystemClock.uptimeMillis(); | |
| 2492 | |
| 2493 mGestureHandler.hasTouchEventHandlers(true); | |
| 2494 | |
| 2495 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTim
e, eventTime); | |
| 2496 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2497 mGestureHandler.confirmTouchEvent( | |
| 2498 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONS
UMED); | |
| 2499 assertTrue("Should have a pending LONG_PRESS", | |
| 2500 mLongPressDetector.hasPendingMessage()); | |
| 2501 | |
| 2502 event = MotionEvent.obtain( | |
| 2503 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 2504 FAKE_COORD_X, FAKE_COORD_Y + 200, 0); | |
| 2505 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2506 mGestureHandler.confirmTouchEvent( | |
| 2507 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED
); | |
| 2508 assertFalse("Should not have a pending LONG_PRESS", | |
| 2509 mLongPressDetector.hasPendingMessage()); | |
| 2510 } | |
| 2511 }); | |
| 2512 assertFalse(mMockListener.mShowPressCalled.await( | |
| 2513 ScalableTimeout.ScaleTimeout(ViewConfiguration.getTapTimeout() +
10), | |
| 2514 TimeUnit.MILLISECONDS)); | |
| 2515 assertFalse(mMockListener.mLongPressCalled.await( | |
| 2516 ScalableTimeout.ScaleTimeout(ViewConfiguration.getLongPressTimeo
ut() + 10), | |
| 2517 TimeUnit.MILLISECONDS)); | |
| 2518 } | |
| 2519 | |
| 2520 /** | |
| 2521 * Verify that a TAP_DOWN will be followed by a TAP_CANCEL if the first | |
| 2522 * touch is unconsumed, but the subsequent touch is consumed. | |
| 2523 * | |
| 2524 * @throws Exception | |
| 2525 */ | |
| 2526 @SmallTest | |
| 2527 @Feature({"Gestures"}) | |
| 2528 public void testTapCancelledAfterTouchConsumed() throws Exception { | |
| 2529 final long downTime = SystemClock.uptimeMillis(); | |
| 2530 final long eventTime = SystemClock.uptimeMillis(); | |
| 2531 | |
| 2532 GestureRecordingMotionEventDelegate mockDelegate = | |
| 2533 new GestureRecordingMotionEventDelegate(); | |
| 2534 mGestureHandler = new ContentViewGestureHandler( | |
| 2535 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager); | |
| 2536 mGestureHandler.hasTouchEventHandlers(true); | |
| 2537 | |
| 2538 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); | |
| 2539 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2540 mGestureHandler.confirmTouchEvent( | |
| 2541 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2542 assertEquals("A TAP_DOWN gesture should have been sent", | |
| 2543 ContentViewGestureHandler.GESTURE_TAP_DOWN, | |
| 2544 mockDelegate.mMostRecentGestureEvent.mType); | |
| 2545 | |
| 2546 event = MotionEvent.obtain( | |
| 2547 downTime, eventTime + 10, MotionEvent.ACTION_MOVE, | |
| 2548 FAKE_COORD_X, FAKE_COORD_Y + 200, 0); | |
| 2549 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2550 mGestureHandler.confirmTouchEvent( | |
| 2551 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2552 assertEquals("A TAP_CANCEL gesture should have been sent", | |
| 2553 ContentViewGestureHandler.GESTURE_TAP_CANCEL, | |
| 2554 mockDelegate.mMostRecentGestureEvent.mType); | |
| 2555 | |
| 2556 event = MotionEvent.obtain( | |
| 2557 downTime, eventTime + 15, MotionEvent.ACTION_MOVE, | |
| 2558 FAKE_COORD_X, FAKE_COORD_Y + 400, 0); | |
| 2559 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 2560 mGestureHandler.confirmTouchEvent( | |
| 2561 ContentViewGestureHandler.INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2562 assertEquals("No further gestures should be sent", | |
| 2563 ContentViewGestureHandler.GESTURE_TAP_CANCEL, | |
| 2564 mockDelegate.mMostRecentGestureEvent.mType); | |
| 2565 } | |
| 2566 } | 1606 } |
| OLD | NEW |