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

Commit 265f2649 authored by Ben Reich's avatar Ben Reich
Browse files

Fix up findSelectionHotspot and remove unused methods

When the use_material3 flag is enabled, the findSelectionHotspot
method attempts to find the `item_root` UiObject2. However it
appears like this ID isn't available. The method then ends up
traversing the hierarchy until the dir_list is found and ends
up selecting the first item in the list instead. Update that
method to instead check at each layer if there exists a hotspot
and return in that case. There are a number of methods that are
not being used either (which call findSelectionHotspot) so let's
remove those to avoid having an inflated number of callees for
this method.

Bug: 383669583
Test: atest com.android.documentsui.FileManagementUiTest
Flag: com.android.documentsui.flags.use_material3
Change-Id: Ifca68eb60563ebd2b5a42ad7615ad60d49106fc4
parent f3343196
Loading
Loading
Loading
Loading
+7 −43
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import androidx.test.uiautomator.Until;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
 * A test helper class that provides support for controlling directory list
@@ -56,16 +55,13 @@ public class DirectoryListBot extends Bots.BaseBot {

    private static final int MAX_LAYOUT_LEVEL = 10;

    private static final BySelector SNACK_DELETE =
            By.text(Pattern.compile("^Deleting [0-9]+ item.+"));

    private final String mDirContainerId;
    private final String mDirListId;
    private final String mItemRootId;
    private final String mPreviewId;
    private final String mIconId;

    private UiAutomation mAutomation;
    private final UiAutomation mAutomation;

    public DirectoryListBot(
            UiDevice device, UiAutomation automation, Context context, int timeout) {
@@ -178,10 +174,6 @@ public class DirectoryListBot extends Bots.BaseBot {
        findPlaceholderMessageTextView().waitForExists(mTimeout);
    }

    public void assertSnackbar(int id) {
        assertNotNull(getSnackbar(mContext.getString(id)));
    }

    public void openDocument(String label) throws UiObjectNotFoundException {
        int toolType = Configurator.getInstance().getToolType();
        Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
@@ -208,13 +200,6 @@ public class DirectoryListBot extends Bots.BaseBot {
        assertSelection(number);
    }

    public boolean isDocumentSelected(String label) throws UiObjectNotFoundException {
        waitForDocument(label);
        UiObject2 selectionHotspot = findSelectionHotspot(label);
        return selectionHotspot.getResourceName()
                .equals(mTargetPackage + ":id/icon_check");
    }

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

@@ -224,20 +209,15 @@ public class DirectoryListBot extends Bots.BaseBot {
        new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));

        UiObject2 parent = mDevice.findObject(list).findObject(selector);
        UiObject2 selectionHotspot = null;
        for (int i = 1; i <= MAX_LAYOUT_LEVEL; i++) {
            parent = parent.getParent();
            if (mItemRootId.equals(parent.getResourceName())) {
            selectionHotspot = parent.findObject(By.res(mIconId));
            if (selectionHotspot != null) {
                break;
            }
        }
        return parent.findObject(By.res(mIconId));
    }

    public void copyFilesToClipboard(String...labels) throws UiObjectNotFoundException {
        for (String label: labels) {
            selectDocument(label);
        }
        mDevice.pressKeyCode(KeyEvent.KEYCODE_C, KeyEvent.META_CTRL_ON);
        return selectionHotspot;
    }

    public void pasteFilesFromClipboard() {
@@ -248,21 +228,6 @@ public class DirectoryListBot extends Bots.BaseBot {
        return mDevice.wait(Until.findObject(By.text(message)), mTimeout);
    }

    public void clickSnackbarAction() throws UiObjectNotFoundException {
        UiObject snackbarAction =
                findObject(mTargetPackage + ":id/snackbar_action");
        snackbarAction.click();
    }

    public void waitForDeleteSnackbar() {
        mDevice.wait(Until.findObject(SNACK_DELETE), mTimeout);
    }

    public void waitForDeleteSnackbarGone() {
        // wait a little longer for snackbar to go away, as it disappears after a timeout.
        mDevice.wait(Until.gone(SNACK_DELETE), mTimeout * 2);
    }

    public void waitForDocument(String label) throws UiObjectNotFoundException {
        findDocument(label).waitForExists(mTimeout);
    }
@@ -295,9 +260,8 @@ public class DirectoryListBot extends Bots.BaseBot {

    public boolean hasDocumentPreview(String label) {
        final BySelector list = By.res(mDirListId);
        final UiObject2 text = mDevice.findObject(list).findObject(By.text(label));

        UiObject2 parent = text;
        UiObject2 parent = mDevice.findObject(list).findObject(By.text(label));
        for (int i = 1; i <= MAX_LAYOUT_LEVEL; i++) {
            parent = parent.getParent();
            if (mItemRootId.equals(parent.getResourceName())) {
@@ -338,7 +302,7 @@ public class DirectoryListBot extends Bots.BaseBot {
        String assertSelectionText = numSelected + " selected";
        UiObject2 selectionText = mDevice.wait(
                Until.findObject(By.text(assertSelectionText)), mTimeout);
        assertTrue(selectionText != null);
        assertNotNull(selectionText);
    }

    public void assertOrder(String[] dirs, String[] files) throws UiObjectNotFoundException {