Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [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.espresso; |
| 18 | |
| 19 | import static android.support.test.espresso.Espresso.onView; |
| 20 | import static android.support.test.espresso.assertion.ViewAssertions.matches; |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 21 | import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup; |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 22 | import static android.support.test.espresso.matcher.RootMatchers.withDecorView; |
| 23 | import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant; |
| 24 | import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; |
| 25 | import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; |
| 26 | import static android.support.test.espresso.matcher.ViewMatchers.withId; |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 27 | |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 28 | import static org.hamcrest.Matchers.allOf; |
| 29 | |
| 30 | import android.support.test.espresso.NoMatchingRootException; |
| 31 | import android.support.test.espresso.NoMatchingViewException; |
| 32 | import android.support.test.espresso.ViewInteraction; |
| 33 | import android.widget.Editor; |
| 34 | |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 35 | public final class DragHandleUtils { |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 36 | |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 37 | private DragHandleUtils() {} |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 38 | |
| 39 | public static void assertNoSelectionHandles() { |
| 40 | try { |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 41 | onView(isAssignableFrom(Editor.SelectionHandleView.class)) |
| 42 | .inRoot(isPlatformPopup()) |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 43 | .check(matches(isDisplayed())); |
| 44 | } catch (NoMatchingRootException | NoMatchingViewException | AssertionError e) { |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 45 | return; |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 46 | } |
| 47 | throw new AssertionError("Selection handle found"); |
| 48 | } |
| 49 | |
| 50 | public static ViewInteraction onHandleView(int id) |
| 51 | throws NoMatchingRootException, NoMatchingViewException, AssertionError { |
Abodunrinwa Toki | 4a056a5 | 2017-08-05 01:56:40 +0100 | [diff] [blame] | 52 | return onView(allOf( |
| 53 | withId(id), |
| 54 | isAssignableFrom(Editor.HandleView.class))) |
| 55 | .inRoot(allOf( |
| 56 | isPlatformPopup(), |
| 57 | withDecorView(hasDescendant(withId(id))))); |
Keisuke Kuroyanagi | d42cb8f | 2015-12-06 10:02:09 -0800 | [diff] [blame] | 58 | } |
| 59 | } |