blob: 6a2233ba126e9ef4f2a6bed82db8a98ed02d3a0e [file] [log] [blame]
Keisuke Kuroyanagid42cb8f2015-12-06 10:02:09 -08001/*
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;
Abodunrinwa Toki4a056a52017-08-05 01:56:40 +010021import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup;
Keisuke Kuroyanagid42cb8f2015-12-06 10:02:09 -080022import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
23import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
24import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
25import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
26import static android.support.test.espresso.matcher.ViewMatchers.withId;
Abodunrinwa Toki4a056a52017-08-05 01:56:40 +010027
Keisuke Kuroyanagid42cb8f2015-12-06 10:02:09 -080028import static org.hamcrest.Matchers.allOf;
29
30import android.support.test.espresso.NoMatchingRootException;
31import android.support.test.espresso.NoMatchingViewException;
32import android.support.test.espresso.ViewInteraction;
33import android.widget.Editor;
34
Abodunrinwa Toki4a056a52017-08-05 01:56:40 +010035public final class DragHandleUtils {
Keisuke Kuroyanagid42cb8f2015-12-06 10:02:09 -080036
Abodunrinwa Toki4a056a52017-08-05 01:56:40 +010037 private DragHandleUtils() {}
Keisuke Kuroyanagid42cb8f2015-12-06 10:02:09 -080038
39 public static void assertNoSelectionHandles() {
40 try {
Abodunrinwa Toki4a056a52017-08-05 01:56:40 +010041 onView(isAssignableFrom(Editor.SelectionHandleView.class))
42 .inRoot(isPlatformPopup())
Keisuke Kuroyanagid42cb8f2015-12-06 10:02:09 -080043 .check(matches(isDisplayed()));
44 } catch (NoMatchingRootException | NoMatchingViewException | AssertionError e) {
Abodunrinwa Toki4a056a52017-08-05 01:56:40 +010045 return;
Keisuke Kuroyanagid42cb8f2015-12-06 10:02:09 -080046 }
47 throw new AssertionError("Selection handle found");
48 }
49
50 public static ViewInteraction onHandleView(int id)
51 throws NoMatchingRootException, NoMatchingViewException, AssertionError {
Abodunrinwa Toki4a056a52017-08-05 01:56:40 +010052 return onView(allOf(
53 withId(id),
54 isAssignableFrom(Editor.HandleView.class)))
55 .inRoot(allOf(
56 isPlatformPopup(),
57 withDecorView(hasDescendant(withId(id)))));
Keisuke Kuroyanagid42cb8f2015-12-06 10:02:09 -080058 }
59}