use of android.support.test.espresso.ViewAssertion in project cameraview by google.
the class CameraViewTest method testAdjustViewBounds.
@Test
public void testAdjustViewBounds() {
onView(withId(R.id.camera)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
CameraView cameraView = (CameraView) view;
assertThat(cameraView.getAdjustViewBounds(), is(false));
cameraView.setAdjustViewBounds(true);
assertThat(cameraView.getAdjustViewBounds(), is(true));
}
}).perform(new AnythingAction("layout") {
@Override
public void perform(UiController uiController, View view) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
view.setLayoutParams(params);
}
}).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
CameraView cameraView = (CameraView) view;
AspectRatio cameraRatio = cameraView.getAspectRatio();
AspectRatio viewRatio = AspectRatio.of(view.getWidth(), view.getHeight());
assertThat(cameraRatio, is(closeToOrInverse(viewRatio)));
}
});
}
use of android.support.test.espresso.ViewAssertion in project material-components-android by material-components.
the class TabLayoutTest method testSetScrollPosition.
private void testSetScrollPosition(final boolean isLtr) throws Throwable {
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activityTestRule.getActivity().setContentView(R.layout.design_tabs_fixed_width);
}
});
final TabLayout tabs = (TabLayout) activityTestRule.getActivity().findViewById(R.id.tabs);
assertEquals(TabLayout.MODE_SCROLLABLE, tabs.getTabMode());
final TabLayoutScrollIdlingResource idler = new TabLayoutScrollIdlingResource(tabs);
Espresso.registerIdlingResources(idler);
// We're going to call setScrollPosition() incrementally, as if scrolling between one tab
// and the next. Use the middle tab for best results. The positionOffsets should be in the
// range [0, 1), so the final call will wrap to 0 but use the next tab's position.
final int middleTab = tabs.getTabCount() / 2;
final int[] positions = { middleTab, middleTab, middleTab, middleTab, middleTab + 1 };
final float[] positionOffsets = { 0f, .25f, .5f, .75f, 0f };
// Set layout direction
onView(withId(R.id.tabs)).perform(setLayoutDirection(isLtr ? ViewCompat.LAYOUT_DIRECTION_LTR : ViewCompat.LAYOUT_DIRECTION_RTL));
// Make sure it's scrolled all the way to the start
onView(withId(R.id.tabs)).perform(selectTab(0));
// Perform a series of setScrollPosition() calls
final AtomicInteger lastScrollX = new AtomicInteger(tabs.getScrollX());
for (int i = 0; i < positions.length; i++) {
onView(withId(R.id.tabs)).perform(setScrollPosition(positions[i], positionOffsets[i])).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException notFoundException) {
if (view == null) {
throw notFoundException;
}
// Verify increasing or decreasing scroll X values
int sx = view.getScrollX();
assertTrue(isLtr ? sx > lastScrollX.get() : sx < lastScrollX.get());
lastScrollX.set(sx);
}
});
}
Espresso.unregisterIdlingResources(idler);
}
use of android.support.test.espresso.ViewAssertion 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));
}
});
}
use of android.support.test.espresso.ViewAssertion 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));
}
});
}
use of android.support.test.espresso.ViewAssertion in project android_frameworks_base by AOSPA.
the class SuggestionsPopupWindowTest method testTextAppearanceInSuggestionsPopup.
@SmallTest
public void testTextAppearanceInSuggestionsPopup() {
final String text = "abc def ghi";
final String[] singleWordCandidates = { "DEF", "Def" };
final SuggestionSpan suggestionSpan = new SuggestionSpan(getActivity(), singleWordCandidates, SuggestionSpan.FLAG_MISSPELLED);
final String[] multiWordCandidates = { "ABC DEF GHI", "Abc Def Ghi" };
final SuggestionSpan multiWordSuggestionSpan = new SuggestionSpan(getActivity(), multiWordCandidates, SuggestionSpan.FLAG_MISSPELLED);
final TypedArray array = getActivity().obtainStyledAttributes(com.android.internal.R.styleable.Theme);
final int id = array.getResourceId(com.android.internal.R.styleable.Theme_textEditSuggestionHighlightStyle, 0);
array.recycle();
final TextAppearanceSpan expectedSpan = new TextAppearanceSpan(getActivity(), id);
final TextPaint tmpTp = new TextPaint();
expectedSpan.updateDrawState(tmpTp);
final int expectedHighlightTextColor = tmpTp.getColor();
final float expectedHighlightTextSize = tmpTp.getTextSize();
final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
// *XX* means that XX is highlighted.
for (int i = 0; i < 2; i++) {
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).perform(replaceText(text));
setSuggestionSpan(suggestionSpan, text.indexOf('d'), text.indexOf('f') + 1);
setSuggestionSpan(multiWordSuggestionSpan, 0, text.length());
showSuggestionsPopup();
assertSuggestionsPopupIsDisplayed();
assertSuggestionsPopupContainsItem("abc DEF ghi");
assertSuggestionsPopupContainsItem("abc Def ghi");
assertSuggestionsPopupContainsItem("ABC DEF GHI");
assertSuggestionsPopupContainsItem("Abc Def Ghi");
assertSuggestionsPopupContainsItem(getActivity().getString(com.android.internal.R.string.delete));
onSuggestionsPopup().check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException e) {
final ListView listView = (ListView) view.findViewById(com.android.internal.R.id.suggestionContainer);
assertNotNull(listView);
final int childNum = listView.getChildCount();
assertEquals(singleWordCandidates.length + multiWordCandidates.length, childNum);
for (int j = 0; j < childNum; j++) {
final TextView suggestion = (TextView) listView.getChildAt(j);
assertNotNull(suggestion);
final Spanned spanned = (Spanned) suggestion.getText();
assertNotNull(spanned);
// Check that the suggestion item order is kept.
final String expectedText;
if (j < singleWordCandidates.length) {
expectedText = "abc " + singleWordCandidates[j] + " ghi";
} else {
expectedText = multiWordCandidates[j - singleWordCandidates.length];
}
assertEquals(expectedText, spanned.toString());
// Check that the text is highlighted with correct color and text size.
final TextAppearanceSpan[] taSpan = spanned.getSpans(text.indexOf('d'), text.indexOf('f') + 1, TextAppearanceSpan.class);
assertEquals(1, taSpan.length);
TextPaint tp = new TextPaint();
taSpan[0].updateDrawState(tp);
assertEquals(expectedHighlightTextColor, tp.getColor());
assertEquals(expectedHighlightTextSize, tp.getTextSize());
// Check the correct part of the text is highlighted.
final int expectedStart;
final int expectedEnd;
if (j < singleWordCandidates.length) {
expectedStart = text.indexOf('d');
expectedEnd = text.indexOf('f') + 1;
} else {
expectedStart = 0;
expectedEnd = text.length();
}
assertEquals(expectedStart, spanned.getSpanStart(taSpan[0]));
assertEquals(expectedEnd, spanned.getSpanEnd(taSpan[0]));
}
}
});
pressBack();
onView(withId(R.id.textview)).inRoot(withDecorView(is(getActivity().getWindow().getDecorView()))).perform(clearText());
}
}
Aggregations