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

Commit 25766b83 authored by Nataniel Borges's avatar Nataniel Borges
Browse files

Generalize app launch transitions

Share code and assertions between the transitions to improve maintainability

Test: atest FlickerTests:com.android.server.wm.flicker.rotation
Bug: 167521849
Change-Id: I5e7e6d44f9c873f11b4ad9f8cf1de840f79b5fff
parent b7138470
Loading
Loading
Loading
Loading
+9 −121
Original line number Original line Diff line number Diff line
@@ -16,37 +16,14 @@


package com.android.server.wm.flicker.launch
package com.android.server.wm.flicker.launch


import android.app.Instrumentation
import android.platform.test.annotations.Presubmit
import android.view.Surface
import androidx.test.filters.FlakyTest
import androidx.test.filters.RequiresDevice
import androidx.test.filters.RequiresDevice
import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.focusChanges
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.server.wm.flicker.navBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.navBarLayerRotatesAndScales
import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.noUncoveredRegions
import com.android.server.wm.flicker.repetitions
import com.android.server.wm.flicker.startRotation
import com.android.server.wm.flicker.startRotation
import com.android.server.wm.flicker.statusBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerRotatesScales
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.visibleWindowsShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.visibleLayersShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.wallpaperWindowBecomesInvisible
import com.android.server.wm.flicker.appLayerReplacesWallpaperLayer
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import org.junit.Assume
import org.junit.FixMethodOrder
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized
@@ -59,115 +36,26 @@ import org.junit.runners.Parameterized
@RunWith(Parameterized::class)
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class OpenAppColdTest(private val testSpec: FlickerTestParameter) {
class OpenAppColdTest(testSpec: FlickerTestParameter) : OpenAppTransition(testSpec) {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
    private val testApp = SimpleAppHelper(instrumentation)
        get() = {

            super.transition(this, it)
    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
            withTestName { testSpec.name }
            repeat { testSpec.config.repetitions }
            setup {
            setup {
                test {
                    device.wakeUpAndGoToHomeScreen()
                }
                eachRun {
                eachRun {
                    this.setRotation(testSpec.config.startRotation)
                    this.setRotation(testSpec.config.startRotation)
                }
                }
            }
            }
            transitions {
                testApp.launchViaIntent(wmHelper)
                // wmHelper.waitForFullScreenApp(testApp.component)
            }
            teardown {
            teardown {
                eachRun {
                eachRun {
                    testApp.exit()
                    testApp.exit(wmHelper)
                    wmHelper.waitForAppTransitionIdle()
                    this.setRotation(Surface.ROTATION_0)
                }
            }
        }
    }

    @Presubmit
    @Test
    fun navBarWindowIsAlwaysVisible() = testSpec.navBarWindowIsAlwaysVisible()

    @Presubmit
    @Test
    fun statusBarWindowIsAlwaysVisible() = testSpec.statusBarWindowIsAlwaysVisible()

    @Presubmit
    @Test
    fun visibleWindowsShownMoreThanOneConsecutiveEntry() =
        testSpec.visibleWindowsShownMoreThanOneConsecutiveEntry()

    @Presubmit
    @Test
    fun appWindowReplacesLauncherAsTopWindow() =
        testSpec.appWindowReplacesLauncherAsTopWindow(testApp)

    @Presubmit
    @Test
    fun wallpaperWindowBecomesInvisible() = testSpec.wallpaperWindowBecomesInvisible()

    @Presubmit
    @Test
    // During testing the launcher is always in portrait mode
    fun noUncoveredRegions() = testSpec.noUncoveredRegions(testSpec.config.startRotation,
        Surface.ROTATION_0)

    @Presubmit
    @Test
    fun navBarLayerIsAlwaysVisible() = testSpec.navBarLayerIsAlwaysVisible()

    @Presubmit
    @Test
    fun statusBarLayerIsAlwaysVisible() = testSpec.statusBarLayerIsAlwaysVisible()

    @Presubmit
    @Test
    fun appLayerReplacesWallpaperLayer() =
        testSpec.appLayerReplacesWallpaperLayer(testApp.`package`)

    @Presubmit
    @Test
    fun navBarLayerRotatesAndScales() {
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.navBarLayerRotatesAndScales(testSpec.config.startRotation, Surface.ROTATION_0)
                }
                }

    @FlakyTest
    @Test
    fun navBarLayerRotatesAndScales_Flaky() {
        Assume.assumeTrue(testSpec.isRotated)
        testSpec.navBarLayerRotatesAndScales(testSpec.config.startRotation, Surface.ROTATION_0)
            }
            }

            transitions {
    @Presubmit
                testApp.launchViaIntent(wmHelper)
    @Test
                wmHelper.waitForFullScreenApp(testApp.component)
    fun statusBarLayerRotatesScales() {
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.statusBarLayerRotatesScales(testSpec.config.startRotation, Surface.ROTATION_0)
            }
            }

    @FlakyTest
    @Test
    fun statusBarLayerRotatesScales_Flaky() {
        Assume.assumeTrue(testSpec.isRotated)
        testSpec.statusBarLayerRotatesScales(testSpec.config.startRotation, Surface.ROTATION_0)
        }
        }


    @Presubmit
    @Test
    fun focusChanges() = testSpec.focusChanges("NexusLauncherActivity", testApp.`package`)

    @FlakyTest
    @Test
    fun visibleLayersShownMoreThanOneConsecutiveEntry() =
        testSpec.visibleLayersShownMoreThanOneConsecutiveEntry()

    companion object {
    companion object {
        @Parameterized.Parameters(name = "{0}")
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        @JvmStatic
+26 −75
Original line number Original line Diff line number Diff line
@@ -16,36 +16,19 @@


package com.android.server.wm.flicker.launch
package com.android.server.wm.flicker.launch


import android.app.Instrumentation
import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.Presubmit
import android.view.Surface
import androidx.test.filters.FlakyTest
import androidx.test.filters.FlakyTest
import androidx.test.filters.RequiresDevice
import androidx.test.filters.RequiresDevice
import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.endRotation
import com.android.server.wm.flicker.focusChanges
import com.android.server.wm.flicker.visibleLayersShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.visibleLayersShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.visibleWindowsShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.visibleWindowsShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.helpers.reopenAppFromOverview
import com.android.server.wm.flicker.helpers.reopenAppFromOverview
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.server.wm.flicker.navBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.navBarLayerRotatesAndScales
import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.noUncoveredRegions
import com.android.server.wm.flicker.repetitions
import com.android.server.wm.flicker.startRotation
import com.android.server.wm.flicker.startRotation
import com.android.server.wm.flicker.statusBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerRotatesScales
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.wallpaperWindowBecomesInvisible
import com.android.server.wm.flicker.wallpaperWindowBecomesInvisible
import com.android.server.wm.flicker.appLayerReplacesWallpaperLayer
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import org.junit.Assume
import org.junit.Assume
import org.junit.FixMethodOrder
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.Test
@@ -61,18 +44,12 @@ import org.junit.runners.Parameterized
@RunWith(Parameterized::class)
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class OpenAppFromOverviewTest(private val testSpec: FlickerTestParameter) {
class OpenAppFromOverviewTest(testSpec: FlickerTestParameter) : OpenAppTransition(testSpec) {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
    private val testApp = SimpleAppHelper(instrumentation)
        get() = {

            super.transition(this, it)
    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
            withTestName { testSpec.name }
            repeat { testSpec.config.repetitions }
            setup {
            setup {
                test {
                test {
                    device.wakeUpAndGoToHomeScreen()
                    testApp.launchViaIntent(wmHelper)
                    testApp.launchViaIntent(wmHelper)
                }
                }
                eachRun {
                eachRun {
@@ -87,71 +64,50 @@ class OpenAppFromOverviewTest(private val testSpec: FlickerTestParameter) {
                device.reopenAppFromOverview(wmHelper)
                device.reopenAppFromOverview(wmHelper)
                wmHelper.waitForFullScreenApp(testApp.component)
                wmHelper.waitForFullScreenApp(testApp.component)
            }
            }
            teardown {
                test {
                    testApp.exit()
                }
            }
        }
        }
        }


    @Presubmit
    @Test
    fun navBarWindowIsAlwaysVisible() = testSpec.navBarWindowIsAlwaysVisible()

    @Presubmit
    @Test
    @Test
    fun statusBarWindowIsAlwaysVisible() = testSpec.statusBarWindowIsAlwaysVisible()
    override fun appWindowReplacesLauncherAsTopWindow() =
        super.appWindowReplacesLauncherAsTopWindow()


    @Test
    @Test
    fun appWindowReplacesLauncherAsTopWindow() =
    override fun wallpaperWindowBecomesInvisible() {
        testSpec.appWindowReplacesLauncherAsTopWindow(testApp)
        testSpec.wallpaperWindowBecomesInvisible()

    @Test
    fun wallpaperWindowBecomesInvisible() = testSpec.wallpaperWindowBecomesInvisible()

    @Presubmit
    @Test
    fun appLayerReplacesWallpaperLayer() =
        testSpec.appLayerReplacesWallpaperLayer(testApp.`package`)

    @Presubmit
    @Test
    fun navBarLayerRotatesAndScales() {
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.navBarLayerRotatesAndScales(testSpec.config.startRotation, Surface.ROTATION_0)
    }
    }


    @Presubmit
    @Presubmit
    @Test
    @Test
    fun statusBarLayerRotatesScales() {
    override fun statusBarLayerIsAlwaysVisible() {
        Assume.assumeFalse(testSpec.isRotated)
        Assume.assumeTrue(testSpec.isRotated)
        testSpec.statusBarLayerRotatesScales(testSpec.config.startRotation, Surface.ROTATION_0)
        super.statusBarLayerIsAlwaysVisible()
    }
    }


    @Presubmit
    @Presubmit
    @Test
    @Test
    fun statusBarLayerIsAlwaysVisible() {
    override fun navBarLayerIsAlwaysVisible() {
        Assume.assumeTrue(testSpec.isRotated)
        Assume.assumeTrue(testSpec.isRotated)
        testSpec.statusBarLayerIsAlwaysVisible()
        super.navBarLayerIsAlwaysVisible()
    }
    }


    @Presubmit
    @FlakyTest
    @Test
    @Test
    fun navBarLayerIsAlwaysVisible() {
    fun statusBarLayerIsAlwaysVisible_Flaky() {
        Assume.assumeTrue(testSpec.isRotated)
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.navBarLayerIsAlwaysVisible()
        super.statusBarLayerIsAlwaysVisible()
    }
    }


    @Presubmit
    @FlakyTest
    @Test
    @Test
    fun focusChanges() = testSpec.focusChanges("NexusLauncherActivity", testApp.`package`)
    fun navBarLayerIsAlwaysVisible_Flaky() {
        Assume.assumeFalse(testSpec.isRotated)
        super.navBarLayerIsAlwaysVisible()
    }


    @Presubmit
    @Presubmit
    @Test
    @Test
    fun visibleWindowsShownMoreThanOneConsecutiveEntry() {
    override fun visibleWindowsShownMoreThanOneConsecutiveEntry() {
        Assume.assumeFalse(testSpec.isRotated)
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.visibleWindowsShownMoreThanOneConsecutiveEntry()
        super.visibleWindowsShownMoreThanOneConsecutiveEntry()
    }
    }


    @FlakyTest
    @FlakyTest
@@ -163,9 +119,9 @@ class OpenAppFromOverviewTest(private val testSpec: FlickerTestParameter) {


    @Presubmit
    @Presubmit
    @Test
    @Test
    fun visibleLayersShownMoreThanOneConsecutiveEntry() {
    override fun visibleLayersShownMoreThanOneConsecutiveEntry() {
        Assume.assumeFalse(testSpec.isRotated)
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.visibleLayersShownMoreThanOneConsecutiveEntry()
        super.visibleLayersShownMoreThanOneConsecutiveEntry()
    }
    }


    @FlakyTest
    @FlakyTest
@@ -175,11 +131,6 @@ class OpenAppFromOverviewTest(private val testSpec: FlickerTestParameter) {
        testSpec.visibleLayersShownMoreThanOneConsecutiveEntry()
        testSpec.visibleLayersShownMoreThanOneConsecutiveEntry()
    }
    }


    @Presubmit
    @Test
    fun noUncoveredRegions() = testSpec.noUncoveredRegions(Surface.ROTATION_0,
        testSpec.config.endRotation)

    companion object {
    companion object {
        @Parameterized.Parameters(name = "{0}")
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        @JvmStatic
+170 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.wm.flicker.launch

import android.app.Instrumentation
import android.platform.test.annotations.Presubmit
import android.view.Surface
import androidx.test.filters.FlakyTest
import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.appLayerReplacesWallpaperLayer
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.endRotation
import com.android.server.wm.flicker.focusChanges
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.helpers.wakeUpAndGoToHomeScreen
import com.android.server.wm.flicker.navBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.navBarLayerRotatesAndScales
import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.noUncoveredRegions
import com.android.server.wm.flicker.repetitions
import com.android.server.wm.flicker.startRotation
import com.android.server.wm.flicker.statusBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerRotatesScales
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.visibleLayersShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.visibleWindowsShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.wallpaperWindowBecomesInvisible
import org.junit.Assume
import org.junit.Test

abstract class OpenAppTransition(protected val testSpec: FlickerTestParameter) {
    protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    protected val testApp: StandardAppHelper = SimpleAppHelper(instrumentation)

    protected open val transition: FlickerBuilder.(Map<String, Any?>) -> Unit = {
        withTestName { testSpec.name }
        repeat { testSpec.config.repetitions }
        setup {
            test {
                device.wakeUpAndGoToHomeScreen()
                this.setRotation(testSpec.config.startRotation)
            }
        }
        teardown {
            test {
                testApp.exit()
            }
        }
    }

    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
            transition(testSpec.config)
        }
    }

    @Presubmit
    @Test
    open fun navBarWindowIsAlwaysVisible() {
        testSpec.navBarWindowIsAlwaysVisible()
    }

    @Presubmit
    @Test
    open fun navBarLayerIsAlwaysVisible() {
        testSpec.navBarLayerIsAlwaysVisible()
    }

    @Presubmit
    @Test
    open fun navBarLayerRotatesAndScales() {
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.navBarLayerRotatesAndScales(Surface.ROTATION_0, testSpec.config.endRotation)
    }

    @FlakyTest
    @Test
    open fun navBarLayerRotatesAndScales_Flaky() {
        Assume.assumeTrue(testSpec.isRotated)
        testSpec.navBarLayerRotatesAndScales(Surface.ROTATION_0, testSpec.config.endRotation)
    }

    @Presubmit
    @Test
    open fun statusBarWindowIsAlwaysVisible() {
        testSpec.statusBarWindowIsAlwaysVisible()
    }

    @Presubmit
    @Test
    open fun statusBarLayerIsAlwaysVisible() {
        testSpec.statusBarLayerIsAlwaysVisible()
    }

    @Presubmit
    @Test
    open fun statusBarLayerRotatesScales() {
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.statusBarLayerRotatesScales(Surface.ROTATION_0, testSpec.config.endRotation)
    }

    @FlakyTest
    @Test
    open fun statusBarLayerRotatesScales_Flaky() {
        Assume.assumeTrue(testSpec.isRotated)
        testSpec.statusBarLayerRotatesScales(Surface.ROTATION_0, testSpec.config.endRotation)
    }

    @Presubmit
    @Test
    open fun visibleWindowsShownMoreThanOneConsecutiveEntry() {
        testSpec.visibleWindowsShownMoreThanOneConsecutiveEntry()
    }

    @FlakyTest
    @Test
    open fun visibleLayersShownMoreThanOneConsecutiveEntry() {
        testSpec.visibleLayersShownMoreThanOneConsecutiveEntry()
    }

    @Presubmit
    @Test
    // During testing the launcher is always in portrait mode
    open fun noUncoveredRegions() {
        testSpec.noUncoveredRegions(Surface.ROTATION_0, testSpec.config.endRotation)
    }

    @Presubmit
    @Test
    open fun focusChanges() {
        testSpec.focusChanges("NexusLauncherActivity", testApp.`package`)
    }

    @Presubmit
    @Test
    open fun appLayerReplacesWallpaperLayer() {
        testSpec.appLayerReplacesWallpaperLayer(testApp.`package`)
    }

    @Presubmit
    @Test
    open fun appWindowReplacesLauncherAsTopWindow() {
        testSpec.appWindowReplacesLauncherAsTopWindow(testApp)
    }

    @Presubmit
    @Test
    open fun wallpaperWindowBecomesInvisible() {
        testSpec.wallpaperWindowBecomesInvisible()
    }
}
 No newline at end of file
+11 −110
Original line number Original line Diff line number Diff line
@@ -16,34 +16,14 @@


package com.android.server.wm.flicker.launch
package com.android.server.wm.flicker.launch


import android.app.Instrumentation
import android.platform.test.annotations.Presubmit
import android.view.Surface
import androidx.test.filters.FlakyTest
import androidx.test.filters.FlakyTest
import androidx.test.filters.RequiresDevice
import androidx.test.filters.RequiresDevice
import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.focusChanges
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.server.wm.flicker.navBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.navBarLayerRotatesAndScales
import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.noUncoveredRegions
import com.android.server.wm.flicker.repetitions
import com.android.server.wm.flicker.startRotation
import com.android.server.wm.flicker.startRotation
import com.android.server.wm.flicker.statusBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerRotatesScales
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.visibleWindowsShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.wallpaperWindowBecomesInvisible
import com.android.server.wm.flicker.appLayerReplacesWallpaperLayer
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import org.junit.Assume
import org.junit.FixMethodOrder
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith
@@ -58,20 +38,13 @@ import org.junit.runners.Parameterized
@RunWith(Parameterized::class)
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class OpenAppWarmTest(private val testSpec: FlickerTestParameter) {
class OpenAppWarmTest(testSpec: FlickerTestParameter) : OpenAppTransition(testSpec) {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
    private val testApp = SimpleAppHelper(instrumentation)
        get() = {

            super.transition(this, it)
    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
            withTestName { testSpec.name }
            repeat { testSpec.config.repetitions }
            setup {
            setup {
                test {
                test {
                    device.wakeUpAndGoToHomeScreen()
                    testApp.launchViaIntent(wmHelper)
                    testApp.launchViaIntent(wmHelper)
                    // wmHelper.waitForFullScreenApp(testApp.component)
                }
                }
                eachRun {
                eachRun {
                    device.pressHome()
                    device.pressHome()
@@ -79,93 +52,21 @@ class OpenAppWarmTest(private val testSpec: FlickerTestParameter) {
                    this.setRotation(testSpec.config.startRotation)
                    this.setRotation(testSpec.config.startRotation)
                }
                }
            }
            }
            transitions {
                testApp.launchViaIntent(wmHelper)
                wmHelper.waitForFullScreenApp(testApp.component)
            }
            teardown {
            teardown {
                eachRun {
                eachRun {
                    this.setRotation(Surface.ROTATION_0)
                    testApp.exit(wmHelper)
                }
                }
                test {
                    testApp.exit()
                }
            }
        }
    }

    @Presubmit
    @Test
    fun navBarWindowIsAlwaysVisible() = testSpec.navBarWindowIsAlwaysVisible()

    @Presubmit
    @Test
    fun statusBarWindowIsAlwaysVisible() = testSpec.statusBarWindowIsAlwaysVisible()

    @FlakyTest
    @Test
    fun visibleWindowsShownMoreThanOneConsecutiveEntry() =
        testSpec.visibleWindowsShownMoreThanOneConsecutiveEntry()

    @Presubmit
    @Test
    fun appWindowReplacesLauncherAsTopWindow() =
        testSpec.appWindowReplacesLauncherAsTopWindow(testApp)

    @Presubmit
    @Test
    fun wallpaperWindowBecomesInvisible() = testSpec.wallpaperWindowBecomesInvisible()

    @Presubmit
    @Test
    // During testing the launcher is always in portrait mode
    fun noUncoveredRegions() = testSpec.noUncoveredRegions(testSpec.config.startRotation,
        Surface.ROTATION_0)

    @Presubmit
    @Test
    fun navBarLayerIsAlwaysVisible() = testSpec.navBarLayerIsAlwaysVisible()

    @Presubmit
    @Test
    fun statusBarLayerIsAlwaysVisible() = testSpec.statusBarLayerIsAlwaysVisible()

    @Presubmit
    @Test
    fun appLayerReplacesWallpaperLayer() =
        testSpec.appLayerReplacesWallpaperLayer(testApp.`package`)

    @Presubmit
    @Test
    fun navBarLayerRotatesAndScales() {
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.navBarLayerRotatesAndScales(testSpec.config.startRotation, Surface.ROTATION_0)
            }
            }

            transitions {
    @FlakyTest
                testApp.launchViaIntent(wmHelper)
    @Test
                wmHelper.waitForFullScreenApp(testApp.component)
    fun navBarLayerRotatesAndScales_Flaky() {
        Assume.assumeTrue(testSpec.isRotated)
        testSpec.navBarLayerRotatesAndScales(testSpec.config.startRotation, Surface.ROTATION_0)
            }
            }

    @Presubmit
    @Test
    fun statusBarLayerRotatesScales() {
        Assume.assumeFalse(testSpec.isRotated)
        testSpec.statusBarLayerRotatesScales(testSpec.config.startRotation, Surface.ROTATION_0)
        }
        }


    @FlakyTest
    @FlakyTest
    @Test
    @Test
    fun statusBarLayerRotatesScales_Flaky() {
    override fun visibleWindowsShownMoreThanOneConsecutiveEntry() =
        Assume.assumeTrue(testSpec.isRotated)
        super.visibleWindowsShownMoreThanOneConsecutiveEntry()
        testSpec.statusBarLayerRotatesScales(testSpec.config.startRotation, Surface.ROTATION_0)
    }

    @Presubmit
    @Test
    fun focusChanges() = testSpec.focusChanges("NexusLauncherActivity", testApp.`package`)


    companion object {
    companion object {
        @Parameterized.Parameters(name = "{0}")
        @Parameterized.Parameters(name = "{0}")