Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.Build; | 8 import android.os.Build; |
| 9 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.os.SystemClock; | 10 import android.os.SystemClock; |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 downTime, eventTime + 10, MotionEvent.ACTION_UP, | 589 downTime, eventTime + 10, MotionEvent.ACTION_UP, |
| 590 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); | 590 FAKE_COORD_X * 10, FAKE_COORD_Y * 10, 0); |
| 591 assertTrue(mGestureHandler.onTouchEvent(event)); | 591 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 592 | 592 |
| 593 // Synchronous, no need to wait. | 593 // Synchronous, no need to wait. |
| 594 assertTrue("Should have a fling", mMockListener.mLastFling1 != null); | 594 assertTrue("Should have a fling", mMockListener.mLastFling1 != null); |
| 595 assertTrue("Should not have a long press", mMockListener.mLastLongPress == null); | 595 assertTrue("Should not have a long press", mMockListener.mLastLongPress == null); |
| 596 } | 596 } |
| 597 | 597 |
| 598 /** | 598 /** |
| 599 * Verify that for a normal scroll the following events are sent: | |
| 600 * - GESTURE_SCROLL_START | |
| 601 * - GESTURE_SCROLL_BY | |
| 602 * - GESTURE_SCROLL_END | |
| 603 * @throws Exception | |
| 604 */ | |
| 605 @SmallTest | |
| 606 @Feature({"Gestures"}) | |
| 607 public void testScrollEventSequence() throws Exception { | |
|
Ted C
2013/10/14 20:05:38
should specify this as action_up in the name to be
cjhopman
2013/10/14 20:37:09
Done.
| |
| 608 doScrollEventSequence(MotionEvent.ACTION_UP); | |
| 609 } | |
| 610 | |
| 611 /** | |
| 612 * Verify that for a cancelled scroll the following events are sent: | |
| 613 * - GESTURE_SCROLL_START | |
| 614 * - GESTURE_SCROLL_BY | |
| 615 * - GESTURE_SCROLL_END | |
| 616 * @throws Exception | |
| 617 */ | |
| 618 @SmallTest | |
| 619 @Feature({"Gestures"}) | |
| 620 public void testScrollEventCancelledSequence() throws Exception { | |
| 621 doScrollEventSequence(MotionEvent.ACTION_CANCEL); | |
| 622 } | |
| 623 | |
|
Ted C
2013/10/14 20:05:38
remove extra blank line
cjhopman
2013/10/14 20:37:09
Done.
| |
| 624 | |
| 625 private void doScrollEventSequence(int endActionType) throws Exception { | |
|
Ted C
2013/10/14 20:05:38
The name of this method seems somewhat unclear to
cjhopman
2013/10/14 20:37:09
How's this?
| |
| 626 final long downTime = SystemClock.uptimeMillis(); | |
| 627 final long eventTime = SystemClock.uptimeMillis(); | |
| 628 final int scrollToX = FAKE_COORD_X + 100; | |
| 629 final int scrollToY = FAKE_COORD_Y + 100; | |
| 630 | |
| 631 GestureRecordingMotionEventDelegate mockDelegate = | |
| 632 new GestureRecordingMotionEventDelegate(); | |
| 633 mGestureHandler = new ContentViewGestureHandler( | |
| 634 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom Manager, | |
| 635 ContentViewCore.INPUT_EVENTS_DELIVERED_AT_VSYNC); | |
| 636 | |
| 637 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT ime); | |
| 638 | |
| 639 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 640 | |
| 641 event = MotionEvent.obtain( | |
| 642 downTime, eventTime + 100, MotionEvent.ACTION_MOVE, scrollToX, s crollToY, 0); | |
| 643 assertTrue(mGestureHandler.onTouchEvent(event)); | |
| 644 assertTrue(mGestureHandler.isNativeScrolling()); | |
| 645 assertTrue("A scrollStart event should have been sent", | |
| 646 mockDelegate.mGestureTypeList.contains( | |
| 647 ContentViewGestureHandler.GESTURE_SCROLL_START)); | |
| 648 assertEquals("We should have started scrolling", | |
| 649 ContentViewGestureHandler.GESTURE_SCROLL_BY, | |
| 650 mockDelegate.mMostRecentGestureEvent.mType); | |
| 651 assertEquals("Only scrollBegin and scrollBy should have been sent", | |
| 652 2, mockDelegate.mGestureTypeList.size()); | |
| 653 | |
| 654 event = MotionEvent.obtain( | |
| 655 downTime, eventTime + 100, endActionType, scrollToX, scrollToY, 0); | |
|
Ted C
2013/10/14 20:05:38
Although it probably doesn't matter, but should yo
cjhopman
2013/10/14 20:37:09
It's pretty common that the framework sends a fina
| |
| 656 assertFalse(mGestureHandler.onTouchEvent(event)); | |
| 657 assertFalse(mGestureHandler.isNativeScrolling()); | |
| 658 assertTrue("A scrollEnd event should have been sent", | |
| 659 mockDelegate.mGestureTypeList.contains( | |
| 660 ContentViewGestureHandler.GESTURE_SCROLL_END)); | |
| 661 assertEquals("We should have stopped scrolling", | |
| 662 ContentViewGestureHandler.GESTURE_SCROLL_END, | |
| 663 mockDelegate.mMostRecentGestureEvent.mType); | |
| 664 assertEquals("Only scrollBegin and scrollBy and scrollEnd should have be en sent", | |
| 665 3, mockDelegate.mGestureTypeList.size()); | |
| 666 } | |
| 667 | |
|
Ted C
2013/10/14 20:05:38
remove extra blank line
cjhopman
2013/10/14 20:37:09
Done.
| |
| 668 | |
| 669 /** | |
| 599 * Verify that for a normal fling (fling after scroll) the following events are sent: | 670 * Verify that for a normal fling (fling after scroll) the following events are sent: |
| 600 * - GESTURE_SCROLL_BEGIN | 671 * - GESTURE_SCROLL_BEGIN |
| 601 * - GESTURE_FLING_START | 672 * - GESTURE_FLING_START |
| 602 * and GESTURE_FLING_CANCEL is sent on the next touch. | 673 * and GESTURE_FLING_CANCEL is sent on the next touch. |
| 603 * @throws Exception | 674 * @throws Exception |
| 604 */ | 675 */ |
| 605 @SmallTest | 676 @SmallTest |
| 606 @Feature({"Gestures"}) | 677 @Feature({"Gestures"}) |
| 607 public void testFlingEventSequence() throws Exception { | 678 public void testFlingEventSequence() throws Exception { |
| 608 final long downTime = SystemClock.uptimeMillis(); | 679 final long downTime = SystemClock.uptimeMillis(); |
| (...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1703 | 1774 |
| 1704 // If events are delivered at vsync, multiple SCROLL_BY and PINCH_BY eve nts should still | 1775 // If events are delivered at vsync, multiple SCROLL_BY and PINCH_BY eve nts should still |
| 1705 // trigger only a single vsync from any given call to confirmTouchEvent( ). | 1776 // trigger only a single vsync from any given call to confirmTouchEvent( ). |
| 1706 if (inputEventsDeliveredAtVSync) { | 1777 if (inputEventsDeliveredAtVSync) { |
| 1707 assertEquals(1, mMockMotionEventDelegate.mTotalSentLastGestureForVSy ncCount); | 1778 assertEquals(1, mMockMotionEventDelegate.mTotalSentLastGestureForVSy ncCount); |
| 1708 } else { | 1779 } else { |
| 1709 assertEquals(0, mMockMotionEventDelegate.mTotalSentLastGestureForVSy ncCount); | 1780 assertEquals(0, mMockMotionEventDelegate.mTotalSentLastGestureForVSy ncCount); |
| 1710 } | 1781 } |
| 1711 } | 1782 } |
| 1712 } | 1783 } |
| OLD | NEW |