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

Commit 4a5a9d14 authored by Ikram Gabiyev's avatar Ikram Gabiyev
Browse files

Assert for a smooth width animation in auto enter

In gesture nav mode, auto entering PiP can initially
make the layer smaller before it gets larger.
However, asserting for area alone is not reliable at all,
since the area fluctuates due to crop and scale animations
going in the opposite directions.

For cases where source rect hint is null a more reliable assertion
is to check that the width of the PiP layer first decreases and then
increases.

Note that we still allow a margin of error of 1px, since around the time
of handoff between gesture nav task view simulator and
SwipePipToHomeAnimator, crop can get a bit smaller and scale can get a
bit larger if swiped aggressively - this can produce off-by-1 errors for
width too.

Allowing for this margin of error should still leave us capable of
catching most of the regressions for this enter PiP case. We do still
want to ideally come up with a better way of asserting animation
smoothness however (see b/363080056).

Bug: 293133362
Flag: EXEMPT bugfix
Test: atest AutoEnterPipOnGoToHomeTest
Test: atest AutoEnterPipWithSourceRectHintTest
Change-Id: I6588e81a6f20dcac444e4e7564917dc5889f913f
parent 3bc44be9
Loading
Loading
Loading
Loading
+52 −1
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@

package com.android.wm.shell.flicker.pip

import android.platform.test.annotations.Postsubmit
import android.platform.test.annotations.Presubmit
import android.tools.flicker.junit.FlickerParametersRunnerFactory
import android.tools.flicker.legacy.FlickerBuilder
import android.tools.flicker.legacy.LegacyFlickerTest
import android.tools.flicker.subject.exceptions.ExceptionMessageBuilder
import android.tools.flicker.subject.exceptions.IncorrectRegionException
import android.tools.flicker.subject.layers.LayerSubject
import androidx.test.filters.FlakyTest
import androidx.test.filters.RequiresDevice
import com.android.wm.shell.flicker.pip.common.EnterPipTransition
@@ -29,6 +33,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized
import kotlin.math.abs

/**
 * Test entering pip from an app via auto-enter property when navigating to home.
@@ -67,9 +72,24 @@ open class AutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : EnterPipTran

    override val defaultTeardown: FlickerBuilder.() -> Unit = { teardown { pipApp.exit(wmHelper) } }

    @FlakyTest(bugId = 293133362)
    private val widthNotSmallerThan: LayerSubject.(LayerSubject) -> Unit = {
        val width = visibleRegion.region.bounds.width()
        val otherWidth = it.visibleRegion.region.bounds.width()
        if (width < otherWidth && abs(width - otherWidth) > EPSILON) {
            val errorMsgBuilder =
                ExceptionMessageBuilder()
                    .forSubject(this)
                    .forIncorrectRegion("width. $width smaller than $otherWidth")
                    .setExpected(width)
                    .setActual(otherWidth)
            throw IncorrectRegionException(errorMsgBuilder)
        }
    }

    @Postsubmit
    @Test
    override fun pipLayerReduces() {
        Assume.assumeFalse(flicker.scenario.isGesturalNavigation)
        flicker.assertLayers {
            val pipLayerList = this.layers { pipApp.layerMatchesAnyOf(it) && it.isVisible }
            pipLayerList.zipWithNext { previous, current ->
@@ -78,6 +98,32 @@ open class AutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : EnterPipTran
        }
    }

    /** Checks that [pipApp] window's width is first decreasing then increasing. */
    @Postsubmit
    @Test
    fun pipLayerWidthDecreasesThenIncreases() {
        Assume.assumeTrue(flicker.scenario.isGesturalNavigation)
        flicker.assertLayers {
            val pipLayerList = this.layers { pipApp.layerMatchesAnyOf(it) && it.isVisible }
            var previousLayer = pipLayerList[0]
            var currentLayer = previousLayer
            var i = 0
            invoke("layer area is decreasing") {
                if (i < pipLayerList.size - 1) {
                    previousLayer = currentLayer
                    currentLayer = pipLayerList[++i]
                    previousLayer.widthNotSmallerThan(currentLayer)
                }
            }.then().invoke("layer are is increasing", true /* isOptional */) {
                if (i < pipLayerList.size - 1) {
                    previousLayer = currentLayer
                    currentLayer = pipLayerList[++i]
                    currentLayer.widthNotSmallerThan(previousLayer)
                }
            }
        }
    }

    /** Checks that [pipApp] window is animated towards default position in right bottom corner */
    @FlakyTest(bugId = 255578530)
    @Test
@@ -108,4 +154,9 @@ open class AutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : EnterPipTran
    override fun visibleLayersShownMoreThanOneConsecutiveEntry() {
        super.visibleLayersShownMoreThanOneConsecutiveEntry()
    }

    companion object {
        // TODO(b/363080056): A margin of error allowed on certain layer size calculations.
        const val EPSILON = 1
    }
}