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

Commit a66e0702 authored by Jeremie Boulic's avatar Jeremie Boulic
Browse files

[DocsUI] Fix functional tests failures related to PeekBot dependency

The PeekBot is initialized with a matcher that makes use of the
MaterialToolbar class. It throws a java.lang.ClassNotFoundException
when M3 is not enabled.

To avoid similar issues in the future, initialize the PeekBot directly
in tests for the Peek feature. The PeekBot is only initialized when Peek
is enabled.

Bug: 408956866
Flag: TEST_ONLY
Flag: com.android.documentsui.flags.use_material3
Flag: com.android.documentsui.flags.use_peek_preview_ro
Test: atest DocumentsUIGoogleTests:com.android.documentsui (with M3
enabled and disabled)
Change-Id: Ie1fcfa8548c9a190894e1c8fd0bc66bbccc69f2f

Change-Id: I745c0182dd2bc58a62069d5c9a4570922469fd60
parent a67d9e7d
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ public final class Bots {
    public final UiBot main;
    public final InspectorBot inspector;
    public final NotificationsBot notifications;
    public final PeekBot peek;

    public Bots(UiDevice device, UiAutomation automation, Context context, int timeout) {
        main = new UiBot(device, context, TIMEOUT);
@@ -64,7 +63,6 @@ public final class Bots {
        menu = new MenuBot(device, context, TIMEOUT);
        inspector = new InspectorBot(device, context, TIMEOUT);
        notifications = new NotificationsBot(device, context, TIMEOUT);
        peek = new PeekBot(device, context, TIMEOUT);
    }

    /**
+17 −8
Original line number Diff line number Diff line
@@ -29,10 +29,12 @@ import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.documentsui.ActivityTestJunit4
import com.android.documentsui.StubProvider
import com.android.documentsui.bots.PeekBot
import com.android.documentsui.files.FilesActivity
import com.android.documentsui.flags.Flags
import com.android.documentsui.rules.TestFilesRule
import junit.framework.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -49,30 +51,37 @@ class PeekUiTest : ActivityTestJunit4<FilesActivity?>() {
            .createFileInRoot(StubProvider.ROOT_0_ID, "image.png", "image/png")
            .createFileInRoot(StubProvider.ROOT_0_ID, "file0.log", "text/plain")

    private lateinit var peekBot: PeekBot

    @Before
    fun setUpTest() {
        peekBot = PeekBot(device!!, context!!, TIMEOUT)
    }

    fun validatePeekContents(fileName: String) {
        bots!!.peek.assertPeekActive()
        bots!!.peek.assertHasTitle(fileName)
        peekBot.assertPeekActive()
        peekBot.assertHasTitle(fileName)
    }

    @Test
    @Throws(Exception::class)
    fun testSequentialFilePreview() {
        bots!!.peek.assertPeekHidden()
        peekBot.assertPeekHidden()
        bots!!.directory.selectDocument("image.png")
        bots!!.main.clickActionItem("Get info")
        validatePeekContents("image.png")
        bots!!.peek.hide()
        peekBot.hide()

        bots!!.directory.selectDocument("file0.log")
        bots!!.main.clickActionItem("Get info")
        validatePeekContents("file0.log")
        bots!!.peek.hide()
        peekBot.hide()
    }

    @Test
    @Throws(Exception::class)
    fun testFileCantBeSelectedDuringFilePreview() {
        bots!!.peek.assertPeekHidden()
        peekBot.assertPeekHidden()
        // Selecting a document should show the "1 selected" label.
        bots!!.directory.selectDocument("image.png", 1)
        bots!!.main.clickActionItem("Get info")
@@ -98,9 +107,9 @@ class PeekUiTest : ActivityTestJunit4<FilesActivity?>() {
        mActivityScenario!!.recreate()
        validatePeekContents("image.png")

        bots!!.peek.hide()
        peekBot.hide()
        mActivityScenario!!.recreate()
        bots!!.peek.assertPeekHidden()
        peekBot.assertPeekHidden()

        bots!!.directory.selectDocument("file0.log")
        bots!!.main.clickActionItem("Get info")