From 7e2cd243f995bf9f7cb3ebbb6da610780914846d Mon Sep 17 00:00:00 2001 From: Yuichi Araki Date: Wed, 30 Nov 2016 03:46:36 +0000 Subject: [PATCH] Merge "Fix BottomSheetBehaviorTest" into mnc-ub-dev am: aeac66ab70 am: 4d2348182e * commit '4d2348182e578284fcfd35c43bcb8852f45967c9': Fix BottomSheetBehaviorTest GitOrigin-RevId=6027352a976254c5fa31ce0501f7444cc9055dc6 PiperOrigin-RevId: 140559579 --- .../widget/BottomSheetBehaviorTest.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/src/android/support/design/widget/BottomSheetBehaviorTest.java b/tests/src/android/support/design/widget/BottomSheetBehaviorTest.java index 98427f43f..192c48a3b 100644 --- a/tests/src/android/support/design/widget/BottomSheetBehaviorTest.java +++ b/tests/src/android/support/design/widget/BottomSheetBehaviorTest.java @@ -23,6 +23,7 @@ import android.support.annotation.NonNull; import android.support.design.test.R; import android.support.test.espresso.Espresso; import android.support.test.espresso.IdlingResource; +import android.support.test.espresso.action.CoordinatesProvider; import android.support.test.espresso.action.GeneralLocation; import android.support.test.espresso.action.GeneralSwipeAction; import android.support.test.espresso.action.Press; @@ -127,8 +128,21 @@ public class BottomSheetBehaviorTest extends public void testSwipeDownToCollapse() { checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed()); Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) - .perform(DesignViewActions.withCustomConstraints(ViewActions.swipeDown(), - ViewMatchers.isDisplayingAtLeast(5))); + .perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction( + Swipe.FAST, GeneralLocation.TOP_CENTER, + // Manually calculate the ending coordinates to make sure that the bottom + // sheet is collapsed, not hidden + new CoordinatesProvider() { + @Override + public float[] calculateCoordinates(View view) { + BottomSheetBehavior behavior = getBehavior(); + return new float[]{ + // x: center of the bottom sheet + view.getWidth() / 2, + // y: just above the peek height + view.getHeight() - behavior.getPeekHeight()}; + } + }, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5))); // Avoid a deadlock (b/26160710) registerIdlingResourceCallback(); try { @@ -162,8 +176,12 @@ public class BottomSheetBehaviorTest extends Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .perform(DesignViewActions.withCustomConstraints( new GeneralSwipeAction(Swipe.FAST, - GeneralLocation.VISIBLE_CENTER, GeneralLocation.TOP_CENTER, - Press.FINGER), + GeneralLocation.VISIBLE_CENTER, new CoordinatesProvider() { + @Override + public float[] calculateCoordinates(View view) { + return new float[]{view.getWidth() / 2, 0}; + } + }, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5))); // Avoid a deadlock (b/26160710) registerIdlingResourceCallback();