use of android.support.test.espresso.NoMatchingViewException in project android_frameworks_base by ResurrectionRemix.
the class TextViewAssertions method hasInsertionPointerAtIndex.
/**
* Returns a {@link ViewAssertion} that asserts that the text view insertion pointer is at
* a specified index.<br>
* <br>
* View constraints:
* <ul>
* <li>must be a text view displayed on screen
* <ul>
*
* @param index A matcher representing the expected index.
*/
public static ViewAssertion hasInsertionPointerAtIndex(final Matcher<Integer> index) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException exception) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
int selectionStart = textView.getSelectionStart();
int selectionEnd = textView.getSelectionEnd();
try {
assertThat(selectionStart, index);
assertThat(selectionEnd, index);
} catch (IndexOutOfBoundsException e) {
throw new AssertionFailedError(e.getMessage());
}
} else {
throw new AssertionFailedError("TextView not found");
}
}
};
}
use of android.support.test.espresso.NoMatchingViewException in project android_frameworks_base by DirtyUnicorns.
the class TextViewAssertions method hasInsertionPointerAtIndex.
/**
* Returns a {@link ViewAssertion} that asserts that the text view insertion pointer is at
* a specified index.<br>
* <br>
* View constraints:
* <ul>
* <li>must be a text view displayed on screen
* <ul>
*
* @param index A matcher representing the expected index.
*/
public static ViewAssertion hasInsertionPointerAtIndex(final Matcher<Integer> index) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException exception) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
int selectionStart = textView.getSelectionStart();
int selectionEnd = textView.getSelectionEnd();
try {
assertThat(selectionStart, index);
assertThat(selectionEnd, index);
} catch (IndexOutOfBoundsException e) {
throw new AssertionFailedError(e.getMessage());
}
} else {
throw new AssertionFailedError("TextView not found");
}
}
};
}
use of android.support.test.espresso.NoMatchingViewException in project mobile-center-sdk-android by Microsoft.
the class EspressoUtils method waitFor.
public static ViewInteraction waitFor(final ViewInteraction viewInteraction, final long millis) throws InterruptedException {
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final View[] found = new View[] { null };
while (System.currentTimeMillis() < endTime) {
try {
viewInteraction.check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
found[0] = view;
}
});
} catch (NoMatchingRootException ignored) {
}
if (found[0] != null)
return viewInteraction;
Thread.sleep(CHECK_DELAY);
}
Assert.fail();
return viewInteraction;
}
use of android.support.test.espresso.NoMatchingViewException in project android_frameworks_base by AOSPA.
the class TextViewAssertions method hasInsertionPointerAtIndex.
/**
* Returns a {@link ViewAssertion} that asserts that the text view insertion pointer is at
* a specified index.<br>
* <br>
* View constraints:
* <ul>
* <li>must be a text view displayed on screen
* <ul>
*
* @param index A matcher representing the expected index.
*/
public static ViewAssertion hasInsertionPointerAtIndex(final Matcher<Integer> index) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException exception) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
int selectionStart = textView.getSelectionStart();
int selectionEnd = textView.getSelectionEnd();
try {
assertThat(selectionStart, index);
assertThat(selectionEnd, index);
} catch (IndexOutOfBoundsException e) {
throw new AssertionFailedError(e.getMessage());
}
} else {
throw new AssertionFailedError("TextView not found");
}
}
};
}
use of android.support.test.espresso.NoMatchingViewException in project platform_frameworks_base by android.
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