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

Commit 586da328 authored by François Degros's avatar François Degros
Browse files

Fix ArchiveUiTest

DirectoryListBot.findPlaceholderMessageTextView() scrolls if necessary
to make the expected message visible. Simplified the tests that use this
method.

Bug: 423769615
Flag: EXEMPT fixing tests
Test: atest DocumentsUIGoogleTests:com.android.documentsui.ArchiveUiTest
Test: atest DocumentsUIGoogleTests:com.android.documentsui.SearchViewUiTest
Test: atest DocumentsUIGoogleTests:com.android.documentsui.FilesActivityDefaultsUiTest
Change-Id: I7703ecd9e608a75814353cb69b12af86b910ea1c
parent 14f4e170
Loading
Loading
Loading
Loading
+10 −11
Original line number Original line Diff line number Diff line
@@ -158,13 +158,11 @@ public class DirectoryListBot extends Bots.BaseBot {
     * Checks against placeholder text. Placeholder can be Empty page, No results page, or the
     * Checks against placeholder text. Placeholder can be Empty page, No results page, or the
     * "Hourglass" page (ie. something-went-wrong page).
     * "Hourglass" page (ie. something-went-wrong page).
     */
     */
    public void assertPlaceholderMessageText(String message) throws UiObjectNotFoundException {
    public void waitAndAssertPlaceholderMessageText(String message)
        UiObject messageTextView = findPlaceholderMessageTextView();
            throws UiObjectNotFoundException {
        final UiObject messageTextView = findPlaceholderMessageTextView();
        assertTrue(messageTextView.exists());
        assertTrue(messageTextView.exists());

        assertEquals(message, messageTextView.getText());
        String msg = String.valueOf(message);
        assertEquals(msg, messageTextView.getText());

    }
    }


    private UiObject findHeaderMessageTextView() {
    private UiObject findHeaderMessageTextView() {
@@ -179,13 +177,14 @@ public class DirectoryListBot extends Bots.BaseBot {
                mTargetPackage + ":id/dismiss_button");
                mTargetPackage + ":id/dismiss_button");
    }
    }


    private UiObject findPlaceholderMessageTextView() {
    private UiObject findPlaceholderMessageTextView() throws UiObjectNotFoundException {
        return findObject(
        final String childResourceId = mTargetPackage + ":id/message";
                mDirContainerId,
        new UiScrollable(new UiSelector().resourceId(mDirContainerId)).scrollIntoView(
                mTargetPackage + ":id/message");
                new UiSelector().text(childResourceId));
        return findObject(mDirContainerId, childResourceId);
    }
    }


    public void waitForHolderMessage() {
    public void waitForHolderMessage() throws UiObjectNotFoundException {
        findPlaceholderMessageTextView().waitForExists(mTimeout);
        findPlaceholderMessageTextView().waitForExists(mTimeout);
    }
    }


+4 −35
Original line number Original line Diff line number Diff line
@@ -16,11 +16,6 @@


package com.android.documentsui;
package com.android.documentsui;


import static com.android.documentsui.flags.Flags.FLAG_USE_SEARCH_V2_READ_ONLY;

import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;

import androidx.test.filters.LargeTest;
import androidx.test.filters.LargeTest;


import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.files.FilesActivity;
@@ -32,14 +27,14 @@ import org.junit.Test;


@LargeTest
@LargeTest
public class ArchiveUiTest extends ActivityTestJunit4<FilesActivity> {
public class ArchiveUiTest extends ActivityTestJunit4<FilesActivity> {

    @Rule
    @Rule
    public final CheckAndForceMaterial3Flag mCheckFlagsRule = new CheckAndForceMaterial3Flag();
    public final CheckAndForceMaterial3Flag mCheckFlagsRule = new CheckAndForceMaterial3Flag();


    @Rule
    @Rule
    public final TestFilesRule mTestFilesRule = new TestFilesRule();
    public final TestFilesRule mTestFilesRule = new TestFilesRule();


    private void archiveValid() throws Exception {
    @Test
    public void withValidArchive() throws Exception {
        bots.roots.openRoot("ResourcesProvider");
        bots.roots.openRoot("ResourcesProvider");
        bots.directory.openDocument("archive.zip");
        bots.directory.openDocument("archive.zip");
        bots.directory.waitForDocument("file1.txt");
        bots.directory.waitForDocument("file1.txt");
@@ -49,35 +44,9 @@ public class ArchiveUiTest extends ActivityTestJunit4<FilesActivity> {
    }
    }


    @Test
    @Test
    @RequiresFlagsDisabled({FLAG_USE_SEARCH_V2_READ_ONLY})
    public void withInvalidArchive() throws Exception {
    public void testArchive_valid() throws Exception {
        archiveValid();
    }

    @Test
    @RequiresFlagsEnabled({FLAG_USE_SEARCH_V2_READ_ONLY})
    public void testArchive_valid_searchV2() throws Exception {
        archiveValid();
    }

    private void archiveInvalid() throws Exception {
        bots.roots.openRoot("ResourcesProvider");
        bots.roots.openRoot("ResourcesProvider");
        bots.directory.openDocument("broken.zip");
        bots.directory.openDocument("broken.zip");

        bots.directory.waitAndAssertPlaceholderMessageText(context.getString(R.string.empty));
        final String msg = String.valueOf(context.getString(R.string.empty));
        bots.directory.waitForHolderMessage();
        bots.directory.assertPlaceholderMessageText(msg);
    }

    @Test
    @RequiresFlagsDisabled({FLAG_USE_SEARCH_V2_READ_ONLY})
    public void testArchive_invalid() throws Exception {
        archiveInvalid();
    }

    @Test
    @RequiresFlagsEnabled({FLAG_USE_SEARCH_V2_READ_ONLY})
    public void testArchive_invalid_searchV2() throws Exception {
        archiveInvalid();
    }
    }
}
}
+1 −3
Original line number Original line Diff line number Diff line
@@ -53,9 +53,7 @@ public class FilesActivityDefaultsUiTest extends ActivityTestJunit4<FilesActivit
        device.waitForIdle();
        device.waitForIdle();


        bots.roots.openRoot(mTestFilesRule.getRoot(ROOT_0_ID).title);
        bots.roots.openRoot(mTestFilesRule.getRoot(ROOT_0_ID).title);

        bots.directory.waitAndAssertPlaceholderMessageText(context.getString(R.string.empty));
        String msg = String.valueOf(context.getString(R.string.empty));
        bots.directory.assertPlaceholderMessageText(msg);


        // Check to make sure back button is properly handled by non-Doc type DocHolders
        // Check to make sure back button is properly handled by non-Doc type DocHolders
        device.pressBack();
        device.pressBack();
+2 −2
Original line number Original line Diff line number Diff line
@@ -244,8 +244,8 @@ public class SearchViewUiTest extends ActivityTestJunit4<FilesActivity> {
        bots.keyboard.pressEnter();
        bots.keyboard.pressEnter();
        device.waitForIdle(3000);
        device.waitForIdle(3000);


        String msg = String.valueOf(context.getString(R.string.no_results));
        bots.directory.waitAndAssertPlaceholderMessageText(
        bots.directory.assertPlaceholderMessageText(String.format(msg, "TEST_ROOT_0"));
                String.format(context.getString(R.string.no_results), "TEST_ROOT_0"));
    }
    }


    @Suppress
    @Suppress