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

Commit 50ec2f2f authored by Ben Reich's avatar Ben Reich
Browse files

Ensure createDocument has a valid RootInfo to create it at

This is currently failing with the following error:

  java.lang.IllegalArgumentException: Can't create file file_1 in null
  parent.

This is because the root used is incorrect, use the appropriate root.

Unfortunately some of the tests also fail when the use_material3 flag is
enabled, so this updates the SortBot to check not only if the
table_header is visible but also if the column to sort by is visible.
This is because on use_material3 the Name table header is shown and
clickable, which causes a false positive.

Fix: 408352609
Test: atest com.android.documentsui.SortDocumentUiTest
Flag: EXEMPT test change
Change-Id: I87c2903849b461a1061ff02e622938e4e6de0017
parent c9384cb1
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class SortBot extends Bots.BaseBot {
        final @StringRes int labelId = mSortModel.getDimensionById(id).getLabelId();
        final String label = mContext.getString(labelId);
        final boolean result;
        if (isHeaderShow()) {
        if (isSortHeaderShown(label)) {
            result = mColumnBot.sortBy(label, direction);
        } else {
            result = sortByMenu(id, direction);
@@ -82,8 +82,10 @@ public class SortBot extends Bots.BaseBot {
        assertTrue("Sorting by id: " + id + " in direction: " + direction + " failed.", result);
    }

    public boolean isHeaderShow() {
        return Matchers.present(ColumnSortBot.MATCHER);
    /** Check if the appropriate sort header is shown */
    public boolean isSortHeaderShown(String label) {
        return Matchers.present(
                allOf(withChild(withText(label)), isDescendantOfA(ColumnSortBot.MATCHER)));
    }

    public void assertHeaderHide() {
+4 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.KeyEvent;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import com.android.documentsui.base.RootInfo;
import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.rules.TestFilesRule;
import com.android.documentsui.sorting.SortDimension;
@@ -98,17 +99,17 @@ public class SortDocumentUiTest extends ActivityTestJunit4<FilesActivity> {
     * @param sleep time to sleep in ms
     */
    private void initFiles(long sleep) throws Exception {
        RootInfo root = mTestFilesRule.docsHelper.getRoot(StubProvider.ROOT_0_ID);
        for (int i = 0; i < FILES.length; ++i) {
            Uri uri =
                    mTestFilesRule.docsHelper.createDocument(
                            StubProvider.ROOT_0_ID, MIMES[i], FILES[i]);
                    mTestFilesRule.docsHelper.createDocument(root, MIMES[i], FILES[i]);
            mTestFilesRule.docsHelper.writeDocument(uri, FILES[i].getBytes());

            Thread.sleep(sleep);
        }

        for (String dir : DIRS) {
            mTestFilesRule.docsHelper.createFolder(StubProvider.ROOT_0_ID, dir);
            mTestFilesRule.docsHelper.createFolder(root, dir);

            Thread.sleep(sleep);
        }