Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package android.widget; |
| 18 | |
| 19 | import static android.support.test.espresso.Espresso.onView; |
| 20 | import static android.support.test.espresso.action.ViewActions.click; |
Abodunrinwa Toki | c5b54ba | 2016-10-25 10:21:36 +0100 | [diff] [blame] | 21 | import static android.support.test.espresso.action.ViewActions.longClick; |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 22 | import static android.support.test.espresso.action.ViewActions.pressKey; |
Keisuke Kuroyanagi | 2645414 | 2015-12-02 15:04:57 -0800 | [diff] [blame] | 23 | import static android.support.test.espresso.action.ViewActions.replaceText; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 24 | import static android.support.test.espresso.assertion.ViewAssertions.matches; |
Abodunrinwa Toki | fc6e25e | 2015-11-30 19:45:32 +0000 | [diff] [blame] | 25 | import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 26 | import static android.support.test.espresso.matcher.ViewMatchers.withId; |
| 27 | import static android.support.test.espresso.matcher.ViewMatchers.withText; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 28 | import static android.widget.espresso.CustomViewActions.longPressAtRelativeCoordinates; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 29 | import static android.widget.espresso.DragHandleUtils.onHandleView; |
Richard Ledley | 26b8722 | 2017-11-30 10:54:08 +0000 | [diff] [blame] | 30 | import static android.widget.espresso.FloatingToolbarEspressoUtils |
| 31 | .assertFloatingToolbarContainsItem; |
| 32 | import static android.widget.espresso.FloatingToolbarEspressoUtils |
| 33 | .assertFloatingToolbarDoesNotContainItem; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 34 | import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarIsDisplayed; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 35 | import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarItemIndex; |
| 36 | import static android.widget.espresso.FloatingToolbarEspressoUtils.clickFloatingToolbarItem; |
| 37 | import static android.widget.espresso.FloatingToolbarEspressoUtils.sleepForFloatingToolbarPopup; |
| 38 | import static android.widget.espresso.TextViewActions.Handle; |
| 39 | import static android.widget.espresso.TextViewActions.clickOnTextAtIndex; |
| 40 | import static android.widget.espresso.TextViewActions.doubleClickOnTextAtIndex; |
| 41 | import static android.widget.espresso.TextViewActions.doubleTapAndDragOnText; |
| 42 | import static android.widget.espresso.TextViewActions.dragHandle; |
| 43 | import static android.widget.espresso.TextViewActions.longPressAndDragOnText; |
| 44 | import static android.widget.espresso.TextViewActions.longPressOnTextAtIndex; |
| 45 | import static android.widget.espresso.TextViewAssertions.doesNotHaveStyledText; |
| 46 | import static android.widget.espresso.TextViewAssertions.hasInsertionPointerAtIndex; |
| 47 | import static android.widget.espresso.TextViewAssertions.hasSelection; |
| 48 | |
Abodunrinwa Toki | f299fc0 | 2018-05-17 17:36:25 +0100 | [diff] [blame] | 49 | import static junit.framework.Assert.assertEquals; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 50 | import static junit.framework.Assert.assertFalse; |
| 51 | import static junit.framework.Assert.assertTrue; |
| 52 | |
Abodunrinwa Toki | c5b54ba | 2016-10-25 10:21:36 +0100 | [diff] [blame] | 53 | import static org.hamcrest.Matchers.anyOf; |
| 54 | import static org.hamcrest.Matchers.is; |
Abodunrinwa Toki | 6264cbd | 2017-11-06 15:12:52 +0000 | [diff] [blame] | 55 | import static org.mockito.Matchers.any; |
| 56 | import static org.mockito.Mockito.mock; |
| 57 | import static org.mockito.Mockito.never; |
| 58 | import static org.mockito.Mockito.verify; |
| 59 | import static org.mockito.Mockito.when; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 60 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 61 | import android.app.Activity; |
| 62 | import android.app.Instrumentation; |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 63 | import android.content.ClipData; |
| 64 | import android.content.ClipboardManager; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 65 | import android.support.test.InstrumentationRegistry; |
| 66 | import android.support.test.espresso.action.EspressoKey; |
| 67 | import android.support.test.filters.MediumTest; |
| 68 | import android.support.test.rule.ActivityTestRule; |
| 69 | import android.support.test.runner.AndroidJUnit4; |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 70 | import android.support.test.uiautomator.UiDevice; |
Abodunrinwa Toki | 89550e8 | 2017-10-31 03:46:46 +0000 | [diff] [blame] | 71 | import android.test.suitebuilder.annotation.Suppress; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 72 | import android.text.InputType; |
| 73 | import android.text.Selection; |
| 74 | import android.text.Spannable; |
Richard Ledley | 26b8722 | 2017-11-30 10:54:08 +0000 | [diff] [blame] | 75 | import android.text.SpannableString; |
| 76 | import android.text.method.LinkMovementMethod; |
Abodunrinwa Toki | 6eecdc9 | 2017-04-11 05:15:25 +0100 | [diff] [blame] | 77 | import android.view.ActionMode; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 78 | import android.view.KeyEvent; |
Abodunrinwa Toki | 6eecdc9 | 2017-04-11 05:15:25 +0100 | [diff] [blame] | 79 | import android.view.Menu; |
| 80 | import android.view.MenuItem; |
Abodunrinwa Toki | f299fc0 | 2018-05-17 17:36:25 +0100 | [diff] [blame] | 81 | import android.view.textclassifier.SelectionEvent; |
Abodunrinwa Toki | 6eecdc9 | 2017-04-11 05:15:25 +0100 | [diff] [blame] | 82 | import android.view.textclassifier.TextClassificationManager; |
| 83 | import android.view.textclassifier.TextClassifier; |
Richard Ledley | 26b8722 | 2017-11-30 10:54:08 +0000 | [diff] [blame] | 84 | import android.view.textclassifier.TextLinks; |
Abodunrinwa Toki | 080c854 | 2018-03-27 00:04:06 +0100 | [diff] [blame] | 85 | import android.view.textclassifier.TextLinksParams; |
Abodunrinwa Toki | 9479d3e | 2016-03-09 19:41:41 +0000 | [diff] [blame] | 86 | import android.widget.espresso.CustomViewActions.RelativeCoordinatesProvider; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 87 | |
Abodunrinwa Toki | c5b54ba | 2016-10-25 10:21:36 +0100 | [diff] [blame] | 88 | import com.android.frameworks.coretests.R; |
Keisuke Kuroyanagi | e27e085 | 2016-01-08 19:05:27 +0900 | [diff] [blame] | 89 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 90 | import org.junit.Before; |
| 91 | import org.junit.Rule; |
| 92 | import org.junit.Test; |
| 93 | import org.junit.runner.RunWith; |
| 94 | |
Abodunrinwa Toki | f299fc0 | 2018-05-17 17:36:25 +0100 | [diff] [blame] | 95 | import java.util.ArrayList; |
| 96 | import java.util.List; |
| 97 | |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 98 | /** |
| 99 | * Tests the TextView widget from an Activity |
| 100 | */ |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 101 | @RunWith(AndroidJUnit4.class) |
Abodunrinwa Toki | c5b54ba | 2016-10-25 10:21:36 +0100 | [diff] [blame] | 102 | @MediumTest |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 103 | public class TextViewActivityTest { |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 104 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 105 | @Rule |
| 106 | public ActivityTestRule<TextViewActivity> mActivityRule = new ActivityTestRule<>( |
| 107 | TextViewActivity.class); |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 108 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 109 | private Activity mActivity; |
| 110 | private Instrumentation mInstrumentation; |
| 111 | |
| 112 | @Before |
| 113 | public void setUp() { |
| 114 | mActivity = mActivityRule.getActivity(); |
| 115 | mInstrumentation = InstrumentationRegistry.getInstrumentation(); |
| 116 | mActivity.getSystemService(TextClassificationManager.class) |
Abodunrinwa Toki | 6eecdc9 | 2017-04-11 05:15:25 +0100 | [diff] [blame] | 117 | .setTextClassifier(TextClassifier.NO_OP); |
Abodunrinwa Toki | c9e924e | 2015-10-08 12:01:35 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 120 | @Test |
| 121 | public void testTypedTextIsOnScreen() { |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 122 | final String helloWorld = "Hello world!"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 123 | // We use replaceText instead of typeTextIntoFocusedView to input text to avoid |
| 124 | // unintentional interactions with software keyboard. |
| 125 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 126 | |
| 127 | onView(withId(R.id.textview)).check(matches(withText(helloWorld))); |
| 128 | } |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 129 | @Test |
| 130 | public void testPositionCursorAtTextAtIndex() { |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 131 | final String helloWorld = "Hello world!"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 132 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 133 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(helloWorld.indexOf("world"))); |
| 134 | |
| 135 | // Delete text at specified index and see if we got the right one. |
| 136 | onView(withId(R.id.textview)).perform(pressKey(KeyEvent.KEYCODE_FORWARD_DEL)); |
| 137 | onView(withId(R.id.textview)).check(matches(withText("Hello orld!"))); |
| 138 | } |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 139 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 140 | @Test |
| 141 | public void testPositionCursorAtTextAtIndex_arabic() { |
Keisuke Kuroyanagi | e27e085 | 2016-01-08 19:05:27 +0900 | [diff] [blame] | 142 | // Arabic text. The expected cursorable boundary is |
| 143 | // | \u0623 \u064F | \u067A | \u0633 \u0652 | |
| 144 | final String text = "\u0623\u064F\u067A\u0633\u0652"; |
Keisuke Kuroyanagi | e27e085 | 2016-01-08 19:05:27 +0900 | [diff] [blame] | 145 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 146 | |
| 147 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(0)); |
| 148 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(0)); |
| 149 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(1)); |
| 150 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(0), is(2)))); |
| 151 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(2)); |
| 152 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(2)); |
| 153 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(3)); |
| 154 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(3)); |
| 155 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(4)); |
| 156 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(3), is(5)))); |
| 157 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(5)); |
| 158 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(5)); |
| 159 | } |
| 160 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 161 | @Test |
| 162 | public void testPositionCursorAtTextAtIndex_devanagari() { |
Keisuke Kuroyanagi | e27e085 | 2016-01-08 19:05:27 +0900 | [diff] [blame] | 163 | // Devanagari text. The expected cursorable boundary is | \u0915 \u093E | |
| 164 | final String text = "\u0915\u093E"; |
Keisuke Kuroyanagi | e27e085 | 2016-01-08 19:05:27 +0900 | [diff] [blame] | 165 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 166 | |
| 167 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(0)); |
| 168 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(0)); |
| 169 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(1)); |
| 170 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(0), is(2)))); |
| 171 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(2)); |
| 172 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(2)); |
| 173 | } |
| 174 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 175 | @Test |
| 176 | public void testLongPressToSelect() { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 177 | final String helloWorld = "Hello Kirk!"; |
| 178 | onView(withId(R.id.textview)).perform(click()); |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 179 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 180 | onView(withId(R.id.textview)).perform( |
| 181 | longPressOnTextAtIndex(helloWorld.indexOf("Kirk"))); |
| 182 | |
| 183 | onView(withId(R.id.textview)).check(hasSelection("Kirk")); |
| 184 | } |
| 185 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 186 | @Test |
| 187 | public void testLongPressEmptySpace() { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 188 | final String helloWorld = "Hello big round sun!"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 189 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 190 | // Move cursor somewhere else |
| 191 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(helloWorld.indexOf("big"))); |
| 192 | // Long-press at end of line. |
Abodunrinwa Toki | 9479d3e | 2016-03-09 19:41:41 +0000 | [diff] [blame] | 193 | onView(withId(R.id.textview)).perform(longPressAtRelativeCoordinates( |
| 194 | RelativeCoordinatesProvider.HorizontalReference.RIGHT, -5, |
| 195 | RelativeCoordinatesProvider.VerticalReference.CENTER, 0)); |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 196 | |
| 197 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(helloWorld.length())); |
| 198 | } |
| 199 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 200 | @Test |
| 201 | public void testLongPressAndDragToSelect() { |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 202 | final String helloWorld = "Hello little handsome boy!"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 203 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 204 | onView(withId(R.id.textview)).perform( |
| 205 | longPressAndDragOnText(helloWorld.indexOf("little"), helloWorld.indexOf(" boy!"))); |
| 206 | |
| 207 | onView(withId(R.id.textview)).check(hasSelection("little handsome")); |
| 208 | } |
| 209 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 210 | @Test |
| 211 | public void testLongPressAndDragToSelect_emoji() { |
Keisuke Kuroyanagi | 133dfc0 | 2016-07-21 18:07:23 +0900 | [diff] [blame] | 212 | final String text = "\uD83D\uDE00\uD83D\uDE01\uD83D\uDE02\uD83D\uDE03"; |
Keisuke Kuroyanagi | 133dfc0 | 2016-07-21 18:07:23 +0900 | [diff] [blame] | 213 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 214 | |
| 215 | onView(withId(R.id.textview)).perform(longPressAndDragOnText(4, 6)); |
| 216 | onView(withId(R.id.textview)).check(hasSelection("\uD83D\uDE02")); |
| 217 | |
| 218 | onView(withId(R.id.textview)).perform(click()); |
| 219 | |
| 220 | onView(withId(R.id.textview)).perform(longPressAndDragOnText(4, 2)); |
| 221 | onView(withId(R.id.textview)).check(hasSelection("\uD83D\uDE01")); |
| 222 | } |
| 223 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 224 | @Test |
| 225 | public void testDragAndDrop() { |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 226 | final String text = "abc def ghi."; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 227 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 228 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf("e"))); |
| 229 | |
| 230 | onView(withId(R.id.textview)).perform( |
| 231 | longPressAndDragOnText(text.indexOf("e"), text.length())); |
| 232 | |
| 233 | onView(withId(R.id.textview)).check(matches(withText("abc ghi.def"))); |
| 234 | onView(withId(R.id.textview)).check(hasSelection("")); |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 235 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex("abc ghi.def".length())); |
Keisuke Kuroyanagi | fae4578 | 2016-02-24 18:53:00 -0800 | [diff] [blame] | 236 | |
| 237 | // Test undo returns to the original state. |
| 238 | onView(withId(R.id.textview)).perform(pressKey( |
| 239 | (new EspressoKey.Builder()).withCtrlPressed(true).withKeyCode(KeyEvent.KEYCODE_Z) |
| 240 | .build())); |
| 241 | onView(withId(R.id.textview)).check(matches(withText(text))); |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 244 | @Test |
| 245 | public void testDoubleTapToSelect() { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 246 | final String helloWorld = "Hello SuetYi!"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 247 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
| 248 | |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 249 | onView(withId(R.id.textview)).perform( |
| 250 | doubleClickOnTextAtIndex(helloWorld.indexOf("SuetYi"))); |
| 251 | |
| 252 | onView(withId(R.id.textview)).check(hasSelection("SuetYi")); |
| 253 | } |
| 254 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 255 | @Test |
| 256 | public void testDoubleTapAndDragToSelect() { |
| 257 | final String helloWorld = "Hello young beautiful person!"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 258 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 259 | onView(withId(R.id.textview)).perform(doubleTapAndDragOnText(helloWorld.indexOf("young"), |
| 260 | helloWorld.indexOf(" person!"))); |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 261 | |
| 262 | onView(withId(R.id.textview)).check(hasSelection("young beautiful")); |
| 263 | } |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 264 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 265 | @Test |
| 266 | public void testDoubleTapAndDragToSelect_multiLine() { |
Sara Kato | 68c433d | 2016-08-09 14:40:45 +0900 | [diff] [blame] | 267 | final String helloWorld = "abcd\n" + "efg\n" + "hijklm\n" + "nop"; |
Sara Kato | 68c433d | 2016-08-09 14:40:45 +0900 | [diff] [blame] | 268 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
| 269 | onView(withId(R.id.textview)).perform( |
| 270 | doubleTapAndDragOnText(helloWorld.indexOf("m"), helloWorld.indexOf("a"))); |
| 271 | onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijklm")); |
| 272 | } |
| 273 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 274 | @Test |
| 275 | public void testSelectBackwordsByTouch() { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 276 | final String helloWorld = "Hello king of the Jungle!"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 277 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 278 | onView(withId(R.id.textview)).perform( |
| 279 | doubleTapAndDragOnText(helloWorld.indexOf(" Jungle!"), helloWorld.indexOf("king"))); |
| 280 | |
| 281 | onView(withId(R.id.textview)).check(hasSelection("king of the")); |
| 282 | } |
| 283 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 284 | @Test |
| 285 | public void testToolbarAppearsAfterSelection() { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 286 | final String text = "Toolbar appears after selection."; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 287 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 288 | onView(withId(R.id.textview)).perform( |
| 289 | longPressOnTextAtIndex(text.indexOf("appears"))); |
| 290 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 291 | sleepForFloatingToolbarPopup(); |
| 292 | assertFloatingToolbarIsDisplayed(); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 295 | @Test |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 296 | public void testToolbarAppearsAfterSelection_withFirstStringLtrAlgorithmAndRtlHint() |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 297 | throws Throwable { |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 298 | // after the hint layout change, the floating toolbar was not visible in the case below |
| 299 | // this test tests that the floating toolbar is displayed on the screen and is visible to |
| 300 | // user. |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 301 | mActivityRule.runOnUiThread(() -> { |
| 302 | final TextView textView = mActivity.findViewById(R.id.textview); |
| 303 | textView.setTextDirection(TextView.TEXT_DIRECTION_FIRST_STRONG_LTR); |
| 304 | textView.setInputType(InputType.TYPE_CLASS_TEXT); |
| 305 | textView.setSingleLine(true); |
| 306 | textView.setHint("الروبوت"); |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 307 | }); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 308 | mInstrumentation.waitForIdleSync(); |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 309 | |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 310 | onView(withId(R.id.textview)).perform(replaceText("test")); |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 311 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(1)); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 312 | clickFloatingToolbarItem(mActivity.getString(com.android.internal.R.string.cut)); |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 313 | onView(withId(R.id.textview)).perform(longClick()); |
| 314 | sleepForFloatingToolbarPopup(); |
| 315 | |
| 316 | assertFloatingToolbarIsDisplayed(); |
| 317 | } |
| 318 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 319 | @Test |
Richard Ledley | 26b8722 | 2017-11-30 10:54:08 +0000 | [diff] [blame] | 320 | public void testToolbarAppearsAfterLinkClicked() throws Throwable { |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 321 | TextLinks.TextLink textLink = addLinkifiedTextToTextView(R.id.textview); |
| 322 | int position = (textLink.getStart() + textLink.getEnd()) / 2; |
| 323 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(position)); |
| 324 | sleepForFloatingToolbarPopup(); |
| 325 | assertFloatingToolbarIsDisplayed(); |
Richard Ledley | 724eff9 | 2017-12-21 10:11:34 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | @Test |
| 329 | public void testToolbarAppearsAfterLinkClickedNonselectable() throws Throwable { |
Abodunrinwa Toki | 29cb768 | 2018-04-11 21:24:20 +0100 | [diff] [blame] | 330 | final TextView textView = mActivity.findViewById(R.id.nonselectable_textview); |
| 331 | final TextLinks.TextLink textLink = addLinkifiedTextToTextView(R.id.nonselectable_textview); |
| 332 | final int position = (textLink.getStart() + textLink.getEnd()) / 2; |
| 333 | |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 334 | onView(withId(R.id.nonselectable_textview)).perform(clickOnTextAtIndex(position)); |
| 335 | sleepForFloatingToolbarPopup(); |
| 336 | assertFloatingToolbarIsDisplayed(); |
Abodunrinwa Toki | 29cb768 | 2018-04-11 21:24:20 +0100 | [diff] [blame] | 337 | assertTrue(textView.hasSelection()); |
| 338 | |
| 339 | // toggle |
| 340 | onView(withId(R.id.nonselectable_textview)).perform(clickOnTextAtIndex(position)); |
| 341 | sleepForFloatingToolbarPopup(); |
| 342 | assertFalse(textView.hasSelection()); |
| 343 | |
| 344 | onView(withId(R.id.nonselectable_textview)).perform(clickOnTextAtIndex(position)); |
| 345 | sleepForFloatingToolbarPopup(); |
| 346 | assertFloatingToolbarIsDisplayed(); |
| 347 | assertTrue(textView.hasSelection()); |
| 348 | |
| 349 | // click outside |
| 350 | onView(withId(R.id.nonselectable_textview)).perform(clickOnTextAtIndex(0)); |
| 351 | sleepForFloatingToolbarPopup(); |
| 352 | assertFalse(textView.hasSelection()); |
Richard Ledley | 724eff9 | 2017-12-21 10:11:34 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 355 | @Test |
| 356 | public void testSelectionRemovedWhenNonselectableTextLosesFocus() throws Throwable { |
Abodunrinwa Toki | 29cb768 | 2018-04-11 21:24:20 +0100 | [diff] [blame] | 357 | final TextLinks.TextLink textLink = addLinkifiedTextToTextView(R.id.nonselectable_textview); |
| 358 | final int position = (textLink.getStart() + textLink.getEnd()) / 2; |
| 359 | final TextView textView = mActivity.findViewById(R.id.nonselectable_textview); |
| 360 | mActivityRule.runOnUiThread(() -> textView.setFocusableInTouchMode(true)); |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 361 | |
Abodunrinwa Toki | 29cb768 | 2018-04-11 21:24:20 +0100 | [diff] [blame] | 362 | onView(withId(R.id.nonselectable_textview)).perform(clickOnTextAtIndex(position)); |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 363 | sleepForFloatingToolbarPopup(); |
| 364 | assertFloatingToolbarIsDisplayed(); |
Abodunrinwa Toki | 29cb768 | 2018-04-11 21:24:20 +0100 | [diff] [blame] | 365 | assertTrue(textView.hasSelection()); |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 366 | |
Abodunrinwa Toki | 29cb768 | 2018-04-11 21:24:20 +0100 | [diff] [blame] | 367 | mActivityRule.runOnUiThread(() -> textView.clearFocus()); |
| 368 | mInstrumentation.waitForIdleSync(); |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 369 | sleepForFloatingToolbarPopup(); |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 370 | |
Abodunrinwa Toki | 29cb768 | 2018-04-11 21:24:20 +0100 | [diff] [blame] | 371 | assertFalse(textView.hasSelection()); |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | @Test |
| 375 | public void testSelectionRemovedFromNonselectableTextWhenWindowLosesFocus() throws Throwable { |
| 376 | TextLinks.TextLink textLink = addLinkifiedTextToTextView(R.id.nonselectable_textview); |
| 377 | int nonselectablePosition = (textLink.getStart() + textLink.getEnd()) / 2; |
| 378 | TextView nonselectableTextView = mActivity.findViewById(R.id.nonselectable_textview); |
| 379 | |
| 380 | onView(withId(R.id.nonselectable_textview)) |
| 381 | .perform(clickOnTextAtIndex(nonselectablePosition)); |
| 382 | sleepForFloatingToolbarPopup(); |
| 383 | assertFloatingToolbarIsDisplayed(); |
| 384 | assertTrue(nonselectableTextView.hasSelection()); |
| 385 | |
| 386 | UiDevice device = UiDevice.getInstance(mInstrumentation); |
| 387 | device.openNotification(); |
| 388 | Thread.sleep(2000); |
| 389 | device.pressBack(); |
| 390 | Thread.sleep(2000); |
| 391 | |
| 392 | assertFalse(nonselectableTextView.hasSelection()); |
| 393 | } |
| 394 | |
| 395 | private TextLinks.TextLink addLinkifiedTextToTextView(int id) throws Throwable { |
Richard Ledley | 724eff9 | 2017-12-21 10:11:34 +0000 | [diff] [blame] | 396 | TextView textView = mActivity.findViewById(id); |
Richard Ledley | 26b8722 | 2017-11-30 10:54:08 +0000 | [diff] [blame] | 397 | useSystemDefaultTextClassifier(); |
| 398 | TextClassificationManager textClassificationManager = |
| 399 | mActivity.getSystemService(TextClassificationManager.class); |
| 400 | TextClassifier textClassifier = textClassificationManager.getTextClassifier(); |
Abodunrinwa Toki | fe20cdd | 2017-12-12 02:31:25 +0000 | [diff] [blame] | 401 | Spannable content = new SpannableString("Call me at +19148277737"); |
Abodunrinwa Toki | 080c854 | 2018-03-27 00:04:06 +0100 | [diff] [blame] | 402 | TextLinks.Request request = new TextLinks.Request.Builder(content).build(); |
| 403 | TextLinks links = textClassifier.generateLinks(request); |
| 404 | TextLinksParams applyParams = new TextLinksParams.Builder() |
| 405 | .setApplyStrategy(TextLinks.APPLY_STRATEGY_REPLACE) |
| 406 | .build(); |
| 407 | applyParams.apply(content, links); |
Richard Ledley | 26b8722 | 2017-11-30 10:54:08 +0000 | [diff] [blame] | 408 | |
| 409 | mActivityRule.runOnUiThread(() -> { |
| 410 | textView.setText(content); |
| 411 | textView.setMovementMethod(LinkMovementMethod.getInstance()); |
| 412 | }); |
| 413 | mInstrumentation.waitForIdleSync(); |
| 414 | |
| 415 | // Wait for the UI thread to refresh |
| 416 | Thread.sleep(1000); |
| 417 | |
Richard Ledley | 5f2f820 | 2018-02-05 14:55:47 +0000 | [diff] [blame] | 418 | return links.getLinks().iterator().next(); |
Richard Ledley | 26b8722 | 2017-11-30 10:54:08 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | @Test |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 422 | public void testToolbarAndInsertionHandle() { |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 423 | final String text = "text"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 424 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 425 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 426 | |
| 427 | onHandleView(com.android.internal.R.id.insertion_handle).perform(click()); |
| 428 | sleepForFloatingToolbarPopup(); |
| 429 | assertFloatingToolbarIsDisplayed(); |
| 430 | |
| 431 | assertFloatingToolbarContainsItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 432 | mActivity.getString(com.android.internal.R.string.selectAll)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 433 | assertFloatingToolbarDoesNotContainItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 434 | mActivity.getString(com.android.internal.R.string.copy)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 435 | assertFloatingToolbarDoesNotContainItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 436 | mActivity.getString(com.android.internal.R.string.cut)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 439 | @Test |
| 440 | public void testToolbarAndSelectionHandle() { |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 441 | final String text = "abcd efg hijk"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 442 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 443 | |
| 444 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf("f"))); |
| 445 | sleepForFloatingToolbarPopup(); |
| 446 | assertFloatingToolbarIsDisplayed(); |
| 447 | |
| 448 | assertFloatingToolbarContainsItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 449 | mActivity.getString(com.android.internal.R.string.selectAll)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 450 | assertFloatingToolbarContainsItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 451 | mActivity.getString(com.android.internal.R.string.copy)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 452 | assertFloatingToolbarContainsItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 453 | mActivity.getString(com.android.internal.R.string.cut)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 454 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 455 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 456 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 457 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); |
| 458 | sleepForFloatingToolbarPopup(); |
| 459 | assertFloatingToolbarIsDisplayed(); |
| 460 | |
| 461 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 462 | .perform(dragHandle(textView, Handle.SELECTION_END, text.length())); |
| 463 | sleepForFloatingToolbarPopup(); |
| 464 | assertFloatingToolbarIsDisplayed(); |
| 465 | |
| 466 | assertFloatingToolbarDoesNotContainItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 467 | mActivity.getString(com.android.internal.R.string.selectAll)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 468 | assertFloatingToolbarContainsItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 469 | mActivity.getString(com.android.internal.R.string.copy)); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 470 | assertFloatingToolbarContainsItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 471 | mActivity.getString(com.android.internal.R.string.cut)); |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 472 | } |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 473 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 474 | @Test |
| 475 | public void testInsertionHandle() { |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 476 | final String text = "abcd efg hijk "; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 477 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 478 | |
| 479 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
| 480 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.length())); |
| 481 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 482 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 483 | |
| 484 | onHandleView(com.android.internal.R.id.insertion_handle) |
| 485 | .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('a'))); |
| 486 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("a"))); |
| 487 | |
| 488 | onHandleView(com.android.internal.R.id.insertion_handle) |
| 489 | .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('f'))); |
| 490 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f"))); |
| 491 | } |
| 492 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 493 | @Test |
| 494 | public void testInsertionHandle_multiLine() { |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 495 | final String text = "abcd\n" + "efg\n" + "hijk\n"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 496 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 497 | |
| 498 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
| 499 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.length())); |
| 500 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 501 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 502 | |
| 503 | onHandleView(com.android.internal.R.id.insertion_handle) |
| 504 | .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('a'))); |
| 505 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("a"))); |
| 506 | |
| 507 | onHandleView(com.android.internal.R.id.insertion_handle) |
| 508 | .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('f'))); |
| 509 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f"))); |
| 510 | } |
| 511 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 512 | @Test |
| 513 | public void testSelectionHandles() { |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 514 | final String text = "abcd efg hijk lmn"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 515 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Abodunrinwa Toki | fc6e25e | 2015-11-30 19:45:32 +0000 | [diff] [blame] | 516 | |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 517 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('f'))); |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 518 | |
Abodunrinwa Toki | fc6e25e | 2015-11-30 19:45:32 +0000 | [diff] [blame] | 519 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 520 | .check(matches(isDisplayed())); |
| 521 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 522 | .check(matches(isDisplayed())); |
| 523 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 524 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 525 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 526 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); |
| 527 | onView(withId(R.id.textview)).check(hasSelection("abcd efg")); |
| 528 | |
| 529 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 530 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('k') + 1)); |
| 531 | onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); |
| 532 | } |
Keisuke Kuroyanagi | c24c2bb | 2015-11-24 18:48:28 +0900 | [diff] [blame] | 533 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 534 | @Test |
| 535 | public void testSelectionHandles_bidi() { |
Keisuke Kuroyanagi | f0bb87b7 | 2016-02-08 23:52:55 +0900 | [diff] [blame] | 536 | final String text = "abc \u0621\u0622\u0623 def"; |
Keisuke Kuroyanagi | f0bb87b7 | 2016-02-08 23:52:55 +0900 | [diff] [blame] | 537 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 538 | |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 539 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('\u0622'))); |
Keisuke Kuroyanagi | f0bb87b7 | 2016-02-08 23:52:55 +0900 | [diff] [blame] | 540 | |
| 541 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 542 | .check(matches(isDisplayed())); |
| 543 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 544 | .check(matches(isDisplayed())); |
| 545 | |
| 546 | onView(withId(R.id.textview)).check(hasSelection("\u0621\u0622\u0623")); |
| 547 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 548 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | f0bb87b7 | 2016-02-08 23:52:55 +0900 | [diff] [blame] | 549 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 550 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('f'))); |
| 551 | onView(withId(R.id.textview)).check(hasSelection("\u0621\u0622\u0623")); |
| 552 | |
| 553 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 554 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); |
| 555 | onView(withId(R.id.textview)).check(hasSelection("\u0621\u0622\u0623")); |
| 556 | |
| 557 | onHandleView(com.android.internal.R.id.selection_start_handle) |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 558 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u0623'), |
Keisuke Kuroyanagi | f0bb87b7 | 2016-02-08 23:52:55 +0900 | [diff] [blame] | 559 | false)); |
| 560 | onView(withId(R.id.textview)).check(hasSelection("\u0623")); |
| 561 | |
| 562 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 563 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u0621'), |
| 564 | false)); |
| 565 | onView(withId(R.id.textview)).check(hasSelection("\u0621\u0622\u0623")); |
| 566 | |
| 567 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 568 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); |
| 569 | onView(withId(R.id.textview)).check(hasSelection("abc \u0621\u0622\u0623")); |
| 570 | |
| 571 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 572 | .perform(dragHandle(textView, Handle.SELECTION_END, text.length())); |
| 573 | onView(withId(R.id.textview)).check(hasSelection("abc \u0621\u0622\u0623 def")); |
| 574 | } |
| 575 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 576 | @Test |
| 577 | public void testSelectionHandles_multiLine() { |
Keisuke Kuroyanagi | c24c2bb | 2015-11-24 18:48:28 +0900 | [diff] [blame] | 578 | final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 579 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 580 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('i'))); |
Keisuke Kuroyanagi | c24c2bb | 2015-11-24 18:48:28 +0900 | [diff] [blame] | 581 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 582 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | c24c2bb | 2015-11-24 18:48:28 +0900 | [diff] [blame] | 583 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 584 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('e'))); |
| 585 | onView(withId(R.id.textview)).check(hasSelection("efg\nhijk")); |
| 586 | |
| 587 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 588 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); |
| 589 | onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk")); |
| 590 | |
| 591 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 592 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n') + 1)); |
| 593 | onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn")); |
| 594 | |
| 595 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 596 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r') + 1)); |
| 597 | onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn\nopqr")); |
| 598 | } |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 599 | |
Abodunrinwa Toki | 89550e8 | 2017-10-31 03:46:46 +0000 | [diff] [blame] | 600 | @Suppress // Consistently failing. |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 601 | @Test |
| 602 | public void testSelectionHandles_multiLine_rtl() { |
Keisuke Kuroyanagi | 2645414 | 2015-12-02 15:04:57 -0800 | [diff] [blame] | 603 | // Arabic text. |
| 604 | final String text = "\u062A\u062B\u062C\n" + "\u062D\u062E\u062F\n" |
| 605 | + "\u0630\u0631\u0632\n" + "\u0633\u0634\u0635\n" + "\u0636\u0637\u0638\n" |
| 606 | + "\u0639\u063A\u063B"; |
Keisuke Kuroyanagi | 2645414 | 2015-12-02 15:04:57 -0800 | [diff] [blame] | 607 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 608 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('\u0634'))); |
Keisuke Kuroyanagi | 2645414 | 2015-12-02 15:04:57 -0800 | [diff] [blame] | 609 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 610 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | 2645414 | 2015-12-02 15:04:57 -0800 | [diff] [blame] | 611 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 612 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u062E'))); |
| 613 | onView(withId(R.id.textview)).check(hasSelection( |
| 614 | text.substring(text.indexOf('\u062D'), text.indexOf('\u0635') + 1))); |
| 615 | |
| 616 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 617 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u062A'))); |
| 618 | onView(withId(R.id.textview)).check(hasSelection( |
| 619 | text.substring(text.indexOf('\u062A'), text.indexOf('\u0635') + 1))); |
| 620 | |
| 621 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 622 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('\u0638'))); |
| 623 | onView(withId(R.id.textview)).check(hasSelection( |
| 624 | text.substring(text.indexOf('\u062A'), text.indexOf('\u0638') + 1))); |
| 625 | |
| 626 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 627 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('\u063B'))); |
| 628 | onView(withId(R.id.textview)).check(hasSelection(text)); |
| 629 | } |
| 630 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 631 | @Test |
| 632 | public void testSelectionHandles_doesNotPassAnotherHandle() { |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 633 | final String text = "abcd efg hijk lmn"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 634 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 635 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('f'))); |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 636 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 637 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 638 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 639 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('l'))); |
| 640 | onView(withId(R.id.textview)).check(hasSelection("g")); |
| 641 | |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 642 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('f'))); |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 643 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 644 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); |
| 645 | onView(withId(R.id.textview)).check(hasSelection("e")); |
| 646 | } |
| 647 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 648 | @Test |
| 649 | public void testSelectionHandles_doesNotPassAnotherHandle_multiLine() { |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 650 | final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 651 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 652 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('i'))); |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 653 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 654 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 655 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 656 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('r') + 1)); |
| 657 | onView(withId(R.id.textview)).check(hasSelection("k")); |
| 658 | |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 659 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('i'))); |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 660 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 661 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); |
| 662 | onView(withId(R.id.textview)).check(hasSelection("h")); |
| 663 | } |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 664 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 665 | @Test |
| 666 | public void testSelectionHandles_snapToWordBoundary() { |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 667 | final String text = "abcd efg hijk lmn opqr"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 668 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 669 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('i'))); |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 670 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 671 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 672 | |
| 673 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 674 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('f'))); |
| 675 | onView(withId(R.id.textview)).check(hasSelection("efg hijk")); |
| 676 | |
| 677 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 678 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d') + 1)); |
| 679 | onView(withId(R.id.textview)).check(hasSelection("efg hijk")); |
| 680 | |
| 681 | |
| 682 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 683 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c'))); |
| 684 | onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); |
| 685 | |
| 686 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 687 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d'))); |
| 688 | onView(withId(R.id.textview)).check(hasSelection("d efg hijk")); |
| 689 | |
| 690 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 691 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('b'))); |
| 692 | onView(withId(R.id.textview)).check(hasSelection("bcd efg hijk")); |
| 693 | |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 694 | onView(withId(R.id.textview)).perform(click()); |
| 695 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('i'))); |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 696 | |
| 697 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 698 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n'))); |
| 699 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn")); |
| 700 | |
| 701 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 702 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('o'))); |
| 703 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn")); |
| 704 | |
| 705 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 706 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('q'))); |
| 707 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn opqr")); |
| 708 | |
| 709 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 710 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p'))); |
| 711 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn o")); |
| 712 | |
| 713 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 714 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r'))); |
| 715 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn opq")); |
| 716 | } |
| 717 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 718 | @Test |
| 719 | public void testSelectionHandles_snapToWordBoundary_multiLine() { |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 720 | final String text = "abcd efg\n" + "hijk lmn\n" + "opqr stu"; |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 721 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 722 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('m'))); |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 723 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 724 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 725 | |
| 726 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 727 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c'))); |
| 728 | onView(withId(R.id.textview)).check(hasSelection("abcd efg\nhijk lmn")); |
| 729 | |
| 730 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 731 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('g'))); |
| 732 | onView(withId(R.id.textview)).check(hasSelection("g\nhijk lmn")); |
| 733 | |
| 734 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 735 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('m'))); |
| 736 | onView(withId(R.id.textview)).check(hasSelection("lmn")); |
| 737 | |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 738 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('i'))); |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 739 | |
| 740 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 741 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('u'))); |
| 742 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn\nopqr stu")); |
| 743 | |
| 744 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 745 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p'))); |
| 746 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn\no")); |
| 747 | |
| 748 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 749 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('i'))); |
| 750 | onView(withId(R.id.textview)).check(hasSelection("hijk")); |
| 751 | } |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 752 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 753 | @Test |
Abodunrinwa Toki | deb2f49 | 2017-11-06 18:55:17 +0000 | [diff] [blame] | 754 | public void testSelectionHandles_visibleEvenWithEmptyMenu() { |
| 755 | ((TextView) mActivity.findViewById(R.id.textview)).setCustomSelectionActionModeCallback( |
| 756 | new ActionMode.Callback() { |
| 757 | @Override |
| 758 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 759 | menu.clear(); |
| 760 | return true; |
| 761 | } |
| 762 | |
| 763 | @Override |
| 764 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 765 | menu.clear(); |
| 766 | return true; |
| 767 | } |
| 768 | |
| 769 | @Override |
| 770 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 771 | return false; |
| 772 | } |
| 773 | |
| 774 | @Override |
| 775 | public void onDestroyActionMode(ActionMode mode) {} |
| 776 | }); |
| 777 | final String text = "abcd efg hijk lmn"; |
| 778 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 779 | |
| 780 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('f'))); |
| 781 | |
| 782 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 783 | .check(matches(isDisplayed())); |
| 784 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 785 | .check(matches(isDisplayed())); |
| 786 | } |
| 787 | |
| 788 | @Test |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 789 | public void testSetSelectionAndActionMode() throws Throwable { |
Abodunrinwa Toki | 6264cbd | 2017-11-06 15:12:52 +0000 | [diff] [blame] | 790 | final TextView textView = mActivity.findViewById(R.id.textview); |
| 791 | final ActionMode.Callback amCallback = mock(ActionMode.Callback.class); |
| 792 | when(amCallback.onCreateActionMode(any(ActionMode.class), any(Menu.class))) |
| 793 | .thenReturn(true); |
| 794 | when(amCallback.onPrepareActionMode(any(ActionMode.class), any(Menu.class))) |
| 795 | .thenReturn(true); |
| 796 | textView.setCustomSelectionActionModeCallback(amCallback); |
| 797 | |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 798 | final String text = "abc def"; |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 799 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 800 | mActivityRule.runOnUiThread( |
| 801 | () -> Selection.setSelection((Spannable) textView.getText(), 0, 3)); |
| 802 | mInstrumentation.waitForIdleSync(); |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 803 | // Don't automatically start action mode. |
Abodunrinwa Toki | 6264cbd | 2017-11-06 15:12:52 +0000 | [diff] [blame] | 804 | verify(amCallback, never()).onCreateActionMode(any(ActionMode.class), any(Menu.class)); |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 805 | // Make sure that "Select All" is included in the selection action mode when the entire text |
| 806 | // is not selected. |
Keisuke Kuroyanagi | 99e862318 | 2016-11-16 20:05:14 +0900 | [diff] [blame] | 807 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('e'))); |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 808 | sleepForFloatingToolbarPopup(); |
| 809 | assertFloatingToolbarIsDisplayed(); |
| 810 | // Changing the selection range by API should not interrupt the selection action mode. |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 811 | mActivityRule.runOnUiThread( |
| 812 | () -> Selection.setSelection((Spannable) textView.getText(), 0, 3)); |
| 813 | mInstrumentation.waitForIdleSync(); |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 814 | sleepForFloatingToolbarPopup(); |
| 815 | assertFloatingToolbarIsDisplayed(); |
| 816 | assertFloatingToolbarContainsItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 817 | mActivity.getString(com.android.internal.R.string.selectAll)); |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 818 | // Make sure that "Select All" is no longer included when the entire text is selected by |
| 819 | // API. |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 820 | mActivityRule.runOnUiThread( |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 821 | () -> Selection.setSelection((Spannable) textView.getText(), 0, text.length())); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 822 | mInstrumentation.waitForIdleSync(); |
| 823 | |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 824 | sleepForFloatingToolbarPopup(); |
| 825 | assertFloatingToolbarIsDisplayed(); |
| 826 | assertFloatingToolbarDoesNotContainItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 827 | mActivity.getString(com.android.internal.R.string.selectAll)); |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 828 | // Make sure that shrinking the selection range to cursor (an empty range) by API |
| 829 | // terminates selection action mode and does not trigger the insertion action mode. |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 830 | mActivityRule.runOnUiThread( |
| 831 | () -> Selection.setSelection((Spannable) textView.getText(), 0)); |
| 832 | mInstrumentation.waitForIdleSync(); |
| 833 | |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 834 | // Make sure that user click can trigger the insertion action mode. |
| 835 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
| 836 | onHandleView(com.android.internal.R.id.insertion_handle).perform(click()); |
| 837 | sleepForFloatingToolbarPopup(); |
| 838 | assertFloatingToolbarIsDisplayed(); |
| 839 | // Make sure that an existing insertion action mode keeps alive after the insertion point is |
| 840 | // moved by API. |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 841 | mActivityRule.runOnUiThread( |
| 842 | () -> Selection.setSelection((Spannable) textView.getText(), 0)); |
| 843 | mInstrumentation.waitForIdleSync(); |
| 844 | |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 845 | sleepForFloatingToolbarPopup(); |
| 846 | assertFloatingToolbarIsDisplayed(); |
| 847 | assertFloatingToolbarDoesNotContainItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 848 | mActivity.getString(com.android.internal.R.string.copy)); |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 849 | // Make sure that selection action mode is started after selection is created by API when |
| 850 | // insertion action mode is active. |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 851 | mActivityRule.runOnUiThread( |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 852 | () -> Selection.setSelection((Spannable) textView.getText(), 1, text.length())); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 853 | mInstrumentation.waitForIdleSync(); |
| 854 | |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 855 | sleepForFloatingToolbarPopup(); |
| 856 | assertFloatingToolbarIsDisplayed(); |
| 857 | assertFloatingToolbarContainsItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 858 | mActivity.getString(com.android.internal.R.string.copy)); |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 859 | } |
Keisuke Kuroyanagi | 183fd50 | 2016-04-01 15:00:53 +0900 | [diff] [blame] | 860 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 861 | @Test |
| 862 | public void testTransientState() throws Throwable { |
Keisuke Kuroyanagi | 183fd50 | 2016-04-01 15:00:53 +0900 | [diff] [blame] | 863 | final String text = "abc def"; |
Keisuke Kuroyanagi | 183fd50 | 2016-04-01 15:00:53 +0900 | [diff] [blame] | 864 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 865 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 866 | final TextView textView = mActivity.findViewById(R.id.textview); |
Keisuke Kuroyanagi | 183fd50 | 2016-04-01 15:00:53 +0900 | [diff] [blame] | 867 | assertFalse(textView.hasTransientState()); |
| 868 | |
| 869 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('b'))); |
| 870 | // hasTransientState should return true when user generated selection is active. |
| 871 | assertTrue(textView.hasTransientState()); |
| 872 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.indexOf('d'))); |
| 873 | // hasTransientState should return false as the selection has been cleared. |
| 874 | assertFalse(textView.hasTransientState()); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 875 | mActivityRule.runOnUiThread( |
Keisuke Kuroyanagi | 183fd50 | 2016-04-01 15:00:53 +0900 | [diff] [blame] | 876 | () -> Selection.setSelection((Spannable) textView.getText(), 0, text.length())); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 877 | mInstrumentation.waitForIdleSync(); |
| 878 | |
Keisuke Kuroyanagi | 183fd50 | 2016-04-01 15:00:53 +0900 | [diff] [blame] | 879 | // hasTransientState should return false when selection is created by API. |
| 880 | assertFalse(textView.hasTransientState()); |
| 881 | } |
Abodunrinwa Toki | 6eecdc9 | 2017-04-11 05:15:25 +0100 | [diff] [blame] | 882 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 883 | @Test |
| 884 | public void testResetMenuItemTitle() throws Throwable { |
| 885 | mActivity.getSystemService(TextClassificationManager.class).setTextClassifier(null); |
| 886 | final TextView textView = mActivity.findViewById(R.id.textview); |
Abodunrinwa Toki | 7b97180 | 2017-05-23 19:01:56 +0100 | [diff] [blame] | 887 | final int itemId = 1; |
| 888 | final String title1 = " AFIGBO"; |
| 889 | final int index = title1.indexOf('I'); |
| 890 | final String title2 = title1.substring(index); |
| 891 | final String[] title = new String[]{title1}; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 892 | mActivityRule.runOnUiThread(() -> textView.setCustomSelectionActionModeCallback( |
Abodunrinwa Toki | 7b97180 | 2017-05-23 19:01:56 +0100 | [diff] [blame] | 893 | new ActionMode.Callback() { |
| 894 | @Override |
| 895 | public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { |
| 896 | return true; |
| 897 | } |
| 898 | |
| 899 | @Override |
| 900 | public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { |
| 901 | menu.removeItem(itemId); |
| 902 | menu.add(Menu.NONE /* group */, itemId, 0 /* order */, title[0]); |
| 903 | return true; |
| 904 | } |
| 905 | |
| 906 | @Override |
| 907 | public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { |
| 908 | return false; |
| 909 | } |
| 910 | |
| 911 | @Override |
| 912 | public void onDestroyActionMode(ActionMode actionMode) { |
| 913 | } |
| 914 | })); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 915 | mInstrumentation.waitForIdleSync(); |
| 916 | |
Abodunrinwa Toki | 7b97180 | 2017-05-23 19:01:56 +0100 | [diff] [blame] | 917 | onView(withId(R.id.textview)).perform(replaceText(title1)); |
| 918 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(index)); |
| 919 | sleepForFloatingToolbarPopup(); |
| 920 | assertFloatingToolbarContainsItem(title1); |
| 921 | |
| 922 | // Change the menu item title. |
| 923 | title[0] = title2; |
| 924 | // Change the selection to invalidate the action mode without restarting it. |
| 925 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 926 | .perform(dragHandle(textView, Handle.SELECTION_START, index)); |
| 927 | sleepForFloatingToolbarPopup(); |
| 928 | assertFloatingToolbarContainsItem(title2); |
| 929 | } |
| 930 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 931 | @Test |
| 932 | public void testAssistItemIsAtIndexZero() throws Throwable { |
Abodunrinwa Toki | 76b51dc | 2017-07-13 23:37:11 +0100 | [diff] [blame] | 933 | useSystemDefaultTextClassifier(); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 934 | final TextView textView = mActivity.findViewById(R.id.textview); |
| 935 | mActivityRule.runOnUiThread(() -> textView.setCustomSelectionActionModeCallback( |
Abodunrinwa Toki | 6eecdc9 | 2017-04-11 05:15:25 +0100 | [diff] [blame] | 936 | new ActionMode.Callback() { |
| 937 | @Override |
| 938 | public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { |
| 939 | // Create another item at order position 0 to confirm that it will never be |
| 940 | // placed before the textAssist item. |
| 941 | menu.add(Menu.NONE, 0 /* id */, 0 /* order */, "Test"); |
| 942 | return true; |
| 943 | } |
| 944 | |
| 945 | @Override |
| 946 | public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { |
| 947 | return true; |
| 948 | } |
| 949 | |
| 950 | @Override |
| 951 | public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { |
| 952 | return false; |
| 953 | } |
| 954 | |
| 955 | @Override |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 956 | public void onDestroyActionMode(ActionMode actionMode) { |
| 957 | } |
Abodunrinwa Toki | 6eecdc9 | 2017-04-11 05:15:25 +0100 | [diff] [blame] | 958 | })); |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 959 | mInstrumentation.waitForIdleSync(); |
Abodunrinwa Toki | 6eecdc9 | 2017-04-11 05:15:25 +0100 | [diff] [blame] | 960 | final String text = "droid@android.com"; |
| 961 | |
| 962 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 963 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('@'))); |
| 964 | sleepForFloatingToolbarPopup(); |
| 965 | assertFloatingToolbarItemIndex(android.R.id.textAssist, 0); |
| 966 | } |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 967 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 968 | @Test |
Abodunrinwa Toki | 76b51dc | 2017-07-13 23:37:11 +0100 | [diff] [blame] | 969 | public void testNoAssistItemForPasswordField() throws Throwable { |
| 970 | useSystemDefaultTextClassifier(); |
| 971 | final TextView textView = mActivity.findViewById(R.id.textview); |
| 972 | mActivityRule.runOnUiThread(() -> { |
| 973 | textView.setInputType( |
| 974 | InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); |
| 975 | }); |
| 976 | mInstrumentation.waitForIdleSync(); |
| 977 | final String password = "afigbo@android.com"; |
| 978 | |
| 979 | onView(withId(R.id.textview)).perform(replaceText(password)); |
| 980 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(password.indexOf('@'))); |
| 981 | sleepForFloatingToolbarPopup(); |
| 982 | assertFloatingToolbarDoesNotContainItem(android.R.id.textAssist); |
| 983 | } |
| 984 | |
| 985 | @Test |
Abodunrinwa Toki | f299fc0 | 2018-05-17 17:36:25 +0100 | [diff] [blame] | 986 | public void testSelectionMetricsLogger_noAbandonAfterCopy() throws Throwable { |
| 987 | final List<SelectionEvent> selectionEvents = new ArrayList<>(); |
| 988 | final TextClassifier classifier = new TextClassifier() { |
| 989 | @Override |
| 990 | public void onSelectionEvent(SelectionEvent event) { |
| 991 | selectionEvents.add(event); |
| 992 | } |
| 993 | }; |
| 994 | final TextView textView = mActivity.findViewById(R.id.textview); |
| 995 | mActivityRule.runOnUiThread(() -> textView.setTextClassifier(classifier)); |
| 996 | mInstrumentation.waitForIdleSync(); |
| 997 | final String text = "andyroid@android.com"; |
| 998 | |
| 999 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 1000 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('@'))); |
| 1001 | sleepForFloatingToolbarPopup(); |
| 1002 | clickFloatingToolbarItem(mActivity.getString(com.android.internal.R.string.copy)); |
| 1003 | mInstrumentation.waitForIdleSync(); |
| 1004 | |
| 1005 | final SelectionEvent lastEvent = selectionEvents.get(selectionEvents.size() - 1); |
| 1006 | assertEquals(SelectionEvent.ACTION_COPY, lastEvent.getEventType()); |
| 1007 | } |
| 1008 | |
| 1009 | @Test |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 1010 | public void testPastePlainText_menuAction() { |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 1011 | initializeClipboardWithText(TextStyle.STYLED); |
| 1012 | |
| 1013 | onView(withId(R.id.textview)).perform(replaceText("")); |
| 1014 | onView(withId(R.id.textview)).perform(longClick()); |
| 1015 | sleepForFloatingToolbarPopup(); |
| 1016 | clickFloatingToolbarItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 1017 | mActivity.getString(com.android.internal.R.string.paste_as_plain_text)); |
| 1018 | mInstrumentation.waitForIdleSync(); |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 1019 | |
| 1020 | onView(withId(R.id.textview)).check(matches(withText("styledtext"))); |
| 1021 | onView(withId(R.id.textview)).check(doesNotHaveStyledText()); |
| 1022 | } |
| 1023 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 1024 | @Test |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 1025 | public void testPastePlainText_noMenuItemForPlainText() { |
| 1026 | initializeClipboardWithText(TextStyle.PLAIN); |
| 1027 | |
| 1028 | onView(withId(R.id.textview)).perform(replaceText("")); |
| 1029 | onView(withId(R.id.textview)).perform(longClick()); |
| 1030 | sleepForFloatingToolbarPopup(); |
| 1031 | |
| 1032 | assertFloatingToolbarDoesNotContainItem( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 1033 | mActivity.getString(com.android.internal.R.string.paste_as_plain_text)); |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 1034 | } |
| 1035 | |
Abodunrinwa Toki | 76b51dc | 2017-07-13 23:37:11 +0100 | [diff] [blame] | 1036 | private void useSystemDefaultTextClassifier() { |
| 1037 | mActivity.getSystemService(TextClassificationManager.class).setTextClassifier(null); |
| 1038 | } |
| 1039 | |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 1040 | private void initializeClipboardWithText(TextStyle textStyle) { |
| 1041 | final ClipData clip; |
| 1042 | switch (textStyle) { |
| 1043 | case STYLED: |
| 1044 | clip = ClipData.newHtmlText("html", "styledtext", "<b>styledtext</b>"); |
| 1045 | break; |
| 1046 | case PLAIN: |
| 1047 | clip = ClipData.newPlainText("plain", "plaintext"); |
| 1048 | break; |
| 1049 | default: |
| 1050 | throw new IllegalArgumentException("Invalid text style"); |
| 1051 | } |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 1052 | mActivity.getWindow().getDecorView().post(() -> |
| 1053 | mActivity.getSystemService(ClipboardManager.class).setPrimaryClip(clip)); |
| 1054 | mInstrumentation.waitForIdleSync(); |
Abodunrinwa Toki | ea6cb12 | 2017-04-28 22:14:13 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | private enum TextStyle { |
| 1058 | PLAIN, STYLED |
| 1059 | } |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 1060 | } |