Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4042903 authored by Nikita Dubrovsky's avatar Nikita Dubrovsky Committed by Android (Google) Code Review
Browse files

Merge "Add test case to TextViewActivityMouseTest for selection handles"

parents c23eeb81 65ed05f0
Loading
Loading
Loading
Loading
+26 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.widget;
import static android.widget.espresso.ContextMenuUtils.assertContextMenuContainsItemDisabled;
import static android.widget.espresso.ContextMenuUtils.assertContextMenuContainsItemEnabled;
import static android.widget.espresso.ContextMenuUtils.assertContextMenuIsNotDisplayed;
import static android.widget.espresso.DragHandleUtils.assertNoSelectionHandles;
import static android.widget.espresso.DragHandleUtils.onHandleView;
import static android.widget.espresso.TextViewActions.mouseClick;
import static android.widget.espresso.TextViewActions.mouseClickOnTextAtIndex;
@@ -87,11 +88,6 @@ public class TextViewActivityMouseTest {
                mouseDragOnText(helloWorld.indexOf("llo"), helloWorld.indexOf("ld!")));
        onView(withId(R.id.textview)).check(hasSelection("llo wor"));

        onHandleView(com.android.internal.R.id.selection_start_handle)
                .check(matches(isDisplayed()));
        onHandleView(com.android.internal.R.id.selection_end_handle)
                .check(matches(isDisplayed()));

        onView(withId(R.id.textview)).perform(mouseClickOnTextAtIndex(helloWorld.indexOf("w")));
        onView(withId(R.id.textview)).check(hasSelection(""));
    }
@@ -393,4 +389,29 @@ public class TextViewActivityMouseTest {
                mouseTripleClickAndDragOnText(text.indexOf("ird"), text.indexOf("First")));
        onView(withId(R.id.textview)).check(hasSelection(text));
    }

    @Test
    public void testSelectionHandlesDisplay() {
        final String helloWorld = "Hello world!";
        onView(withId(R.id.textview)).perform(mouseClick());
        onView(withId(R.id.textview)).perform(replaceText(helloWorld));

        onView(withId(R.id.textview)).perform(
                mouseDragOnText(helloWorld.indexOf("llo"), helloWorld.indexOf("ld!")));
        onView(withId(R.id.textview)).check(hasSelection("llo wor"));

        // Confirm that selection handles are shown when there is a selection.
        onHandleView(com.android.internal.R.id.selection_start_handle)
                .check(matches(isDisplayed()));
        onHandleView(com.android.internal.R.id.selection_end_handle)
                .check(matches(isDisplayed()));

        onView(withId(R.id.textview)).perform(mouseClickOnTextAtIndex(helloWorld.indexOf("w")));
        onView(withId(R.id.textview)).check(hasSelection(""));

        // Confirm that the selection handles are not shown when there is no selection. This
        // assertion is slow so we only do it in this one test case. The rest of the tests just
        // assert via `hasSelection("")`.
        assertNoSelectionHandles();
    }
}