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

Commit 834f257f authored by Abodunrinwa Toki's avatar Abodunrinwa Toki Committed by Android (Google) Code Review
Browse files

Merge "Regression test: Menu item title updates." into oc-dev

parents 20e1c8c0 7b97180d
Loading
Loading
Loading
Loading
+45 −5
Original line number Diff line number Diff line
@@ -50,14 +50,11 @@ import static org.hamcrest.Matchers.is;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.text.TextUtils;
import android.text.Spanned;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.ViewAssertion;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.textclassifier.TextClassificationManager;
import android.view.textclassifier.TextClassifier;
import android.widget.espresso.CustomViewActions.RelativeCoordinatesProvider;
@@ -72,8 +69,6 @@ import android.view.KeyEvent;

import com.android.frameworks.coretests.R;

import junit.framework.AssertionFailedError;

/**
 * Tests the TextView widget from an Activity
 */
@@ -694,6 +689,51 @@ public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextV
        assertFalse(textView.hasTransientState());
    }

    public void testResetMenuItemTitle() throws Exception {
        getActivity().getSystemService(TextClassificationManager.class).setTextClassifier(null);
        final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
        final int itemId = 1;
        final String title1 = " AFIGBO";
        final int index = title1.indexOf('I');
        final String title2 = title1.substring(index);
        final String[] title = new String[]{title1};
        textView.post(() -> textView.setCustomSelectionActionModeCallback(
                new ActionMode.Callback() {
                    @Override
                    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                        return true;
                    }

                    @Override
                    public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
                        menu.removeItem(itemId);
                        menu.add(Menu.NONE /* group */, itemId, 0 /* order */, title[0]);
                        return true;
                    }

                    @Override
                    public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
                        return false;
                    }

                    @Override
                    public void onDestroyActionMode(ActionMode actionMode) {
                    }
                }));
        onView(withId(R.id.textview)).perform(replaceText(title1));
        onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(index));
        sleepForFloatingToolbarPopup();
        assertFloatingToolbarContainsItem(title1);

        // Change the menu item title.
        title[0] = title2;
        // Change the selection to invalidate the action mode without restarting it.
        onHandleView(com.android.internal.R.id.selection_start_handle)
                .perform(dragHandle(textView, Handle.SELECTION_START, index));
        sleepForFloatingToolbarPopup();
        assertFloatingToolbarContainsItem(title2);
    }

    public void testAssistItemIsAtIndexZero() throws Exception {
        getActivity().getSystemService(TextClassificationManager.class).setTextClassifier(null);
        final TextView textView = (TextView) getActivity().findViewById(R.id.textview);