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

Commit c9cd787b authored by Nataniel Borges's avatar Nataniel Borges
Browse files

5/ Clean up flicker tests

1. Remove unused arguments
2. Fix bug IDs on flaky assertions
3. Remove unnecessary wait conditions
4. Update for standard kotlin syntax

Bug: 236131465
Test: atest FlickerTests
Change-Id: I3308000421be4b6c8f60a10ace48332450dfdaa3
parent 0fc8e8d7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -111,8 +111,8 @@ fun FlickerTestParameter.statusBarLayerIsVisible() {
 */
fun FlickerTestParameter.navBarLayerPositionStart() {
    assertLayersStart {
        val display = this.entry.displays.minByOrNull { it.id }
            ?: throw RuntimeException("There is no display!")
        val display = this.entry.displays.firstOrNull { !it.isVirtual }
                ?: error("There is no display!")
        this.visibleRegion(FlickerComponentName.NAV_BAR)
            .coversExactly(WindowUtils.getNavigationBarPosition(display, isGesturalNavigation))
    }
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ class CloseAppBackButtonTest(testSpec: FlickerTestParameter) : CloseAppTransitio
        }

    /** {@inheritDoc} */
    @FlakyTest
    @FlakyTest(bugId = 206753786)
    @Test
    override fun navBarLayerRotatesAndScales() = super.navBarLayerRotatesAndScales()

+2 −17
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.server.wm.flicker.close

import android.platform.test.annotations.FlakyTest
import android.platform.test.annotations.Presubmit
import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
@@ -77,31 +76,17 @@ class CloseAppHomeButtonTest(testSpec: FlickerTestParameter) : CloseAppTransitio
        }

    /** {@inheritDoc} */
    @FlakyTest
    @FlakyTest(bugId = 206753786)
    @Test
    override fun navBarLayerRotatesAndScales() = super.navBarLayerRotatesAndScales()

    /** {@inheritDoc} */
    @FlakyTest(bugId = 227430489)
    @FlakyTest(bugId = 206753786)
    @Test
    override fun statusBarLayerRotatesScales() {
        super.statusBarLayerRotatesScales()
    }

    /** {@inheritDoc} */
    @Presubmit
    @Test
    override fun launcherLayerReplacesApp() {
        super.launcherLayerReplacesApp()
    }

    /** {@inheritDoc} */
    @Presubmit
    @Test
    override fun entireScreenCovered() {
        super.entireScreenCovered()
    }

    /** {@inheritDoc} */
    @FlakyTest(bugId = 229762973)
    @Test
+4 −8
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.view.WindowInsets.Type.ime
import android.view.WindowInsets.Type.navigationBars
import android.view.WindowInsets.Type.statusBars
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.testapp.ActivityOptions
import com.android.server.wm.traces.common.FlickerComponentName
@@ -37,12 +36,9 @@ class ImeAppAutoFocusHelper @JvmOverloads constructor(
    component: FlickerComponentName =
        ActivityOptions.IME_ACTIVITY_AUTO_FOCUS_COMPONENT_NAME.toFlickerComponent()
) : ImeAppHelper(instr, launcherName, component) {
    override fun openIME(
        device: UiDevice,
        wmHelper: WindowManagerStateHelper?
    ) {
    override fun openIME(wmHelper: WindowManagerStateHelper) {
        // do nothing (the app is focused automatically)
        waitIMEShown(device, wmHelper)
        waitIMEShown(wmHelper)
    }

    override fun launchViaIntent(
@@ -52,7 +48,7 @@ class ImeAppAutoFocusHelper @JvmOverloads constructor(
        stringExtras: Map<String, String>
    ) {
        super.launchViaIntent(wmHelper, expectedWindowName, action, stringExtras)
        waitIMEShown(uiDevice, wmHelper)
        waitIMEShown(wmHelper)
    }

    override fun open() {
@@ -68,7 +64,7 @@ class ImeAppAutoFocusHelper @JvmOverloads constructor(
        val button = uiDevice.wait(Until.findObject(By.res(getPackage(),
                "start_dialog_themed_activity_btn")), FIND_TIMEOUT)

        require(button != null) {
        requireNotNull(button) {
            "Button not found, this usually happens when the device " +
                    "was left in an unknown state (e.g. Screen turned off)"
        }
+20 −42
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.app.Instrumentation
import android.support.test.launcherhelper.ILauncherStrategy
import android.support.test.launcherhelper.LauncherStrategyFactory
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.testapp.ActivityOptions
import com.android.server.wm.traces.common.FlickerComponentName
@@ -39,70 +38,49 @@ open class ImeAppHelper @JvmOverloads constructor(
    /**
     * Opens the IME and wait for it to be displayed
     *
     * @param device UIDevice instance to interact with the device
     * @param wmHelper Helper used to wait for WindowManager states
     */
    @JvmOverloads
    open fun openIME(device: UiDevice, wmHelper: WindowManagerStateHelper? = null) {
        val editText = device.wait(
    open fun openIME(wmHelper: WindowManagerStateHelper) {
        val editText = uiDevice.wait(
            Until.findObject(By.res(getPackage(), "plain_text_input")),
            FIND_TIMEOUT)

        require(editText != null) {
        requireNotNull(editText) {
            "Text field not found, this usually happens when the device " +
                "was left in an unknown state (e.g. in split screen)"
        }
        editText.click()
        waitIMEShown(device, wmHelper)
        waitIMEShown(wmHelper)
    }

    protected fun waitIMEShown(
        device: UiDevice,
        wmHelper: WindowManagerStateHelper? = null
    ) {
        if (wmHelper == null) {
            device.waitForIdle()
        } else {
    protected fun waitIMEShown(wmHelper: WindowManagerStateHelper) {
        wmHelper.StateSyncBuilder()
            .withImeShown()
            .waitForAndVerify()
    }
    }

    /**
     * Opens the IME and wait for it to be gone
     *
     * @param device UIDevice instance to interact with the device
     * @param wmHelper Helper used to wait for WindowManager states
     */
    @JvmOverloads
    open fun closeIME(device: UiDevice, wmHelper: WindowManagerStateHelper? = null) {
        device.pressBack()
        // Using only the AccessibilityInfo it is not possible to identify if the IME is active
        if (wmHelper == null) {
            device.waitForIdle()
        } else {
    open fun closeIME(wmHelper: WindowManagerStateHelper) {
        uiDevice.pressBack()
        wmHelper.StateSyncBuilder()
            .withImeGone()
            .waitForAndVerify()
    }
    }

    @JvmOverloads
    open fun finishActivity(device: UiDevice, wmHelper: WindowManagerStateHelper? = null) {
        val finishButton = device.wait(
    open fun finishActivity(wmHelper: WindowManagerStateHelper) {
        val finishButton = uiDevice.wait(
                Until.findObject(By.res(getPackage(), "finish_activity_btn")),
                FIND_TIMEOUT)
        require(finishButton != null) {
        requireNotNull(finishButton) {
            "Finish activity button not found, probably IME activity is not on the screen?"
        }
        finishButton.click()
        if (wmHelper == null) {
            device.waitForIdle()
        } else {
        wmHelper.StateSyncBuilder()
            .withActivityRemoved(component)
            .waitForAndVerify()
    }
}
}
Loading