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