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

Commit 8e6b425d authored by Nataniel Borges's avatar Nataniel Borges
Browse files

Add support for Tablets on quick switch tests

Moreover, refactor the test to reuse the base test class with general assertions and fix ktlint errors

Bug: 234735502
Test: atest FlickerTests
Change-Id: I536b3993621b4817efd04c781a9048f87c24b558
parent eb44e956
Loading
Loading
Loading
Loading
+77 −112
Original line number Diff line number Diff line
@@ -16,15 +16,13 @@

package com.android.server.wm.flicker.quickswitch

import android.app.Instrumentation
import android.platform.test.annotations.FlakyTest
import android.platform.test.annotations.Postsubmit
import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresDevice
import android.view.Surface
import android.view.WindowManagerPolicyConstants
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.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
@@ -33,11 +31,6 @@ import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.NonResizeableAppHelper
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import com.android.server.wm.flicker.helpers.isShellTransitionsEnabled
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.statusBarLayerIsVisible
import com.android.server.wm.flicker.statusBarWindowIsVisible
import com.android.server.wm.traces.common.ComponentMatcher
import com.android.server.wm.traces.common.Rect
import org.junit.Assume
@@ -64,10 +57,9 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group1
open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestParameter) {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val tapl = LauncherInstrumentation()

open class QuickSwitchBetweenTwoAppsBackTest(
    testSpec: FlickerTestParameter
) : BaseTest(testSpec) {
    private val testApp1 = SimpleAppHelper(instrumentation)
    private val testApp2 = NonResizeableAppHelper(instrumentation)

@@ -76,9 +68,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
        Assume.assumeFalse(isShellTransitionsEnabled)
    }

    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
    /** {@inheritDoc} */
    override val transition: FlickerBuilder.() -> Unit = {
        setup {
            test {
                tapl.setExpectedRotation(testSpec.startRotation)
@@ -93,7 +84,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
        transitions {
            tapl.launchedAppState.quickSwitchToPreviousApp()
            wmHelper.StateSyncBuilder()
                    .withNavBarStatusBarVisible()
                .withNavOrTaskBarVisible()
                .withStatusBarVisible()
                .waitForAndVerify()
        }

@@ -104,7 +96,6 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
            }
        }
    }
    }

    /**
     * Checks that the transition starts with [testApp2]'s windows filling/covering exactly the
@@ -142,8 +133,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
    }

    /**
     * Checks that [testApp1] windows fill the entire screen (i.e. is "fullscreen") at the end of the
     * transition once we have fully quick switched from [testApp2] back to the [testApp1].
     * Checks that [testApp1] windows fill the entire screen (i.e. is "fullscreen") at the end of
     * the transition once we have fully quick switched from [testApp2] back to the [testApp1].
     */
    @Presubmit
    @Test
@@ -154,8 +145,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
    }

    /**
     * Checks that [testApp1] layers fill the entire screen (i.e. is "fullscreen") at the end of the
     * transition once we have fully quick switched from [testApp2] back to the [testApp1].
     * Checks that [testApp1] layers fill the entire screen (i.e. is "fullscreen") at the end of
     * the transition once we have fully quick switched from [testApp2] back to the [testApp1].
     */
    @Presubmit
    @Test
@@ -166,8 +157,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
    }

    /**
     * Checks that [testApp1] is the top window at the end of the transition once we have fully quick
     * switched from [testApp2] back to the [testApp1].
     * Checks that [testApp1] is the top window at the end of the transition once we have fully
     * quick switched from [testApp2] back to the [testApp1].
     */
    @Presubmit
    @Test
@@ -178,8 +169,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
    }

    /**
     * Checks that [testApp1]'s window starts off invisible and becomes visible at some point before
     * the end of the transition and then stays visible until the end of the transition.
     * Checks that [testApp1]'s window starts off invisible and becomes visible at some point
     * before the end of the transition and then stays visible until the end of the transition.
     */
    @Presubmit
    @Test
@@ -194,8 +185,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
    }

    /**
     * Checks that [testApp1]'s layer starts off invisible and becomes visible at some point before
     * the end of the transition and then stays visible until the end of the transition.
     * Checks that [testApp1]'s layer starts off invisible and becomes visible at some point
     * before the end of the transition and then stays visible until the end of the transition.
     */
    @Presubmit
    @Test
@@ -208,8 +199,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
    }

    /**
     * Checks that [testApp2]'s window starts off visible and becomes invisible at some point before
     * the end of the transition and then stays invisible until the end of the transition.
     * Checks that [testApp2]'s window starts off visible and becomes invisible at some point
     * before the end of the transition and then stays invisible until the end of the transition.
     */
    @Presubmit
    @Test
@@ -222,8 +213,8 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
    }

    /**
     * Checks that [testApp2]'s layer starts off visible and becomes invisible at some point before
     * the end of the transition and then stays invisible until the end of the transition.
     * Checks that [testApp2]'s layer starts off visible and becomes invisible at some point
     * before the end of the transition and then stays invisible until the end of the transition.
     */
    @Presubmit
    @Test
@@ -274,42 +265,16 @@ open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestPa
        }
    }

    /**
     * Checks that the navbar window is visible throughout the entire transition.
     */
    @Presubmit
    @Test
    fun navBarWindowIsAlwaysVisible() = testSpec.navBarWindowIsVisible()

    /**
     * Checks that the navbar layer is visible throughout the entire transition.
     */
    @Presubmit
    @Test
    fun navBarLayerAlwaysIsVisible() = testSpec.navBarLayerIsVisible()

    /**
     * Checks that the navbar is always in the right position and covers the expected region.
     *
     * NOTE: This doesn't check that the navbar is visible or not.
     */
    /** {@inheritDoc} */
    @FlakyTest
    @Test
    fun navbarIsAlwaysInRightPosition() = testSpec.navBarLayerRotatesAndScales()
    override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd()

    /**
     * Checks that the status bar window is visible throughout the entire transition.
     */
    @Presubmit
    @Test
    fun statusBarWindowIsAlwaysVisible() = testSpec.statusBarWindowIsVisible()

    /**
     * Checks that the status bar layer is visible throughout the entire transition.
     */
    @Presubmit
    /** {@inheritDoc} */
    @Postsubmit
    @Test
    fun statusBarLayerIsAlwaysVisible() = testSpec.statusBarLayerIsVisible()
    override fun statusBarLayerIsVisibleAtStartAndEnd() =
        super.statusBarLayerIsVisibleAtStartAndEnd()

    companion object {
        private var startDisplayBounds = Rect.EMPTY
+45 −77
Original line number Diff line number Diff line
@@ -16,15 +16,13 @@

package com.android.server.wm.flicker.quickswitch

import android.app.Instrumentation
import android.platform.test.annotations.FlakyTest
import android.platform.test.annotations.Postsubmit
import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresDevice
import android.view.Surface
import android.view.WindowManagerPolicyConstants
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.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
@@ -33,11 +31,6 @@ import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.NonResizeableAppHelper
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import com.android.server.wm.flicker.helpers.isShellTransitionsEnabled
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.statusBarLayerIsVisible
import com.android.server.wm.flicker.statusBarWindowIsVisible
import com.android.server.wm.traces.common.ComponentMatcher
import com.android.server.wm.traces.common.Rect
import org.junit.Assume
@@ -64,10 +57,9 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group1
open class QuickSwitchBetweenTwoAppsForwardTest(private val testSpec: FlickerTestParameter) {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val tapl = LauncherInstrumentation()

open class QuickSwitchBetweenTwoAppsForwardTest(
    testSpec: FlickerTestParameter
) : BaseTest(testSpec) {
    private val testApp1 = SimpleAppHelper(instrumentation)
    private val testApp2 = NonResizeableAppHelper(instrumentation)

@@ -76,9 +68,8 @@ open class QuickSwitchBetweenTwoAppsForwardTest(private val testSpec: FlickerTes
        Assume.assumeFalse(isShellTransitionsEnabled)
    }

    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
    /** {@inheritDoc} */
    override val transition: FlickerBuilder.() -> Unit = {
        setup {
            test {
                tapl.setExpectedRotation(testSpec.startRotation)
@@ -88,7 +79,8 @@ open class QuickSwitchBetweenTwoAppsForwardTest(private val testSpec: FlickerTes
                testApp2.launchViaIntent(wmHelper)
                tapl.launchedAppState.quickSwitchToPreviousApp()
                wmHelper.StateSyncBuilder()
                        .withNavBarStatusBarVisible()
                    .withNavOrTaskBarVisible()
                    .withStatusBarVisible()
                    .waitForAndVerify()
                startDisplayBounds = wmHelper.currentState.layerState
                    .physicalDisplayBounds ?: error("Display not found")
@@ -97,7 +89,8 @@ open class QuickSwitchBetweenTwoAppsForwardTest(private val testSpec: FlickerTes
        transitions {
            tapl.launchedAppState.quickSwitchToPreviousAppSwipeLeft()
            wmHelper.StateSyncBuilder()
                    .withNavBarStatusBarVisible()
                .withNavOrTaskBarVisible()
                .withStatusBarVisible()
                .waitForAndVerify()
        }

@@ -108,7 +101,6 @@ open class QuickSwitchBetweenTwoAppsForwardTest(private val testSpec: FlickerTes
            }
        }
    }
    }

    /**
     * Checks that the transition starts with [testApp1]'s windows filling/covering exactly the
@@ -279,52 +271,28 @@ open class QuickSwitchBetweenTwoAppsForwardTest(private val testSpec: FlickerTes
        }
    }

    /**
     * Checks that the navbar window is visible throughout the entire transition.
     */
    @Presubmit
    @Test
    open fun navBarWindowIsAlwaysVisible() {
        testSpec.navBarWindowIsVisible()
    }

    /**
     * Checks that the navbar layer is visible throughout the entire transition.
     */
    @Presubmit
    /** {@inheritDoc} */
    @FlakyTest
    @Test
    open fun navBarLayerAlwaysIsVisible() {
        testSpec.navBarLayerIsVisible()
    }
    override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd()

    /**
     * Checks that the navbar is always in the right position and covers the expected region.
     *
     * NOTE: This doesn't check that the navbar is visible or not.
     */
    @FlakyTest
    /** {@inheritDoc} */
    @Postsubmit
    @Test
    open fun navbarIsAlwaysInRightPosition() {
        testSpec.navBarLayerRotatesAndScales()
    }
    override fun visibleLayersShownMoreThanOneConsecutiveEntry() =
        super.visibleLayersShownMoreThanOneConsecutiveEntry()

    /**
     * Checks that the status bar window is visible throughout the entire transition.
     */
    @Presubmit
    /** {@inheritDoc} */
    @Postsubmit
    @Test
    open fun statusBarWindowIsAlwaysVisible() {
        testSpec.statusBarWindowIsVisible()
    }
    override fun statusBarLayerPositionAtStartAndEnd() =
        super.statusBarLayerPositionAtStartAndEnd()

    /**
     * Checks that the status bar layer is visible throughout the entire transition.
     */
    @Presubmit
    /** {@inheritDoc} */
    @Postsubmit
    @Test
    open fun statusBarLayerIsAlwaysVisible() {
        testSpec.statusBarLayerIsVisible()
    }
    override fun visibleWindowsShownMoreThanOneConsecutiveEntry() =
        super.visibleWindowsShownMoreThanOneConsecutiveEntry()

    companion object {
        private var startDisplayBounds = Rect.EMPTY
+58 −87
Original line number Diff line number Diff line
@@ -16,26 +16,18 @@

package com.android.server.wm.flicker.quickswitch

import android.app.Instrumentation
import android.platform.test.annotations.Postsubmit
import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresDevice
import android.view.Surface
import android.view.WindowManagerPolicyConstants
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.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.annotation.Group1
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.navBarLayerIsVisible
import com.android.server.wm.flicker.navBarLayerRotatesAndScales
import com.android.server.wm.flicker.navBarWindowIsVisible
import com.android.server.wm.flicker.statusBarLayerIsVisible
import com.android.server.wm.flicker.statusBarWindowIsVisible
import com.android.server.wm.traces.common.ComponentMatcher
import com.android.server.wm.traces.common.Rect
import org.junit.FixMethodOrder
@@ -60,18 +52,14 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group1
class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val taplInstrumentation = LauncherInstrumentation()

class QuickSwitchFromLauncherTest(testSpec: FlickerTestParameter) : BaseTest(testSpec) {
    private val testApp = SimpleAppHelper(instrumentation)

    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
    /** {@inheritDoc} */
    override val transition: FlickerBuilder.() -> Unit = {
        setup {
            test {
                    taplInstrumentation.setExpectedRotation(testSpec.startRotation)
                tapl.setExpectedRotation(testSpec.startRotation)
            }

            eachRun {
@@ -87,10 +75,11 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
            }
        }
        transitions {
                taplInstrumentation.workspace.quickSwitchToPreviousApp()
            tapl.workspace.quickSwitchToPreviousApp()
            wmHelper.StateSyncBuilder()
                .withFullScreenApp(testApp)
                    .withNavBarStatusBarVisible()
                .withNavOrTaskBarVisible()
                .withStatusBarVisible()
                .waitForAndVerify()
        }

@@ -100,7 +89,6 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
            }
        }
    }
    }

    /**
     * Checks that [testApp] windows fill the entire screen (i.e. is "fullscreen") at the end of the
@@ -150,8 +138,8 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
    }

    /**
     * Checks that the transition starts with the launcher windows filling/covering exactly the
     * entirety of the display.
     * Checks that the transition starts with the [ComponentMatcher.LAUNCHER] windows
     * filling/covering exactly display size
     */
    @Presubmit
    @Test
@@ -162,8 +150,8 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
    }

    /**
     * Checks that the transition starts with the launcher layers filling/covering exactly the
     * entirety of the display.
     * Checks that the transition starts with the [ComponentMatcher.LAUNCHER] layers
     * filling/covering exactly the display size.
     */
    @Presubmit
    @Test
@@ -174,7 +162,7 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
    }

    /**
     * Checks that the transition starts with the launcher being the top window.
     * Checks that the transition starts with the [ComponentMatcher.LAUNCHER] being the top window.
     */
    @Presubmit
    @Test
@@ -225,7 +213,8 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
    }

    /**
     * Checks that the launcher window starts off visible and becomes invisible at some point before
     * Checks that the [ComponentMatcher.LAUNCHER] window starts off visible and becomes invisible
     * at some point before
     * the end of the transition and then stays invisible until the end of the transition.
     */
    @Presubmit
@@ -239,7 +228,8 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
    }

    /**
     * Checks that the launcher layer starts off visible and becomes invisible at some point before
     * Checks that the [ComponentMatcher.LAUNCHER] layer starts off visible and becomes invisible
     * at some point before
     * the end of the transition and then stays invisible until the end of the transition.
     */
    @Presubmit
@@ -253,7 +243,8 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
    }

    /**
     * Checks that the launcher window is visible at least until the app window is visible. Ensures
     * Checks that the [ComponentMatcher.LAUNCHER] window is visible at least until the app window
     * is visible. Ensures
     * that at any point, either the launcher or [testApp] windows are at least partially visible.
     */
    @Presubmit
@@ -269,8 +260,9 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
    }

    /**
     * Checks that the launcher layer is visible at least until the app layer is visible. Ensures
     * that at any point, either the launcher or [testApp] layers are at least partially visible.
     * Checks that the [ComponentMatcher.LAUNCHER] layer is visible at least until the app layer
     * is visible. Ensures that at any point, either the launcher or [testApp] layers are at least
     * partially visible.
     */
    @Presubmit
    @Test
@@ -284,49 +276,28 @@ class QuickSwitchFromLauncherTest(private val testSpec: FlickerTestParameter) {
        }
    }

    /**
     * Checks that the navbar window is visible throughout the entire transition.
     */
    @Presubmit
    /** {@inheritDoc} */
    @Postsubmit
    @Test
    fun navBarWindowIsAlwaysVisible() = testSpec.navBarWindowIsVisible()
    override fun statusBarLayerPositionAtStartAndEnd() =
        super.statusBarLayerPositionAtStartAndEnd()

    /**
     * Checks that the navbar layer is visible throughout the entire transition.
     */
    @Presubmit
    /** {@inheritDoc} */
    @Postsubmit
    @Test
    fun navBarLayerAlwaysIsVisible() = testSpec.navBarLayerIsVisible()
    override fun taskBarLayerIsVisibleAtStartAndEnd() = super.taskBarLayerIsVisibleAtStartAndEnd()

    /**
     * Checks that the navbar is always in the right position and covers the expected region.
     *
     * NOTE: This doesn't check that the navbar is visible or not.
     */
    @Presubmit
    /** {@inheritDoc} */
    @Postsubmit
    @Test
    fun navbarIsAlwaysInRightPosition() = testSpec.navBarLayerRotatesAndScales()
    override fun visibleLayersShownMoreThanOneConsecutiveEntry() =
        super.visibleLayersShownMoreThanOneConsecutiveEntry()

    /**
     * Checks that the status bar window is visible throughout the entire transition.
     */
    @Presubmit
    @Test
    fun statusBarWindowIsAlwaysVisible() = testSpec.statusBarWindowIsVisible()

    /**
     * Checks that the status bar layer is visible throughout the entire transition.
     */
    @Presubmit
    @Test
    fun statusBarLayerIsAlwaysVisible() = testSpec.statusBarLayerIsVisible()

    /**
     * Checks that the screen is always fully covered by visible layers throughout the transition.
     */
    @Presubmit
    /** {@inheritDoc} */
    @Postsubmit
    @Test
    fun screenIsAlwaysFilled() = testSpec.entireScreenCovered()
    override fun visibleWindowsShownMoreThanOneConsecutiveEntry() =
        super.visibleWindowsShownMoreThanOneConsecutiveEntry()

    companion object {
        private var startDisplayBounds = Rect.EMPTY