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