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));
}
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));
}
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));
}
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));
}
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));
}
});
}
Aggregations