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 17package android.widget.espresso; 18 19import static android.support.test.espresso.Espresso.onView; 20import static android.support.test.espresso.assertion.ViewAssertions.matches; 21import static android.support.test.espresso.matcher.RootMatchers.withDecorView; 22import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant; 23import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; 24import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 25import static android.support.test.espresso.matcher.ViewMatchers.withId; 26import static org.hamcrest.Matchers.allOf; 27 28import android.support.test.espresso.NoMatchingRootException; 29import android.support.test.espresso.NoMatchingViewException; 30import android.support.test.espresso.ViewInteraction; 31import android.widget.Editor; 32 33public class DragHandleUtils { 34 private DragHandleUtils() { 35 36 } 37 38 public static void assertNoSelectionHandles() { 39 try { 40 onHandleView(com.android.internal.R.id.selection_start_handle) 41 .check(matches(isDisplayed())); 42 } catch (NoMatchingRootException | NoMatchingViewException | AssertionError e) { 43 try { 44 onHandleView(com.android.internal.R.id.selection_end_handle) 45 .check(matches(isDisplayed())); 46 } catch (NoMatchingRootException | NoMatchingViewException | AssertionError e1) { 47 return; 48 } 49 } 50 throw new AssertionError("Selection handle found"); 51 } 52 53 public static ViewInteraction onHandleView(int id) 54 throws NoMatchingRootException, NoMatchingViewException, AssertionError { 55 return onView(allOf(withId(id), isAssignableFrom(Editor.HandleView.class))) 56 .inRoot(withDecorView(hasDescendant(withId(id)))); 57 } 58} 59