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 androidx.test.espresso.Espresso.onView;
20 import static androidx.test.espresso.assertion.ViewAssertions.matches;
21 import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup;
22 import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
23 import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
24 import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
25 import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
26 import static androidx.test.espresso.matcher.ViewMatchers.withId;
27 
28 import static org.hamcrest.Matchers.allOf;
29 
30 import android.widget.Editor;
31 
32 import androidx.test.espresso.NoMatchingRootException;
33 import androidx.test.espresso.NoMatchingViewException;
34 import androidx.test.espresso.ViewInteraction;
35 
36 public final class DragHandleUtils {
37 
DragHandleUtils()38     private DragHandleUtils() {}
39 
40     /**
41      * @deprecated Negative assertions are taking too long to timeout in Espresso.
42      */
43     @Deprecated
assertNoSelectionHandles()44     public static void assertNoSelectionHandles() {
45         try {
46             onView(isAssignableFrom(Editor.SelectionHandleView.class))
47                     .inRoot(isPlatformPopup())
48                     .check(matches(isDisplayed()));
49         } catch (NoMatchingRootException | NoMatchingViewException | AssertionError e) {
50             return;
51         }
52         throw new AssertionError("Selection handle found");
53     }
54 
onHandleView(int id)55     public static ViewInteraction onHandleView(int id)
56             throws NoMatchingRootException, NoMatchingViewException, AssertionError {
57         return onView(allOf(
58                         withId(id),
59                         isAssignableFrom(Editor.HandleView.class)))
60                 .inRoot(allOf(
61                         isPlatformPopup(),
62                         withDecorView(hasDescendant(withId(id)))));
63     }
64 }
65