Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [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 | |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 19 | |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 20 | import static android.support.test.espresso.Espresso.onView; |
| 21 | import static android.support.test.espresso.Espresso.pressBack; |
| 22 | import static android.support.test.espresso.action.ViewActions.replaceText; |
| 23 | import static android.support.test.espresso.action.ViewActions.typeText; |
| 24 | import static android.support.test.espresso.assertion.ViewAssertions.matches; |
| 25 | import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; |
| 26 | import static android.support.test.espresso.matcher.ViewMatchers.withId; |
| 27 | import static android.support.test.espresso.matcher.ViewMatchers.withText; |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 28 | import static android.widget.espresso.ContextMenuUtils.assertContextMenuContainsItemDisabled; |
| 29 | import static android.widget.espresso.ContextMenuUtils.assertContextMenuContainsItemEnabled; |
| 30 | import static android.widget.espresso.ContextMenuUtils.assertContextMenuIsNotDisplayed; |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 31 | import static android.widget.espresso.DragHandleUtils.assertNoSelectionHandles; |
| 32 | import static android.widget.espresso.DragHandleUtils.onHandleView; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 33 | import static android.widget.espresso.TextViewActions.mouseClick; |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 34 | import static android.widget.espresso.TextViewActions.mouseClickOnTextAtIndex; |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 35 | import static android.widget.espresso.TextViewActions.mouseDoubleClickAndDragOnText; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 36 | import static android.widget.espresso.TextViewActions.mouseDoubleClickOnTextAtIndex; |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 37 | import static android.widget.espresso.TextViewActions.mouseDragOnText; |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 38 | import static android.widget.espresso.TextViewActions.mouseLongClickAndDragOnText; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 39 | import static android.widget.espresso.TextViewActions.mouseLongClickOnTextAtIndex; |
Keisuke Kuroyanagi | 46faad6 | 2015-12-06 10:03:23 -0800 | [diff] [blame] | 40 | import static android.widget.espresso.TextViewActions.mouseTripleClickAndDragOnText; |
| 41 | import static android.widget.espresso.TextViewActions.mouseTripleClickOnTextAtIndex; |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 42 | import static android.widget.espresso.TextViewAssertions.hasInsertionPointerAtIndex; |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 43 | import static android.widget.espresso.TextViewAssertions.hasSelection; |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 44 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 45 | import android.app.Activity; |
| 46 | import android.support.test.filters.MediumTest; |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 47 | import android.support.test.filters.Suppress; |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 48 | import android.support.test.rule.ActivityTestRule; |
| 49 | import android.support.test.runner.AndroidJUnit4; |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 50 | import android.view.MotionEvent; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 51 | import android.view.textclassifier.TextClassificationManager; |
| 52 | import android.view.textclassifier.TextClassifier; |
| 53 | |
| 54 | import com.android.frameworks.coretests.R; |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 55 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 56 | import org.junit.Before; |
| 57 | import org.junit.Rule; |
| 58 | import org.junit.Test; |
| 59 | import org.junit.runner.RunWith; |
| 60 | |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 61 | /** |
| 62 | * Tests mouse interaction of the TextView widget from an Activity |
| 63 | */ |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 64 | @RunWith(AndroidJUnit4.class) |
| 65 | @MediumTest |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 66 | @Suppress // Consistently failing. b/29591177 |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 67 | public class TextViewActivityMouseTest { |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 68 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 69 | @Rule |
| 70 | public ActivityTestRule<TextViewActivity> mActivityRule = new ActivityTestRule<>( |
| 71 | TextViewActivity.class); |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 72 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 73 | private Activity mActivity; |
| 74 | |
| 75 | @Before |
| 76 | public void setUp() { |
| 77 | mActivity = mActivityRule.getActivity(); |
| 78 | mActivity.getSystemService(TextClassificationManager.class) |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 79 | .setTextClassifier(TextClassifier.NO_OP); |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 82 | @Test |
| 83 | public void testSelectTextByDrag() { |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 84 | final String helloWorld = "Hello world!"; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 85 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 86 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 87 | |
| 88 | assertNoSelectionHandles(); |
| 89 | |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 90 | onView(withId(R.id.textview)).perform( |
| 91 | mouseDragOnText(helloWorld.indexOf("llo"), helloWorld.indexOf("ld!"))); |
| 92 | |
| 93 | onView(withId(R.id.textview)).check(hasSelection("llo wor")); |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 94 | |
| 95 | onHandleView(com.android.internal.R.id.selection_start_handle) |
| 96 | .check(matches(isDisplayed())); |
| 97 | onHandleView(com.android.internal.R.id.selection_end_handle) |
| 98 | .check(matches(isDisplayed())); |
| 99 | |
| 100 | onView(withId(R.id.textview)).perform(mouseClickOnTextAtIndex(helloWorld.indexOf("w"))); |
| 101 | onView(withId(R.id.textview)).check(hasSelection("")); |
| 102 | |
| 103 | assertNoSelectionHandles(); |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 104 | } |
Keisuke Kuroyanagi | ead6ba3 | 2015-10-27 17:26:07 +0900 | [diff] [blame] | 105 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 106 | @Test |
| 107 | public void testSelectTextByDrag_reverse() { |
Keisuke Kuroyanagi | ead6ba3 | 2015-10-27 17:26:07 +0900 | [diff] [blame] | 108 | final String helloWorld = "Hello world!"; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 109 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 110 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Keisuke Kuroyanagi | ead6ba3 | 2015-10-27 17:26:07 +0900 | [diff] [blame] | 111 | onView(withId(R.id.textview)).perform( |
| 112 | mouseDragOnText( helloWorld.indexOf("ld!"), helloWorld.indexOf("llo"))); |
| 113 | |
| 114 | onView(withId(R.id.textview)).check(hasSelection("llo wor")); |
| 115 | } |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 116 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 117 | @Test |
| 118 | public void testContextMenu() { |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 119 | final String text = "abc def ghi."; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 120 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 121 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 122 | |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 123 | assertContextMenuIsNotDisplayed(); |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 124 | |
| 125 | onView(withId(R.id.textview)).perform( |
| 126 | mouseClickOnTextAtIndex(text.indexOf("d"), MotionEvent.BUTTON_SECONDARY)); |
| 127 | |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 128 | assertContextMenuContainsItemDisabled( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 129 | mActivity.getString(com.android.internal.R.string.copy)); |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 130 | assertContextMenuContainsItemDisabled( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 131 | mActivity.getString(com.android.internal.R.string.undo)); |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 132 | |
| 133 | // Hide context menu. |
| 134 | pressBack(); |
| 135 | assertContextMenuIsNotDisplayed(); |
| 136 | |
| 137 | // type something to enable Undo |
| 138 | onView(withId(R.id.textview)).perform( |
| 139 | mouseClickOnTextAtIndex(text.indexOf("."))); |
| 140 | onView(withId(R.id.textview)).perform(typeText(" ")); |
| 141 | |
| 142 | onView(withId(R.id.textview)).perform( |
| 143 | mouseClickOnTextAtIndex(text.indexOf("d"), MotionEvent.BUTTON_SECONDARY)); |
| 144 | |
| 145 | assertContextMenuContainsItemDisabled( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 146 | mActivity.getString(com.android.internal.R.string.copy)); |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 147 | assertContextMenuContainsItemEnabled( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 148 | mActivity.getString(com.android.internal.R.string.undo)); |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 149 | |
| 150 | // Hide context menu. |
| 151 | pressBack(); |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 152 | assertContextMenuIsNotDisplayed(); |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 153 | |
| 154 | onView(withId(R.id.textview)).perform( |
| 155 | mouseDragOnText(text.indexOf("c"), text.indexOf("h"))); |
| 156 | onView(withId(R.id.textview)).perform( |
| 157 | mouseClickOnTextAtIndex(text.indexOf("d"), MotionEvent.BUTTON_SECONDARY)); |
| 158 | |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 159 | assertContextMenuContainsItemEnabled( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 160 | mActivity.getString(com.android.internal.R.string.copy)); |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 161 | assertContextMenuContainsItemEnabled( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 162 | mActivity.getString(com.android.internal.R.string.undo)); |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 163 | |
| 164 | // Hide context menu. |
| 165 | pressBack(); |
| 166 | |
| 167 | onView(withId(R.id.textview)).check(hasSelection("c def g")); |
| 168 | |
| 169 | onView(withId(R.id.textview)).perform( |
| 170 | mouseClickOnTextAtIndex(text.indexOf("i"), MotionEvent.BUTTON_SECONDARY)); |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 171 | assertContextMenuContainsItemDisabled( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 172 | mActivity.getString(com.android.internal.R.string.copy)); |
Keisuke Kuroyanagi | 31eb74f | 2016-04-06 19:37:46 +0900 | [diff] [blame] | 173 | assertContextMenuContainsItemEnabled( |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 174 | mActivity.getString(com.android.internal.R.string.undo)); |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 175 | |
| 176 | // Hide context menu. |
| 177 | pressBack(); |
| 178 | |
| 179 | onView(withId(R.id.textview)).check(hasSelection("")); |
| 180 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex(text.indexOf("i"))); |
Keisuke Kuroyanagi | 182f5fe | 2016-03-11 16:31:29 +0900 | [diff] [blame] | 181 | |
| 182 | // TODO: Add tests for suggestions |
Keisuke Kuroyanagi | a0b3c06 | 2015-12-07 11:09:40 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 185 | @Test |
| 186 | public void testDragAndDrop() { |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 187 | final String text = "abc def ghi."; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 188 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 189 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 190 | onView(withId(R.id.textview)).perform( |
| 191 | mouseDragOnText(text.indexOf("d"), text.indexOf("f") + 1)); |
| 192 | |
| 193 | onView(withId(R.id.textview)).perform( |
| 194 | mouseDragOnText(text.indexOf("e"), text.length())); |
| 195 | |
| 196 | onView(withId(R.id.textview)).check(matches(withText("abc ghi.def"))); |
| 197 | onView(withId(R.id.textview)).check(hasSelection("")); |
| 198 | assertNoSelectionHandles(); |
| 199 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex("abc ghi.def".length())); |
| 200 | } |
| 201 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 202 | @Test |
| 203 | public void testDragAndDrop_longClick() { |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 204 | final String text = "abc def ghi."; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 205 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 206 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 4307aeb | 2015-12-07 11:16:39 -0800 | [diff] [blame] | 207 | onView(withId(R.id.textview)).perform( |
| 208 | mouseDragOnText(text.indexOf("d"), text.indexOf("f") + 1)); |
| 209 | |
| 210 | onView(withId(R.id.textview)).perform( |
| 211 | mouseLongClickAndDragOnText(text.indexOf("e"), text.length())); |
| 212 | |
| 213 | onView(withId(R.id.textview)).check(matches(withText("abc ghi.def"))); |
| 214 | onView(withId(R.id.textview)).check(hasSelection("")); |
| 215 | assertNoSelectionHandles(); |
| 216 | onView(withId(R.id.textview)).check(hasInsertionPointerAtIndex("abc ghi.def".length())); |
| 217 | } |
| 218 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 219 | @Test |
| 220 | public void testSelectTextByLongClick() { |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 221 | final String helloWorld = "Hello world!"; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 222 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 223 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 224 | |
| 225 | onView(withId(R.id.textview)).perform(mouseLongClickOnTextAtIndex(0)); |
| 226 | onView(withId(R.id.textview)).check(hasSelection("Hello")); |
| 227 | |
| 228 | onView(withId(R.id.textview)).perform(mouseLongClickOnTextAtIndex( |
| 229 | helloWorld.indexOf("world"))); |
| 230 | onView(withId(R.id.textview)).check(hasSelection("world")); |
| 231 | |
| 232 | onView(withId(R.id.textview)).perform(mouseLongClickOnTextAtIndex( |
| 233 | helloWorld.indexOf("llo"))); |
| 234 | onView(withId(R.id.textview)).check(hasSelection("Hello")); |
| 235 | |
| 236 | onView(withId(R.id.textview)).perform(mouseLongClickOnTextAtIndex( |
| 237 | helloWorld.indexOf("rld"))); |
| 238 | onView(withId(R.id.textview)).check(hasSelection("world")); |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 239 | |
| 240 | onView(withId(R.id.textview)).perform(mouseLongClickOnTextAtIndex(helloWorld.length())); |
| 241 | onView(withId(R.id.textview)).check(hasSelection("!")); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 244 | @Test |
| 245 | public void testSelectTextByDoubleClick() { |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 246 | final String helloWorld = "hello world!"; |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 247 | |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 248 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 249 | onView(withId(R.id.textview)).perform(replaceText(helloWorld)); |
| 250 | |
| 251 | onView(withId(R.id.textview)).perform(mouseDoubleClickOnTextAtIndex(1)); |
| 252 | onView(withId(R.id.textview)).check(hasSelection("hello")); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 253 | |
| 254 | onView(withId(R.id.textview)).perform(mouseDoubleClickOnTextAtIndex( |
| 255 | helloWorld.indexOf("world"))); |
| 256 | onView(withId(R.id.textview)).check(hasSelection("world")); |
| 257 | |
| 258 | onView(withId(R.id.textview)).perform(mouseDoubleClickOnTextAtIndex( |
| 259 | helloWorld.indexOf("llo"))); |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 260 | onView(withId(R.id.textview)).check(hasSelection("hello")); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 261 | |
| 262 | onView(withId(R.id.textview)).perform(mouseDoubleClickOnTextAtIndex( |
| 263 | helloWorld.indexOf("rld"))); |
| 264 | onView(withId(R.id.textview)).check(hasSelection("world")); |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 265 | |
| 266 | onView(withId(R.id.textview)).perform(mouseDoubleClickOnTextAtIndex(helloWorld.length())); |
| 267 | onView(withId(R.id.textview)).check(hasSelection("!")); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 270 | @Test |
| 271 | public void testSelectTextByDoubleClickAndDrag() { |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 272 | final String text = "abcd efg hijk lmn"; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 273 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 274 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 275 | |
| 276 | onView(withId(R.id.textview)).perform( |
| 277 | mouseDoubleClickAndDragOnText(text.indexOf("f"), text.indexOf("j"))); |
| 278 | onView(withId(R.id.textview)).check(hasSelection("efg hijk")); |
| 279 | } |
| 280 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 281 | @Test |
| 282 | public void testSelectTextByDoubleClickAndDrag_reverse() { |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 283 | final String text = "abcd efg hijk lmn"; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 284 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 285 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 286 | |
| 287 | onView(withId(R.id.textview)).perform( |
| 288 | mouseDoubleClickAndDragOnText(text.indexOf("j"), text.indexOf("f"))); |
| 289 | onView(withId(R.id.textview)).check(hasSelection("efg hijk")); |
| 290 | } |
| 291 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 292 | @Test |
| 293 | public void testSelectTextByLongPressAndDrag() { |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 294 | final String text = "abcd efg hijk lmn"; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 295 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 296 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 297 | |
| 298 | onView(withId(R.id.textview)).perform( |
| 299 | mouseLongClickAndDragOnText(text.indexOf("f"), text.indexOf("j"))); |
| 300 | onView(withId(R.id.textview)).check(hasSelection("efg hijk")); |
| 301 | } |
| 302 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 303 | @Test |
| 304 | public void testSelectTextByLongPressAndDrag_reverse() { |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 305 | final String text = "abcd efg hijk lmn"; |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 306 | onView(withId(R.id.textview)).perform(mouseClick()); |
| 307 | onView(withId(R.id.textview)).perform(replaceText(text)); |
Keisuke Kuroyanagi | 2ff41d4 | 2015-12-01 16:58:53 -0800 | [diff] [blame] | 308 | |
| 309 | onView(withId(R.id.textview)).perform( |
| 310 | mouseLongClickAndDragOnText(text.indexOf("j"), text.indexOf("f"))); |
| 311 | onView(withId(R.id.textview)).check(hasSelection("efg hijk")); |
| 312 | } |
Keisuke Kuroyanagi | 46faad6 | 2015-12-06 10:03:23 -0800 | [diff] [blame] | 313 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 314 | @Test |
| 315 | public void testSelectTextByTripleClick() { |
Keisuke Kuroyanagi | 46faad6 | 2015-12-06 10:03:23 -0800 | [diff] [blame] | 316 | final StringBuilder builder = new StringBuilder(); |
| 317 | builder.append("First paragraph.\n"); |
| 318 | builder.append("Second paragraph."); |
| 319 | for (int i = 0; i < 10; i++) { |
| 320 | builder.append(" This paragraph is very long."); |
| 321 | } |
| 322 | builder.append('\n'); |
| 323 | builder.append("Third paragraph."); |
| 324 | final String text = builder.toString(); |
| 325 | |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 326 | onView(withId(R.id.textview)).perform(mouseClick()); |
Keisuke Kuroyanagi | 46faad6 | 2015-12-06 10:03:23 -0800 | [diff] [blame] | 327 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 328 | |
| 329 | onView(withId(R.id.textview)).perform( |
| 330 | mouseTripleClickOnTextAtIndex(text.indexOf("rst"))); |
| 331 | onView(withId(R.id.textview)).check(hasSelection("First paragraph.\n")); |
| 332 | |
| 333 | onView(withId(R.id.textview)).perform( |
| 334 | mouseTripleClickOnTextAtIndex(text.indexOf("cond"))); |
| 335 | onView(withId(R.id.textview)).check(hasSelection( |
| 336 | text.substring(text.indexOf("Second"), text.indexOf("Third")))); |
| 337 | |
| 338 | onView(withId(R.id.textview)).perform( |
| 339 | mouseTripleClickOnTextAtIndex(text.indexOf("ird"))); |
| 340 | onView(withId(R.id.textview)).check(hasSelection("Third paragraph.")); |
| 341 | |
| 342 | onView(withId(R.id.textview)).perform( |
| 343 | mouseTripleClickOnTextAtIndex(text.indexOf("very long"))); |
| 344 | onView(withId(R.id.textview)).check(hasSelection( |
| 345 | text.substring(text.indexOf("Second"), text.indexOf("Third")))); |
| 346 | } |
| 347 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 348 | @Test |
| 349 | public void testSelectTextByTripleClickAndDrag() { |
Keisuke Kuroyanagi | 46faad6 | 2015-12-06 10:03:23 -0800 | [diff] [blame] | 350 | final StringBuilder builder = new StringBuilder(); |
| 351 | builder.append("First paragraph.\n"); |
| 352 | builder.append("Second paragraph."); |
| 353 | for (int i = 0; i < 10; i++) { |
| 354 | builder.append(" This paragraph is very long."); |
| 355 | } |
| 356 | builder.append('\n'); |
| 357 | builder.append("Third paragraph."); |
| 358 | final String text = builder.toString(); |
| 359 | |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 360 | onView(withId(R.id.textview)).perform(mouseClick()); |
Keisuke Kuroyanagi | 46faad6 | 2015-12-06 10:03:23 -0800 | [diff] [blame] | 361 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 362 | |
| 363 | onView(withId(R.id.textview)).perform( |
| 364 | mouseTripleClickAndDragOnText(text.indexOf("irst"), text.indexOf("st"))); |
| 365 | onView(withId(R.id.textview)).check(hasSelection("First paragraph.\n")); |
| 366 | |
| 367 | onView(withId(R.id.textview)).perform( |
| 368 | mouseTripleClickAndDragOnText(text.indexOf("cond"), text.indexOf("Third") - 2)); |
| 369 | onView(withId(R.id.textview)).check(hasSelection( |
| 370 | text.substring(text.indexOf("Second"), text.indexOf("Third")))); |
| 371 | |
| 372 | onView(withId(R.id.textview)).perform( |
| 373 | mouseTripleClickAndDragOnText(text.indexOf("First"), text.indexOf("ird"))); |
| 374 | onView(withId(R.id.textview)).check(hasSelection(text)); |
| 375 | } |
| 376 | |
Siyamed Sinir | 2191418 | 2017-06-16 15:24:00 -0700 | [diff] [blame] | 377 | @Test |
| 378 | public void testSelectTextByTripleClickAndDrag_reverse() { |
Keisuke Kuroyanagi | 46faad6 | 2015-12-06 10:03:23 -0800 | [diff] [blame] | 379 | final StringBuilder builder = new StringBuilder(); |
| 380 | builder.append("First paragraph.\n"); |
| 381 | builder.append("Second paragraph."); |
| 382 | for (int i = 0; i < 10; i++) { |
| 383 | builder.append(" This paragraph is very long."); |
| 384 | } |
| 385 | builder.append('\n'); |
| 386 | builder.append("Third paragraph."); |
| 387 | final String text = builder.toString(); |
| 388 | |
Siyamed Sinir | 6b61d81 | 2017-06-14 11:13:30 -0700 | [diff] [blame] | 389 | onView(withId(R.id.textview)).perform(mouseClick()); |
Keisuke Kuroyanagi | 46faad6 | 2015-12-06 10:03:23 -0800 | [diff] [blame] | 390 | onView(withId(R.id.textview)).perform(replaceText(text)); |
| 391 | |
| 392 | onView(withId(R.id.textview)).perform( |
| 393 | mouseTripleClickAndDragOnText(text.indexOf("st"), text.indexOf("irst"))); |
| 394 | onView(withId(R.id.textview)).check(hasSelection("First paragraph.\n")); |
| 395 | |
| 396 | onView(withId(R.id.textview)).perform( |
| 397 | mouseTripleClickAndDragOnText(text.indexOf("Third") - 2, text.indexOf("cond"))); |
| 398 | onView(withId(R.id.textview)).check(hasSelection( |
| 399 | text.substring(text.indexOf("Second"), text.indexOf("Third")))); |
| 400 | |
| 401 | onView(withId(R.id.textview)).perform( |
| 402 | mouseTripleClickAndDragOnText(text.indexOf("ird"), text.indexOf("First"))); |
| 403 | onView(withId(R.id.textview)).check(hasSelection(text)); |
| 404 | } |
Keisuke Kuroyanagi | 88cabed | 2015-10-08 19:12:56 +0900 | [diff] [blame] | 405 | } |