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

Commit aed34a36 authored by Toshiki Kikuchi's avatar Toshiki Kikuchi
Browse files

Longer timeout for cuttlefish devices

This CL extends some timeouts only on cuttlefish devices which are
usually slower than physical devices by utilizing
android.platform.uiautomatorhelpers.DurationUtils.platformAdjust()
method.

Flag: EXEMPT - test stabilization
Bug: 442453305
Bug: 442453913
Bug: 442454448
Bug: 441594940
Bug: 442453123
Bug: 442453799
Test: atest WMShellSmokeTestsDesktopMode
Change-Id: I8144c9dba7f20eddddf585f414b511871c016ed1
parent 6f2d4a55
Loading
Loading
Loading
Loading
+37 −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)
@@ -161,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)
@@ -186,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
        }

@@ -547,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()
    }
@@ -564,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()
@@ -578,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.
@@ -603,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"
        }

@@ -614,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()
@@ -625,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(
@@ -640,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,
@@ -690,7 +707,7 @@ class ConnectedDisplayCujSmokeTests {
            )
        }
        displayManager.displayTopology = topology
        WaitUtils.ensureThat("Display topology updated") {
        WaitUtils.ensureThat("Display topology updated", timeout = UIAUTOMATOR_TIMEOUT) {
            topology == displayManager.displayTopology
        }
    }
@@ -698,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 =
@@ -753,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()
    }
}