Merge "Prevent exception when surrounding text retrieval" into rvc-dev

This commit is contained in:
Wale Ogunwale
2020-07-21 01:03:03 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 4 deletions

View File

@@ -264,6 +264,25 @@ public class EditorInfoTest {
InputConnection.GET_TEXT_WITH_STYLES)));
}
@Test
public void surroundingTextRetrieval_writeToParcel_noException() {
StringBuilder sb = new StringBuilder("abcdefg");
Parcel parcel = Parcel.obtain();
EditorInfo editorInfo = new EditorInfo();
editorInfo.initialSelStart = 2;
editorInfo.initialSelEnd = 5;
editorInfo.inputType = EditorInfo.TYPE_CLASS_TEXT;
editorInfo.setInitialSurroundingText(sb);
sb.setLength(0);
editorInfo.writeToParcel(parcel, 0);
try {
editorInfo.getInitialTextBeforeCursor(60, 1);
fail("Test shouldn't have exception");
} catch (AssertionError e) { }
}
private static void assertExpectedTextLength(EditorInfo editorInfo,
@Nullable Integer expectBeforeCursorLength, @Nullable Integer expectSelectionLength,
@Nullable Integer expectAfterCursorLength) {