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

Commit 6264cbdd authored by Abodunrinwa Toki's avatar Abodunrinwa Toki
Browse files

Implement assertActionModeNotStarted.

Bug: 67023680
Test: bit FrameworksCoreTests:android.widget.TextViewActivityTest\#testSetSelectionAndActionMode
Change-Id: I96f7ffcd9c26535f152a5fda05a45f468cc3600d
parent 993ebff1
Loading
Loading
Loading
Loading
+14 −3
Original line number Original line Diff line number Diff line
@@ -49,6 +49,11 @@ import static junit.framework.Assert.assertTrue;


import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.is;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;


import android.app.Activity;
import android.app.Activity;
import android.app.Instrumentation;
import android.app.Instrumentation;
@@ -633,15 +638,21 @@ public class TextViewActivityTest {


    @Test
    @Test
    public void testSetSelectionAndActionMode() throws Throwable {
    public void testSetSelectionAndActionMode() throws Throwable {
        final TextView textView = mActivity.findViewById(R.id.textview);
        final ActionMode.Callback amCallback = mock(ActionMode.Callback.class);
        when(amCallback.onCreateActionMode(any(ActionMode.class), any(Menu.class)))
                .thenReturn(true);
        when(amCallback.onPrepareActionMode(any(ActionMode.class), any(Menu.class)))
                .thenReturn(true);
        textView.setCustomSelectionActionModeCallback(amCallback);

        final String text = "abc def";
        final String text = "abc def";
        onView(withId(R.id.textview)).perform(replaceText(text));
        onView(withId(R.id.textview)).perform(replaceText(text));

        final TextView textView = mActivity.findViewById(R.id.textview);
        mActivityRule.runOnUiThread(
        mActivityRule.runOnUiThread(
                () -> Selection.setSelection((Spannable) textView.getText(), 0, 3));
                () -> Selection.setSelection((Spannable) textView.getText(), 0, 3));
        mInstrumentation.waitForIdleSync();
        mInstrumentation.waitForIdleSync();
        // Don't automatically start action mode.
        // Don't automatically start action mode.
        // TODO: Implement assertActionModeNotStarted()
        verify(amCallback, never()).onCreateActionMode(any(ActionMode.class), any(Menu.class));
        // Make sure that "Select All" is included in the selection action mode when the entire text
        // Make sure that "Select All" is included in the selection action mode when the entire text
        // is not selected.
        // is not selected.
        onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('e')));
        onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('e')));