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

Commit bbf0d16b authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Add flicker test for closing apps.

Assert that apps become invisible and we end up on Launcher.

Test: atest CloseAllAppsViaAppHeaderExitTest
Fix: 418215568
Flag: EXEMPT test
Change-Id: I8d7dc7b6e28232d959164969af40a1a618d59260
parent 8c29ff7f
Loading
Loading
Loading
Loading
+0 −47
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.wm.shell.flicker

import android.tools.Rotation
import android.tools.flicker.FlickerConfig
import android.tools.flicker.annotation.ExpectedScenarios
import android.tools.flicker.annotation.FlickerConfigProvider
import android.tools.flicker.config.FlickerConfig
import android.tools.flicker.config.FlickerServiceConfig
import android.tools.flicker.junit.FlickerServiceJUnit4ClassRunner
import com.android.wm.shell.flicker.DesktopModeFlickerScenarios.Companion.CLOSE_APP
import com.android.wm.shell.flicker.DesktopModeFlickerScenarios.Companion.CLOSE_LAST_APP
import com.android.wm.shell.scenarios.CloseAllAppsWithAppHeaderExit
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(FlickerServiceJUnit4ClassRunner::class)
class CloseAllAppWithAppHeaderExitLandscape : CloseAllAppsWithAppHeaderExit(Rotation.ROTATION_90) {
    @ExpectedScenarios(["CLOSE_APP", "CLOSE_LAST_APP"])
    @Test
    override fun closeAllAppsInDesktop() = super.closeAllAppsInDesktop()

    companion object {
        @JvmStatic
        @FlickerConfigProvider
        fun flickerConfigProvider(): FlickerConfig =
            FlickerConfig()
                .use(FlickerServiceConfig.DEFAULT)
                .use(CLOSE_APP)
                .use(CLOSE_LAST_APP)
    }
}
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.wm.shell.flicker.fundamentals

import android.platform.test.annotations.RequiresDevice
import android.tools.NavBar
import android.tools.flicker.assertions.FlickerTest
import android.tools.flicker.junit.FlickerParametersRunnerFactory
import android.tools.flicker.legacy.FlickerBuilder
import android.tools.flicker.legacy.LegacyFlickerTest
import android.tools.flicker.legacy.LegacyFlickerTestFactory
import android.tools.traces.component.ComponentNameMatcher
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.DesktopModeBaseTest
import com.android.wm.shell.flicker.utils.appWindowIsInvisibleAtEnd
import com.android.wm.shell.flicker.utils.appWindowOnTopAtEnd
import com.android.wm.shell.scenarios.CloseAllAppsWithAppHeaderExit
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Test closing all apps in desktop mode by clicking the exit button on the app header.
 *
 * To run this test: atest CloseAllAppsViaAppHeaderExitTest
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
class CloseAllAppsViaAppHeaderExitTest(flicker: LegacyFlickerTest) : DesktopModeBaseTest(flicker) {
    inner class CloseAllAppsWithAppHeaderExitScenario : CloseAllAppsWithAppHeaderExit(flicker.scenario.startRotation)

    @Rule
    @JvmField
    val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, flicker.scenario.startRotation)
    val scenario = CloseAllAppsWithAppHeaderExitScenario()
    private val appsInZOrder = scenario.appsInZOrder


    override val transition: FlickerBuilder.() -> Unit
        get() = {
            setup {
                scenario.setup()
            }
            transitions {
                scenario.closeAllAppsInDesktop()
            }
            teardown {
                scenario.teardown()
            }
        }

    @Test
    fun appWindowIsInvisibleAtEnd() =
        appsInZOrder.forEach { flicker.appWindowIsInvisibleAtEnd(it) }

    @Test
    fun launcherWindowOnTopAtEnd() =
        flicker.appWindowOnTopAtEnd(ComponentNameMatcher.LAUNCHER)

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): Collection<FlickerTest> {
            return LegacyFlickerTestFactory.nonRotationTests(
                supportedNavigationModes = listOf(NavBar.MODE_GESTURAL)
            )
        }
    }
}
 No newline at end of file
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 * Copyright (C) 2025 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.
@@ -14,34 +14,16 @@
 * limitations under the License.
 */

package com.android.wm.shell.flicker
package com.android.wm.shell.functional.fundamentals

import android.tools.Rotation
import android.tools.flicker.FlickerConfig
import android.tools.flicker.annotation.ExpectedScenarios
import android.tools.flicker.annotation.FlickerConfigProvider
import android.tools.flicker.config.FlickerConfig
import android.tools.flicker.config.FlickerServiceConfig
import android.tools.flicker.junit.FlickerServiceJUnit4ClassRunner
import com.android.wm.shell.flicker.DesktopModeFlickerScenarios.Companion.CLOSE_APP
import com.android.wm.shell.flicker.DesktopModeFlickerScenarios.Companion.CLOSE_LAST_APP
import android.platform.test.annotations.Postsubmit
import android.platform.test.rule.ScreenRecordRule
import com.android.wm.shell.scenarios.CloseAllAppsWithAppHeaderExit
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.BlockJUnit4ClassRunner

@RunWith(FlickerServiceJUnit4ClassRunner::class)
class CloseAllAppWithAppHeaderExitPortrait : CloseAllAppsWithAppHeaderExit(Rotation.ROTATION_0) {
    @ExpectedScenarios(["CLOSE_APP", "CLOSE_LAST_APP"])
    @Test
    override fun closeAllAppsInDesktop() = super.closeAllAppsInDesktop()

    companion object {
        @JvmStatic
        @FlickerConfigProvider
        fun flickerConfigProvider(): FlickerConfig =
            FlickerConfig()
                .use(FlickerServiceConfig.DEFAULT)
                .use(CLOSE_APP)
                .use(CLOSE_LAST_APP)
    }
}
/* Functional test for [CloseAllAppsViaAppHeaderExit]. */
@RunWith(BlockJUnit4ClassRunner::class)
@Postsubmit
@ScreenRecordRule.ScreenRecord
class CloseAllAppsViaAppHeaderExitTest : CloseAllAppsWithAppHeaderExit()
+8 −2
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import com.android.server.wm.flicker.helpers.DesktopModeAppHelper
import com.android.server.wm.flicker.helpers.MailAppHelper
import com.android.server.wm.flicker.helpers.NonResizeableAppHelper
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import com.android.window.flags.Flags
import com.android.wm.shell.Utils
import com.android.wm.shell.shared.desktopmode.DesktopState
import org.junit.After
@@ -47,9 +46,11 @@ abstract class CloseAllAppsWithAppHeaderExit (
    private val tapl = LauncherInstrumentation()
    private val wmHelper = WindowManagerStateHelper(instrumentation)
    private val device = UiDevice.getInstance(instrumentation)
    private val testApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation))
    private val mailApp = DesktopModeAppHelper(MailAppHelper(instrumentation))
    private val nonResizeableApp = DesktopModeAppHelper(NonResizeableAppHelper(instrumentation))
    private val testApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation))

    val appsInZOrder: ArrayList<DesktopModeAppHelper> = ArrayList()

    @Rule @JvmField val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, rotation)

@@ -62,8 +63,13 @@ abstract class CloseAllAppsWithAppHeaderExit (
        tapl.setEnableRotation(true)
        tapl.setExpectedRotation(rotation.value)
        testApp.enterDesktopMode(wmHelper, device)
        appsInZOrder.add(testApp)

        mailApp.launchViaIntent(wmHelper)
        appsInZOrder.add( mailApp)

        nonResizeableApp.launchViaIntent(wmHelper)
        appsInZOrder.add(nonResizeableApp)
    }

    @Test