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

Commit 4376aa7c authored by Tony Huang's avatar Tony Huang
Browse files

Enhance some UI tests

1. Make UI tests can click or select with scroll
2. Reduce notification from test provider which might cause find root
   failed
3. Fine tune select function in tests

Bug: 150257481
Test: atest DocumentsUIGoogleTests
Change-Id: I531a3f1d87ba1a9927c264d04e0e19cc236e2e7f
parent 538ace73
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
        android:orientation="horizontal" >

        <FrameLayout
            android:id="@android:id/icon"
            android:id="@+id/icon"
            android:pointerIcon="hand"
            android:layout_width="@dimen/list_item_width"
            android:layout_height="@dimen/list_item_height"
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ final class ListDocumentHolder extends DocumentHolder {
            Lookup<String, String> fileTypeLookup) {
        super(context, parent, R.layout.item_doc_list);

        mIconLayout = itemView.findViewById(android.R.id.icon);
        mIconLayout = itemView.findViewById(R.id.icon);
        mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime);
        mIconThumb = (ImageView) itemView.findViewById(R.id.icon_thumb);
        mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check);
+32 −19
Original line number Diff line number Diff line
@@ -34,13 +34,13 @@ import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.Arrays;
@@ -62,6 +62,7 @@ public class DirectoryListBot extends Bots.BaseBot {
    private final String mDirListId;
    private final String mItemRootId;
    private final String mPreviewId;
    private final String mIconId;

    private UiAutomation mAutomation;

@@ -73,6 +74,7 @@ public class DirectoryListBot extends Bots.BaseBot {
        mDirListId = mTargetPackage + ":id/dir_list";
        mItemRootId = mTargetPackage + ":id/item_root";
        mPreviewId = mTargetPackage + ":id/preview_icon";
        mIconId = mTargetPackage + ":id/icon";
    }

    public void assertDocumentsCount(int count) throws UiObjectNotFoundException {
@@ -182,7 +184,7 @@ public class DirectoryListBot extends Bots.BaseBot {
    public void openDocument(String label) throws UiObjectNotFoundException {
        int toolType = Configurator.getInstance().getToolType();
        Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
        UiObject doc = findDocument(label);
        UiObject doc = findDocument(label, true);
        doc.click();
        Configurator.getInstance().setToolType(toolType);
    }
@@ -212,20 +214,22 @@ public class DirectoryListBot extends Bots.BaseBot {
                .equals(mTargetPackage + ":id/icon_check");
    }

    public UiObject2 findSelectionHotspot(String label) {
    public UiObject2 findSelectionHotspot(String label) throws UiObjectNotFoundException {
        final BySelector list = By.res(mDirListId);

        BySelector selector = By.hasChild(By.text(label));

        final UiSelector docList = findDocumentsListSelector();
        new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));

        UiObject2 parent = mDevice.findObject(list).findObject(selector);
        if (parent.getClassName().equals("android.widget.LinearLayout")
                || parent.getClassName().equals("android.widget.RelativeLayout")) {
            // For list mode and doc grid, the parent of the textView does not contain the selector
            // icon, but the grandparent of the textView does
            // Gotta go one more level up
            selector = By.hasDescendant(By.text(label).depth(2));
            parent = mDevice.findObject(list).findObject(selector);
        for (int i = 1; i <= MAX_LAYOUT_LEVEL; i++) {
            parent = parent.getParent();
            if (mItemRootId.equals(parent.getResourceName())) {
                break;
            }
        }
        return parent.findObject(By.clazz(ImageView.class));
        return parent.findObject(By.res(mIconId));
    }

    public void copyFilesToClipboard(String...labels) throws UiObjectNotFoundException {
@@ -263,14 +267,19 @@ public class DirectoryListBot extends Bots.BaseBot {
    }

    public UiObject findDocument(String label) throws UiObjectNotFoundException {
        final UiSelector docList = new UiSelector().resourceId(
                mDirContainerId).childSelector(
                        new UiSelector().resourceId(mDirListId));
        return findDocument(label, false);
    }

    public UiObject findDocument(String label, boolean withScroll)
            throws UiObjectNotFoundException {
        final UiSelector docList = findDocumentsListSelector();

        // Wait for the first list item to appear
        new UiObject(docList.childSelector(new UiSelector())).waitForExists(mTimeout);

        // new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));
        if (withScroll) {
            new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));
        }
        return mDevice.findObject(docList.childSelector(new UiSelector().text(label)));
    }

@@ -299,9 +308,7 @@ public class DirectoryListBot extends Bots.BaseBot {
    }

    public void assertFirstDocumentHasFocus() throws UiObjectNotFoundException {
        final UiSelector docList = new UiSelector().resourceId(
                mDirContainerId).childSelector(
                        new UiSelector().resourceId(mDirListId));
        final UiSelector docList = findDocumentsListSelector();

        // Wait for the first list item to appear
        UiObject doc = new UiObject(docList.childSelector(new UiSelector()));
@@ -316,6 +323,12 @@ public class DirectoryListBot extends Bots.BaseBot {
                mDirListId);
    }

    private UiSelector findDocumentsListSelector() {
        return new UiSelector().resourceId(
                mDirContainerId).childSelector(
                new UiSelector().resourceId(mDirListId));
    }

    public void assertHasFocus() {
        assertHasFocus(mDirListId);
    }
@@ -342,7 +355,7 @@ public class DirectoryListBot extends Bots.BaseBot {
    }

    public void rightClickDocument(String label) throws UiObjectNotFoundException {
        Rect startCoord = findDocument(label).getBounds();
        Rect startCoord = findDocument(label, true).getBounds();
        rightClickDocument(new Point(startCoord.centerX(), startCoord.centerY()));
    }

+2 −0
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@ public class CancelFromNotificationUiTest extends ActivityTest<FilesActivity> {
        // So, reset the storage size again to 500MB.
        Bundle bundle = new Bundle();
        bundle.putLong(EXTRA_SIZE, 500L);
        // Set a flag to prevent many refreshes.
        bundle.putBoolean(StubProvider.EXTRA_ENABLE_ROOT_NOTIFICATION, false);
        mDocsHelper.configure(null, bundle);

        try {