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 testScrollEventActionUpSequence() throws Exception { |
| 608 checkScrollEventSequenceForEndActionType(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 testScrollEventActionCancelSequence() throws Exception { |
| 621 checkScrollEventSequenceForEndActionType(MotionEvent.ACTION_CANCEL); |
| 622 } |
| 623 |
| 624 private void checkScrollEventSequenceForEndActionType(int endActionType) thr
ows Exception { |
| 625 final long downTime = SystemClock.uptimeMillis(); |
| 626 final long eventTime = SystemClock.uptimeMillis(); |
| 627 final int scrollToX = FAKE_COORD_X + 100; |
| 628 final int scrollToY = FAKE_COORD_Y + 100; |
| 629 |
| 630 GestureRecordingMotionEventDelegate mockDelegate = |
| 631 new GestureRecordingMotionEventDelegate(); |
| 632 mGestureHandler = new ContentViewGestureHandler( |
| 633 getInstrumentation().getTargetContext(), mockDelegate, mMockZoom
Manager, |
| 634 ContentViewCore.INPUT_EVENTS_DELIVERED_AT_VSYNC); |
| 635 |
| 636 MotionEvent event = motionEvent(MotionEvent.ACTION_DOWN, downTime, downT
ime); |
| 637 |
| 638 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 639 |
| 640 event = MotionEvent.obtain( |
| 641 downTime, eventTime + 1000, MotionEvent.ACTION_MOVE, scrollToX,
scrollToY, 0); |
| 642 assertTrue(mGestureHandler.onTouchEvent(event)); |
| 643 assertTrue(mGestureHandler.isNativeScrolling()); |
| 644 assertTrue("A scrollStart event should have been sent", |
| 645 mockDelegate.mGestureTypeList.contains( |
| 646 ContentViewGestureHandler.GESTURE_SCROLL_START)); |
| 647 assertEquals("We should have started scrolling", |
| 648 ContentViewGestureHandler.GESTURE_SCROLL_BY, |
| 649 mockDelegate.mMostRecentGestureEvent.mType); |
| 650 assertEquals("Only scrollBegin and scrollBy should have been sent", |
| 651 2, mockDelegate.mGestureTypeList.size()); |
| 652 |
| 653 event = MotionEvent.obtain( |
| 654 downTime, eventTime + 1000, endActionType, scrollToX, scrollToY,
0); |
| 655 mGestureHandler.onTouchEvent(event); |
| 656 assertFalse(mGestureHandler.isNativeScrolling()); |
| 657 assertTrue("A scrollEnd event should have been sent", |
| 658 mockDelegate.mGestureTypeList.contains( |
| 659 ContentViewGestureHandler.GESTURE_SCROLL_END)); |
| 660 assertEquals("We should have stopped scrolling", |
| 661 ContentViewGestureHandler.GESTURE_SCROLL_END, |
| 662 mockDelegate.mMostRecentGestureEvent.mType); |
| 663 assertEquals("Only scrollBegin and scrollBy and scrollEnd should have be
en sent", |
| 664 3, mockDelegate.mGestureTypeList.size()); |
| 665 } |
| 666 |
| 667 /** |
599 * Verify that for a normal fling (fling after scroll) the following events
are sent: | 668 * Verify that for a normal fling (fling after scroll) the following events
are sent: |
600 * - GESTURE_SCROLL_BEGIN | 669 * - GESTURE_SCROLL_BEGIN |
601 * - GESTURE_FLING_START | 670 * - GESTURE_FLING_START |
602 * and GESTURE_FLING_CANCEL is sent on the next touch. | 671 * and GESTURE_FLING_CANCEL is sent on the next touch. |
603 * @throws Exception | 672 * @throws Exception |
604 */ | 673 */ |
605 @SmallTest | 674 @SmallTest |
606 @Feature({"Gestures"}) | 675 @Feature({"Gestures"}) |
607 public void testFlingEventSequence() throws Exception { | 676 public void testFlingEventSequence() throws Exception { |
608 final long downTime = SystemClock.uptimeMillis(); | 677 final long downTime = SystemClock.uptimeMillis(); |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 | 1772 |
1704 // If events are delivered at vsync, multiple SCROLL_BY and PINCH_BY eve
nts should still | 1773 // 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(
). | 1774 // trigger only a single vsync from any given call to confirmTouchEvent(
). |
1706 if (inputEventsDeliveredAtVSync) { | 1775 if (inputEventsDeliveredAtVSync) { |
1707 assertEquals(1, mMockMotionEventDelegate.mTotalSentLastGestureForVSy
ncCount); | 1776 assertEquals(1, mMockMotionEventDelegate.mTotalSentLastGestureForVSy
ncCount); |
1708 } else { | 1777 } else { |
1709 assertEquals(0, mMockMotionEventDelegate.mTotalSentLastGestureForVSy
ncCount); | 1778 assertEquals(0, mMockMotionEventDelegate.mTotalSentLastGestureForVSy
ncCount); |
1710 } | 1779 } |
1711 } | 1780 } |
1712 } | 1781 } |
OLD | NEW |