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

Commit 1c393b7f authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "Create flicker test for trampoline task launch in desktop" into main

parents 31ce3cde c6b60fd1
Loading
Loading
Loading
Loading
+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.appcompat

import android.platform.test.annotations.Postsubmit
import android.platform.test.annotations.RequiresDesktopDevice
import android.tools.NavBar
import android.tools.flicker.FlickerBuilder
import android.tools.flicker.FlickerTest
import android.tools.flicker.FlickerTestFactory
import android.tools.flicker.assertions.FlickerChecker
import android.tools.flicker.junit.FlickerParametersRunnerFactory
import android.tools.traces.parsers.toFlickerComponent
import com.android.server.wm.flicker.testapp.ActivityOptions
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.DesktopModeBaseTest
import com.android.wm.shell.flicker.utils.appLayerPositionedBottomRightAtEnd
import com.android.wm.shell.flicker.utils.appWindowInsideDisplayBoundsAtEnd
import com.android.wm.shell.flicker.utils.appWindowOnTopAtEnd
import com.android.wm.shell.flicker.utils.layerIsVisibleAtEnd
import com.android.wm.shell.scenarios.OpenTrampolineAppInDesktopModeTaskPosition
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RequiresDesktopDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Postsubmit
class OpenTrampolineAppInDesktopModeTaskPositionFlickerTest(flicker: FlickerTest) :
    DesktopModeBaseTest(flicker) {
    inner class OpenTrampolineAppInDesktopModeTaskPositionScenario : OpenTrampolineAppInDesktopModeTaskPosition(flicker.scenario.startRotation)

    @Rule
    @JvmField
    val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, flicker.scenario.startRotation)
    val scenario = OpenTrampolineAppInDesktopModeTaskPositionScenario()
    val finalTrampolineActivity = ActivityOptions.TrampolineFinishActivity.COMPONENT.toFlickerComponent()

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

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

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

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

    @Test
    fun appLayerPositionedBottomRightAtEnd() =
        flicker.appLayerPositionedBottomRightAtEnd(finalTrampolineActivity)

    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
+64 −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.Rotation
import android.tools.traces.parsers.WindowManagerStateHelper
import android.tools.traces.parsers.toFlickerComponent
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.android.server.wm.flicker.helpers.DesktopModeAppHelper
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import com.android.server.wm.flicker.testapp.ActivityOptions
import org.junit.After
import org.junit.Before
import org.junit.Ignore
import org.junit.Test

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

    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val wmHelper = WindowManagerStateHelper(instrumentation)
    private val device = UiDevice.getInstance(instrumentation)

    private val testApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation))

    private val trampolineApp = SimpleAppHelper(
        instrumentation,
        launcherName = ActivityOptions.TrampolineStartActivity.LABEL,
        component = ActivityOptions.TrampolineStartActivity.COMPONENT.toFlickerComponent()
    )

    @Before
    fun setup() {
        testApp.enterDesktopMode(wmHelper, device)
    }

    @Test
    open fun openTrampolineApp() {
        trampolineApp.launchViaIntent()
    }

    @After
    fun teardown() {
        trampolineApp.exit(wmHelper)
        testApp.exit(wmHelper)
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -40,6 +40,19 @@ fun FlickerTest.cascadingEffectAppliedAtEnd(component: IComponentMatcher) {
    }
}

fun FlickerTest.appLayerPositionedBottomRightAtEnd(component: IComponentMatcher) {
    assertWmEnd {
        val displayAppBounds = WindowUtils.getInsetDisplayBounds(scenario.startRotation)
        val windowBounds = visibleRegion(component).region.bounds

        val onRightSide = windowBounds.right == displayAppBounds.right
        val onBottomSide = windowBounds.bottom == displayAppBounds.bottom

        check { "window corner must meet display corner" }.that(onRightSide && onBottomSide)
            .isEqual(true)
    }
}

fun FlickerTest.appLayerHasMaxDisplayHeightAtEnd(component: IComponentMatcher) {
    assertLayersEnd {
        val displayBounds = WindowUtils.getInsetDisplayBounds(scenario.startRotation)