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

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

Add support for Tablets on app close tests

Moreover, refactor the test to reuse the base test class with general assertions

Bug: 234735502
Test: atest FlickerTests
Change-Id: I01c354cc3e08ca4bc6dd495ac8f968dd9e311f85
parent 0f81dec3
Loading
Loading
Loading
Loading
+50 −14
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import com.android.server.wm.traces.common.IComponentMatcher
 * Checks that [ComponentMatcher.STATUS_BAR] window is visible and above the app windows in
 * all WM trace entries
 */
fun FlickerTestParameter.statusBarWindowIsVisible() {
fun FlickerTestParameter.statusBarWindowIsAlwaysVisible() {
    assertWm {
        this.isAboveAppWindowVisible(ComponentMatcher.STATUS_BAR)
    }
@@ -36,12 +36,22 @@ fun FlickerTestParameter.statusBarWindowIsVisible() {
 * Checks that [ComponentMatcher.NAV_BAR] window is visible and above the app windows in
 * all WM trace entries
 */
fun FlickerTestParameter.navBarWindowIsVisible() {
fun FlickerTestParameter.navBarWindowIsAlwaysVisible() {
    assertWm {
        this.isAboveAppWindowVisible(ComponentMatcher.NAV_BAR)
    }
}

/**
 * Checks that [ComponentMatcher.TASK_BAR] window is visible and above the app windows in
 * all WM trace entries
 */
fun FlickerTestParameter.taskBarWindowIsAlwaysVisible() {
    assertWm {
        this.isAboveAppWindowVisible(ComponentMatcher.TASK_BAR)
    }
}

/**
 * If [allStates] is true, checks if the stack space of all displays is fully covered
 * by any visible layer, during the whole transitions
@@ -79,7 +89,7 @@ fun FlickerTestParameter.entireScreenCovered(allStates: Boolean = true) {
 * Checks that [ComponentMatcher.NAV_BAR] layer is visible at the start and end of the SF
 * trace
 */
fun FlickerTestParameter.navBarLayerIsVisible() {
fun FlickerTestParameter.navBarLayerIsVisibleAtStartAndEnd() {
    assertLayersStart {
        this.isVisible(ComponentMatcher.NAV_BAR)
    }
@@ -88,11 +98,37 @@ fun FlickerTestParameter.navBarLayerIsVisible() {
    }
}

/**
 * Checks that [ComponentMatcher.TASK_BAR] layer is visible at the start and end of the SF
 * trace
 */
fun FlickerTestParameter.taskBarLayerIsVisibleAtStartAndEnd() {
    assertLayersStart {
        this.isVisible(ComponentMatcher.TASK_BAR)
    }
    assertLayersEnd {
        this.isVisible(ComponentMatcher.TASK_BAR)
    }
}

/**
 * Checks that [ComponentMatcher.TASK_BAR] layer is visible at the start and end of the SF
 * trace
 */
fun FlickerTestParameter.navTaskLayerIsVisibleAtStartAndEnd() {
    assertLayersStart {
        this.isVisible(ComponentMatcher.TASK_BAR)
    }
    assertLayersEnd {
        this.isVisible(ComponentMatcher.TASK_BAR)
    }
}

/**
 * Checks that [ComponentMatcher.STATUS_BAR] layer is visible at the start and end of the SF
 * trace
 */
fun FlickerTestParameter.statusBarLayerIsVisible() {
fun FlickerTestParameter.statusBarLayerIsVisibleAtStartAndEnd() {
    assertLayersStart {
        this.isVisible(ComponentMatcher.STATUS_BAR)
    }
@@ -105,7 +141,7 @@ fun FlickerTestParameter.statusBarLayerIsVisible() {
 * Asserts that the [ComponentMatcher.NAV_BAR] layer is at the correct position at the start
 * of the SF trace
 */
fun FlickerTestParameter.navBarLayerPositionStart() {
fun FlickerTestParameter.navBarLayerPositionAtStart() {
    assertLayersStart {
        val display = this.entry.displays.firstOrNull { !it.isVirtual }
                ?: error("There is no display!")
@@ -118,7 +154,7 @@ fun FlickerTestParameter.navBarLayerPositionStart() {
 * Asserts that the [ComponentMatcher.NAV_BAR] layer is at the correct position at the end
 * of the SF trace
 */
fun FlickerTestParameter.navBarLayerPositionEnd() {
fun FlickerTestParameter.navBarLayerPositionAtEnd() {
    assertLayersEnd {
        val display = this.entry.displays.minByOrNull { it.id }
            ?: throw RuntimeException("There is no display!")
@@ -131,16 +167,16 @@ fun FlickerTestParameter.navBarLayerPositionEnd() {
 * Asserts that the [ComponentMatcher.NAV_BAR] layer is at the correct position at the start
 * and end of the SF trace
 */
fun FlickerTestParameter.navBarLayerRotatesAndScales() {
    navBarLayerPositionStart()
    navBarLayerPositionEnd()
fun FlickerTestParameter.navBarLayerPositionAtStartAndEnd() {
    navBarLayerPositionAtStart()
    navBarLayerPositionAtEnd()
}

/**
 * Asserts that the [ComponentMatcher.STATUS_BAR] layer is at the correct position at the start
 * of the SF trace
 */
fun FlickerTestParameter.statusBarLayerPositionStart() {
fun FlickerTestParameter.statusBarLayerPositionAtStart() {
    assertLayersStart {
        val display = this.entry.displays.minByOrNull { it.id }
            ?: throw RuntimeException("There is no display!")
@@ -153,7 +189,7 @@ fun FlickerTestParameter.statusBarLayerPositionStart() {
 * Asserts that the [ComponentMatcher.STATUS_BAR] layer is at the correct position at the end
 * of the SF trace
 */
fun FlickerTestParameter.statusBarLayerPositionEnd() {
fun FlickerTestParameter.statusBarLayerPositionAtEnd() {
    assertLayersEnd {
        val display = this.entry.displays.minByOrNull { it.id }
            ?: throw RuntimeException("There is no display!")
@@ -166,9 +202,9 @@ fun FlickerTestParameter.statusBarLayerPositionEnd() {
 * Asserts that the [ComponentMatcher.STATUS_BAR] layer is at the correct position at the start
 * and end of the SF trace
 */
fun FlickerTestParameter.statusBarLayerRotatesScales() {
    statusBarLayerPositionStart()
    statusBarLayerPositionEnd()
fun FlickerTestParameter.statusBarLayerPositionAtStartAndEnd() {
    statusBarLayerPositionAtStart()
    statusBarLayerPositionAtEnd()
}

/**
+9 −9
Original line number Diff line number Diff line
@@ -25,8 +25,7 @@ import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.annotation.Group4
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.isShellTransitionsEnabled
import org.junit.Assume.assumeFalse
import org.junit.Assume.assumeTrue
import org.junit.Assume
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
@@ -68,6 +67,7 @@ import org.junit.runners.Parameterized
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group4
class CloseAppBackButtonTest(testSpec: FlickerTestParameter) : CloseAppTransition(testSpec) {
    /** {@inheritDoc} */
    override val transition: FlickerBuilder.() -> Unit
        get() = {
            super.transition(this)
@@ -82,22 +82,22 @@ class CloseAppBackButtonTest(testSpec: FlickerTestParameter) : CloseAppTransitio
    /** {@inheritDoc} */
    @FlakyTest(bugId = 206753786)
    @Test
    override fun navBarLayerRotatesAndScales() = super.navBarLayerRotatesAndScales()
    override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd()

    /** {@inheritDoc} */
    @FlakyTest(bugId = 206753786)
    @Test
    override fun statusBarLayerRotatesScales() {
    override fun statusBarLayerPositionAtStartAndEnd() {
        // This test doesn't work in shell transitions because of b/206753786
        assumeFalse(isShellTransitionsEnabled)
        super.statusBarLayerRotatesScales()
        Assume.assumeFalse(isShellTransitionsEnabled)
        super.statusBarLayerPositionAtStartAndEnd()
    }

    @FlakyTest(bugId = 214452854)
    @Test
    fun statusBarLayerRotatesScales_shellTransit() {
        assumeTrue(isShellTransitionsEnabled)
        super.statusBarLayerRotatesScales()
    fun statusBarLayerPositionAtStartAndEnd_shellTransit() {
        Assume.assumeTrue(isShellTransitionsEnabled)
        super.statusBarLayerPositionAtStartAndEnd()
    }

    /** {@inheritDoc} */
+4 −4
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import org.junit.runners.Parameterized
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group4
class CloseAppHomeButtonTest(testSpec: FlickerTestParameter) : CloseAppTransition(testSpec) {
    /** {@inheritDoc} */
    override val transition: FlickerBuilder.() -> Unit
        get() = {
            super.transition(this)
@@ -82,14 +83,13 @@ class CloseAppHomeButtonTest(testSpec: FlickerTestParameter) : CloseAppTransitio
    /** {@inheritDoc} */
    @FlakyTest(bugId = 206753786)
    @Test
    override fun navBarLayerRotatesAndScales() = super.navBarLayerRotatesAndScales()
    override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd()

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

    /** {@inheritDoc} */
    @FlakyTest(bugId = 229762973)
+8 −114
Original line number Diff line number Diff line
@@ -16,39 +16,25 @@

package com.android.server.wm.flicker.close

import android.app.Instrumentation
import android.platform.test.annotations.Presubmit
import androidx.test.platform.app.InstrumentationRegistry
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.BaseTest
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.entireScreenCovered
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import com.android.server.wm.flicker.helpers.StandardAppHelper
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.navBarLayerIsVisible
import com.android.server.wm.flicker.navBarLayerRotatesAndScales
import com.android.server.wm.flicker.navBarWindowIsVisible
import com.android.server.wm.flicker.replacesLayer
import com.android.server.wm.flicker.statusBarLayerIsVisible
import com.android.server.wm.flicker.statusBarLayerRotatesScales
import com.android.server.wm.flicker.statusBarWindowIsVisible
import com.android.server.wm.traces.common.ComponentMatcher.Companion.LAUNCHER
import org.junit.Test

/**
 * Base test class for transitions that close an app back to the launcher screen
 */
abstract class CloseAppTransition(protected val testSpec: FlickerTestParameter) {
    protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
abstract class CloseAppTransition(testSpec: FlickerTestParameter) : BaseTest(testSpec) {
    protected open val testApp: StandardAppHelper = SimpleAppHelper(instrumentation)
    protected val tapl = LauncherInstrumentation()

    /**
     * Specification of the test transition to execute
     */
    protected open val transition: FlickerBuilder.() -> Unit = {
    /** {@inheritDoc} */
    override val transition: FlickerBuilder.() -> Unit = {
        setup {
            test {
                tapl.setExpectedRotation(testSpec.startRotation)
@@ -65,98 +51,6 @@ abstract class CloseAppTransition(protected val testSpec: FlickerTestParameter)
        }
    }

    /**
     * Entry point for the test runner. It will use this method to initialize and cache
     * flicker executions
     */
    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
            transition()
        }
    }

    /**
     * Checks that the navigation bar window is visible during the whole transition
     */
    @Presubmit
    @Test
    open fun navBarWindowIsVisible() {
        testSpec.navBarWindowIsVisible()
    }

    /**
     * Checks that the status bar window is visible during the whole transition
     */
    @Presubmit
    @Test
    open fun statusBarWindowIsVisible() {
        testSpec.statusBarWindowIsVisible()
    }

    /**
     * Checks that the navigation bar layer is visible during the whole transition
     */
    @Presubmit
    @Test
    open fun navBarLayerIsVisible() {
        testSpec.navBarLayerIsVisible()
    }

    /**
     * Checks that the status bar layer is visible during the whole transition
     */
    @Presubmit
    @Test
    open fun statusBarLayerIsVisible() {
        testSpec.statusBarLayerIsVisible()
    }

    /**
     * Checks the position of the navigation bar at the start and end of the transition
     */
    @Presubmit
    @Test
    open fun navBarLayerRotatesAndScales() = testSpec.navBarLayerRotatesAndScales()

    /**
     * Checks the position of the status bar at the start and end of the transition
     */
    @Presubmit
    @Test
    open fun statusBarLayerRotatesScales() = testSpec.statusBarLayerRotatesScales()

    /**
     * Checks that all windows that are visible on the trace, are visible for at least 2
     * consecutive entries.
     */
    @Presubmit
    @Test
    open fun visibleWindowsShownMoreThanOneConsecutiveEntry() {
        testSpec.assertWm {
            this.visibleWindowsShownMoreThanOneConsecutiveEntry()
        }
    }

    /**
     * Checks that all layers that are visible on the trace, are visible for at least 2
     * consecutive entries.
     */
    @Presubmit
    @Test
    open fun visibleLayersShownMoreThanOneConsecutiveEntry() {
        testSpec.assertLayers {
            this.visibleLayersShownMoreThanOneConsecutiveEntry()
        }
    }

    /**
     * Checks that all parts of the screen are covered during the transition
     */
    @Presubmit
    @Test
    open fun entireScreenCovered() = testSpec.entireScreenCovered()

    /**
     * Checks that [testApp] is the top visible app window at the start of the transition and
     * that it is replaced by [LAUNCHER] during the transition