Search in sources :

Example 11 with MediumTest

use of android.support.test.filters.MediumTest in project material-components-android by material-components.

the class BottomSheetBehaviorTest method testDragOutside.

@Test
@MediumTest
public void testDragOutside() {
    // Swipe up outside of the bottom sheet
    Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction(Swipe.FAST, // Just above the bottom sheet
    new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            return new float[] { view.getWidth() / 2, view.getHeight() - getBehavior().getPeekHeight() - 9 };
        }
    }, // Top of the CoordinatorLayout
    new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            return new float[] { view.getWidth() / 2, 1 };
        }
    }, Press.FINGER), ViewMatchers.isDisplayed()));
    registerIdlingResourceCallback();
    try {
        Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
        // The bottom sheet should remain collapsed
        assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
    } finally {
        unregisterIdlingResourceCallback();
    }
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 12 with MediumTest

use of android.support.test.filters.MediumTest in project material-components-android by material-components.

the class BottomSheetBehaviorTest method testSwipeUpToExpand.

@Test
@MediumTest
public void testSwipeUpToExpand() {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction(Swipe.FAST, GeneralLocation.VISIBLE_CENTER, new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            return new float[] { view.getWidth() / 2, 0 };
        }
    }, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5)));
    registerIdlingResourceCallback();
    try {
        Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
        assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
    } finally {
        unregisterIdlingResourceCallback();
    }
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 13 with MediumTest

use of android.support.test.filters.MediumTest in project material-components-android by material-components.

the class BottomSheetBehaviorTest method testNestedScroll.

@Test
@MediumTest
public void testNestedScroll() throws Throwable {
    final ViewGroup bottomSheet = getBottomSheet();
    final BottomSheetBehavior behavior = getBehavior();
    final NestedScrollView scroll = new NestedScrollView(activityTestRule.getActivity());
    // Set up nested scrolling area
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            bottomSheet.addView(scroll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            TextView view = new TextView(activityTestRule.getActivity());
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 500; ++i) {
                sb.append("It is fine today. ");
            }
            view.setText(sb);
            view.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                // Do nothing
                }
            });
            scroll.addView(view);
            assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
            // The scroll offset is 0 at first
            assertThat(scroll.getScrollY(), is(0));
        }
    });
    // Swipe from the very bottom of the bottom sheet to the top edge of the screen so that the
    // scrolling content is also scrolled
    Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(new GeneralSwipeAction(Swipe.SLOW, new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            return new float[] { view.getWidth() / 2, view.getHeight() - 1 };
        }
    }, new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            return new float[] { view.getWidth() / 2, 1 };
        }
    }, Press.FINGER));
    registerIdlingResourceCallback();
    try {
        Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
        activityTestRule.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_EXPANDED));
                // This confirms that the nested scrolling area was scrolled continuously after
                // the bottom sheet is expanded.
                assertThat(scroll.getScrollY(), is(not(0)));
            }
        });
    } finally {
        unregisterIdlingResourceCallback();
    }
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) ViewGroup(android.view.ViewGroup) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) TextView(android.widget.TextView) NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 14 with MediumTest

use of android.support.test.filters.MediumTest in project material-components-android by material-components.

the class BottomSheetBehaviorTest method testDynamicContent.

@Test
@MediumTest
public void testDynamicContent() throws Throwable {
    registerIdlingResourceCallback();
    try {
        activityTestRule.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                ViewGroup.LayoutParams params = getBottomSheet().getLayoutParams();
                params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                getBottomSheet().setLayoutParams(params);
                View view = new View(getBottomSheet().getContext());
                int size = getBehavior().getPeekHeight() * 2;
                getBottomSheet().addView(view, new ViewGroup.LayoutParams(size, size));
                assertThat(getBottomSheet().getChildCount(), is(1));
                // Shrink the content height.
                ViewGroup.LayoutParams lp = view.getLayoutParams();
                lp.height = (int) (size * 0.8);
                view.setLayoutParams(lp);
                // Immediately expand the bottom sheet.
                getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
            }
        });
        Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
        assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
        // Make sure that the bottom sheet is not floating above the bottom.
        assertThat(getBottomSheet().getBottom(), is(getCoordinatorLayout().getBottom()));
    } finally {
        unregisterIdlingResourceCallback();
    }
}
Also used : View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 15 with MediumTest

use of android.support.test.filters.MediumTest in project material-components-android by material-components.

the class BottomSheetBehaviorTest method testInvisibleThenVisible.

@Test
@MediumTest
public void testInvisibleThenVisible() throws Throwable {
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // The bottom sheet is initially invisible
            getBottomSheet().setVisibility(View.INVISIBLE);
            // Then it becomes visible when the CoL is touched
            getCoordinatorLayout().setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View view, MotionEvent e) {
                    if (e.getAction() == MotionEvent.ACTION_DOWN) {
                        getBottomSheet().setVisibility(View.VISIBLE);
                        return true;
                    }
                    return false;
                }
            });
            assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
    });
    // Drag over the CoL
    Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(new DragAction(GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER)).check(new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException e) {
            // The bottom sheet should not react to the touch events
            assertThat(getBottomSheet(), is(ViewMatchers.isDisplayed()));
            assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
    });
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Aggregations

MediumTest (android.support.test.filters.MediumTest)32 Test (org.junit.Test)32 Intent (android.content.Intent)11 Handler (android.os.Handler)11 FlakyTest (android.support.test.filters.FlakyTest)11 TelephonyTest (com.android.internal.telephony.TelephonyTest)11 Parcelable (android.os.Parcelable)10 SmallTest (android.support.test.filters.SmallTest)10 AsyncResult (android.os.AsyncResult)9 View (android.view.View)9 NestedScrollView (android.support.v4.widget.NestedScrollView)8 TextView (android.widget.TextView)8 CoordinatesProvider (android.support.test.espresso.action.CoordinatesProvider)6 GeneralSwipeAction (android.support.test.espresso.action.GeneralSwipeAction)6 SmsHeader (com.android.internal.telephony.SmsHeader)5 Ignore (org.junit.Ignore)4 CustomSnackbar (android.support.design.testapp.custom.CustomSnackbar)2 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentValues (android.content.ContentValues)1 IntentFilter (android.content.IntentFilter)1