TextViewActivityTest.java revision e27e0850fe4acbdc911e2e4e6272be10ac2f2779
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 testDoubleTapToSelect() throws Exception { 163 final String helloWorld = "Hello SuetYi!"; 164 onView(withId(R.id.textview)).perform(click()); 165 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 166 onView(withId(R.id.textview)).perform( 167 doubleClickOnTextAtIndex(helloWorld.indexOf("SuetYi"))); 168 169 onView(withId(R.id.textview)).check(hasSelection("SuetYi")); 170 } 171 172 @SmallTest 173 public void testDoubleTapAndDragToSelect() throws Exception { 174 final String helloWorld = "Hello young beautiful girl!"; 175 onView(withId(R.id.textview)).perform(click()); 176 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 177 onView(withId(R.id.textview)).perform( 178 doubleTapAndDragOnText(helloWorld.indexOf("young"), helloWorld.indexOf(" girl!"))); 179 180 onView(withId(R.id.textview)).check(hasSelection("young beautiful")); 181 } 182 183 @SmallTest 184 public void testSelectBackwordsByTouch() throws Exception { 185 final String helloWorld = "Hello king of the Jungle!"; 186 onView(withId(R.id.textview)).perform(click()); 187 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(helloWorld)); 188 onView(withId(R.id.textview)).perform( 189 doubleTapAndDragOnText(helloWorld.indexOf(" Jungle!"), helloWorld.indexOf("king"))); 190 191 onView(withId(R.id.textview)).check(hasSelection("king of the")); 192 } 193 194 @SmallTest 195 public void testToolbarAppearsAfterSelection() throws Exception { 196 final String text = "Toolbar appears after selection."; 197 onView(withId(R.id.textview)).perform(click()); 198 assertFloatingToolbarIsNotDisplayed(); 199 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 200 onView(withId(R.id.textview)).perform( 201 longPressOnTextAtIndex(text.indexOf("appears"))); 202 203 sleepForFloatingToolbarPopup(); 204 assertFloatingToolbarIsDisplayed(); 205 206 final String text2 = "Toolbar disappears after typing text."; 207 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text2)); 208 assertFloatingToolbarIsNotDisplayed(); 209 } 210 211 @SmallTest 212 public void testToolbarAndInsertionHandle() throws Exception { 213 final String text = "text"; 214 onView(withId(R.id.textview)).perform(click()); 215 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 216 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); 217 assertFloatingToolbarIsNotDisplayed(); 218 219 onHandleView(com.android.internal.R.id.insertion_handle).perform(click()); 220 sleepForFloatingToolbarPopup(); 221 assertFloatingToolbarIsDisplayed(); 222 223 assertFloatingToolbarContainsItem( 224 getActivity().getString(com.android.internal.R.string.selectAll)); 225 assertFloatingToolbarDoesNotContainItem( 226 getActivity().getString(com.android.internal.R.string.copy)); 227 assertFloatingToolbarDoesNotContainItem( 228 getActivity().getString(com.android.internal.R.string.cut)); 229 } 230 231 @SmallTest 232 public void testToolbarAndSelectionHandle() throws Exception { 233 final String text = "abcd efg hijk"; 234 onView(withId(R.id.textview)).perform(click()); 235 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 236 237 onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf("f"))); 238 sleepForFloatingToolbarPopup(); 239 assertFloatingToolbarIsDisplayed(); 240 241 assertFloatingToolbarContainsItem( 242 getActivity().getString(com.android.internal.R.string.selectAll)); 243 assertFloatingToolbarContainsItem( 244 getActivity().getString(com.android.internal.R.string.copy)); 245 assertFloatingToolbarContainsItem( 246 getActivity().getString(com.android.internal.R.string.cut)); 247 248 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 249 onHandleView(com.android.internal.R.id.selection_start_handle) 250 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); 251 sleepForFloatingToolbarPopup(); 252 assertFloatingToolbarIsDisplayed(); 253 254 onHandleView(com.android.internal.R.id.selection_end_handle) 255 .perform(dragHandle(textView, Handle.SELECTION_END, text.length())); 256 sleepForFloatingToolbarPopup(); 257 assertFloatingToolbarIsDisplayed(); 258 259 assertFloatingToolbarDoesNotContainItem( 260 getActivity().getString(com.android.internal.R.string.selectAll)); 261 assertFloatingToolbarContainsItem( 262 getActivity().getString(com.android.internal.R.string.copy)); 263 assertFloatingToolbarContainsItem( 264 getActivity().getString(com.android.internal.R.string.cut)); 265 } 266 267 @SmallTest 268 public void testInsertionHandle() throws Exception { 269 final String text = "abcd efg hijk "; 270 onView(withId(R.id.textview)).perform(click()); 271 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 272 273 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); 274 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.length())); 275 276 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 277 278 onHandleView(com.android.internal.R.id.insertion_handle) 279 .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('a'))); 280 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("a"))); 281 282 onHandleView(com.android.internal.R.id.insertion_handle) 283 .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('f'))); 284 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f"))); 285 } 286 287 @SmallTest 288 public void testInsertionHandle_multiLine() throws Exception { 289 final String text = "abcd\n" + "efg\n" + "hijk\n"; 290 onView(withId(R.id.textview)).perform(click()); 291 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 292 293 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); 294 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.length())); 295 296 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 297 298 onHandleView(com.android.internal.R.id.insertion_handle) 299 .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('a'))); 300 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("a"))); 301 302 onHandleView(com.android.internal.R.id.insertion_handle) 303 .perform(dragHandle(textView, Handle.INSERTION, text.indexOf('f'))); 304 onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("f"))); 305 } 306 307 @SmallTest 308 public void testSelectionHandles() throws Exception { 309 final String text = "abcd efg hijk lmn"; 310 onView(withId(R.id.textview)).perform(click()); 311 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 312 313 assertNoSelectionHandles(); 314 315 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); 316 317 onHandleView(com.android.internal.R.id.selection_start_handle) 318 .check(matches(isDisplayed())); 319 onHandleView(com.android.internal.R.id.selection_end_handle) 320 .check(matches(isDisplayed())); 321 322 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 323 onHandleView(com.android.internal.R.id.selection_start_handle) 324 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); 325 onView(withId(R.id.textview)).check(hasSelection("abcd efg")); 326 327 onHandleView(com.android.internal.R.id.selection_end_handle) 328 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('k') + 1)); 329 onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); 330 } 331 332 @SmallTest 333 public void testSelectionHandles_multiLine() throws Exception { 334 final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; 335 onView(withId(R.id.textview)).perform(click()); 336 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 337 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 338 339 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 340 onHandleView(com.android.internal.R.id.selection_start_handle) 341 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('e'))); 342 onView(withId(R.id.textview)).check(hasSelection("efg\nhijk")); 343 344 onHandleView(com.android.internal.R.id.selection_start_handle) 345 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('a'))); 346 onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk")); 347 348 onHandleView(com.android.internal.R.id.selection_end_handle) 349 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n') + 1)); 350 onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn")); 351 352 onHandleView(com.android.internal.R.id.selection_end_handle) 353 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r') + 1)); 354 onView(withId(R.id.textview)).check(hasSelection("abcd\nefg\nhijk\nlmn\nopqr")); 355 } 356 357 @SmallTest 358 public void testSelectionHandles_multiLine_rtl() throws Exception { 359 // Arabic text. 360 final String text = "\u062A\u062B\u062C\n" + "\u062D\u062E\u062F\n" 361 + "\u0630\u0631\u0632\n" + "\u0633\u0634\u0635\n" + "\u0636\u0637\u0638\n" 362 + "\u0639\u063A\u063B"; 363 onView(withId(R.id.textview)).perform(click()); 364 onView(withId(R.id.textview)).perform(replaceText(text)); 365 onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.length())); 366 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('\u0634'))); 367 368 final TextView textView = (TextView)getActivity().findViewById(R.id.textview); 369 onHandleView(com.android.internal.R.id.selection_start_handle) 370 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u062E'))); 371 onView(withId(R.id.textview)).check(hasSelection( 372 text.substring(text.indexOf('\u062D'), text.indexOf('\u0635') + 1))); 373 374 onHandleView(com.android.internal.R.id.selection_start_handle) 375 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('\u062A'))); 376 onView(withId(R.id.textview)).check(hasSelection( 377 text.substring(text.indexOf('\u062A'), text.indexOf('\u0635') + 1))); 378 379 onHandleView(com.android.internal.R.id.selection_end_handle) 380 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('\u0638'))); 381 onView(withId(R.id.textview)).check(hasSelection( 382 text.substring(text.indexOf('\u062A'), text.indexOf('\u0638') + 1))); 383 384 onHandleView(com.android.internal.R.id.selection_end_handle) 385 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('\u063B'))); 386 onView(withId(R.id.textview)).check(hasSelection(text)); 387 } 388 389 390 @SmallTest 391 public void testSelectionHandles_doesNotPassAnotherHandle() throws Exception { 392 final String text = "abcd efg hijk lmn"; 393 onView(withId(R.id.textview)).perform(click()); 394 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 395 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); 396 397 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 398 onHandleView(com.android.internal.R.id.selection_start_handle) 399 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('l'))); 400 onView(withId(R.id.textview)).check(hasSelection("g")); 401 402 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('f'))); 403 onHandleView(com.android.internal.R.id.selection_end_handle) 404 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); 405 onView(withId(R.id.textview)).check(hasSelection("e")); 406 } 407 408 @SmallTest 409 public void testSelectionHandles_doesNotPassAnotherHandle_multiLine() throws Exception { 410 final String text = "abcd\n" + "efg\n" + "hijk\n" + "lmn\n" + "opqr"; 411 onView(withId(R.id.textview)).perform(click()); 412 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 413 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 414 415 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 416 onHandleView(com.android.internal.R.id.selection_start_handle) 417 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('r') + 1)); 418 onView(withId(R.id.textview)).check(hasSelection("k")); 419 420 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 421 onHandleView(com.android.internal.R.id.selection_end_handle) 422 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('a'))); 423 onView(withId(R.id.textview)).check(hasSelection("h")); 424 } 425 426 @SmallTest 427 public void testSelectionHandles_snapToWordBoundary() throws Exception { 428 final String text = "abcd efg hijk lmn opqr"; 429 onView(withId(R.id.textview)).perform(click()); 430 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 431 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 432 433 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 434 435 onHandleView(com.android.internal.R.id.selection_start_handle) 436 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('f'))); 437 onView(withId(R.id.textview)).check(hasSelection("efg hijk")); 438 439 onHandleView(com.android.internal.R.id.selection_start_handle) 440 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d') + 1)); 441 onView(withId(R.id.textview)).check(hasSelection("efg hijk")); 442 443 444 onHandleView(com.android.internal.R.id.selection_start_handle) 445 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c'))); 446 onView(withId(R.id.textview)).check(hasSelection("abcd efg hijk")); 447 448 onHandleView(com.android.internal.R.id.selection_start_handle) 449 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('d'))); 450 onView(withId(R.id.textview)).check(hasSelection("d efg hijk")); 451 452 onHandleView(com.android.internal.R.id.selection_start_handle) 453 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('b'))); 454 onView(withId(R.id.textview)).check(hasSelection("bcd efg hijk")); 455 456 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 457 458 onHandleView(com.android.internal.R.id.selection_end_handle) 459 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('n'))); 460 onView(withId(R.id.textview)).check(hasSelection("hijk lmn")); 461 462 onHandleView(com.android.internal.R.id.selection_end_handle) 463 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('o'))); 464 onView(withId(R.id.textview)).check(hasSelection("hijk lmn")); 465 466 onHandleView(com.android.internal.R.id.selection_end_handle) 467 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('q'))); 468 onView(withId(R.id.textview)).check(hasSelection("hijk lmn opqr")); 469 470 onHandleView(com.android.internal.R.id.selection_end_handle) 471 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p'))); 472 onView(withId(R.id.textview)).check(hasSelection("hijk lmn o")); 473 474 onHandleView(com.android.internal.R.id.selection_end_handle) 475 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('r'))); 476 onView(withId(R.id.textview)).check(hasSelection("hijk lmn opq")); 477 } 478 479 @SmallTest 480 public void testSelectionHandles_snapToWordBoundary_multiLine() throws Exception { 481 final String text = "abcd efg\n" + "hijk lmn\n" + "opqr stu"; 482 onView(withId(R.id.textview)).perform(click()); 483 onView(withId(R.id.textview)).perform(typeTextIntoFocusedView(text)); 484 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('m'))); 485 486 final TextView textView = (TextView) getActivity().findViewById(R.id.textview); 487 488 onHandleView(com.android.internal.R.id.selection_start_handle) 489 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('c'))); 490 onView(withId(R.id.textview)).check(hasSelection("abcd efg\nhijk lmn")); 491 492 onHandleView(com.android.internal.R.id.selection_start_handle) 493 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('g'))); 494 onView(withId(R.id.textview)).check(hasSelection("g\nhijk lmn")); 495 496 onHandleView(com.android.internal.R.id.selection_start_handle) 497 .perform(dragHandle(textView, Handle.SELECTION_START, text.indexOf('m'))); 498 onView(withId(R.id.textview)).check(hasSelection("lmn")); 499 500 onView(withId(R.id.textview)).perform(doubleClickOnTextAtIndex(text.indexOf('i'))); 501 502 onHandleView(com.android.internal.R.id.selection_end_handle) 503 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('u'))); 504 onView(withId(R.id.textview)).check(hasSelection("hijk lmn\nopqr stu")); 505 506 onHandleView(com.android.internal.R.id.selection_end_handle) 507 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('p'))); 508 onView(withId(R.id.textview)).check(hasSelection("hijk lmn\no")); 509 510 onHandleView(com.android.internal.R.id.selection_end_handle) 511 .perform(dragHandle(textView, Handle.SELECTION_END, text.indexOf('i'))); 512 onView(withId(R.id.textview)).check(hasSelection("hijk")); 513 } 514} 515