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

Commit 125c2aaa authored by Ben Reich's avatar Ben Reich
Browse files

Make testClearSelectionInRecentsResetsActions more robust

If the device returns results that exceed the limits of the recents max,
then sometimes the file isn't returned immediately. Given the fact the
file exists or not is not required, just the selected state, let's
simply select the first file in the list of Recents. Regardless if the
file is visible or not (will fail if NO file is visible still).

Bug: 412776499
Test: atest com.android.documentsui.FilesActivityUiTest
Flag: com.android.documentsui.flags.use_material3
Change-Id: I1a6aa1ff06d81a606ff95cc5dbe073aa99a4779d
parent 033fa0df
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -215,6 +215,25 @@ public class DirectoryListBot extends Bots.BaseBot {
        assertSelection(number);
    }

    private BySelector getSelectionRegionSelector() {
        BySelector selectionRegionSelector = By.res(mGridSelectionRegionId);
        if (mDevice.findObject(selectionRegionSelector) == null) {
            selectionRegionSelector = By.res(mListSelectionRegionId);
        }
        return selectionRegionSelector;
    }

    /** Select the first document that has a selectable region in the list or grid view. */
    public void selectFirstDocument() throws UiObjectNotFoundException {
        final BySelector list = By.res(mDirListId);
        final BySelector selectionRegionSelector = getSelectionRegionSelector();

        UiObject2 firstAvailableSelectionHotspot =
                mDevice.findObject(list).findObject(selectionRegionSelector);
        firstAvailableSelectionHotspot.click();
        assertSelection(1);
    }

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

@@ -223,10 +242,7 @@ public class DirectoryListBot extends Bots.BaseBot {
        final UiSelector docList = findDocumentsListSelector();
        new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));

        BySelector selectionRegionSelector = By.res(mGridSelectionRegionId);
        if (mDevice.findObject(selectionRegionSelector) == null) {
            selectionRegionSelector = By.res(mListSelectionRegionId);
        }
        final BySelector selectionRegionSelector = getSelectionRegionSelector();
        UiObject2 parent = mDevice.findObject(list).findObject(selector);
        UiObject2 selectionHotspot = null;
        for (int i = 1; i <= MAX_LAYOUT_LEVEL; i++) {
+5 −3
Original line number Diff line number Diff line
@@ -304,9 +304,11 @@ public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> {
            // the options menu being refreshed (it should only show when a file is selected).
            onView(withId(R.id.action_menu_share)).check(doesNotExist());

            // Select the recent document, which will refresh the options menu and the share action
            // menu item should appear.
            bots.directory.selectDocument(fileName, 1);
            // Select the first document in Recents that has a selectable region. We have previously
            // staged a file so there should be at least 1, but depending on the device and the
            // cleanup of the device this might not always be the case. The document that gets
            // selected doesn't really matter, just that one is selected.
            bots.directory.selectFirstDocument();
            onView(withId(R.id.action_menu_share)).check(matches(isDisplayed()));

            // Deselect the file and ensure the share menu disappears (this ensures the menu is