Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0aaed5d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix Angler search tests."

parents 10683847 38212a49
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.documentsui.StubProvider.ROOT_1_ID;


import android.net.Uri;
import android.net.Uri;
import android.os.RemoteException;
import android.os.RemoteException;
import android.support.test.filters.Suppress;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.KeyEvent;
import android.view.KeyEvent;


@@ -50,6 +51,7 @@ public class FileManagementUiTest extends ActivityTest<FilesActivity> {
        mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text");
        mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text");
    }
    }


    @Suppress
    public void testCreateDirectory() throws Exception {
    public void testCreateDirectory() throws Exception {
        bots.main.openOverflowMenu();
        bots.main.openOverflowMenu();
        device.waitForIdle();
        device.waitForIdle();
+8 −26
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.documentsui.StubProvider.ROOT_0_ID;
import static com.android.documentsui.StubProvider.ROOT_1_ID;
import static com.android.documentsui.StubProvider.ROOT_1_ID;


import android.support.test.filters.Suppress;
import android.support.test.filters.Suppress;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.v7.recyclerview.R;
import android.support.v7.recyclerview.R;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.LargeTest;


@@ -38,16 +37,18 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
      // Drawer interferes with a lot of search action; going to try to close any opened ones
      // Drawer interferes with a lot of search action; going to try to close any opened ones
      bots.roots.closeDrawer();
      bots.roots.closeDrawer();


      openRoot(ROOT_0_ID);  // Even if this is the default root...it `wait`s for more better tests
      // wait for a file to be present in default dir.
      bots.directory.waitForDocument(fileName1);
    }
    }


    public void testSearchIconVisible_RootWithSearchSupport() throws Exception {
    public void testSearchIconVisible() throws Exception {
        // The default root (root 0) supports search
        bots.search.assertInputExists(false);
        bots.search.assertInputExists(false);
        bots.search.assertIconVisible(true);
        bots.search.assertIconVisible(true);
    }
    }


    public void testSearchIconHidden_RootNoSearchSupport() throws Exception {
    public void testSearchIconHidden() throws Exception {
        openRoot(ROOT_1_ID);
        bots.roots.openRoot(ROOT_1_ID);  // root 1 doesn't support search


        bots.search.assertIconVisible(false);
        bots.search.assertIconVisible(false);
        bots.search.assertInputExists(false);
        bots.search.assertInputExists(false);
@@ -152,32 +153,13 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {


        bots.keyboard.pressEnter();
        bots.keyboard.pressEnter();


        openRoot(ROOT_1_ID);
        bots.roots.openRoot(ROOT_1_ID);
        device.waitForIdle();
        device.waitForIdle();
        assertDefaultContentOfTestDir1();
        assertDefaultContentOfTestDir1();


        openRoot(ROOT_0_ID);
        bots.roots.openRoot(ROOT_0_ID);
        device.waitForIdle();
        device.waitForIdle();


        assertDefaultContentOfTestDir0();
        assertDefaultContentOfTestDir0();
    }
    }

    void openRoot(String rootId) throws UiObjectNotFoundException {
        bots.roots.openRoot(rootId);
        // Open the named root and wait for a known file in it.
        // You can find known files by looking in super.initTestFiles();
        switch(rootId) {
            case ROOT_0_ID:
                bots.directory.waitForDocument(fileName1);
                break;
            case ROOT_1_ID:
                bots.directory.waitForDocument(fileName3);
                break;
            case "Downloads":
                device.waitForIdle();
                break;
            default:
                throw new IllegalArgumentException("Unsupported root: " + rootId);
        }
    }
}
}
+18 −3
Original line number Original line Diff line number Diff line
@@ -20,8 +20,10 @@ import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.is;


import android.content.Context;
import android.content.Context;
@@ -29,9 +31,11 @@ import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.view.View;


import com.android.documentsui.DragOverTextView;
import com.android.documentsui.DragOverTextView;
import com.android.documentsui.DropdownBreadcrumb;
import com.android.documentsui.DropdownBreadcrumb;
import com.android.documentsui.R;
import com.android.documentsui.model.DocumentInfo;
import com.android.documentsui.model.DocumentInfo;


import org.hamcrest.Description;
import org.hamcrest.Description;
@@ -53,6 +57,18 @@ import junit.framework.Assert;
public class BreadBot extends Bots.BaseBot {
public class BreadBot extends Bots.BaseBot {


    public static final String TARGET_PKG = "com.android.documentsui";
    public static final String TARGET_PKG = "com.android.documentsui";

    private static final Matcher<View> DROPDOWN_BREADCRUMB = withId(
            R.id.dropdown_breadcrumb);

    private static final Matcher<View> HORIZONTAL_BREADCRUMB = withId(
            R.id.horizontal_breadcrumb);

    // When any 'ol breadcrumb will do. Could be dropdown or horizontal.
    @SuppressWarnings("unchecked")
    private static final Matcher<View> BREADCRUMB = anyOf(
            DROPDOWN_BREADCRUMB, HORIZONTAL_BREADCRUMB);

    private UiBot mMain;
    private UiBot mMain;


    public BreadBot(UiDevice device, Context context, int timeout, UiBot main) {
    public BreadBot(UiDevice device, Context context, int timeout, UiBot main) {
@@ -65,7 +81,7 @@ public class BreadBot extends Bots.BaseBot {
        // so we only test on dropdown.
        // so we only test on dropdown.
        if (mMain.inDrawerLayout()) {
        if (mMain.inDrawerLayout()) {
            Matcher<Object> titleMatcher = dropdownTitleMatcher(expected);
            Matcher<Object> titleMatcher = dropdownTitleMatcher(expected);
            onView(Matchers.BREADCRUMB)
            onView(BREADCRUMB)
                    .check(matches(titleMatcher));
                    .check(matches(titleMatcher));
        }
        }
    }
    }
@@ -76,7 +92,7 @@ public class BreadBot extends Bots.BaseBot {
     */
     */
    public void revealAsNeeded() throws Exception {
    public void revealAsNeeded() throws Exception {
        if (mMain.inDrawerLayout()) {
        if (mMain.inDrawerLayout()) {
            onView(Matchers.DROPDOWN_BREADCRUMB).perform(click());
            onView(DROPDOWN_BREADCRUMB).perform(click());
        }
        }
    }
    }


@@ -115,7 +131,6 @@ public class BreadBot extends Bots.BaseBot {


    @SuppressWarnings("unchecked")
    @SuppressWarnings("unchecked")
    public ViewInteraction findHorizontalEntry(String label) {
    public ViewInteraction findHorizontalEntry(String label) {
        // Matchers.HORIZONTAL_BREADCRUMB
        return onView(allOf(isAssignableFrom(DragOverTextView.class), withText(label)));
        return onView(allOf(isAssignableFrom(DragOverTextView.class), withText(label)));
    }
    }


+1 −60
Original line number Original line Diff line number Diff line
@@ -18,79 +18,20 @@ package com.android.documentsui.bots;


import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withResourceName;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.Matchers.endsWith;


import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toolbar;

import com.android.documentsui.R;
import com.android.internal.view.menu.ActionMenuItemView;


import org.hamcrest.Matcher;
import org.hamcrest.Matcher;


/**
/**
 * Handy matchers useful for finding stuff in the UI. Use with Espresso testing.
 * Support methods for working with Espresso related matchers 'n stuff.
 */
 */
@SuppressWarnings("unchecked")
public final class Matchers {
public final class Matchers {


    private Matchers() {}
    private Matchers() {}


    public static final Matcher<View> TOOLBAR = allOf(
            isAssignableFrom(Toolbar.class),
            withId(R.id.toolbar));

    public static final Matcher<View> ACTIONBAR = allOf(
            withClassName(endsWith("ActionBarContextView")));

    public static final Matcher<View> SEARCH_MENU = allOf(
            withId(R.id.menu_search),
            isDisplayed());

    public static final Matcher<View> SEARCH_BUTTON = allOf(
            isAssignableFrom(ImageView.class),
            withResourceName("search_button"));

    public static final Matcher<View> MENU_SEARCH = allOf(
            isAssignableFrom(ActionMenuItemView.class),
            withResourceName("menu_search"));

    public static final Matcher<View> DROPDOWN_BREADCRUMB = withId(
            R.id.dropdown_breadcrumb);

    public static final Matcher<View> HORIZONTAL_BREADCRUMB = withId(
            R.id.horizontal_breadcrumb);

    // When any 'ol breadcrumb will do. Could be dropdown or horizontal.
    public static final Matcher<View> BREADCRUMB = anyOf(
            DROPDOWN_BREADCRUMB, HORIZONTAL_BREADCRUMB);

    public static final Matcher<View> TEXT_ENTRY = allOf(
            withClassName(endsWith("EditText")));

    public static final Matcher<View> TOOLBAR_OVERFLOW = allOf(
            withClassName(endsWith("OverflowMenuButton")),
            ViewMatchers.isDescendantOfA(TOOLBAR));

    public static final Matcher<View> ACTIONBAR_OVERFLOW = allOf(
            withClassName(endsWith("OverflowMenuButton")),
            ViewMatchers.isDescendantOfA(ACTIONBAR));

    public static final Matcher<View> DIRECTORY_LIST = allOf(
            isAssignableFrom(RecyclerView.class),
            withId(R.id.dir_list));

    public static boolean present(Matcher<View> matcher) {
    public static boolean present(Matcher<View> matcher) {
        return present(onView(matcher), isDisplayed());
        return present(onView(matcher), isDisplayed());
    }
    }
+26 −3
Original line number Original line Diff line number Diff line
@@ -18,15 +18,24 @@ package com.android.documentsui.bots;


import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isClickable;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;


import android.content.Context;
import android.content.Context;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.v7.recyclerview.R;
import android.support.v7.recyclerview.R;
import android.view.View;

import org.hamcrest.Matcher;


/**
/**
 * A test helper class that provides support for controlling the search UI
 * A test helper class that provides support for controlling the search UI
@@ -38,6 +47,20 @@ public class SearchBot extends Bots.BaseBot {


    public static final String TARGET_PKG = "com.android.documentsui";
    public static final String TARGET_PKG = "com.android.documentsui";


    // Dumb search layout changes substantially between Ryu and Angler.
    @SuppressWarnings("unchecked")
    private static final Matcher<View> SEARCH_WIDGET = allOf(
            withId(R.id.menu_search),
            anyOf(isClickable(), hasDescendant(isClickable())));

    // Note that input is visible when the clicky button is not
    // present. So to clearly qualify the two...we explicitly
    // require this input be not clickable.
    @SuppressWarnings("unchecked")
    private static final Matcher<View> SEARCH_INPUT = allOf(
            withId(R.id.menu_search),
            isDisplayed());

    public SearchBot(UiDevice device, Context context, int timeout) {
    public SearchBot(UiDevice device, Context context, int timeout) {
        super(device, context, timeout);
        super(device, context, timeout);
    }
    }
@@ -49,18 +72,18 @@ public class SearchBot extends Bots.BaseBot {
    }
    }


    public void setInputText(String query) throws UiObjectNotFoundException {
    public void setInputText(String query) throws UiObjectNotFoundException {
        onView(Matchers.SEARCH_MENU).perform(typeText(query));
        onView(SEARCH_INPUT).perform(typeText(query));
    }
    }


    public void assertIconVisible(boolean visible) {
    public void assertIconVisible(boolean visible) {
        if (visible) {
        if (visible) {
            assertTrue(
            assertTrue(
                    "Search icon should be visible.",
                    "Search icon should be visible.",
                    Matchers.present(Matchers.SEARCH_BUTTON));
                    Matchers.present(SEARCH_WIDGET));
        } else {
        } else {
            assertFalse(
            assertFalse(
                    "Search icon should not be visible.",
                    "Search icon should not be visible.",
                    Matchers.present(Matchers.SEARCH_BUTTON));
                    Matchers.present(SEARCH_WIDGET));
        }
        }
    }
    }


Loading