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 | |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 19 | import static android.support.test.espresso.action.ViewActions.longClick; |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 20 | import static android.widget.espresso.DragHandleUtils.assertNoSelectionHandles; |
| 21 | import static android.widget.espresso.DragHandleUtils.onHandleView; |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 22 | import static android.widget.espresso.FloatingToolbarEspressoUtils.onFloatingToolBarItem; |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 23 | import static android.widget.espresso.TextViewActions.clickOnTextAtIndex; |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 24 | import static android.widget.espresso.TextViewActions.doubleTapAndDragOnText; |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 25 | import static android.widget.espresso.TextViewActions.doubleClickOnTextAtIndex; |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 26 | import static android.widget.espresso.TextViewActions.dragHandle; |
| 27 | import static android.widget.espresso.TextViewActions.Handle; |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 28 | import static android.widget.espresso.TextViewActions.longPressAndDragOnText; |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 29 | import static android.widget.espresso.TextViewActions.longPressOnTextAtIndex; |
| 30 | import static android.widget.espresso.TextViewAssertions.hasInsertionPointerAtIndex; |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 31 | import static android.widget.espresso.TextViewAssertions.hasSelection; |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 32 | import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarIsDisplayed; |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 33 | import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarIsNotDisplayed; |
| 34 | import static android.widget.espresso.FloatingToolbarEspressoUtils.sleepForFloatingToolbarPopup; |
| 35 | import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarContainsItem; |
| 36 | import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarDoesNotContainItem; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 37 | import static android.support.test.espresso.Espresso.onView; |
| 38 | import static android.support.test.espresso.action.ViewActions.click; |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 39 | import static android.support.test.espresso.action.ViewActions.pressKey; |
Keisuke Kuroyanagi | 2645414 | 2015-12-02 15:04:57 -0800 | [diff] [blame] | 40 | import static android.support.test.espresso.action.ViewActions.replaceText; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 41 | import static android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView; |
| 42 | import static android.support.test.espresso.assertion.ViewAssertions.matches; |
Abodunrinwa Toki | fc6e25e | 2015-11-30 19:45:32 +0000 | [diff] [blame] | 43 | import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 44 | import static android.support.test.espresso.matcher.ViewMatchers.withId; |
| 45 | import static android.support.test.espresso.matcher.ViewMatchers.withText; |
| 46 | |
| 47 | import com.android.frameworks.coretests.R; |
| 48 | |
Keisuke Kuroyanagi | fae4578 | 2016-02-24 18:53:00 -0800 | [diff] [blame] | 49 | import android.support.test.espresso.action.EspressoKey; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 50 | import android.test.ActivityInstrumentationTestCase2; |
| 51 | import android.test.suitebuilder.annotation.SmallTest; |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 52 | import android.text.Selection; |
| 53 | import android.text.Spannable; |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 54 | import android.text.InputType; |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 55 | import android.view.KeyEvent; |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 56 | |
Keisuke Kuroyanagi | e27e085 | 2016-01-08 19:05:27 +0900 | [diff] [blame] | 57 | import static org.hamcrest.Matchers.anyOf; |
| 58 | import static org.hamcrest.Matchers.is; |
| 59 | |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 60 | /** |
| 61 | * Tests the TextView widget from an Activity |
| 62 | */ |
| 63 | public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextViewActivity>{ |
| 64 | |
| 65 | public TextViewActivityTest() { |
| 66 | super(TextViewActivity.class); |
| 67 | } |
| 68 | |
Abodunrinwa Toki | c9e924e | 2015-10-08 12:01:35 +0100 | [diff] [blame] | 69 | @Override |
| 70 | public void setUp() { |
Abodunrinwa Toki | e36c711 | 2015-11-03 14:08:03 +0000 | [diff] [blame] | 71 | getActivity(); |
Abodunrinwa Toki | c9e924e | 2015-10-08 12:01:35 +0100 | [diff] [blame] | 72 | } |
| 73 | |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 74 | @SmallTest |
| 75 | public void testTypedTextIsOnScreen() throws Exception { |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 76 | final String helloWorld = "Hello world!"; |
| 77 | onView(withId(R.id.textview)).perform(click()); |
| 78 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); |
| 79 | |
| 80 | onView(withId(R.id.textview)).check(matches(withText(helloWorld))); |
| 81 | } |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 82 | |
| 83 | @SmallTest |
| 84 | public void testPositionCursorAtTextAtIndex() throws Exception { |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 85 | final String helloWorld = "Hello world!"; |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 86 | onView(withId(R.id.textview)).perform(click()); |
Abodunrinwa Toki | 90cdfe0 | 2015-09-15 21:15:56 +0100 | [diff] [blame] | 87 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); |
| 88 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(helloWorld.indexOf("world"))); |
| 89 | |
| 90 | // Delete text at specified index and see if we got the right one. |
| 91 | onView(withId(R.id.textview)).perform(pressKey(KeyEvent.KEYCODE_FORWARD_DEL)); |
| 92 | onView(withId(R.id.textview)).check(matches(withText("Hello orld!"))); |
| 93 | } |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 94 | |
| 95 | @SmallTest |
Keisuke Kuroyanagi | e27e085 | 2016-01-08 19:05:27 +0900 | [diff] [blame] | 96 | public void testPositionCursorAtTextAtIndex_arabic() throws Exception { |
| 97 | // Arabic text. The expected cursorable boundary is |
| 98 | // | \u0623 \u064F | \u067A | \u0633 \u0652 | |
| 99 | final String text = "\u0623\u064F\u067A\u0633\u0652"; |
| 100 | onView(withId(R.id.textview)).perform(click()); |
| 101 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 102 | |
| 103 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(0)); |
| 104 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(0)); |
| 105 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(1)); |
| 106 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(0), is(2)))); |
| 107 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(2)); |
| 108 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(2)); |
| 109 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(3)); |
| 110 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(3)); |
| 111 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(4)); |
| 112 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(3), is(5)))); |
| 113 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(5)); |
| 114 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(5)); |
| 115 | } |
| 116 | |
| 117 | @SmallTest |
| 118 | public void testPositionCursorAtTextAtIndex_devanagari() throws Exception { |
| 119 | // Devanagari text. The expected cursorable boundary is | \u0915 \u093E | |
| 120 | final String text = "\u0915\u093E"; |
| 121 | onView(withId(R.id.textview)).perform(click()); |
| 122 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 123 | |
| 124 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(0)); |
| 125 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(0)); |
| 126 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(1)); |
| 127 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(0), is(2)))); |
| 128 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(2)); |
| 129 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(2)); |
| 130 | } |
| 131 | |
| 132 | @SmallTest |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 133 | public void testLongPressToSelect() throws Exception { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 134 | final String helloWorld = "Hello Kirk!"; |
| 135 | onView(withId(R.id.textview)).perform(click()); |
| 136 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); |
| 137 | onView(withId(R.id.textview)).perform( |
| 138 | longPressOnTextAtIndex(helloWorld.indexOf("Kirk"))); |
| 139 | |
| 140 | onView(withId(R.id.textview)).check(hasSelection("Kirk")); |
| 141 | } |
| 142 | |
| 143 | @SmallTest |
| 144 | public void testLongPressEmptySpace() throws Exception { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 145 | final String helloWorld = "Hello big round sun!"; |
| 146 | onView(withId(R.id.textview)).perform(click()); |
| 147 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); |
| 148 | // Move cursor somewhere else |
| 149 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(helloWorld.indexOf("big"))); |
| 150 | // Long-press at end of line. |
| 151 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(helloWorld.length())); |
| 152 | |
| 153 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(helloWorld.length())); |
| 154 | } |
| 155 | |
| 156 | @SmallTest |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 157 | public void testLongPressAndDragToSelect() throws Exception { |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 158 | final String helloWorld = "Hello little handsome boy!"; |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 159 | onView(withId(R.id.textview)).perform(click()); |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 160 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); |
| 161 | onView(withId(R.id.textview)).perform( |
| 162 | longPressAndDragOnText(helloWorld.indexOf("little"), helloWorld.indexOf(" boy!"))); |
| 163 | |
| 164 | onView(withId(R.id.textview)).check(hasSelection("little handsome")); |
| 165 | } |
| 166 | |
| 167 | @SmallTest |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 168 | public void testDragAndDrop() throws Exception { |
| 169 | final String text = "abc def ghi."; |
| 170 | onView(withId(R.id.textview)).perform(click()); |
| 171 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 172 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf("e"))); |
| 173 | |
| 174 | onView(withId(R.id.textview)).perform( |
| 175 | longPressAndDragOnText(text.indexOf("e"), text.length())); |
| 176 | |
| 177 | onView(withId(R.id.textview)).check(matches(withText("abc ghi.def"))); |
| 178 | onView(withId(R.id.textview)).check(hasSelection("")); |
| 179 | assertNoSelectionHandles(); |
| 180 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex("abc ghi.def".length())); |
Keisuke Kuroyanagi | fae4578 | 2016-02-24 18:53:00 -0800 | [diff] [blame] | 181 | |
| 182 | // Test undo returns to the original state. |
| 183 | onView(withId(R.id.textview)).perform(pressKey( |
| 184 | (new EspressoKey.Builder()).withCtrlPressed(true).withKeyCode(KeyEvent.KEYCODE_Z) |
| 185 | .build())); |
| 186 | onView(withId(R.id.textview)).check(matches(withText(text))); |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @SmallTest |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 190 | public void testDoubleTapToSelect() throws Exception { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 191 | final String helloWorld = "Hello SuetYi!"; |
| 192 | onView(withId(R.id.textview)).perform(click()); |
| 193 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); |
| 194 | onView(withId(R.id.textview)).perform( |
| 195 | doubleClickOnTextAtIndex(helloWorld.indexOf("SuetYi"))); |
| 196 | |
| 197 | onView(withId(R.id.textview)).check(hasSelection("SuetYi")); |
| 198 | } |
| 199 | |
| 200 | @SmallTest |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 201 | public void testDoubleTapAndDragToSelect() throws Exception { |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 202 | final String helloWorld = "Hello young beautiful girl!"; |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 203 | onView(withId(R.id.textview)).perform(click()); |
Abodunrinwa Toki | ca4aaf3 | 2015-09-22 20:31:21 +0100 | [diff] [blame] | 204 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); |
| 205 | onView(withId(R.id.textview)).perform( |
| 206 | doubleTapAndDragOnText(helloWorld.indexOf("young"), helloWorld.indexOf(" girl!"))); |
| 207 | |
| 208 | onView(withId(R.id.textview)).check(hasSelection("young beautiful")); |
| 209 | } |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 210 | |
| 211 | @SmallTest |
| 212 | public void testSelectBackwordsByTouch() throws Exception { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 213 | final String helloWorld = "Hello king of the Jungle!"; |
| 214 | onView(withId(R.id.textview)).perform(click()); |
| 215 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); |
| 216 | onView(withId(R.id.textview)).perform( |
| 217 | doubleTapAndDragOnText(helloWorld.indexOf(" Jungle!"), helloWorld.indexOf("king"))); |
| 218 | |
| 219 | onView(withId(R.id.textview)).check(hasSelection("king of the")); |
| 220 | } |
| 221 | |
| 222 | @SmallTest |
| 223 | public void testToolbarAppearsAfterSelection() throws Exception { |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 224 | final String text = "Toolbar appears after selection."; |
| 225 | onView(withId(R.id.textview)).perform(click()); |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 226 | assertFloatingToolbarIsNotDisplayed(); |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 227 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 228 | onView(withId(R.id.textview)).perform( |
| 229 | longPressOnTextAtIndex(text.indexOf("appears"))); |
| 230 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 231 | sleepForFloatingToolbarPopup(); |
| 232 | assertFloatingToolbarIsDisplayed(); |
| 233 | |
| 234 | final String text2 = "Toolbar disappears after typing text."; |
| 235 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text2)); |
| 236 | assertFloatingToolbarIsNotDisplayed(); |
| 237 | } |
| 238 | |
| 239 | @SmallTest |
Siyamed Sinir | 987ec65 | 2016-02-17 19:44:41 -0800 | [diff] [blame] | 240 | public void testToolbarAppearsAfterSelection_withFirstStringLtrAlgorithmAndRtlHint() |
| 241 | throws Exception { |
| 242 | // after the hint layout change, the floating toolbar was not visible in the case below |
| 243 | // this test tests that the floating toolbar is displayed on the screen and is visible to |
| 244 | // user. |
| 245 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
| 246 | textView.post(new Runnable() { |
| 247 | @Override |
| 248 | public void run() { |
| 249 | textView.setTextDirection(TextView.TEXT_DIRECTION_FIRST_STRONG_LTR); |
| 250 | textView.setInputType(InputType.TYPE_CLASS_TEXT); |
| 251 | textView.setSingleLine(true); |
| 252 | textView.setHint("الروبوت"); |
| 253 | } |
| 254 | }); |
| 255 | getInstrumentation().waitForIdleSync(); |
| 256 | |
| 257 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView("test")); |
| 258 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(1)); |
| 259 | onFloatingToolBarItem(withText(com.android.internal.R.string.cut)).perform(click()); |
| 260 | onView(withId(R.id.textview)).perform(longClick()); |
| 261 | sleepForFloatingToolbarPopup(); |
| 262 | |
| 263 | assertFloatingToolbarIsDisplayed(); |
| 264 | } |
| 265 | |
| 266 | @SmallTest |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 267 | public void testToolbarAndInsertionHandle() throws Exception { |
| 268 | final String text = "text"; |
| 269 | onView(withId(R.id.textview)).perform(click()); |
| 270 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 271 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
| 272 | assertFloatingToolbarIsNotDisplayed(); |
| 273 | |
| 274 | onHandleView(com.android.internal.R.id.insertion_handle).perform(click()); |
| 275 | sleepForFloatingToolbarPopup(); |
| 276 | assertFloatingToolbarIsDisplayed(); |
| 277 | |
| 278 | assertFloatingToolbarContainsItem( |
| 279 | getActivity().getString(com.android.internal.R.string.selectAll)); |
| 280 | assertFloatingToolbarDoesNotContainItem( |
| 281 | getActivity().getString(com.android.internal.R.string.copy)); |
| 282 | assertFloatingToolbarDoesNotContainItem( |
| 283 | getActivity().getString(com.android.internal.R.string.cut)); |
| 284 | } |
| 285 | |
| 286 | @SmallTest |
| 287 | public void testToolbarAndSelectionHandle() throws Exception { |
| 288 | final String text = "abcd efg hijk"; |
| 289 | onView(withId(R.id.textview)).perform(click()); |
| 290 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 291 | |
| 292 | onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf("f"))); |
| 293 | sleepForFloatingToolbarPopup(); |
| 294 | assertFloatingToolbarIsDisplayed(); |
| 295 | |
| 296 | assertFloatingToolbarContainsItem( |
| 297 | getActivity().getString(com.android.internal.R.string.selectAll)); |
| 298 | assertFloatingToolbarContainsItem( |
| 299 | getActivity().getString(com.android.internal.R.string.copy)); |
| 300 | assertFloatingToolbarContainsItem( |
| 301 | getActivity().getString(com.android.internal.R.string.cut)); |
| 302 | |
| 303 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
| 304 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 305 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); |
| 306 | sleepForFloatingToolbarPopup(); |
| 307 | assertFloatingToolbarIsDisplayed(); |
| 308 | |
| 309 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 310 | .perform(dragHandle(textView, Handle.SELECTION_END, text.length())); |
| 311 | sleepForFloatingToolbarPopup(); |
| 312 | assertFloatingToolbarIsDisplayed(); |
| 313 | |
| 314 | assertFloatingToolbarDoesNotContainItem( |
| 315 | getActivity().getString(com.android.internal.R.string.selectAll)); |
| 316 | assertFloatingToolbarContainsItem( |
| 317 | getActivity().getString(com.android.internal.R.string.copy)); |
| 318 | assertFloatingToolbarContainsItem( |
| 319 | getActivity().getString(com.android.internal.R.string.cut)); |
Abodunrinwa Toki | 8a5e1ae | 2015-09-28 21:59:04 +0100 | [diff] [blame] | 320 | } |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 321 | |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 322 | @SmallTest |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 323 | public void testInsertionHandle() throws Exception { |
| 324 | final String text = "abcd efg hijk "; |
| 325 | onView(withId(R.id.textview)).perform(click()); |
| 326 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 327 | |
| 328 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
| 329 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.length())); |
| 330 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 331 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 332 | |
| 333 | onHandleView(com.android.internal.R.id.insertion_handle) |
| 334 | .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('a'))); |
| 335 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("a"))); |
| 336 | |
| 337 | onHandleView(com.android.internal.R.id.insertion_handle) |
| 338 | .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('f'))); |
| 339 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f"))); |
| 340 | } |
| 341 | |
| 342 | @SmallTest |
| 343 | public void testInsertionHandle_multiLine() throws Exception { |
| 344 | final String text = "abcd\n" + "efg\n" + "hijk\n"; |
| 345 | onView(withId(R.id.textview)).perform(click()); |
| 346 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 347 | |
| 348 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
| 349 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.length())); |
| 350 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 351 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
Keisuke Kuroyanagi | e8b3dd4 | 2015-11-26 14:19:27 +0900 | [diff] [blame] | 352 | |
| 353 | onHandleView(com.android.internal.R.id.insertion_handle) |
| 354 | .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('a'))); |
| 355 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("a"))); |
| 356 | |
| 357 | onHandleView(com.android.internal.R.id.insertion_handle) |
| 358 | .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('f'))); |
| 359 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f"))); |
| 360 | } |
| 361 | |
| 362 | @SmallTest |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 363 | public void testSelectionHandles() throws Exception { |
| 364 | final String text = "abcd efg hijk lmn"; |
| 365 | onView(withId(R.id.textview)).perform(click()); |
| 366 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
Abodunrinwa Toki | fc6e25e | 2015-11-30 19:45:32 +0000 | [diff] [blame] | 367 | |
| 368 | assertNoSelectionHandles(); |
| 369 | |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 370 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); |
| 371 | |
Abodunrinwa Toki | fc6e25e | 2015-11-30 19:45:32 +0000 | [diff] [blame] | 372 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 373 | .check(matches(isDisplayed())); |
| 374 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 375 | .check(matches(isDisplayed())); |
| 376 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 377 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
Keisuke Kuroyanagi | da79ee6 | 2015-11-25 16:15:15 +0900 | [diff] [blame] | 378 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 379 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); |
| 380 | onView(withId(R.id.textview)).check(hasSelection("abcd efg")); |
| 381 | |
| 382 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 383 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('k') + 1)); |
| 384 | onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); |
| 385 | } |
Keisuke Kuroyanagi | c24c2bb | 2015-11-24 18:48:28 +0900 | [diff] [blame] | 386 | |
| 387 | @SmallTest |
Keisuke Kuroyanagi | f0bb87b7 | 2016-02-08 23:52:55 +0900 | [diff] [blame] | 388 | public void testSelectionHandles_bidi() throws Exception { |
| 389 | final String text = "abc \u0621\u0622\u0623 def"; |
| 390 | onView(withId(R.id.textview)).perform(click()); |
| 391 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 392 | |
| 393 | assertNoSelectionHandles(); |
| 394 | |
| 395 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('\u0622'))); |
| 396 | |
| 397 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 398 | .check(matches(isDisplayed())); |
| 399 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 400 | .check(matches(isDisplayed())); |
| 401 | |
| 402 | onView(withId(R.id.textview)).check(hasSelection("\u0621\u0622\u0623")); |
| 403 | |
| 404 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
| 405 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 406 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('f'))); |
| 407 | onView(withId(R.id.textview)).check(hasSelection("\u0621\u0622\u0623")); |
| 408 | |
| 409 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 410 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); |
| 411 | onView(withId(R.id.textview)).check(hasSelection("\u0621\u0622\u0623")); |
| 412 | |
| 413 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 414 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u0623') + 1, |
| 415 | false)); |
| 416 | onView(withId(R.id.textview)).check(hasSelection("\u0623")); |
| 417 | |
| 418 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 419 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u0621'), |
| 420 | false)); |
| 421 | onView(withId(R.id.textview)).check(hasSelection("\u0621\u0622\u0623")); |
| 422 | |
| 423 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 424 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); |
| 425 | onView(withId(R.id.textview)).check(hasSelection("abc \u0621\u0622\u0623")); |
| 426 | |
| 427 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 428 | .perform(dragHandle(textView, Handle.SELECTION_END, text.length())); |
| 429 | onView(withId(R.id.textview)).check(hasSelection("abc \u0621\u0622\u0623 def")); |
| 430 | } |
| 431 | |
| 432 | @SmallTest |
Keisuke Kuroyanagi | c24c2bb | 2015-11-24 18:48:28 +0900 | [diff] [blame] | 433 | public void testSelectionHandles_multiLine() throws Exception { |
| 434 | final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; |
| 435 | onView(withId(R.id.textview)).perform(click()); |
| 436 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 437 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); |
| 438 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 439 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
Keisuke Kuroyanagi | c24c2bb | 2015-11-24 18:48:28 +0900 | [diff] [blame] | 440 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 441 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('e'))); |
| 442 | onView(withId(R.id.textview)).check(hasSelection("efg\nhijk")); |
| 443 | |
| 444 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 445 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); |
| 446 | onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk")); |
| 447 | |
| 448 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 449 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n') + 1)); |
| 450 | onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn")); |
| 451 | |
| 452 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 453 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r') + 1)); |
| 454 | onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn\nopqr")); |
| 455 | } |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 456 | |
| 457 | @SmallTest |
Keisuke Kuroyanagi | 2645414 | 2015-12-02 15:04:57 -0800 | [diff] [blame] | 458 | public void testSelectionHandles_multiLine_rtl() throws Exception { |
| 459 | // Arabic text. |
| 460 | final String text = "\u062A\u062B\u062C\n" + "\u062D\u062E\u062F\n" |
| 461 | + "\u0630\u0631\u0632\n" + "\u0633\u0634\u0635\n" + "\u0636\u0637\u0638\n" |
| 462 | + "\u0639\u063A\u063B"; |
| 463 | onView(withId(R.id.textview)).perform(click()); |
| 464 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 465 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
| 466 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('\u0634'))); |
| 467 | |
| 468 | final TextView textView = (TextView)getActivity().findViewById(R.id.textview); |
| 469 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 470 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u062E'))); |
| 471 | onView(withId(R.id.textview)).check(hasSelection( |
| 472 | text.substring(text.indexOf('\u062D'), text.indexOf('\u0635') + 1))); |
| 473 | |
| 474 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 475 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u062A'))); |
| 476 | onView(withId(R.id.textview)).check(hasSelection( |
| 477 | text.substring(text.indexOf('\u062A'), text.indexOf('\u0635') + 1))); |
| 478 | |
| 479 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 480 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('\u0638'))); |
| 481 | onView(withId(R.id.textview)).check(hasSelection( |
| 482 | text.substring(text.indexOf('\u062A'), text.indexOf('\u0638') + 1))); |
| 483 | |
| 484 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 485 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('\u063B'))); |
| 486 | onView(withId(R.id.textview)).check(hasSelection(text)); |
| 487 | } |
| 488 | |
| 489 | |
| 490 | @SmallTest |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 491 | public void testSelectionHandles_doesNotPassAnotherHandle() throws Exception { |
| 492 | final String text = "abcd efg hijk lmn"; |
| 493 | onView(withId(R.id.textview)).perform(click()); |
| 494 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 495 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); |
| 496 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 497 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 498 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 499 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('l'))); |
| 500 | onView(withId(R.id.textview)).check(hasSelection("g")); |
| 501 | |
| 502 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); |
| 503 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 504 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); |
| 505 | onView(withId(R.id.textview)).check(hasSelection("e")); |
| 506 | } |
| 507 | |
| 508 | @SmallTest |
| 509 | public void testSelectionHandles_doesNotPassAnotherHandle_multiLine() throws Exception { |
| 510 | final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; |
| 511 | onView(withId(R.id.textview)).perform(click()); |
| 512 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 513 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); |
| 514 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 515 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
Keisuke Kuroyanagi | cb6e842 | 2015-11-24 18:51:48 +0900 | [diff] [blame] | 516 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 517 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('r') + 1)); |
| 518 | onView(withId(R.id.textview)).check(hasSelection("k")); |
| 519 | |
| 520 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); |
| 521 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 522 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); |
| 523 | onView(withId(R.id.textview)).check(hasSelection("h")); |
| 524 | } |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 525 | |
| 526 | @SmallTest |
| 527 | public void testSelectionHandles_snapToWordBoundary() throws Exception { |
| 528 | final String text = "abcd efg hijk lmn opqr"; |
| 529 | onView(withId(R.id.textview)).perform(click()); |
| 530 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 531 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); |
| 532 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 533 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 534 | |
| 535 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 536 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('f'))); |
| 537 | onView(withId(R.id.textview)).check(hasSelection("efg hijk")); |
| 538 | |
| 539 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 540 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d') + 1)); |
| 541 | onView(withId(R.id.textview)).check(hasSelection("efg hijk")); |
| 542 | |
| 543 | |
| 544 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 545 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c'))); |
| 546 | onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); |
| 547 | |
| 548 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 549 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d'))); |
| 550 | onView(withId(R.id.textview)).check(hasSelection("d efg hijk")); |
| 551 | |
| 552 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 553 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('b'))); |
| 554 | onView(withId(R.id.textview)).check(hasSelection("bcd efg hijk")); |
| 555 | |
| 556 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); |
| 557 | |
| 558 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 559 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n'))); |
| 560 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn")); |
| 561 | |
| 562 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 563 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('o'))); |
| 564 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn")); |
| 565 | |
| 566 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 567 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('q'))); |
| 568 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn opqr")); |
| 569 | |
| 570 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 571 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p'))); |
| 572 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn o")); |
| 573 | |
| 574 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 575 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r'))); |
| 576 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn opq")); |
| 577 | } |
| 578 | |
| 579 | @SmallTest |
| 580 | public void testSelectionHandles_snapToWordBoundary_multiLine() throws Exception { |
| 581 | final String text = "abcd efg\n" + "hijk lmn\n" + "opqr stu"; |
| 582 | onView(withId(R.id.textview)).perform(click()); |
| 583 | onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); |
| 584 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('m'))); |
| 585 | |
Keisuke Kuroyanagi | b0dd77c | 2015-12-02 13:27:01 -0800 | [diff] [blame] | 586 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
Keisuke Kuroyanagi | ec913c0 | 2015-11-24 18:56:20 +0900 | [diff] [blame] | 587 | |
| 588 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 589 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c'))); |
| 590 | onView(withId(R.id.textview)).check(hasSelection("abcd efg\nhijk lmn")); |
| 591 | |
| 592 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 593 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('g'))); |
| 594 | onView(withId(R.id.textview)).check(hasSelection("g\nhijk lmn")); |
| 595 | |
| 596 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 597 | .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('m'))); |
| 598 | onView(withId(R.id.textview)).check(hasSelection("lmn")); |
| 599 | |
| 600 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); |
| 601 | |
| 602 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 603 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('u'))); |
| 604 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn\nopqr stu")); |
| 605 | |
| 606 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 607 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p'))); |
| 608 | onView(withId(R.id.textview)).check(hasSelection("hijk lmn\no")); |
| 609 | |
| 610 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 611 | .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('i'))); |
| 612 | onView(withId(R.id.textview)).check(hasSelection("hijk")); |
| 613 | } |
Keisuke Kuroyanagi | c477b58 | 2016-03-15 15:38:40 +0900 | [diff] [blame] | 614 | |
| 615 | @SmallTest |
| 616 | public void testSetSelectionAndActionMode() throws Exception { |
| 617 | final String text = "abc def"; |
| 618 | onView(withId(R.id.textview)).perform(click()); |
| 619 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 620 | |
| 621 | final TextView textView = (TextView) getActivity().findViewById(R.id.textview); |
| 622 | assertFloatingToolbarIsNotDisplayed(); |
| 623 | textView.post(() -> Selection.setSelection((Spannable) textView.getText(), 0, 3)); |
| 624 | getInstrumentation().waitForIdleSync(); |
| 625 | sleepForFloatingToolbarPopup(); |
| 626 | // Don't automatically start action mode. |
| 627 | assertFloatingToolbarIsNotDisplayed(); |
| 628 | // Make sure that "Select All" is included in the selection action mode when the entire text |
| 629 | // is not selected. |
| 630 | onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('e'))); |
| 631 | sleepForFloatingToolbarPopup(); |
| 632 | assertFloatingToolbarIsDisplayed(); |
| 633 | // Changing the selection range by API should not interrupt the selection action mode. |
| 634 | textView.post(() -> Selection.setSelection((Spannable) textView.getText(), 0, 3)); |
| 635 | getInstrumentation().waitForIdleSync(); |
| 636 | sleepForFloatingToolbarPopup(); |
| 637 | assertFloatingToolbarIsDisplayed(); |
| 638 | assertFloatingToolbarContainsItem( |
| 639 | getActivity().getString(com.android.internal.R.string.selectAll)); |
| 640 | // Make sure that "Select All" is no longer included when the entire text is selected by |
| 641 | // API. |
| 642 | textView.post( |
| 643 | () -> Selection.setSelection((Spannable) textView.getText(), 0, text.length())); |
| 644 | getInstrumentation().waitForIdleSync(); |
| 645 | sleepForFloatingToolbarPopup(); |
| 646 | assertFloatingToolbarIsDisplayed(); |
| 647 | assertFloatingToolbarDoesNotContainItem( |
| 648 | getActivity().getString(com.android.internal.R.string.selectAll)); |
| 649 | // Make sure that shrinking the selection range to cursor (an empty range) by API |
| 650 | // terminates selection action mode and does not trigger the insertion action mode. |
| 651 | textView.post(() -> Selection.setSelection((Spannable) textView.getText(), 0)); |
| 652 | getInstrumentation().waitForIdleSync(); |
| 653 | sleepForFloatingToolbarPopup(); |
| 654 | assertFloatingToolbarIsNotDisplayed(); |
| 655 | // Make sure that user click can trigger the insertion action mode. |
| 656 | onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); |
| 657 | onHandleView(com.android.internal.R.id.insertion_handle).perform(click()); |
| 658 | sleepForFloatingToolbarPopup(); |
| 659 | assertFloatingToolbarIsDisplayed(); |
| 660 | // Make sure that an existing insertion action mode keeps alive after the insertion point is |
| 661 | // moved by API. |
| 662 | textView.post(() -> Selection.setSelection((Spannable) textView.getText(), 0)); |
| 663 | getInstrumentation().waitForIdleSync(); |
| 664 | sleepForFloatingToolbarPopup(); |
| 665 | assertFloatingToolbarIsDisplayed(); |
| 666 | assertFloatingToolbarDoesNotContainItem( |
| 667 | getActivity().getString(com.android.internal.R.string.copy)); |
| 668 | // Make sure that selection action mode is started after selection is created by API when |
| 669 | // insertion action mode is active. |
| 670 | textView.post( |
| 671 | () -> Selection.setSelection((Spannable) textView.getText(), 1, text.length())); |
| 672 | getInstrumentation().waitForIdleSync(); |
| 673 | sleepForFloatingToolbarPopup(); |
| 674 | assertFloatingToolbarIsDisplayed(); |
| 675 | assertFloatingToolbarContainsItem( |
| 676 | getActivity().getString(com.android.internal.R.string.copy)); |
| 677 | } |
Abodunrinwa Toki | 223c839 | 2015-07-24 20:55:59 -0700 | [diff] [blame] | 678 | } |