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

Commit d587fcdb authored by Ikram Gabiyev's avatar Ikram Gabiyev Committed by Android (Google) Code Review
Browse files

Merge "Make sure PipDragThenTest is gravity agnostic" into udc-dev

parents 981f0d97 f66b621c
Loading
Loading
Loading
Loading
+21 −5
Original line number Original line Diff line number Diff line
@@ -41,6 +41,9 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class PipDragThenSnapTest(flicker: FlickerTest) : PipTransition(flicker){
class PipDragThenSnapTest(flicker: FlickerTest) : PipTransition(flicker){
    // represents the direction in which the pip window should be snapping
    private var willSnapRight: Boolean = true

    override val transition: FlickerBuilder.() -> Unit
    override val transition: FlickerBuilder.() -> Unit
        get() = {
        get() = {
            val stringExtras: Map<String, String> =
            val stringExtras: Map<String, String> =
@@ -55,9 +58,16 @@ class PipDragThenSnapTest(flicker: FlickerTest) : PipTransition(flicker){
                RemoveAllTasksButHomeRule.removeAllTasksButHome()
                RemoveAllTasksButHomeRule.removeAllTasksButHome()
                pipApp.launchViaIntentAndWaitForPip(wmHelper, stringExtras = stringExtras)
                pipApp.launchViaIntentAndWaitForPip(wmHelper, stringExtras = stringExtras)


                val initRegion = pipApp.dragPipWindowAwayFromEdge(wmHelper, 50)
                // get the initial region bounds and cache them
                val initRegion = pipApp.getWindowRect(wmHelper)
                startBounds
                startBounds
                        .set(initRegion.left, initRegion.top, initRegion.right, initRegion.bottom)
                        .set(initRegion.left, initRegion.top, initRegion.right, initRegion.bottom)

                // drag the pip window away from the edge
                pipApp.dragPipWindowAwayFromEdge(wmHelper, 50)

                // determine the direction in which the snapping should occur
                willSnapRight = pipApp.isCloserToRightEdge(wmHelper)
            }
            }
            transitions {
            transitions {
                // continue the transition until the PIP snaps
                // continue the transition until the PIP snaps
@@ -65,14 +75,20 @@ class PipDragThenSnapTest(flicker: FlickerTest) : PipTransition(flicker){
            }
            }
        }
        }


    /** Checks that the visible region area of [pipApp] always moves right during the animation. */
    /**
     * Checks that the visible region area of [pipApp] moves to closest edge during the animation.
     */
    @Postsubmit
    @Postsubmit
    @Test
    @Test
    fun pipLayerMovesRight() {
    fun pipLayerMovesToClosestEdge() {
        flicker.assertLayers {
        flicker.assertLayers {
            val pipLayerList = layers { pipApp.layerMatchesAnyOf(it) && it.isVisible }
            val pipLayerList = layers { pipApp.layerMatchesAnyOf(it) && it.isVisible }
            pipLayerList.zipWithNext { previous, current ->
            pipLayerList.zipWithNext { previous, current ->
                if (willSnapRight) {
                    current.visibleRegion.isToTheRight(previous.visibleRegion.region)
                    current.visibleRegion.isToTheRight(previous.visibleRegion.region)
                } else {
                    previous.visibleRegion.isToTheRight(current.visibleRegion.region)
                }
            }
            }
        }
        }
    }
    }
+8 −7
Original line number Original line Diff line number Diff line
@@ -61,9 +61,8 @@ open class PipAppHelper(instrumentation: Instrumentation) :
     * Drags the PIP window away from the screen edge while not crossing the display center.
     * Drags the PIP window away from the screen edge while not crossing the display center.
     *
     *
     * @throws IllegalStateException if default display bounds are not available
     * @throws IllegalStateException if default display bounds are not available
     * @return initial bounds of the PIP window
     */
     */
    fun dragPipWindowAwayFromEdge(wmHelper: WindowManagerStateHelper, steps: Int): Rect {
    fun dragPipWindowAwayFromEdge(wmHelper: WindowManagerStateHelper, steps: Int) {
        val initWindowRect = getWindowRect(wmHelper).clone()
        val initWindowRect = getWindowRect(wmHelper).clone()


        // initial pointer at the center of the window
        // initial pointer at the center of the window
@@ -83,8 +82,6 @@ open class PipAppHelper(instrumentation: Instrumentation) :


        // drag the window to the left but not beyond the center of the display
        // drag the window to the left but not beyond the center of the display
        uiDevice.drag(startX, y, endX, y, steps)
        uiDevice.drag(startX, y, endX, y, steps)

        return initWindowRect
    }
    }


    /**
    /**
@@ -92,7 +89,7 @@ open class PipAppHelper(instrumentation: Instrumentation) :
     *
     *
     * @throws IllegalStateException if default display bounds are not available
     * @throws IllegalStateException if default display bounds are not available
     */
     */
    private fun isCloserToRightEdge(wmHelper: WindowManagerStateHelper): Boolean {
    fun isCloserToRightEdge(wmHelper: WindowManagerStateHelper): Boolean {
        val windowRect = getWindowRect(wmHelper)
        val windowRect = getWindowRect(wmHelper)


        val displayRect = wmHelper.currentState.wmState.getDefaultDisplay()?.displayRect
        val displayRect = wmHelper.currentState.wmState.getDefaultDisplay()?.displayRect
@@ -267,7 +264,10 @@ open class PipAppHelper(instrumentation: Instrumentation) :
        closePipWindow(WindowManagerStateHelper(mInstrumentation))
        closePipWindow(WindowManagerStateHelper(mInstrumentation))
    }
    }


    private fun getWindowRect(wmHelper: WindowManagerStateHelper): Rect {
    /**
     * Returns the pip window bounds.
     */
    fun getWindowRect(wmHelper: WindowManagerStateHelper): Rect {
        val windowRegion = wmHelper.getWindowRegion(this)
        val windowRegion = wmHelper.getWindowRegion(this)
        require(!windowRegion.isEmpty) { "Unable to find a PIP window in the current state" }
        require(!windowRegion.isEmpty) { "Unable to find a PIP window in the current state" }
        return windowRegion.bounds
        return windowRegion.bounds
@@ -354,7 +354,7 @@ open class PipAppHelper(instrumentation: Instrumentation) :
    /**
    /**
     * Waits until the PIP window snaps horizontally to the provided bounds.
     * Waits until the PIP window snaps horizontally to the provided bounds.
     *
     *
     * @param finalRightX the final x coordinate of the right edge of the pip window
     * @param finalBounds the bounds to wait for PIP window to snap to
     */
     */
    fun waitForPipToSnapTo(wmHelper: WindowManagerStateHelper, finalBounds: android.graphics.Rect) {
    fun waitForPipToSnapTo(wmHelper: WindowManagerStateHelper, finalBounds: android.graphics.Rect) {
        wmHelper
        wmHelper
@@ -369,6 +369,7 @@ open class PipAppHelper(instrumentation: Instrumentation) :
                return@add pipRegionBounds.left == finalBounds.left &&
                return@add pipRegionBounds.left == finalBounds.left &&
                    pipRegionBounds.right == finalBounds.right
                    pipRegionBounds.right == finalBounds.right
            }
            }
            .add(ConditionsFactory.isWMStateComplete())
            .waitForAndVerify()
            .waitForAndVerify()
    }
    }