package android.widget;
import static android.widget.espresso.CustomViewActions.longPressAtRelativeCoordinates;
-import static android.support.test.espresso.action.ViewActions.longClick;
import static android.widget.espresso.DragHandleUtils.assertNoSelectionHandles;
import static android.widget.espresso.DragHandleUtils.onHandleView;
import static android.widget.espresso.TextViewActions.clickOnTextAtIndex;
import static android.widget.espresso.FloatingToolbarEspressoUtils.sleepForFloatingToolbarPopup;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
+import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.pressKey;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static org.hamcrest.Matchers.anyOf;
+import static org.hamcrest.Matchers.is;
import android.widget.espresso.CustomViewActions.RelativeCoordinatesProvider;
-import com.android.frameworks.coretests.R;
import android.support.test.espresso.action.EspressoKey;
import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.test.suitebuilder.annotation.MediumTest;
import android.text.Selection;
import android.text.Spannable;
import android.text.InputType;
import android.view.KeyEvent;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.is;
+import com.android.frameworks.coretests.R;
/**
* Tests the TextView widget from an Activity
*/
+@MediumTest
public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextViewActivity>{
public TextViewActivityTest() {
getActivity();
}
- @SmallTest
public void testTypedTextIsOnScreen() throws Exception {
final String helloWorld = "Hello world!";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(matches(withText(helloWorld)));
}
- @SmallTest
public void testPositionCursorAtTextAtIndex() throws Exception {
final String helloWorld = "Hello world!";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(matches(withText("Hello orld!")));
}
- @SmallTest
public void testPositionCursorAtTextAtIndex_arabic() throws Exception {
// Arabic text. The expected cursorable boundary is
// | \u0623 \u064F | \u067A | \u0633 \u0652 |
onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(5));
}
- @SmallTest
public void testPositionCursorAtTextAtIndex_devanagari() throws Exception {
// Devanagari text. The expected cursorable boundary is | \u0915 \u093E |
final String text = "\u0915\u093E";
onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(2));
}
- @SmallTest
public void testLongPressToSelect() throws Exception {
final String helloWorld = "Hello Kirk!";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("Kirk"));
}
- @SmallTest
public void testLongPressEmptySpace() throws Exception {
final String helloWorld = "Hello big round sun!";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(helloWorld.length()));
}
- @SmallTest
public void testLongPressAndDragToSelect() throws Exception {
final String helloWorld = "Hello little handsome boy!";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("little handsome"));
}
- @SmallTest
public void testLongPressAndDragToSelect_emoji() throws Exception {
final String text = "\uD83D\uDE00\uD83D\uDE01\uD83D\uDE02\uD83D\uDE03";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("\uD83D\uDE01"));
}
- @SmallTest
public void testDragAndDrop() throws Exception {
final String text = "abc def ghi.";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(matches(withText(text)));
}
- @SmallTest
public void testDoubleTapToSelect() throws Exception {
final String helloWorld = "Hello SuetYi!";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("SuetYi"));
}
- @SmallTest
public void testDoubleTapAndDragToSelect() throws Exception {
final String helloWorld = "Hello young beautiful girl!";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("young beautiful"));
}
- @SmallTest
public void testDoubleTapAndDragToSelect_multiLine() throws Exception {
final String helloWorld = "abcd\n" + "efg\n" + "hijklm\n" + "nop";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijklm"));
}
- @SmallTest
public void testSelectBackwordsByTouch() throws Exception {
final String helloWorld = "Hello king of the Jungle!";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("king of the"));
}
- @SmallTest
public void testToolbarAppearsAfterSelection() throws Exception {
final String text = "Toolbar appears after selection.";
onView(withId(R.id.textview)).perform(click());
assertFloatingToolbarIsNotDisplayed();
}
- @SmallTest
public void testToolbarAppearsAfterSelection_withFirstStringLtrAlgorithmAndRtlHint()
throws Exception {
// after the hint layout change, the floating toolbar was not visible in the case below
assertFloatingToolbarIsDisplayed();
}
- @SmallTest
public void testToolbarAndInsertionHandle() throws Exception {
final String text = "text";
onView(withId(R.id.textview)).perform(click());
getActivity().getString(com.android.internal.R.string.cut));
}
- @SmallTest
public void testToolbarAndSelectionHandle() throws Exception {
final String text = "abcd efg hijk";
onView(withId(R.id.textview)).perform(click());
getActivity().getString(com.android.internal.R.string.cut));
}
- @SmallTest
public void testInsertionHandle() throws Exception {
final String text = "abcd efg hijk ";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f")));
}
- @SmallTest
public void testInsertionHandle_multiLine() throws Exception {
final String text = "abcd\n" + "efg\n" + "hijk\n";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f")));
}
- @SmallTest
public void testSelectionHandles() throws Exception {
final String text = "abcd efg hijk lmn";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk"));
}
- @SmallTest
public void testSelectionHandles_bidi() throws Exception {
final String text = "abc \u0621\u0622\u0623 def";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("abc \u0621\u0622\u0623 def"));
}
- @SmallTest
public void testSelectionHandles_multiLine() throws Exception {
final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn\nopqr"));
}
- @SmallTest
public void testSelectionHandles_multiLine_rtl() throws Exception {
// Arabic text.
final String text = "\u062A\u062B\u062C\n" + "\u062D\u062E\u062F\n"
}
- @SmallTest
public void testSelectionHandles_doesNotPassAnotherHandle() throws Exception {
final String text = "abcd efg hijk lmn";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("e"));
}
- @SmallTest
public void testSelectionHandles_doesNotPassAnotherHandle_multiLine() throws Exception {
final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("h"));
}
- @SmallTest
public void testSelectionHandles_snapToWordBoundary() throws Exception {
final String text = "abcd efg hijk lmn opqr";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("hijk lmn opq"));
}
- @SmallTest
public void testSelectionHandles_snapToWordBoundary_multiLine() throws Exception {
final String text = "abcd efg\n" + "hijk lmn\n" + "opqr stu";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).check(hasSelection("hijk"));
}
- @SmallTest
public void testSetSelectionAndActionMode() throws Exception {
final String text = "abc def";
onView(withId(R.id.textview)).perform(click());
getActivity().getString(com.android.internal.R.string.copy));
}
- @SmallTest
public void testTransientState() throws Exception {
final String text = "abc def";
onView(withId(R.id.textview)).perform(click());