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

Commit 79bd60e4 authored by Alexander Bolodurin's avatar Alexander Bolodurin Committed by Android (Google) Code Review
Browse files

Merge "[docsui] use TestFilesRule.createTestFiles in tests" into main

parents 143d4fa6 3b5a7ae7
Loading
Loading
Loading
Loading
+1 −34
Original line number Diff line number Diff line
@@ -74,8 +74,7 @@ class TestFilesRule(private val skipCreation: Boolean = false) : ExternalResourc

    /**
     * Run file/folder create operations encapsulated in a provided function. Technically this lets
     * running any DocumentsProviderHelper functions, but should only be used to create files. Use
     * if dynamically generated files are required to be created.
     * running any DocumentsProviderHelper functions, but should only be used to create files.
     */
    fun createTestFiles(createTestFiles: CreateFilesFunction): TestFilesRule {
        deferredOperations.add {
@@ -84,38 +83,6 @@ class TestFilesRule(private val skipCreation: Boolean = false) : ExternalResourc
        return this
    }

    /** Create a folder in `root`. */
    fun createFolderInRoot(root: String, folderName: String): TestFilesRule {
        deferredOperations.add {
            val rootInfo = docsHelper.getRoot(root)
            val uri = docsHelper.createFolder(rootInfo, folderName)
            require(!createdUris.containsKey(folderName)) { "$folderName has already been created" }
            createdUris[folderName] = uri
        }
        return this
    }

    /** Creates a folder in `root` with `parentName`. The `parentName` must be already created. */
    fun createFolderWithParent(parentName: String, folderName: String): TestFilesRule {
        deferredOperations.add {
            val parentUri = createdUris[parentName]
            requireNotNull(parentUri) { "Parent folder $parentName not initialized" }
            val uri = docsHelper.createFolder(parentUri, folderName)
            createdUris[folderName] = uri
        }
        return this
    }

    /** Creates a file in `root` with the specified `fileName` and `mimeType`. */
    fun createFileInRoot(root: String, fileName: String, mimeType: String): TestFilesRule {
        deferredOperations.add {
            val rootInfo = docsHelper.getRoot(root)
            val uri = docsHelper.createDocument(rootInfo, mimeType, fileName)
            createdUris[fileName] = uri
        }
        return this
    }

    /** Returns `Uri` of the file with `filename` within the `root`. */
    fun getUriInRoot(root: String, fileName: String): Uri? {
        return docsHelper.findDocument(getRoot(root).documentId, fileName).derivedUri
+14 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.documentsui.util.FlagUtils.isDesktopFileHandlingFlagEn

import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;

@@ -51,14 +52,19 @@ public class ContextMenuUiTest extends ActivityTestJunit4<FilesActivity> {
    @Rule
    public final TestFilesRule mTestFilesRule =
            new TestFilesRule()
                    .createFolderInRoot(ROOT_0_ID, TestFilesRule.DIR_NAME_1)
                    .createFolderWithParent(TestFilesRule.DIR_NAME_1, "ChildDir1")
                    .createFileInRoot(ROOT_0_ID, "file0.log", "text/plain")
                    .createFileInRoot(ROOT_0_ID, "file1.png", "image/png")
                    .createFileInRoot(ROOT_0_ID, "file2.csv", "text/csv")
                    .createFileInRoot(ROOT_0_ID, "archive.zip", "application/zip")
                    .createFileInRoot(ROOT_0_ID, "anotherFile0.log", "text/plain")
                    .createFileInRoot(ROOT_0_ID, "poodles.text", "text/plain");
                    .createTestFiles(
                            (docsHelper) -> {
                                final RootInfo root = docsHelper.getRoot(ROOT_0_ID);
                                final Uri dir1 =
                                        docsHelper.createFolder(root, TestFilesRule.DIR_NAME_1);
                                docsHelper.createFolder(dir1, "ChildDir1");
                                docsHelper.createDocument(root, "text/plain", "file0.log");
                                docsHelper.createDocument(root, "image/png", "file1.png");
                                docsHelper.createDocument(root, "text/csv", "file2.csv");
                                docsHelper.createDocument(root, "application/zip", "archive.zip");
                                docsHelper.createDocument(root, "text/plain", "anotherFile0.log");
                                docsHelper.createDocument(root, "text/plain", "poodles.text");
                            });

    private Map<String, Boolean> menuItems;

+13 −7
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.KeyEvent;
import androidx.test.filters.LargeTest;

import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.Shared;
import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.filters.HugeLongTest;
@@ -48,13 +49,18 @@ public class FileManagementUiTest extends ActivityTestJunit4<FilesActivity> {
    @Rule
    public final TestFilesRule mTestFilesRule =
            new TestFilesRule()
                    .createFolderInRoot(ROOT_0_ID, TestFilesRule.DIR_NAME_1)
                    .createFolderWithParent(TestFilesRule.DIR_NAME_1, "ChildDir1")
                    .createFileInRoot(ROOT_0_ID, "file0.log", "text/plain")
                    .createFileInRoot(ROOT_0_ID, "file1.png", "image/png")
                    .createFileInRoot(ROOT_0_ID, "file2.csv", "text/csv")
                    .createFileInRoot(ROOT_0_ID, "anotherFile0.log", "text/plain")
                    .createFileInRoot(ROOT_0_ID, "poodles.text", "text/plain");
                    .createTestFiles(
                            (docsHelper) -> {
                                final RootInfo root = docsHelper.getRoot(ROOT_0_ID);
                                final Uri dir1 =
                                        docsHelper.createFolder(root, TestFilesRule.DIR_NAME_1);
                                docsHelper.createFolder(dir1, "ChildDir1");
                                docsHelper.createDocument(root, "text/plain", "file0.log");
                                docsHelper.createDocument(root, "image/png", "file1.png");
                                docsHelper.createDocument(root, "text/csv", "file2.csv");
                                docsHelper.createDocument(root, "text/plain", "anotherFile0.log");
                                docsHelper.createDocument(root, "text/plain", "poodles.text");
                            });

    @Ignore
    @Test
+12 −7
Original line number Diff line number Diff line
@@ -73,13 +73,18 @@ public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> {
    @Rule
    public final TestFilesRule mTestFilesRule =
            new TestFilesRule()
                    .createFolderInRoot(ROOT_0_ID, TestFilesRule.DIR_NAME_1)
                    .createFolderWithParent(TestFilesRule.DIR_NAME_1, TestFilesRule.CHILD_DIR_1)
                    .createFileInRoot(ROOT_0_ID, "file0.log", "text/plain")
                    .createFileInRoot(ROOT_0_ID, "file1.png", "image/png")
                    .createFileInRoot(ROOT_0_ID, "file2.csv", "text/csv")
                    .createFileInRoot(ROOT_0_ID, "anotherFile0.log", "text/plain")
                    .createFileInRoot(ROOT_0_ID, "poodles.text", "text/plain");
                    .createTestFiles(
                            (docsHelper) -> {
                                final RootInfo root = docsHelper.getRoot(ROOT_0_ID);
                                final Uri dir1 =
                                        docsHelper.createFolder(root, TestFilesRule.DIR_NAME_1);
                                docsHelper.createFolder(dir1, TestFilesRule.CHILD_DIR_1);
                                docsHelper.createDocument(root, "text/plain", "file0.log");
                                docsHelper.createDocument(root, "image/png", "file1.png");
                                docsHelper.createDocument(root, "text/csv", "file2.csv");
                                docsHelper.createDocument(root, "text/plain", "anotherFile0.log");
                                docsHelper.createDocument(root, "text/plain", "poodles.text");
                            });

    // Recents is a strange meta root that gathers entries from other providers.
    // It is special cased in a variety of ways, which is why we just want
+8 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.KeyEvent;
import androidx.annotation.IdRes;
import androidx.test.filters.LargeTest;

import com.android.documentsui.base.RootInfo;
import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.rules.OverrideFlagsRule;
import com.android.documentsui.rules.TestFilesRule;
@@ -46,8 +47,13 @@ public class KeyboardNavigationUiTest extends ActivityTestJunit4<FilesActivity>
    public final OverrideFlagsRule mOverrideFlagsRule = new OverrideFlagsRule();

    @Rule
    public final TestFilesRule mTestFilesRule = new TestFilesRule().createFileInRoot(ROOT_0_ID,
            "files1.png", "image/png");
    public final TestFilesRule mTestFilesRule =
            new TestFilesRule()
                    .createTestFiles(
                            (docsHelper) -> {
                                final RootInfo root = docsHelper.getRoot(ROOT_0_ID);
                                docsHelper.createDocument(root, "image/png", "files1.png");
                            });

    // Tests that pressing tab switches focus between the roots and directory listings.
    @Ignore
Loading