Make sure PipDragThenTest is gravity agnostic

Make sure we check for the correct direction
of the movement as the pip window is getting snapped.

Moreover, make sure waitForPipToSnapTo also checks for
isWMStateComplete in case any other animation is ongoing in WM

Bug: 271864694
Test: atest WMShellFlickerTest:PipDragThenSnapTest
Change-Id: I8626e15d1d368a8a8190f7ceacdf65bdc57486d9
(cherry picked from commit 9ad934f0a5)
Merged-In: I8626e15d1d368a8a8190f7ceacdf65bdc57486d9
This commit is contained in:
Ikram Gabiyev
2023-03-07 20:55:41 +00:00
parent 889578565c
commit f66b621c87
2 changed files with 29 additions and 12 deletions

View File

@@ -41,6 +41,9 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
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
get() = {
val stringExtras: Map<String, String> =
@@ -55,9 +58,16 @@ class PipDragThenSnapTest(flicker: FlickerTest) : PipTransition(flicker){
RemoveAllTasksButHomeRule.removeAllTasksButHome()
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
.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 {
// 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
@Test
fun pipLayerMovesRight() {
fun pipLayerMovesToClosestEdge() {
flicker.assertLayers {
val pipLayerList = layers { pipApp.layerMatchesAnyOf(it) && it.isVisible }
pipLayerList.zipWithNext { previous, current ->
current.visibleRegion.isToTheRight(previous.visibleRegion.region)
if (willSnapRight) {
current.visibleRegion.isToTheRight(previous.visibleRegion.region)
} else {
previous.visibleRegion.isToTheRight(current.visibleRegion.region)
}
}
}
}

View File

@@ -61,9 +61,8 @@ open class PipAppHelper(instrumentation: Instrumentation) :
* Drags the PIP window away from the screen edge while not crossing the display center.
*
* @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()
// 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
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
*/
private fun isCloserToRightEdge(wmHelper: WindowManagerStateHelper): Boolean {
fun isCloserToRightEdge(wmHelper: WindowManagerStateHelper): Boolean {
val windowRect = getWindowRect(wmHelper)
val displayRect = wmHelper.currentState.wmState.getDefaultDisplay()?.displayRect
@@ -267,7 +264,10 @@ open class PipAppHelper(instrumentation: Instrumentation) :
closePipWindow(WindowManagerStateHelper(mInstrumentation))
}
private fun getWindowRect(wmHelper: WindowManagerStateHelper): Rect {
/**
* Returns the pip window bounds.
*/
fun getWindowRect(wmHelper: WindowManagerStateHelper): Rect {
val windowRegion = wmHelper.getWindowRegion(this)
require(!windowRegion.isEmpty) { "Unable to find a PIP window in the current state" }
return windowRegion.bounds
@@ -354,7 +354,7 @@ open class PipAppHelper(instrumentation: Instrumentation) :
/**
* 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) {
wmHelper
@@ -369,6 +369,7 @@ open class PipAppHelper(instrumentation: Instrumentation) :
return@add pipRegionBounds.left == finalBounds.left &&
pipRegionBounds.right == finalBounds.right
}
.add(ConditionsFactory.isWMStateComplete())
.waitForAndVerify()
}