TextViewActivityTest.java revision a2756f601865c37f9cc9b58943bd3285cbeb4b49
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 17package android.widget; 18 19import static android.widget.espresso.DragHandleUtils.assertNoSelectionHandles; 20import static android.widget.espresso.DragHandleUtils.onHandleView; 21import static android.widget.espresso.TextViewActions.clickOnTextAtIndex; 22import static android.widget.espresso.TextViewActions.doubleTapAndDragOnText; 23import static android.widget.espresso.TextViewActions.doubleClickOnTextAtIndex; 24import static android.widget.espresso.TextViewActions.dragHandle; 25import static android.widget.espresso.TextViewActions.Handle; 26import static android.widget.espresso.TextViewActions.longPressAndDragOnText; 27import static android.widget.espresso.TextViewActions.longPressOnTextAtIndex; 28import static android.widget.espresso.TextViewAssertions.hasInsertionPointerAtIndex; 29import static android.widget.espresso.TextViewAssertions.hasSelection; 30import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarIsDisplayed; 31import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarIsNotDisplayed; 32import static android.widget.espresso.FloatingToolbarEspressoUtils.sleepForFloatingToolbarPopup; 33import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarContainsItem; 34import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarDoesNotContainItem; 35import static android.support.test.espresso.Espresso.onView; 36import static android.support.test.espresso.action.ViewActions.click; 37import static android.support.test.espresso.action.ViewActions.pressKey; 38import static android.support.test.espresso.action.ViewActions.replaceText; 39import static android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView; 40import static android.support.test.espresso.assertion.ViewAssertions.matches; 41import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 42import static android.support.test.espresso.matcher.ViewMatchers.withId; 43import static android.support.test.espresso.matcher.ViewMatchers.withText; 44 45import com.android.frameworks.coretests.R; 46 47import android.test.ActivityInstrumentationTestCase2; 48import android.test.suitebuilder.annotation.SmallTest; 49import android.view.KeyEvent; 50 51import static org.hamcrest.Matchers.anyOf; 52import static org.hamcrest.Matchers.is; 53 54/** 55 * Tests the TextView widget from an Activity 56 */ 57public class TextViewActivityTest extends ActivityInstrumentationTestCase2<TextViewActivity>{ 58 59 public TextViewActivityTest() { 60 super(TextViewActivity.class); 61 } 62 63 @Override 64 public void setUp() { 65 getActivity(); 66 } 67 68 @SmallTest 69 public void testTypedTextIsOnScreen() throws Exception { 70 final String helloWorld = "Hello world!"; 71 onView(withId(R.id.textview)).perform(click()); 72 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 73 74 onView(withId(R.id.textview)).check(matches(withText(helloWorld))); 75 } 76 77 @SmallTest 78 public void testPositionCursorAtTextAtIndex() throws Exception { 79 final String helloWorld = "Hello world!"; 80 onView(withId(R.id.textview)).perform(click()); 81 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 82 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(helloWorld.indexOf("world"))); 83 84 // Delete text at specified index and see if we got the right one. 85 onView(withId(R.id.textview)).perform(pressKey(KeyEvent.KEYCODE_FORWARD_DEL)); 86 onView(withId(R.id.textview)).check(matches(withText("Hello orld!"))); 87 } 88 89 @SmallTest 90 public void testPositionCursorAtTextAtIndex_arabic() throws Exception { 91 // Arabic text. The expected cursorable boundary is 92 // | \u0623 \u064F | \u067A | \u0633 \u0652 | 93 final String text = "\u0623\u064F\u067A\u0633\u0652"; 94 onView(withId(R.id.textview)).perform(click()); 95 onView(withId(R.id.textview)).perform(replaceText(text)); 96 97 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(0)); 98 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(0)); 99 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(1)); 100 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(0), is(2)))); 101 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(2)); 102 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(2)); 103 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(3)); 104 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(3)); 105 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(4)); 106 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(3), is(5)))); 107 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(5)); 108 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(5)); 109 } 110 111 @SmallTest 112 public void testPositionCursorAtTextAtIndex_devanagari() throws Exception { 113 // Devanagari text. The expected cursorable boundary is | \u0915 \u093E | 114 final String text = "\u0915\u093E"; 115 onView(withId(R.id.textview)).perform(click()); 116 onView(withId(R.id.textview)).perform(replaceText(text)); 117 118 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(0)); 119 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(0)); 120 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(1)); 121 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(anyOf(is(0), is(2)))); 122 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(2)); 123 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(2)); 124 } 125 126 @SmallTest 127 public void testLongPressToSelect() throws Exception { 128 final String helloWorld = "Hello Kirk!"; 129 onView(withId(R.id.textview)).perform(click()); 130 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 131 onView(withId(R.id.textview)).perform( 132 longPressOnTextAtIndex(helloWorld.indexOf("Kirk"))); 133 134 onView(withId(R.id.textview)).check(hasSelection("Kirk")); 135 } 136 137 @SmallTest 138 public void testLongPressEmptySpace() throws Exception { 139 final String helloWorld = "Hello big round sun!"; 140 onView(withId(R.id.textview)).perform(click()); 141 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 142 // Move cursor somewhere else 143 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(helloWorld.indexOf("big"))); 144 // Long-press at end of line. 145 onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(helloWorld.length())); 146 147 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(helloWorld.length())); 148 } 149 150 @SmallTest 151 public void testLongPressAndDragToSelect() throws Exception { 152 final String helloWorld = "Hello little handsome boy!"; 153 onView(withId(R.id.textview)).perform(click()); 154 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 155 onView(withId(R.id.textview)).perform( 156 longPressAndDragOnText(helloWorld.indexOf("little"), helloWorld.indexOf(" boy!"))); 157 158 onView(withId(R.id.textview)).check(hasSelection("little handsome")); 159 } 160 161 @SmallTest 162 public void testDragAndDrop() throws Exception { 163 final String text = "abc def ghi."; 164 onView(withId(R.id.textview)).perform(click()); 165 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 166 onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf("e"))); 167 168 onView(withId(R.id.textview)).perform( 169 longPressAndDragOnText(text.indexOf("e"), text.length())); 170 171 onView(withId(R.id.textview)).check(matches(withText("abc ghi.def"))); 172 onView(withId(R.id.textview)).check(hasSelection("")); 173 assertNoSelectionHandles(); 174 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex("abc ghi.def".length())); 175 } 176 177 @SmallTest 178 public void testDoubleTapToSelect() throws Exception { 179 final String helloWorld = "Hello SuetYi!"; 180 onView(withId(R.id.textview)).perform(click()); 181 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 182 onView(withId(R.id.textview)).perform( 183 doubleClickOnTextAtIndex(helloWorld.indexOf("SuetYi"))); 184 185 onView(withId(R.id.textview)).check(hasSelection("SuetYi")); 186 } 187 188 @SmallTest 189 public void testDoubleTapAndDragToSelect() throws Exception { 190 final String helloWorld = "Hello young beautiful girl!"; 191 onView(withId(R.id.textview)).perform(click()); 192 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 193 onView(withId(R.id.textview)).perform( 194 doubleTapAndDragOnText(helloWorld.indexOf("young"), helloWorld.indexOf(" girl!"))); 195 196 onView(withId(R.id.textview)).check(hasSelection("young beautiful")); 197 } 198 199 @SmallTest 200 public void testSelectBackwordsByTouch() throws Exception { 201 final String helloWorld = "Hello king of the Jungle!"; 202 onView(withId(R.id.textview)).perform(click()); 203 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 204 onView(withId(R.id.textview)).perform( 205 doubleTapAndDragOnText(helloWorld.indexOf(" Jungle!"), helloWorld.indexOf("king"))); 206 207 onView(withId(R.id.textview)).check(hasSelection("king of the")); 208 } 209 210 @SmallTest 211 public void testToolbarAppearsAfterSelection() throws Exception { 212 final String text = "Toolbar appears after selection."; 213 onView(withId(R.id.textview)).perform(click()); 214 assertFloatingToolbarIsNotDisplayed(); 215 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 216 onView(withId(R.id.textview)).perform( 217 longPressOnTextAtIndex(text.indexOf("appears"))); 218 219 sleepForFloatingToolbarPopup(); 220 assertFloatingToolbarIsDisplayed(); 221 222 final String text2 = "Toolbar disappears after typing text."; 223 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text2)); 224 assertFloatingToolbarIsNotDisplayed(); 225 } 226 227 @SmallTest 228 public void testToolbarAndInsertionHandle() throws Exception { 229 final String text = "text"; 230 onView(withId(R.id.textview)).perform(click()); 231 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 232 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); 233 assertFloatingToolbarIsNotDisplayed(); 234 235 onHandleView(com.android.internal.R.id.insertion_handle).perform(click()); 236 sleepForFloatingToolbarPopup(); 237 assertFloatingToolbarIsDisplayed(); 238 239 assertFloatingToolbarContainsItem( 240 getActivity().getString(com.android.internal.R.string.selectAll)); 241 assertFloatingToolbarDoesNotContainItem( 242 getActivity().getString(com.android.internal.R.string.copy)); 243 assertFloatingToolbarDoesNotContainItem( 244 getActivity().getString(com.android.internal.R.string.cut)); 245 } 246 247 @SmallTest 248 public void testToolbarAndSelectionHandle() throws Exception { 249 final String text = "abcd efg hijk"; 250 onView(withId(R.id.textview)).perform(click()); 251 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 252 253 onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf("f"))); 254 sleepForFloatingToolbarPopup(); 255 assertFloatingToolbarIsDisplayed(); 256 257 assertFloatingToolbarContainsItem( 258 getActivity().getString(com.android.internal.R.string.selectAll)); 259 assertFloatingToolbarContainsItem( 260 getActivity().getString(com.android.internal.R.string.copy)); 261 assertFloatingToolbarContainsItem( 262 getActivity().getString(com.android.internal.R.string.cut)); 263 264 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 265 onHandleView(com.android.internal.R.id.selection_start_handle) 266 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); 267 sleepForFloatingToolbarPopup(); 268 assertFloatingToolbarIsDisplayed(); 269 270 onHandleView(com.android.internal.R.id.selection_end_handle) 271 .perform(dragHandle(textView, Handle.SELECTION_END, text.length())); 272 sleepForFloatingToolbarPopup(); 273 assertFloatingToolbarIsDisplayed(); 274 275 assertFloatingToolbarDoesNotContainItem( 276 getActivity().getString(com.android.internal.R.string.selectAll)); 277 assertFloatingToolbarContainsItem( 278 getActivity().getString(com.android.internal.R.string.copy)); 279 assertFloatingToolbarContainsItem( 280 getActivity().getString(com.android.internal.R.string.cut)); 281 } 282 283 @SmallTest 284 public void testInsertionHandle() throws Exception { 285 final String text = "abcd efg hijk "; 286 onView(withId(R.id.textview)).perform(click()); 287 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 288 289 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); 290 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.length())); 291 292 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 293 294 onHandleView(com.android.internal.R.id.insertion_handle) 295 .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('a'))); 296 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("a"))); 297 298 onHandleView(com.android.internal.R.id.insertion_handle) 299 .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('f'))); 300 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f"))); 301 } 302 303 @SmallTest 304 public void testInsertionHandle_multiLine() throws Exception { 305 final String text = "abcd\n" + "efg\n" + "hijk\n"; 306 onView(withId(R.id.textview)).perform(click()); 307 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 308 309 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); 310 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.length())); 311 312 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 313 314 onHandleView(com.android.internal.R.id.insertion_handle) 315 .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('a'))); 316 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("a"))); 317 318 onHandleView(com.android.internal.R.id.insertion_handle) 319 .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('f'))); 320 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f"))); 321 } 322 323 @SmallTest 324 public void testSelectionHandles() throws Exception { 325 final String text = "abcd efg hijk lmn"; 326 onView(withId(R.id.textview)).perform(click()); 327 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 328 329 assertNoSelectionHandles(); 330 331 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); 332 333 onHandleView(com.android.internal.R.id.selection_start_handle) 334 .check(matches(isDisplayed())); 335 onHandleView(com.android.internal.R.id.selection_end_handle) 336 .check(matches(isDisplayed())); 337 338 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 339 onHandleView(com.android.internal.R.id.selection_start_handle) 340 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); 341 onView(withId(R.id.textview)).check(hasSelection("abcd efg")); 342 343 onHandleView(com.android.internal.R.id.selection_end_handle) 344 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('k') + 1)); 345 onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); 346 } 347 348 @SmallTest 349 public void testSelectionHandles_multiLine() throws Exception { 350 final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; 351 onView(withId(R.id.textview)).perform(click()); 352 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 353 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 354 355 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 356 onHandleView(com.android.internal.R.id.selection_start_handle) 357 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('e'))); 358 onView(withId(R.id.textview)).check(hasSelection("efg\nhijk")); 359 360 onHandleView(com.android.internal.R.id.selection_start_handle) 361 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); 362 onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk")); 363 364 onHandleView(com.android.internal.R.id.selection_end_handle) 365 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n') + 1)); 366 onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn")); 367 368 onHandleView(com.android.internal.R.id.selection_end_handle) 369 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r') + 1)); 370 onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn\nopqr")); 371 } 372 373 @SmallTest 374 public void testSelectionHandles_multiLine_rtl() throws Exception { 375 // Arabic text. 376 final String text = "\u062A\u062B\u062C\n" + "\u062D\u062E\u062F\n" 377 + "\u0630\u0631\u0632\n" + "\u0633\u0634\u0635\n" + "\u0636\u0637\u0638\n" 378 + "\u0639\u063A\u063B"; 379 onView(withId(R.id.textview)).perform(click()); 380 onView(withId(R.id.textview)).perform(replaceText(text)); 381 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); 382 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('\u0634'))); 383 384 final TextView textView = (TextView)getActivity().findViewById(R.id.textview); 385 onHandleView(com.android.internal.R.id.selection_start_handle) 386 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u062E'))); 387 onView(withId(R.id.textview)).check(hasSelection( 388 text.substring(text.indexOf('\u062D'), text.indexOf('\u0635') + 1))); 389 390 onHandleView(com.android.internal.R.id.selection_start_handle) 391 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u062A'))); 392 onView(withId(R.id.textview)).check(hasSelection( 393 text.substring(text.indexOf('\u062A'), text.indexOf('\u0635') + 1))); 394 395 onHandleView(com.android.internal.R.id.selection_end_handle) 396 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('\u0638'))); 397 onView(withId(R.id.textview)).check(hasSelection( 398 text.substring(text.indexOf('\u062A'), text.indexOf('\u0638') + 1))); 399 400 onHandleView(com.android.internal.R.id.selection_end_handle) 401 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('\u063B'))); 402 onView(withId(R.id.textview)).check(hasSelection(text)); 403 } 404 405 406 @SmallTest 407 public void testSelectionHandles_doesNotPassAnotherHandle() throws Exception { 408 final String text = "abcd efg hijk lmn"; 409 onView(withId(R.id.textview)).perform(click()); 410 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 411 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); 412 413 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 414 onHandleView(com.android.internal.R.id.selection_start_handle) 415 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('l'))); 416 onView(withId(R.id.textview)).check(hasSelection("g")); 417 418 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); 419 onHandleView(com.android.internal.R.id.selection_end_handle) 420 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); 421 onView(withId(R.id.textview)).check(hasSelection("e")); 422 } 423 424 @SmallTest 425 public void testSelectionHandles_doesNotPassAnotherHandle_multiLine() throws Exception { 426 final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; 427 onView(withId(R.id.textview)).perform(click()); 428 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 429 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 430 431 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 432 onHandleView(com.android.internal.R.id.selection_start_handle) 433 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('r') + 1)); 434 onView(withId(R.id.textview)).check(hasSelection("k")); 435 436 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 437 onHandleView(com.android.internal.R.id.selection_end_handle) 438 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); 439 onView(withId(R.id.textview)).check(hasSelection("h")); 440 } 441 442 @SmallTest 443 public void testSelectionHandles_snapToWordBoundary() throws Exception { 444 final String text = "abcd efg hijk lmn opqr"; 445 onView(withId(R.id.textview)).perform(click()); 446 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 447 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 448 449 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 450 451 onHandleView(com.android.internal.R.id.selection_start_handle) 452 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('f'))); 453 onView(withId(R.id.textview)).check(hasSelection("efg hijk")); 454 455 onHandleView(com.android.internal.R.id.selection_start_handle) 456 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d') + 1)); 457 onView(withId(R.id.textview)).check(hasSelection("efg hijk")); 458 459 460 onHandleView(com.android.internal.R.id.selection_start_handle) 461 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c'))); 462 onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); 463 464 onHandleView(com.android.internal.R.id.selection_start_handle) 465 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d'))); 466 onView(withId(R.id.textview)).check(hasSelection("d efg hijk")); 467 468 onHandleView(com.android.internal.R.id.selection_start_handle) 469 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('b'))); 470 onView(withId(R.id.textview)).check(hasSelection("bcd efg hijk")); 471 472 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 473 474 onHandleView(com.android.internal.R.id.selection_end_handle) 475 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n'))); 476 onView(withId(R.id.textview)).check(hasSelection("hijk lmn")); 477 478 onHandleView(com.android.internal.R.id.selection_end_handle) 479 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('o'))); 480 onView(withId(R.id.textview)).check(hasSelection("hijk lmn")); 481 482 onHandleView(com.android.internal.R.id.selection_end_handle) 483 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('q'))); 484 onView(withId(R.id.textview)).check(hasSelection("hijk lmn opqr")); 485 486 onHandleView(com.android.internal.R.id.selection_end_handle) 487 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p'))); 488 onView(withId(R.id.textview)).check(hasSelection("hijk lmn o")); 489 490 onHandleView(com.android.internal.R.id.selection_end_handle) 491 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r'))); 492 onView(withId(R.id.textview)).check(hasSelection("hijk lmn opq")); 493 } 494 495 @SmallTest 496 public void testSelectionHandles_snapToWordBoundary_multiLine() throws Exception { 497 final String text = "abcd efg\n" + "hijk lmn\n" + "opqr stu"; 498 onView(withId(R.id.textview)).perform(click()); 499 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 500 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('m'))); 501 502 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 503 504 onHandleView(com.android.internal.R.id.selection_start_handle) 505 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c'))); 506 onView(withId(R.id.textview)).check(hasSelection("abcd efg\nhijk lmn")); 507 508 onHandleView(com.android.internal.R.id.selection_start_handle) 509 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('g'))); 510 onView(withId(R.id.textview)).check(hasSelection("g\nhijk lmn")); 511 512 onHandleView(com.android.internal.R.id.selection_start_handle) 513 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('m'))); 514 onView(withId(R.id.textview)).check(hasSelection("lmn")); 515 516 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 517 518 onHandleView(com.android.internal.R.id.selection_end_handle) 519 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('u'))); 520 onView(withId(R.id.textview)).check(hasSelection("hijk lmn\nopqr stu")); 521 522 onHandleView(com.android.internal.R.id.selection_end_handle) 523 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p'))); 524 onView(withId(R.id.textview)).check(hasSelection("hijk lmn\no")); 525 526 onHandleView(com.android.internal.R.id.selection_end_handle) 527 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('i'))); 528 onView(withId(R.id.textview)).check(hasSelection("hijk")); 529 } 530} 531