/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.documentsui.bots;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasFocus;
import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.endsWith;
import android.content.Context;
import android.util.TypedValue;
import android.view.View;
import androidx.appcompat.widget.Toolbar;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.matcher.BoundedMatcher;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;
import androidx.test.uiautomator.Until;
import com.android.documentsui.R;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import java.util.Iterator;
import java.util.List;
/**
* A test helper class that provides support for controlling DocumentsUI activities
* programmatically, and making assertions against the state of the UI.
*
* Support for working directly with Roots and Directory view can be found in the respective bots.
*/
public class UiBot extends Bots.BaseBot {
@SuppressWarnings("unchecked")
private static final Matcher TOOLBAR = allOf(
isAssignableFrom(Toolbar.class),
withId(R.id.toolbar));
@SuppressWarnings("unchecked")
private static final Matcher ACTIONBAR = allOf(
withClassName(endsWith("ActionBarContextView")));
@SuppressWarnings("unchecked")
private static final Matcher TEXT_ENTRY = allOf(
withClassName(endsWith("EditText")));
@SuppressWarnings("unchecked")
private static final Matcher TOOLBAR_OVERFLOW = allOf(
withClassName(endsWith("OverflowMenuButton")),
ViewMatchers.isDescendantOfA(TOOLBAR));
@SuppressWarnings("unchecked")
private static final Matcher ACTIONBAR_OVERFLOW = allOf(
withClassName(endsWith("OverflowMenuButton")),
ViewMatchers.isDescendantOfA(ACTIONBAR));
public static String targetPackageName;
public UiBot(UiDevice device, Context context, int timeout) {
super(device, context, timeout);
targetPackageName =
InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName();
}
private static Matcher