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

Commit 1574f792 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Split inheritance structure between OpenAppFromLauncher and OpenAppFromLock tests

OpenAppNonResizeableTest was inheriting from OpenAppTransition which specified assertions assuming the app was launched from the launcher but that isn't the case there, we launch from the lock screen

Test: atest FlickerTests:OpenAppColdTest FlickerTests:OpenAppFromOverviewTest FlickerTests:OpenAppNonResizeableTest

Bug: 213856453
Change-Id: I4bc1eca68598471452e4cac94903f0d92dba635b
parent eafc7435
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group1
class OpenAppColdTest(testSpec: FlickerTestParameter) : OpenAppTransition(testSpec) {
class OpenAppColdTest(testSpec: FlickerTestParameter) : OpenAppFromLauncherTransition(testSpec) {
    /**
     * Defines the transition used to run the test
     */
@@ -101,11 +101,6 @@ class OpenAppColdTest(testSpec: FlickerTestParameter) : OpenAppTransition(testSp
    override fun appWindowReplacesLauncherAsTopWindow() =
        super.appWindowReplacesLauncherAsTopWindow()

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

    /** {@inheritDoc} */
    @Presubmit
    @Test
+71 −0
Original line number 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.platform.test.annotations.Presubmit
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.LAUNCHER_COMPONENT
import com.android.server.wm.flicker.replacesLayer
import com.android.server.wm.traces.common.FlickerComponentName
import org.junit.Test

/**
 * Base class for app launch tests
 */
abstract class OpenAppFromLauncherTransition(testSpec: FlickerTestParameter)
    : OpenAppTransition(testSpec) {

    /**
     * Checks that the focus changes from the launcher to [testApp]
     */
    @Presubmit
    @Test
    open fun focusChanges() {
        testSpec.assertEventLog {
            this.focusChanges("NexusLauncherActivity", testApp.`package`)
        }
    }

    /**
     * Checks that [LAUNCHER_COMPONENT] layer is visible at the start of the transition, and
     * is replaced by [testApp], which remains visible until the end
     */
    open fun appLayerReplacesLauncher() {
        testSpec.replacesLayer(LAUNCHER_COMPONENT, testApp.component,
                ignoreEntriesWithRotationLayer = true, ignoreSnapshot = true,
                ignoreSplashscreen = true)
    }

    /**
     * Checks that [LAUNCHER_COMPONENT] window is visible at the start of the transition, and
     * is replaced by a snapshot or splash screen (optional), and finally, is replaced by
     * [testApp], which remains visible until the end
     */
    @Presubmit
    @Test
    open fun appWindowReplacesLauncherAsTopWindow() {
        testSpec.assertWm {
            this.isAppWindowOnTop(LAUNCHER_COMPONENT)
                    .then()
                    .isAppWindowOnTop(FlickerComponentName.SNAPSHOT, isOptional = true)
                    .then()
                    .isAppWindowOnTop(FlickerComponentName.SPLASH_SCREEN, isOptional = true)
                    .then()
                    .isAppWindowOnTop(testApp.component)
        }
    }
}
 No newline at end of file
+102 −0
Original line number 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.platform.test.annotations.Presubmit
import androidx.test.filters.FlakyTest
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.traces.common.FlickerComponentName
import org.junit.Test

/**
 * Base class for app launch tests from lock screen
 */
abstract class OpenAppFromLockTransition(testSpec: FlickerTestParameter)
    : OpenAppTransition(testSpec) {

    /**
     * Defines the transition used to run the test
     */
    override val transition: FlickerBuilder.() -> Unit
        get() = {
            super.transition(this)
            setup {
                eachRun {
                    device.sleep()
                    wmHelper.waitFor("noAppWindowsOnTop") {
                        it.wmState.topVisibleAppWindow.isEmpty()
                    }
                }
            }
            teardown {
                eachRun {
                    testApp.exit(wmHelper)
                }
            }
            transitions {
                testApp.launchViaIntent(wmHelper)
                wmHelper.waitForFullScreenApp(testApp.component)
            }
        }

    /**
     * Check that we go from no focus to focus on the [testApp]
     */
    @Presubmit
    @Test
    open fun focusChanges() {
        testSpec.assertEventLog {
            this.focusChanges("", testApp.`package`)
        }
    }

    /**
     * Checks that we start of with no top windows and then [testApp] becomes the first and only top
     * window of the transition, with snapshot or splash screen windows optionally showing first.
     */
    @FlakyTest(bugId = 203538234)
    @Test
    open fun appWindowBecomesFirstAndOnlyTopWindow() {
        testSpec.assertWm {
            this.hasNoVisibleAppWindow()
                    .then()
                    .isAppWindowOnTop(FlickerComponentName.SNAPSHOT, isOptional = true)
                    .then()
                    .isAppWindowOnTop(FlickerComponentName.SPLASH_SCREEN, isOptional = true)
                    .then()
                    .isAppWindowOnTop(testApp.component)
        }
    }

    /**
     * Checks that the screen is locked at the start of the transition ([colorFadComponent])
     * layer is visible
     */
    @Presubmit
    @Test
    fun screenLockedStart() {
        testSpec.assertLayersStart {
            isEmpty()
        }
    }

    /** {@inheritDoc} */
    @FlakyTest(bugId = 203538234)
    @Test
    override fun appWindowBecomesVisible() = super.appWindowBecomesVisible()
}
+10 −4
Original line number Diff line number Diff line
@@ -62,7 +62,8 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group1
class OpenAppFromOverviewTest(testSpec: FlickerTestParameter) : OpenAppTransition(testSpec) {
class OpenAppFromOverviewTest(testSpec: FlickerTestParameter)
    : OpenAppFromLauncherTransition(testSpec) {
    /**
     * Defines the transition used to run the test
     */
@@ -116,17 +117,22 @@ class OpenAppFromOverviewTest(testSpec: FlickerTestParameter) : OpenAppTransitio
    /** {@inheritDoc} */
    @Presubmit
    @Test
    override fun launcherWindowBecomesInvisible() = super.launcherWindowBecomesInvisible()
    override fun navBarLayerIsVisible() = super.navBarLayerIsVisible()

    /** {@inheritDoc} */
    @Presubmit
    @Test
    override fun navBarLayerIsVisible() = super.navBarLayerIsVisible()
    override fun navBarWindowIsVisible() = super.navBarWindowIsVisible()

    /** {@inheritDoc} */
    @Presubmit
    @Test
    override fun navBarWindowIsVisible() = super.navBarWindowIsVisible()
    override fun appLayerBecomesVisible() = super.appLayerBecomesVisible_warmStart()

    /** {@inheritDoc} */
    @Presubmit
    @Test
    override fun appWindowBecomesVisible() = super.appWindowBecomesVisible_warmStart()

    /** {@inheritDoc} */
    @Presubmit
+4 −102
Original line number Diff line number Diff line
@@ -27,10 +27,8 @@ 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.helpers.NonResizeableAppHelper
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.WindowUtils
import com.android.server.wm.traces.common.FlickerComponentName
import com.google.common.truth.Truth
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
@@ -59,35 +57,11 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group1
class OpenAppNonResizeableTest(testSpec: FlickerTestParameter) : OpenAppTransition(testSpec) {
class OpenAppNonResizeableTest(testSpec: FlickerTestParameter)
    : OpenAppFromLockTransition(testSpec) {
    override val testApp = NonResizeableAppHelper(instrumentation)
    private val colorFadComponent = FlickerComponentName("", "ColorFade BLAST#")

    /**
     * Defines the transition used to run the test
     */
    override val transition: FlickerBuilder.() -> Unit
        get() = {
            super.transition(this)
            setup {
                eachRun {
                    device.sleep()
                    wmHelper.waitFor("noAppWindowsOnTop") {
                        it.wmState.topVisibleAppWindow.isEmpty()
                    }
                }
            }
            teardown {
                eachRun {
                    testApp.exit(wmHelper)
                }
            }
            transitions {
                testApp.launchViaIntent(wmHelper)
                wmHelper.waitForFullScreenApp(testApp.component)
            }
        }

    /**
     * Checks that the nav bar layer starts invisible, becomes visible during unlocking animation
     * and remains visible at the end
@@ -102,41 +76,6 @@ class OpenAppNonResizeableTest(testSpec: FlickerTestParameter) : OpenAppTransiti
        }
    }

    /**
     * Checks that the app layer doesn't exist at the start of the transition, that it is
     * created (invisible) and becomes visible during the transition
     */
    @Postsubmit
    @Test
    fun appLayerBecomesVisible() {
        testSpec.assertLayers {
            this.notContains(testApp.component)
                    .then()
                    .isInvisible(testApp.component)
                    .then()
                    .isVisible(testApp.component)
        }
    }

    /**
     * Checks that the app window doesn't exist at the start of the transition, that it is
     * created (invisible - optional) and becomes visible during the transition
     *
     * The `isAppWindowInvisible` step is optional because we log once per frame, upon logging,
     * the window may be visible or not depending on what was processed until that moment.
     */
    @FlakyTest(bugId = 203538234)
    @Test
    fun appWindowBecomesVisible() {
        testSpec.assertWm {
            this.notContains(testApp.component)
                    .then()
                    .isAppWindowInvisible(testApp.component, isOptional = true)
                    .then()
                    .isAppWindowVisible(testApp.component)
        }
    }

    /**
     * Checks if [testApp] is visible at the end of the transition
     */
@@ -193,6 +132,7 @@ class OpenAppNonResizeableTest(testSpec: FlickerTestParameter) : OpenAppTransiti
        }
    }

    /** {@inheritDoc} */
    @FlakyTest
    @Test
    override fun navBarLayerRotatesAndScales() = super.navBarLayerRotatesAndScales()
@@ -208,44 +148,6 @@ class OpenAppNonResizeableTest(testSpec: FlickerTestParameter) : OpenAppTransiti
    @Test
    override fun entireScreenCovered() = super.entireScreenCovered()

    /**
     * Checks that the focus changes from the launcher to [testApp]
     */
    @FlakyTest
    @Test
    override fun focusChanges() = super.focusChanges()

    /**
     * Checks that the screen is locked at the start of the transition ([colorFadComponent])
     * layer is visible
     */
    @Presubmit
    @Test
    fun screenLockedStart() {
        testSpec.assertLayersStart {
            isEmpty()
        }
    }

    /**
     * This test checks if the launcher is visible at the start and the app at the end,
     * it cannot use the regular assertion (check over time), because on lock screen neither
     * the app not the launcher are visible, and there is no top visible window.
     */
    @FlakyTest(bugId = 203538234)
    @Test
    override fun appWindowReplacesLauncherAsTopWindow() {
        testSpec.assertWm {
            this.invoke("noAppWindowsOnTop") {
                    Truth.assertWithMessage("Should not have any app window on top " +
                        "when the screen is locked")
                        .that(it.wmState.topVisibleAppWindow)
                        .isEmpty()
                }.then()
                .isAppWindowOnTop(testApp.component)
        }
    }

    companion object {
        /**
         * Creates the test configurations.
Loading