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

Commit caa125d5 authored by Ikram Gabiyev's avatar Ikram Gabiyev
Browse files

Minimize pip on pinch in flicker test

Implement a flicker test for pinching in
in order to minimize the pip window through
resizing.

Bug: 264554945

Test: atest WMShellFlickerTests:PipPinchInTest
Change-Id: I0250e390343d327a32c29a629b40d9e93ab6e409
parent dbdde5e1
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.pip

import android.platform.test.annotations.Postsubmit
import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.FlickerBuilder
import com.android.server.wm.flicker.FlickerTest
import com.android.server.wm.flicker.FlickerTestFactory
import com.android.server.wm.flicker.junit.FlickerParametersRunnerFactory
import com.android.server.wm.traces.common.service.PlatformConsts
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized

/** Test minimizing a pip window via pinch in gesture. */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class PipPinchInTest(flicker: FlickerTest) : PipTransition(flicker) {
    override val transition: FlickerBuilder.() -> Unit
        get() = buildTransition { transitions { pipApp.pinchInPipWindow(wmHelper, 0.4f, 30) } }

    /** Checks that the visible region area of [pipApp] always decreases during the animation. */
    @Postsubmit
    @Test
    fun pipLayerAreaDecreases() {
        flicker.assertLayers {
            val pipLayerList = this.layers { pipApp.layerMatchesAnyOf(it) && it.isVisible }
            pipLayerList.zipWithNext { previous, current ->
                current.visibleRegion.notBiggerThan(previous.visibleRegion.region)
            }
        }
    }

    companion object {
        /**
         * Creates the test configurations.
         *
         * See [FlickerTestFactory.nonRotationTests] for configuring screen orientation and
         * navigation modes.
         */
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): List<FlickerTest> {
            return FlickerTestFactory.nonRotationTests(
                supportedRotations = listOf(PlatformConsts.Rotation.ROTATION_0)
            )
        }
    }
}
+66 −0
Original line number Diff line number Diff line
@@ -102,6 +102,54 @@ open class PipAppHelper(instrumentation: Instrumentation) :
        waitForPipWindowToExpandFrom(wmHelper, Region.from(windowRect))
    }

    /**
     * Minimizes the PIP window my using the pinch in gesture.
     *
     * @param percent The percentage by which to decrease the pip window size.
     * @throws IllegalArgumentException if percentage isn't between 0.0f and 1.0f
     */
    fun pinchInPipWindow(wmHelper: WindowManagerStateHelper, percent: Float, steps: Int) {
        // the percentage must be between 0.0f and 1.0f
        if (percent <= 0.0f || percent > 1.0f) {
            throw IllegalArgumentException("Percent must be between 0.0f and 1.0f")
        }

        val windowRect = getWindowRect(wmHelper)

        // first pointer's initial x coordinate is halfway between the left edge and the center
        val initLeftX = (windowRect.centerX() - windowRect.width / 4).toFloat()
        // second pointer's initial x coordinate is halfway between the right edge and the center
        val initRightX = (windowRect.centerX() + windowRect.width / 4).toFloat()

        // decrease by the distance specified through the percentage
        val distDecrease = windowRect.width * percent

        // get the final x-coordinates and make sure they are not passing the center of the window
        val finalLeftX = Math.min(initLeftX + (distDecrease / 2), windowRect.centerX().toFloat())
        val finalRightX = Math.max(initRightX - (distDecrease / 2), windowRect.centerX().toFloat())

        // y-coordinate is the same throughout this animation
        val yCoord = windowRect.centerY().toFloat()

        var adjustedSteps = MIN_STEPS_TO_ANIMATE

        // if distance per step is at least 1, then we can use the number of steps requested
        if (distDecrease.toInt() / (steps * 2) >= 1) {
            adjustedSteps = steps
        }

        // if the distance per step is less than 1, carry out the animation in two steps
        gestureHelper.pinch(
            Tuple(initLeftX, yCoord),
            Tuple(initRightX, yCoord),
            Tuple(finalLeftX, yCoord),
            Tuple(finalRightX, yCoord),
            adjustedSteps
        )

        waitForPipWindowToMinimizeFrom(wmHelper, Region.from(windowRect))
    }

    /**
     * Launches the app through an intent instead of interacting with the launcher and waits until
     * the app window is in PIP mode
@@ -238,6 +286,24 @@ open class PipAppHelper(instrumentation: Instrumentation) :
            .waitForAndVerify()
    }

    private fun waitForPipWindowToMinimizeFrom(
        wmHelper: WindowManagerStateHelper,
        windowRect: Region
    ) {
        wmHelper
            .StateSyncBuilder()
            .add("pipWindowMinimized") {
                val pipAppWindow =
                        it.wmState.visibleWindows.firstOrNull { window ->
                            this.windowMatchesAnyOf(window)
                        }
                                ?: return@add false
                val pipRegion = pipAppWindow.frameRegion
                return@add windowRect.coversMoreThan(pipRegion)
            }
            .waitForAndVerify()
    }

    companion object {
        private const val TAG = "PipAppHelper"
        private const val ENTER_PIP_BUTTON_ID = "enter_pip"