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

Commit 2fe5b226 authored by Ben Reich's avatar Ben Reich Committed by Android (Google) Code Review
Browse files

Merge "Show selection mode when search bar is available on Recents" into main

parents 2e2afbfd 83ebecc5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -337,7 +337,7 @@ public class NavigationViewManager extends SelectionTracker.SelectionObserver<St
            mToolbar.setNavigationContentDescription(null);
        }

        if (shouldShowSearchBar()) {
        if ((!isUseMaterial3FlagEnabled() || !inSelectionMode()) && shouldShowSearchBar()) {
            mBreadcrumb.show(false);
            mToolbar.setTitle(null);
            mSearchBarView.setVisibility(View.VISIBLE);
+10 −0
Original line number Diff line number Diff line
@@ -302,6 +302,16 @@ public class UiBot extends Bots.BaseBot {
        onView(withId(android.R.id.button1)).check(matches(hasFocus()));
    }

    /** Clicks the OK button on a dialog. */
    public void clickNonTextDialogOkButton() {
        UiObject2 okButton = mDevice.findObject(By.res("android:id/button1"));
        okButton.click();
    }

    /**
     * Clicks the OK button on a dialog and attempts to close the soft keyboard.
     * TODO(b/405807817): Merge this with the above method and update callers.
     */
    public void clickDialogOkButton() {
        // Espresso has flaky results when keyboard shows up, so hiding it for now
        // before trying to click on any dialog button
+60 −1
Original line number Diff line number Diff line
@@ -16,11 +16,19 @@

package com.android.documentsui;

import static com.android.documentsui.base.Providers.AUTHORITY_STORAGE;
import static com.android.documentsui.base.Providers.ROOT_ID_DEVICE;
import static com.android.documentsui.flags.Flags.FLAG_HIDE_ROOTS_ON_DESKTOP_RO;
import static com.android.documentsui.flags.Flags.FLAG_USE_SEARCH_V2_READ_ONLY;
import static com.android.documentsui.flags.Flags.FLAG_USE_MATERIAL3;
import static com.android.documentsui.flags.Flags.FLAG_USE_SEARCH_V2_READ_ONLY;

import static com.google.common.truth.TruthJUnit.assume;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import android.app.Instrumentation;
import android.content.ContentResolver;
import android.net.Uri;
import android.os.RemoteException;
import android.platform.test.annotations.RequiresFlagsDisabled;
@@ -31,6 +39,9 @@ import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.UserId;
import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.filters.HugeLongTest;
import com.android.documentsui.inspector.InspectorActivity;
@@ -88,6 +99,54 @@ public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> {
        }
    }

    @Test
    @RequiresFlagsEnabled(FLAG_USE_MATERIAL3)
    public void testRecentsSelectionClearsSearchBar() throws Exception {
        assume().that(context.getResources().getBoolean(R.bool.show_search_bar)).isTrue();

        // Create DocumentsProviderHelper to create files in Internal storage.
        DocumentsProviderHelper storageDocsHelper =
                new DocumentsProviderHelper(
                        UserId.DEFAULT_USER, AUTHORITY_STORAGE, context, AUTHORITY_STORAGE);

        RootInfo primaryRoot = storageDocsHelper.getRoot(ROOT_ID_DEVICE);

        // Create Download folder if it doesn't exist.
        DocumentInfo info = storageDocsHelper.findFile(primaryRoot.documentId, "Download");

        if (info == null) {
            ContentResolver cr = context.getContentResolver();
            Uri uri = storageDocsHelper.createFolder(primaryRoot.documentId, "Download");
            info = DocumentInfo.fromUri(cr, uri, UserId.DEFAULT_USER);
        }

        assertTrue(info != null && info.isDirectory());

        // Open up Recents and create a file that should appear.
        bots.roots.openRoot("Recent");
        final String fileName = "Recent.txt";
        storageDocsHelper.createDocument(info.documentId, "text/plain", fileName);
        try {
            bots.directory.waitForDocument(fileName);
            bots.directory.selectDocument(fileName, 1);
        } finally {
            // Unselect the file and remove it.
            bots.directory.selectDocument(fileName);
            bots.roots.openRoot(primaryRoot.title);
            bots.directory.openDocument("Download");

            bots.directory.waitForDocument(fileName);
            bots.directory.selectDocument(fileName, 1);

            bots.main.clickToolbarItem(R.id.action_menu_delete);
            bots.main.clickNonTextDialogOkButton();
            device.waitForIdle();

            bots.directory.findDocument(fileName).waitUntilGone(5000);
            assertFalse(bots.directory.hasDocuments(fileName));
        }
    }

    @Test
    @RequiresFlagsDisabled(FLAG_HIDE_ROOTS_ON_DESKTOP_RO)
    public void testRootClick_SetsWindowTitle() throws Exception {