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

Commit 63843897 authored by Chilun Huang's avatar Chilun Huang
Browse files

Add assertions for layers become visible

Add more assertions for layers become visible.

Bug: 232878493
Test: atest EnterSplitScreenByDragFromAllApps

Change-Id: Ida948525b618b800915813cf2927523600e23724
parent 39cf0dcd
Loading
Loading
Loading
Loading
+71 −3
Original line number Diff line number Diff line
@@ -44,10 +44,58 @@ fun FlickerTestParameter.appPairsDividerBecomesVisible() {
}

fun FlickerTestParameter.splitScreenDividerBecomesVisible() {
    layerBecomesVisible(SPLIT_SCREEN_DIVIDER_COMPONENT)
}

fun FlickerTestParameter.layerBecomesVisible(
    component: FlickerComponentName
) {
    assertLayers {
        this.isInvisible(SPLIT_SCREEN_DIVIDER_COMPONENT)
        this.isInvisible(component)
            .then()
            .isVisible(SPLIT_SCREEN_DIVIDER_COMPONENT)
            .isVisible(component)
    }
}

fun FlickerTestParameter.layerIsVisibleAtEnd(
    component: FlickerComponentName
) {
    assertLayersEnd {
        this.isVisible(component)
    }
}

fun FlickerTestParameter.splitAppLayerBoundsBecomesVisible(
    rotation: Int,
    component: FlickerComponentName,
    splitLeftTop: Boolean
) {
    assertLayers {
        this.isInvisible(component)
            .then()
            .invoke("splitAppLayerBoundsBecomesVisible") {
                val dividerRegion = it.layer(SPLIT_SCREEN_DIVIDER_COMPONENT).visibleRegion.region
                it.visibleRegion(component).overlaps(if (splitLeftTop) {
                    getSplitLeftTopRegion(dividerRegion, rotation)
                } else {
                    getSplitRightBottomRegion(dividerRegion, rotation)
                })
            }
    }
}

fun FlickerTestParameter.splitAppLayerBoundsIsVisibleAtEnd(
    rotation: Int,
    component: FlickerComponentName,
    splitLeftTop: Boolean
) {
    assertLayersEnd {
        val dividerRegion = layer(SPLIT_SCREEN_DIVIDER_COMPONENT).visibleRegion.region
        visibleRegion(component).overlaps(if (splitLeftTop) {
            getSplitLeftTopRegion(dividerRegion, rotation)
        } else {
            getSplitRightBottomRegion(dividerRegion, rotation)
        })
    }
}

@@ -162,3 +210,23 @@ fun getSecondaryRegion(dividerRegion: Region, rotation: Int): Region {
            displayBounds.bounds.right, displayBounds.bounds.bottom)
    }
}

fun getSplitLeftTopRegion(dividerRegion: Region, rotation: Int): Region {
    val displayBounds = WindowUtils.getDisplayBounds(rotation)
    return if (displayBounds.width > displayBounds.height) {
        Region.from(0, 0, dividerRegion.bounds.left, displayBounds.bounds.bottom)
    } else {
        Region.from(0, 0, displayBounds.bounds.right, dividerRegion.bounds.top)
    }
}

fun getSplitRightBottomRegion(dividerRegion: Region, rotation: Int): Region {
    val displayBounds = WindowUtils.getDisplayBounds(rotation)
    return if (displayBounds.width > displayBounds.height) {
        Region.from(dividerRegion.bounds.right, 0, displayBounds.bounds.right,
                displayBounds.bounds.bottom)
    } else {
        Region.from(0, dividerRegion.bounds.bottom, displayBounds.bounds.right,
                displayBounds.bounds.bottom)
    }
}
+38 −0
Original line number Diff line number Diff line
@@ -24,10 +24,15 @@ import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.annotation.Group1
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.traces.common.Rect
import com.android.wm.shell.flicker.layerBecomesVisible
import com.android.wm.shell.flicker.layerIsVisibleAtEnd
import com.android.wm.shell.flicker.appWindowBecomesVisible
import com.android.wm.shell.flicker.appWindowIsVisibleAtEnd
import com.android.wm.shell.flicker.helpers.SplitScreenHelper
import com.android.wm.shell.flicker.splitScreenDividerBecomesVisible
import com.android.wm.shell.flicker.splitAppLayerBoundsBecomesVisible
import com.android.wm.shell.flicker.splitAppLayerBoundsIsVisibleAtEnd
import org.junit.Assume
import org.junit.Before
import org.junit.FixMethodOrder
@@ -71,6 +76,11 @@ class EnterSplitScreenByDragFromAllApps(
                        .getAppIcon(secondaryApp.appName)
                        .dragToSplitscreen(secondaryApp.component.packageName,
                                primaryApp.component.packageName)

                endDisplayBounds = wmHelper.currentState.layerState
                        .displays.firstOrNull { !it.isVirtual }
                        ?.layerStackSpace
                        ?: error("Display not found")
            }
        }

@@ -78,6 +88,24 @@ class EnterSplitScreenByDragFromAllApps(
    @Test
    fun dividerBecomesVisible() = testSpec.splitScreenDividerBecomesVisible()

    @Presubmit
    @Test
    fun primaryAppLayerIsVisibleAtEnd() = testSpec.layerIsVisibleAtEnd(primaryApp.component)

    @Presubmit
    @Test
    fun secondaryAppLayerBecomesVisible() = testSpec.layerBecomesVisible(secondaryApp.component)

    @Presubmit
    @Test
    fun primaryAppBoundsIsVisibleAtEnd() = testSpec.splitAppLayerBoundsIsVisibleAtEnd(
            testSpec.endRotation, primaryApp.component, isAppLeftTop(true))

    @Presubmit
    @Test
    fun secondaryAppBoundsBecomesVisible() = testSpec.splitAppLayerBoundsBecomesVisible(
            testSpec.endRotation, secondaryApp.component, isAppLeftTop(false))

    @Presubmit
    @Test
    fun primaryAppWindowIsVisibleAtEnd() = testSpec.appWindowIsVisibleAtEnd(primaryApp.component)
@@ -87,6 +115,14 @@ class EnterSplitScreenByDragFromAllApps(
    fun secondaryAppWindowBecomesVisible() =
            testSpec.appWindowBecomesVisible(secondaryApp.component)

    private fun isAppLeftTop(primary: Boolean): Boolean {
        return if (endDisplayBounds.width > endDisplayBounds.height) {
            !primary
        } else {
            primary
        }
    }

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
@@ -97,5 +133,7 @@ class EnterSplitScreenByDragFromAllApps(
                    supportedNavigationModes =
                        listOf(WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY))
        }

        private lateinit var endDisplayBounds: Rect
    }
}