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

Commit d1d7e2b2 authored by Hanna Nizhnikava's avatar Hanna Nizhnikava
Browse files

Add a flicker test for desktop apps switching using Alt + Tab

The flicker test, AltTabSwitchInDesktopModeFlickerTest, opens 3 apps in
desktop mode and switches to the first opened app, using the existing
scenario, AltTabSwitchInDesktopMode. It then verifies that the
first app window is on top at the end of the test, and all 3 app layers
stay visible throughout the test execution.

The test is added to a new subfolder, keyboardshortcuts.

Test: atest AltTabSwitchInDesktopModeFlickerTest
Bug: 425918059
Flag: EXEMPT, not needed for e2e tests
Change-Id: Ied71d60f2273dd5a04cb05f7da9399e6002a17a4
parent 4d1f3b8e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -83,6 +83,13 @@ test_module_config {
    ],
}

test_module_config {
    name: "WMShellFlickerTestsDesktopMode-keyboardshortcuts-AltTabSwitchInDesktopModeFlickerTest",
    base: "WMShellFlickerTestsDesktopMode",
    test_suites: ["device-tests"],
    include_filters: ["com.android.wm.shell.flicker.keyboardshortcuts.AltTabSwitchInDesktopModeFlickerTest"],
}

test_module_config {
    name: "WMShellFlickerTestsDesktopMode-fundamentals-CloseAllAppsViaAppHeaderExitTest",
    base: "WMShellFlickerTestsDesktopMode",
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@
    {
      "name": "WMShellFlickerTestsDesktopMode-fundamentals-SwitchToOverviewFromDesktopFlickerTest"
    },
    {
      "name": "WMShellFlickerTestsDesktopMode-keyboardshortcuts-AltTabSwitchInDesktopModeFlickerTest"
    },
    {
      "name": "WMShellFlickerTestsDesktopMode-maximize-MaximizeAppDoubleTapAppHeaderFlickerTest"
    },
+90 −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.keyboardshortcuts

import android.platform.test.annotations.RequiresDevice
import android.tools.NavBar
import android.tools.flicker.assertions.FlickerChecker
import android.tools.flicker.junit.FlickerParametersRunnerFactory
import android.tools.flicker.FlickerBuilder
import android.tools.flicker.FlickerTest
import android.tools.flicker.FlickerTestFactory
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.DesktopModeBaseTest
import android.tools.traces.component.ComponentNameMatcher.Companion.DESKTOP_WALLPAPER_ACTIVITY
import com.android.wm.shell.flicker.utils.appWindowOnTopAtEnd
import com.android.wm.shell.flicker.utils.layerIsVisibleAtEnd
import com.android.wm.shell.flicker.utils.layerKeepVisible
import com.android.wm.shell.scenarios.AltTabSwitchInDesktopMode
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Tests desktop app switching using the Alt + Tab keyboard shortcut.
 *
 * To run this test: atest AltTabSwitchInDesktopModeFlickerTest
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
class AltTabSwitchInDesktopModeFlickerTest(flicker: FlickerTest) : DesktopModeBaseTest(flicker) {
    inner class AltTabSwitchInDesktopModeScenario : AltTabSwitchInDesktopMode(rotation = flicker.scenario.startRotation)

    @Rule
    @JvmField
    val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, flicker.scenario.startRotation)
    val scenario = AltTabSwitchInDesktopModeScenario()
    private val firstApp = scenario.firstApp
    private val appsInDesktop = scenario.appsInDesktop

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

    @Test
    fun appWindowOnTopAtEnd() = flicker.appWindowOnTopAtEnd(firstApp)

    @Test
    fun layersKeepVisible() = appsInDesktop.forEach { flicker.layerKeepVisible(it) }

    @Test
    fun layerIsVisibleAtEnd() = flicker.layerIsVisibleAtEnd(firstApp)

    @Test
    fun wallpaperActivityStaysVisible() = flicker.layerKeepVisible(DESKTOP_WALLPAPER_ACTIVITY)

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): Collection<FlickerChecker> {
            return FlickerTestFactory.nonRotationTests(
                supportedNavigationModes = listOf(NavBar.MODE_GESTURAL)
            )
        }
    }
}
 No newline at end of file
+8 −3
Original line number Diff line number Diff line
@@ -40,15 +40,20 @@ abstract class AltTabSwitchInDesktopMode(
    private val tapl = LauncherInstrumentation()
    private val wmHelper = WindowManagerStateHelper(instrumentation)
    private val device = UiDevice.getInstance(instrumentation)
    private val firstApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation))
    private val secondApp = MailAppHelper(instrumentation)
    private val thirdApp = NewTasksAppHelper(instrumentation)
    val firstApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation))
    val secondApp = DesktopModeAppHelper(MailAppHelper(instrumentation))
    val thirdApp = DesktopModeAppHelper(NewTasksAppHelper(instrumentation))

    val appsInDesktop: ArrayList<DesktopModeAppHelper> = ArrayList()

    @Before
    fun setup() {
        firstApp.enterDesktopMode(wmHelper, device)
        appsInDesktop.add(firstApp)
        secondApp.launchViaIntent(wmHelper)
        appsInDesktop.add(secondApp)
        thirdApp.launchViaIntent(wmHelper)
        appsInDesktop.add(thirdApp)
    }

    @Test