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

Commit f60b8bb8 authored by CHIA-HSUAN HSU (xWF)'s avatar CHIA-HSUAN HSU (xWF) Committed by Android (Google) Code Review
Browse files

Merge "b/399823963 Add new test case for using the app header menu to go from...

Merge "b/399823963 Add new test case for using the app header menu to go from split screen to windowing mode" into main
parents 09ab9acb 6f88c810
Loading
Loading
Loading
Loading
+93 −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 com.android.wm.shell.flicker.DesktopModeBaseTest
import com.android.wm.shell.scenarios.EnterDesktopFromSplitScreenWithAppHandleMenu
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.utils.appWindowInsideDisplayBoundsAtEnd
import com.android.wm.shell.flicker.utils.appWindowIsInvisibleAtEnd
import com.android.wm.shell.flicker.utils.appWindowOnTopAtEnd
import com.android.wm.shell.flicker.utils.layerIsVisibleAtEnd
import com.android.wm.shell.flicker.utils.splitScreenDividerBecomesInvisible
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Enter the app to desktop mode from split screen via app handle menu.
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
class EnterDesktopFromSplitScreenWithAppHandleMenuFlickerTest(flicker: LegacyFlickerTest) : DesktopModeBaseTest(flicker) {

    inner class EnterDesktopFromSplitScreenWithAppHandleMenuScenario : EnterDesktopFromSplitScreenWithAppHandleMenu(flicker.scenario.startRotation)

    @Rule
    @JvmField
    val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, flicker.scenario.startRotation)
    val scenario = EnterDesktopFromSplitScreenWithAppHandleMenuScenario()
    private val testApp = scenario.testApp
    private val secondApp = scenario.calculatorApp

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

    @Test
    fun appWindowInsideDisplayBoundsAtEnd() = flicker.appWindowInsideDisplayBoundsAtEnd(testApp)

    @Test
    fun appWindowIsInvisibleAtEnd() = flicker.appWindowIsInvisibleAtEnd(secondApp)

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

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

    @Test
    fun splitScreenDividerBecomesInvisible() = flicker.splitScreenDividerBecomesInvisible()

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): Collection<FlickerTest> {
            return LegacyFlickerTestFactory.nonRotationTests(
                    supportedNavigationModes = listOf(NavBar.MODE_GESTURAL)
            )
        }
    }
}
+30 −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.functional.fundamentals

import android.platform.test.annotations.Postsubmit
import android.platform.test.rule.ScreenRecordRule
import com.android.wm.shell.scenarios.EnterDesktopFromSplitScreenWithAppHandleMenu
import org.junit.runner.RunWith
import org.junit.runners.BlockJUnit4ClassRunner

/* Functional test for [EnterDesktopFromSplitScreenWithAppHandleMenu]. */

@RunWith(BlockJUnit4ClassRunner::class)
@Postsubmit
@ScreenRecordRule.ScreenRecord
class EnterDesktopFromSplitScreenWithAppHandleMenuTest : EnterDesktopFromSplitScreenWithAppHandleMenu()
+87 −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.scenarios

import android.app.Instrumentation
import android.tools.NavBar
import android.tools.PlatformConsts.DEFAULT_DISPLAY
import android.tools.Rotation
import android.tools.device.apphelpers.CalculatorAppHelper
import android.tools.flicker.rules.ChangeDisplayOrientationRule
import android.tools.traces.parsers.WindowManagerStateHelper
import android.view.KeyEvent.KEYCODE_META_RIGHT
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.server.wm.flicker.helpers.DesktopModeAppHelper
import com.android.server.wm.flicker.helpers.KeyEventHelper
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import com.android.wm.shell.Utils
import com.android.wm.shell.shared.desktopmode.DesktopState
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

@Ignore("Test Base Class")
abstract class EnterDesktopFromSplitScreenWithAppHandleMenu(val rotation: Rotation = Rotation.ROTATION_0) : TestScenarioBase() {

    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val tapl = LauncherInstrumentation()
    private val wmHelper = WindowManagerStateHelper(instrumentation)
    private val device = UiDevice.getInstance(instrumentation)
    private val keyEventHelper = KeyEventHelper(InstrumentationRegistry.getInstrumentation())
    private val simpleAppHelper = SimpleAppHelper(instrumentation)
    val calculatorApp = CalculatorAppHelper(instrumentation)
    val testApp = DesktopModeAppHelper(simpleAppHelper)

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

    @Before
    fun setup() {
        Assume.assumeTrue(
            DesktopState.fromContext(instrumentation.context)
                .isDesktopModeSupportedOnDisplay(DEFAULT_DISPLAY)
        )
        tapl.setEnableRotation(true)
        tapl.setExpectedRotation(rotation.value)
        tapl.enableTransientTaskbar(false)
        ChangeDisplayOrientationRule.setRotation(rotation)
        // Launch app in order to enter split screen
        simpleAppHelper.launchViaIntent(wmHelper)
        testApp.enterSplitScreenFromAppHandleMenu(wmHelper, device)
        // Open allApps via keyboard shortcut
        keyEventHelper.press(KEYCODE_META_RIGHT)
        tapl.allApps
            .getAppIcon(calculatorApp.appName)
            .launch(calculatorApp.packageName)
    }

    @Test
    open fun enterDesktopFromSplitScreen() {
        testApp.enterDesktopModeFromAppHandleMenu(wmHelper, device)
    }

    @After
    fun teardown() {
        testApp.exit(wmHelper)
    }
}
+26 −7
Original line number Diff line number Diff line
@@ -553,19 +553,23 @@ open class DesktopModeAppHelper(private val innerHelper: StandardAppHelper) :
        waitForTransitionToFullscreen(wmHelper)
    }

    fun enterDesktopModeFromAppHandleMenu(
        wmHelper: WindowManagerStateHelper,
        device: UiDevice
    ) {
        if (isAnyDesktopWindowVisible(wmHelper)) error("Already in Desktop Mode")

    private fun clickAppHandle(wmHelper: WindowManagerStateHelper, device: UiDevice) {
        val windowRect = wmHelper.getWindowRegion(innerHelper).bounds
        val startX = windowRect.centerX()
        // Click a little under the top to prevent opening the notification shade.
        val startY = 10
        val startY = windowRect.top + 30

        // Click on the app handle coordinates.
        device.click(startX, startY)
    }

    fun enterDesktopModeFromAppHandleMenu(
        wmHelper: WindowManagerStateHelper,
        device: UiDevice
    ) {
        if (isAnyDesktopWindowVisible(wmHelper)) error("Already in Desktop Mode")

        clickAppHandle(wmHelper, device)
        wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify()

        val pill = getDesktopAppViewByRes(PILL_CONTAINER)
@@ -577,6 +581,21 @@ open class DesktopModeAppHelper(private val innerHelper: StandardAppHelper) :
        waitForTransitionToFreeform(wmHelper)
    }

    fun enterSplitScreenFromAppHandleMenu(
        wmHelper: WindowManagerStateHelper,
        device: UiDevice
    ) {
        clickAppHandle(wmHelper, device)

        val pill = getDesktopAppViewByRes(PILL_CONTAINER)
        val splitScreenButton =
            pill.children?.find { it.resourceName.endsWith(SPLIT_SCREEN_BUTTON) }
                ?: error("Unable to find Split Screen button")

        splitScreenButton.click()
        wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify()
    }

    fun exitDesktopModeToFullScreenWithAppHeader(wmHelper:WindowManagerStateHelper) {
        val openMenuButton = getDesktopAppViewByRes(OPEN_MENU_BUTTON)
        openMenuButton?.click()