Search in sources :

Example 1 with CoordinatorLayoutActivity

use of android.support.design.testapp.CoordinatorLayoutActivity in project material-components-android by material-components.

the class CoordinatorLayoutTest method testNestedScrollingDispatchingToBehaviorWithGoneView.

@Test
public void testNestedScrollingDispatchingToBehaviorWithGoneView() throws Throwable {
    final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
    final CoordinatorLayout col = activity.mCoordinatorLayout;
    // Now create a GONE view and add it to the CoordinatorLayout with the spy behavior,
    // along with a NestedScrollView
    final ImageView imageView = new ImageView(activity);
    imageView.setVisibility(View.GONE);
    final CoordinatorLayout.Behavior behavior = spy(new NestedScrollingBehavior());
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            LayoutInflater.from(activity).inflate(R.layout.include_nestedscrollview, col, true);
            CoordinatorLayout.LayoutParams clp = new CoordinatorLayout.LayoutParams(200, 200);
            clp.setBehavior(behavior);
            col.addView(imageView, clp);
        }
    });
    // Now vertically swipe up on the NSV, causing nested scrolling to occur
    onView(withId(R.id.nested_scrollview)).perform(swipeUp());
    // Verify that the Behavior's onStartNestedScroll was not called
    verify(behavior, never()).onStartNestedScroll(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class), // direct child target
    any(View.class), // axes
    any(int.class));
    // Verify that the Behavior's onNestedScrollAccepted was not called
    verify(behavior, never()).onNestedScrollAccepted(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class), // direct child target
    any(View.class), // axes
    any(int.class));
    // Verify that the Behavior's onNestedPreScroll was not called
    verify(behavior, never()).onNestedPreScroll(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class), // dx
    any(int.class), // dy
    any(int.class), // consumed
    any(int[].class));
    // Verify that the Behavior's onNestedScroll was not called
    verify(behavior, never()).onNestedScroll(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class), // dx consumed
    any(int.class), // dy consumed
    any(int.class), // dx unconsumed
    any(int.class), // dy unconsumed
    any(int.class));
    // Verify that the Behavior's onStopNestedScroll was not called
    verify(behavior, never()).onStopNestedScroll(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class));
}
Also used : Behavior(android.support.design.widget.CoordinatorLayout.Behavior) CoordinatorLayoutActivity(android.support.design.testapp.CoordinatorLayoutActivity) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 2 with CoordinatorLayoutActivity

use of android.support.design.testapp.CoordinatorLayoutActivity in project material-components-android by material-components.

the class CoordinatorLayoutTest method testNestedScrollingTriggeringDependentViewChanged.

@Test
public void testNestedScrollingTriggeringDependentViewChanged() throws Throwable {
    final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
    final CoordinatorLayout col = activity.mCoordinatorLayout;
    // First a NestedScrollView to trigger nested scrolling
    final View scrollView = LayoutInflater.from(activity).inflate(R.layout.include_nestedscrollview, col, false);
    // Now create a View and Behavior which depend on the scrollview
    final ImageView dependentView = new ImageView(activity);
    final CoordinatorLayout.Behavior dependentBehavior = spy(new DependentBehavior(scrollView));
    // Finally a view which accepts nested scrolling in the CoordinatorLayout
    final ImageView nestedScrollAwareView = new ImageView(activity);
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // First add the ScrollView
            col.addView(scrollView);
            // Now add the view which depends on the scrollview
            CoordinatorLayout.LayoutParams clp = new CoordinatorLayout.LayoutParams(200, 200);
            clp.setBehavior(dependentBehavior);
            col.addView(dependentView, clp);
            // Now add the nested scrolling aware view
            clp = new CoordinatorLayout.LayoutParams(200, 200);
            clp.setBehavior(new NestedScrollingBehavior());
            col.addView(nestedScrollAwareView, clp);
        }
    });
    // Wait for any layouts, and reset the Behavior so that the call counts are 0
    getInstrumentation().waitForIdleSync();
    reset(dependentBehavior);
    // Now vertically swipe up on the NSV, causing nested scrolling to occur
    onView(withId(R.id.nested_scrollview)).perform(swipeUp());
    // Verify that the Behavior's onDependentViewChanged is not called due to the
    // nested scroll
    verify(dependentBehavior, never()).onDependentViewChanged(// parent
    eq(col), // child
    eq(dependentView), // axes
    eq(scrollView));
}
Also used : DependentBehavior(android.support.design.testutils.CoordinatorLayoutUtils.DependentBehavior) Behavior(android.support.design.widget.CoordinatorLayout.Behavior) CoordinatorLayoutActivity(android.support.design.testapp.CoordinatorLayoutActivity) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 3 with CoordinatorLayoutActivity

use of android.support.design.testapp.CoordinatorLayoutActivity in project material-components-android by material-components.

the class CoordinatorLayoutTest method testGoneViewsNotMeasuredLaidOut.

@Test
public void testGoneViewsNotMeasuredLaidOut() throws Throwable {
    final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
    final CoordinatorLayout col = activity.mCoordinatorLayout;
    // Now create a GONE view and add it to the CoordinatorLayout
    final View imageView = new View(activity);
    imageView.setVisibility(View.GONE);
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            col.addView(imageView, 200, 200);
        }
    });
    // Wait for a layout and measure pass
    getInstrumentation().waitForIdleSync();
    // And assert that it has not been laid out
    assertFalse(imageView.getMeasuredWidth() > 0);
    assertFalse(imageView.getMeasuredHeight() > 0);
    assertFalse(ViewCompat.isLaidOut(imageView));
    // Now set the view to INVISIBLE
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            imageView.setVisibility(View.INVISIBLE);
        }
    });
    // Wait for a layout and measure pass
    getInstrumentation().waitForIdleSync();
    // And assert that it has been laid out
    assertTrue(imageView.getMeasuredWidth() > 0);
    assertTrue(imageView.getMeasuredHeight() > 0);
    assertTrue(ViewCompat.isLaidOut(imageView));
}
Also used : CoordinatorLayoutActivity(android.support.design.testapp.CoordinatorLayoutActivity) ImageView(android.widget.ImageView) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 4 with CoordinatorLayoutActivity

use of android.support.design.testapp.CoordinatorLayoutActivity in project material-components-android by material-components.

the class CoordinatorLayoutTest method testNestedScrollingDispatchesToBehavior.

@Test
public void testNestedScrollingDispatchesToBehavior() throws Throwable {
    final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
    final CoordinatorLayout col = activity.mCoordinatorLayout;
    // Now create a view and add it to the CoordinatorLayout with the spy behavior,
    // along with a NestedScrollView
    final ImageView imageView = new ImageView(activity);
    final CoordinatorLayout.Behavior behavior = spy(new NestedScrollingBehavior());
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            LayoutInflater.from(activity).inflate(R.layout.include_nestedscrollview, col, true);
            CoordinatorLayout.LayoutParams clp = new CoordinatorLayout.LayoutParams(200, 200);
            clp.setBehavior(behavior);
            col.addView(imageView, clp);
        }
    });
    // Now vertically swipe up on the NSV, causing nested scrolling to occur
    onView(withId(R.id.nested_scrollview)).perform(swipeUp());
    // Verify that the Behavior's onStartNestedScroll was called once
    verify(behavior, times(1)).onStartNestedScroll(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class), // direct child target
    any(View.class), // axes
    any(int.class));
    // Verify that the Behavior's onNestedScrollAccepted was called once
    verify(behavior, times(1)).onNestedScrollAccepted(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class), // direct child target
    any(View.class), // axes
    any(int.class));
    // Verify that the Behavior's onNestedPreScroll was called at least once
    verify(behavior, atLeastOnce()).onNestedPreScroll(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class), // dx
    any(int.class), // dy
    any(int.class), // consumed
    any(int[].class));
    // Verify that the Behavior's onNestedScroll was called at least once
    verify(behavior, atLeastOnce()).onNestedScroll(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class), // dx consumed
    any(int.class), // dy consumed
    any(int.class), // dx unconsumed
    any(int.class), // dy unconsumed
    any(int.class));
    // Verify that the Behavior's onStopNestedScroll was called once
    verify(behavior, times(1)).onStopNestedScroll(// parent
    eq(col), // child
    eq(imageView), // target
    any(View.class));
}
Also used : Behavior(android.support.design.widget.CoordinatorLayout.Behavior) CoordinatorLayoutActivity(android.support.design.testapp.CoordinatorLayoutActivity) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 5 with CoordinatorLayoutActivity

use of android.support.design.testapp.CoordinatorLayoutActivity in project material-components-android by material-components.

the class BottomSheetBehaviorTouchTest method testTouchCoordinatorLayout.

@Test
public void testTouchCoordinatorLayout() {
    final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
    mDown = false;
    Espresso.onView(sameInstance((View) activity.mCoordinatorLayout)).perform(// Click outside the bottom sheet
    ViewActions.click()).check(new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException e) {
            assertThat(e, is(nullValue()));
            assertThat(view, is(notNullValue()));
            // Check that the touch event fell through to the container
            assertThat(mDown, is(true));
        }
    });
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) CoordinatorLayoutActivity(android.support.design.testapp.CoordinatorLayoutActivity) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) View(android.view.View) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

CoordinatorLayoutActivity (android.support.design.testapp.CoordinatorLayoutActivity)5 MediumTest (android.support.test.filters.MediumTest)5 View (android.view.View)5 Test (org.junit.Test)5 Espresso.onView (android.support.test.espresso.Espresso.onView)4 ImageView (android.widget.ImageView)4 Behavior (android.support.design.widget.CoordinatorLayout.Behavior)3 DependentBehavior (android.support.design.testutils.CoordinatorLayoutUtils.DependentBehavior)1 NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)1 ViewAssertion (android.support.test.espresso.ViewAssertion)1