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

Commit b9c74f49 authored by CHIA-HSUAN HSU's avatar CHIA-HSUAN HSU Committed by CHIA-HSUAN HSU (xWF)
Browse files

b/418205309 Migrate MaximizeAppNonResizable to legacy flicker test

Test: USE_RBE=false atest WMShellFlickerTestsDesktopMode:com.android.wm.shell.flicker.fundamentals.MaximizeAppNonResizableFlickerTest -c (http://ab/I19000010413232203)
Video: http://recall/-/bd0PqVrOf5tE6WVTKxZSxp
Flag: EXEMPT migrate test case
Bug: 418205309
Change-Id: I35880b15629067373992eb23afa6f8bd4a75f023
parent 48d6d962
Loading
Loading
Loading
Loading
+0 −51
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.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 androidx.test.filters.RequiresDevice
import com.android.wm.shell.flicker.DesktopModeFlickerScenarios.Companion.MAXIMIZE_APP_NON_RESIZABLE
import com.android.wm.shell.scenarios.MaximizeAppWindow
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Maximize non-resizable app window by pressing the maximize button on the app header.
 *
 * Assert that the app window keeps the same increases in size, maintaining its aspect ratio, until
 * filling the vertical or horizontal stable display bounds.
 */
@RequiresDevice
@RunWith(FlickerServiceJUnit4ClassRunner::class)
class MaximizeAppNonResizablePortrait : MaximizeAppWindow(isResizable = false) {
    @ExpectedScenarios(["MAXIMIZE_APP_NON_RESIZABLE"])
    @Test
    override fun maximizeAppWindow() = super.maximizeAppWindow()


    companion object {
        @JvmStatic
        @FlickerConfigProvider
        fun flickerConfigProvider(): FlickerConfig =
            FlickerConfig().use(FlickerServiceConfig.DEFAULT).use(MAXIMIZE_APP_NON_RESIZABLE)
    }
}
 No newline at end of file
+90 −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,20 +14,25 @@
 * limitations under the License.
 */

package com.android.wm.shell.flicker

import android.tools.Rotation.ROTATION_90
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 androidx.test.filters.RequiresDevice
import com.android.wm.shell.flicker.DesktopModeFlickerScenarios.Companion.MAXIMIZE_APP_NON_RESIZABLE
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.MaximizeAppWindow
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.utils.appLayerHasMaxBoundsInOnlyOneDimension
import com.android.wm.shell.flicker.utils.appLayerMaintainsAspectRatioAlways
import com.android.wm.shell.flicker.utils.resizeVeilKeepsIncreasingInSize
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Maximize non-resizable app window by pressing the maximize button on the app header.
@@ -35,21 +40,51 @@ import org.junit.runner.RunWith
 * Assert that the app window keeps the same increases in size, maintaining its aspect ratio, until
 * filling the vertical or horizontal stable display bounds.
 */

@RequiresDevice
@RunWith(FlickerServiceJUnit4ClassRunner::class)
class MaximizeAppNonResizableLandscape : MaximizeAppWindow(
    rotation = ROTATION_90,
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
class MaximizeAppNonResizableFlickerTest(flicker: LegacyFlickerTest) : DesktopModeBaseTest(flicker) {
    inner class MaximizeAppNonResizableScenario : MaximizeAppWindow(
        rotation = flicker.scenario.startRotation,
        isResizable = false
) {
    @ExpectedScenarios(["MAXIMIZE_APP_NON_RESIZABLE"])
    )

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

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

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

    @Test
    override fun maximizeAppWindow() = super.maximizeAppWindow()
    fun appLayerMaintainsAspectRatioAlways() = flicker.appLayerMaintainsAspectRatioAlways(testApp)

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

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        @FlickerConfigProvider
        fun flickerConfigProvider(): FlickerConfig =
            FlickerConfig().use(FlickerServiceConfig.DEFAULT).use(MAXIMIZE_APP_NON_RESIZABLE)
        fun getParams(): Collection<FlickerTest> {
            return LegacyFlickerTestFactory.nonRotationTests(
                supportedNavigationModes = listOf(NavBar.MODE_GESTURAL)
            )
        }
    }
}
+26 −0
Original line number Diff line number Diff line
@@ -57,6 +57,32 @@ fun LegacyFlickerTest.appLayerHasMaxDisplayWidthAtEnd(component: IComponentMatch
    }
}

fun LegacyFlickerTest.appLayerHasMaxBoundsInOnlyOneDimension(component: IComponentMatcher) {
    assertWmEnd {
        val maxDisplayBounds = WindowUtils.getInsetDisplayBounds(scenario.startRotation)
        val windowBounds = visibleRegion(component).region.bounds

        val hasMaxHeight =
            windowBounds.top == maxDisplayBounds.top &&
                windowBounds.bottom == maxDisplayBounds.bottom
        val hasMaxWidth =
            windowBounds.left == maxDisplayBounds.left &&
                windowBounds.right == maxDisplayBounds.right
        val isMaxInOneDimension = hasMaxHeight.xor(hasMaxWidth)

        check { "only one max bounds" }.that(isMaxInOneDimension).isEqual(true)
    }
}

fun LegacyFlickerTest.appLayerMaintainsAspectRatioAlways(component: IComponentMatcher) {
    assertLayers {
        val desktopWindowLayerList = layers { component.layerMatchesAnyOf(it) && it.isVisible }
        desktopWindowLayerList.zipWithNext { previous, current ->
            current.visibleRegion.isSameAspectRatio(previous.visibleRegion)
        }
    }
}

fun LegacyFlickerTest.resizeVeilKeepsIncreasingInSize(component: IComponentMatcher) {
    assertLayers {
        val layerList = layers {