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