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

Commit 11854639 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I8144c9db,I825b22ab into main

* changes:
  Longer timeout for cuttlefish devices
  Wait for transitions before starting a test scenario
parents 3ec5a533 aed34a36
Loading
Loading
Loading
Loading
+40 −16
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.platform.uiautomatorhelpers.BetterSwipe
import android.platform.uiautomatorhelpers.DeviceHelpers
import android.platform.uiautomatorhelpers.DeviceHelpers.assertInvisible
import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible
import android.platform.uiautomatorhelpers.DurationUtils.platformAdjust
import android.platform.uiautomatorhelpers.WaitUtils
import android.provider.Settings
import android.tools.NavBar
@@ -72,6 +73,7 @@ import org.junit.runners.BlockJUnit4ClassRunner
import platform.test.desktop.DesktopMouseTestRule
import platform.test.desktop.ShadeDisplayGoesAroundTestRule
import platform.test.desktop.SimulatedConnectedDisplayTestRule
import java.time.Duration

// TODO(b/416608975) - Move the utility methods to shared library or/and utilize existing library (
// e.g., sysui-tapl).
@@ -89,7 +91,8 @@ class ConnectedDisplayCujSmokeTests {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val context = instrumentation.targetContext
    private val tapl = LauncherInstrumentation()
    private val wmHelper = WindowManagerStateHelper(instrumentation)
    private val wmHelper =
        WindowManagerStateHelper(instrumentation, retryIntervalMs = FLICKER_LIB_RETRY_INTERVAL_MS)
    private val device = UiDevice.getInstance(instrumentation)
    private val browserApp = BrowserAppHelper(instrumentation)
    private val clockApp = ClockAppHelper(instrumentation)
@@ -140,6 +143,9 @@ class ConnectedDisplayCujSmokeTests {

        // Ensure the transient taskbar is disabled.
        tapl.enableTransientTaskbar(false)

        // Ensure all transitions are completed before running a test.
        wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify()
    }

    fun cuj1() {
@@ -158,17 +164,18 @@ class ConnectedDisplayCujSmokeTests {
        resetTopology(externalDisplayId)

        // Navigate to display topology settings in Settings app
        DeviceHelpers.waitForObj(By.text(CONNECTED_DEVICES_TEXT)) {
        DeviceHelpers.waitForObj(By.text(CONNECTED_DEVICES_TEXT), timeout = UIAUTOMATOR_TIMEOUT) {
            "Can't find a connected device on setting"
        }.click()
        DeviceHelpers.waitForObj(By.text(EXTERNAL_DISPLAY_TEXT)) {
        DeviceHelpers.waitForObj(By.text(EXTERNAL_DISPLAY_TEXT), timeout = UIAUTOMATOR_TIMEOUT) {
            "Can't find a external display on setting"
        }.click()

        // Modify the topology.
        val paneObject =
            DeviceHelpers.waitForObj(
                By.res(SETTINGS_PACKAGE, DISPLAY_TOPOLOGY_PANE_CONTENT_RES_ID)
                By.res(SETTINGS_PACKAGE, DISPLAY_TOPOLOGY_PANE_CONTENT_RES_ID),
                timeout = UIAUTOMATOR_TIMEOUT
            ) { "Can't find a display panel on setting" }

        val defaultDisplayObject = findDefaultDisplayObject(paneObject)
@@ -183,7 +190,7 @@ class ConnectedDisplayCujSmokeTests {
                paneObject.visibleBounds.bottom.toFloat() - 1f
            )
        )
        WaitUtils.ensureThat("Display topology changed") {
        WaitUtils.ensureThat("Display topology changed", timeout = UIAUTOMATOR_TIMEOUT) {
            originalTopology != displayManager.displayTopology
        }

@@ -544,7 +551,7 @@ class ConnectedDisplayCujSmokeTests {
    fun launchAppFromTaskbar(displayId: Int, appHelper: StandardAppHelper) {
        val selector = By.text(appHelper.appName).hasAncestor(taskbarSelector(displayId))
        val appName = appHelper.appName
        DeviceHelpers.waitForObj(selector) {
        DeviceHelpers.waitForObj(selector, timeout = UIAUTOMATOR_TIMEOUT) {
            "Can't find an app icon of $appName on taskbar on display#$displayId"
        }.click()
    }
@@ -561,7 +568,10 @@ class ConnectedDisplayCujSmokeTests {
            instrumentation.uiAutomation.syncInputTransactions()
        } else {
            val taskbar =
                DeviceHelpers.waitForObj(taskbarSelector(displayId)) {
                DeviceHelpers.waitForObj(
                    taskbarSelector(displayId),
                    timeout = UIAUTOMATOR_TIMEOUT
                ) {
                    "Can't find a taskbar on display#$displayId"
                }
            taskbar.children.first().click()
@@ -575,7 +585,7 @@ class ConnectedDisplayCujSmokeTests {
        openAllApps(displayId)

        val appsListSelector = appsListSelector(displayId)
        val appsList = DeviceHelpers.waitForObj(appsListSelector)
        val appsList = DeviceHelpers.waitForObj(appsListSelector, timeout = UIAUTOMATOR_TIMEOUT)
        val appIconSelector = By.text(appName).hasParent(appsListSelector)

        // Scroll down All Apps until the app icon is visible.
@@ -600,10 +610,12 @@ class ConnectedDisplayCujSmokeTests {
    }

    fun assertTaskbarVisible(displayId: Int) =
        taskbarSelector(displayId).assertVisible() { "Can't find a taskbar on display#$displayId" }
        taskbarSelector(displayId).assertVisible(timeout = UIAUTOMATOR_TIMEOUT) {
            "Can't find a taskbar on display#$displayId"
        }

    fun assertTaskbarInvisible(displayId: Int) =
        taskbarSelector(displayId).assertInvisible() {
        taskbarSelector(displayId).assertInvisible(timeout = UIAUTOMATOR_TIMEOUT) {
            "A taskbar is visible unexpectedly on display#$displayId"
        }

@@ -611,7 +623,11 @@ class ConnectedDisplayCujSmokeTests {
        componentMatcher: IComponentNameMatcher,
        resId: String
    ): UiObject2 {
        val objects = DeviceHelpers.waitForPossibleEmpty(By.res(SYSTEMUI_PACKAGE, resId))
        val objects =
            DeviceHelpers.waitForPossibleEmpty(
                By.res(SYSTEMUI_PACKAGE, resId),
                timeout = UIAUTOMATOR_TIMEOUT
            )
        assertTrue("Unable to find view for $resId", objects.isNotEmpty())
        // TODO(b/416608975) - Check the app window bounds to filter out the uninteresting objects.
        return objects.first()
@@ -622,14 +638,16 @@ class ConnectedDisplayCujSmokeTests {

    fun openAppHandleMenuForFullscreenApp(displayId: Int) {
        val selector = By.res(SYSTEMUI_PACKAGE, STATUS_BAR_CONTAINER_RES_ID).displayId(displayId)
        DeviceHelpers.waitForObj(selector).click()
        DeviceHelpers.waitForObj(selector, timeout = UIAUTOMATOR_TIMEOUT).click()
    }

    fun assertOverviewDesktopItemVisible(displayId: Int) =
        By.res(
            TestHelpers.getOverviewPackageName(),
            TASK_VIEW_DESKTOP_RES_ID
        ).displayId(displayId).assertVisible() { "Unable to find overview desktop item" }
        ).displayId(displayId).assertVisible(timeout = UIAUTOMATOR_TIMEOUT) {
            "Unable to find overview desktop item"
        }

    fun assertOverviewItemVisible(appHelper: StandardAppHelper, displayId: Int) =
        By.descEndsWith(appHelper.appName).hasAncestor(
@@ -637,7 +655,9 @@ class ConnectedDisplayCujSmokeTests {
                TestHelpers.getOverviewPackageName(),
                TASK_VIEW_SINGLE_RES_ID
            ).displayId(displayId)
        ).assertVisible() { "Can't find overview item for ${appHelper.appName}" }
        ).assertVisible(timeout = UIAUTOMATOR_TIMEOUT) {
            "Can't find overview item for ${appHelper.appName}"
        }

    fun verifyActivityState(
        componentMatcher: IComponentNameMatcher,
@@ -687,7 +707,7 @@ class ConnectedDisplayCujSmokeTests {
            )
        }
        displayManager.displayTopology = topology
        WaitUtils.ensureThat("Display topology updated") {
        WaitUtils.ensureThat("Display topology updated", timeout = UIAUTOMATOR_TIMEOUT) {
            topology == displayManager.displayTopology
        }
    }
@@ -695,7 +715,7 @@ class ConnectedDisplayCujSmokeTests {
    fun clickRecentsButton(displayId: Int) {
        val selector = By.res(device.launcherPackageName, RECENTS_BUTTON_RES_ID)
            .displayId(displayId)
        DeviceHelpers.waitForObj(selector).click()
        DeviceHelpers.waitForObj(selector, timeout = UIAUTOMATOR_TIMEOUT).click()
    }

    fun taskbarSelector(displayId: Int): BySelector =
@@ -750,5 +770,9 @@ class ConnectedDisplayCujSmokeTests {
        const val CONNECTED_DEVICES_TEXT = "Connected devices"
        const val SETTINGS_PACKAGE = "com.android.settings"
        const val SCROLL_RETRY_MAX = 5

        // Following timeouts are adjusted for each platform by [platformAdjust()].
        val FLICKER_LIB_RETRY_INTERVAL_MS = Duration.ofMillis(500).platformAdjust().toMillis()
        val UIAUTOMATOR_TIMEOUT = Duration.ofSeconds(10).platformAdjust()
    }
}