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

Commit 218868bb authored by Bill Lin's avatar Bill Lin Committed by Wale Ogunwale
Browse files

1/ Refactor LegacySplitScreenTests

1) Separate NonResizable activity tests
2) Fix flaky in visibleWindowsShownMoreThanOneConsecutiveEntry
3) Fix flaky in OpenAppToLegacySplitScreenTest
4) Align implementation of ExitLegacySplitScreenFromBottomTest

Test: atest WMShellFlickerTests
Bug: 176897747
Bug: 176923301
Bug: 176134495
Change-Id: I1e3efdbb1645f6d1a77950101e2c9f5b34856a2f
parent b71323aa
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,18 @@ fun LayersAssertion.appPairsDividerIsInvisible(
    }
    }
}
}


@JvmOverloads
fun LayersAssertion.appPairsDividerBecomesVisible(
    bugId: Int = 0,
    enabled: Boolean = bugId == 0
) {
    all("dividerLayerBecomesVisible") {
        this.hidesLayer(FlickerTestBase.DOCKED_STACK_DIVIDER)
                .then()
                .showsLayer(FlickerTestBase.DOCKED_STACK_DIVIDER)
    }
}

@JvmOverloads
@JvmOverloads
fun LayersAssertion.dockedStackDividerIsVisible(
fun LayersAssertion.dockedStackDividerIsVisible(
    bugId: Int = 0,
    bugId: Int = 0,
+7 −79
Original line number Original line Diff line number Diff line
@@ -21,7 +21,6 @@ import android.view.Surface
import androidx.test.filters.RequiresDevice
import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.dsl.runWithFlicker
import com.android.server.wm.flicker.dsl.runWithFlicker
import com.android.server.wm.flicker.helpers.WindowUtils
import com.android.server.wm.flicker.helpers.canSplitScreen
import com.android.server.wm.flicker.helpers.canSplitScreen
import com.android.server.wm.flicker.helpers.exitSplitScreen
import com.android.server.wm.flicker.helpers.exitSplitScreen
import com.android.server.wm.flicker.helpers.isInSplitScreen
import com.android.server.wm.flicker.helpers.isInSplitScreen
@@ -35,6 +34,7 @@ import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.navBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.navBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible

import com.android.wm.shell.flicker.dockedStackPrimaryBoundsIsVisible
import com.android.wm.shell.flicker.dockedStackPrimaryBoundsIsVisible
import com.android.wm.shell.flicker.dockedStackSecondaryBoundsIsVisible
import com.android.wm.shell.flicker.dockedStackSecondaryBoundsIsVisible
import org.junit.Assert
import org.junit.Assert
@@ -59,8 +59,6 @@ class EnterLegacySplitScreenTest(
    rotationName: String,
    rotationName: String,
    rotation: Int
    rotation: Int
) : SplitScreenTestBase(rotationName, rotation) {
) : SplitScreenTestBase(rotationName, rotation) {
    private val letterBox = "Letterbox"

    private val splitScreenSetup: FlickerBuilder
    private val splitScreenSetup: FlickerBuilder
        get() = FlickerBuilder(instrumentation).apply {
        get() = FlickerBuilder(instrumentation).apply {
            val testLaunchActivity = "launch_splitScreen_test_activity"
            val testLaunchActivity = "launch_splitScreen_test_activity"
@@ -91,7 +89,6 @@ class EnterLegacySplitScreenTest(
                windowManagerTrace {
                windowManagerTrace {
                    navBarWindowIsAlwaysVisible()
                    navBarWindowIsAlwaysVisible()
                    statusBarWindowIsAlwaysVisible()
                    statusBarWindowIsAlwaysVisible()
                    visibleWindowsShownMoreThanOneConsecutiveEntry(listOf(launcherPackageName))
                }
                }
            }
            }
        }
        }
@@ -114,7 +111,8 @@ class EnterLegacySplitScreenTest(
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                    dockedStackDividerBecomesVisible()
                    dockedStackDividerBecomesVisible()
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                            listOf(launcherPackageName, splitScreenApp.defaultWindowName)
                            listOf(LAUNCHER_PACKAGE_NAME, splitScreenApp.defaultWindowName,
                                    LIVE_WALLPAPER_PACKAGE_NAME)
                    )
                    )
                }
                }
                windowManagerTrace {
                windowManagerTrace {
@@ -148,7 +146,7 @@ class EnterLegacySplitScreenTest(
                            rotation, secondaryApp.defaultWindowName, 169271943)
                            rotation, secondaryApp.defaultWindowName, 169271943)
                    dockedStackDividerBecomesVisible()
                    dockedStackDividerBecomesVisible()
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                            listOf(launcherPackageName, splitScreenApp.defaultWindowName,
                            listOf(LAUNCHER_PACKAGE_NAME, splitScreenApp.defaultWindowName,
                                    secondaryApp.defaultWindowName)
                                    secondaryApp.defaultWindowName)
                    )
                    )
                }
                }
@@ -157,6 +155,7 @@ class EnterLegacySplitScreenTest(
                        showsAppWindow(splitScreenApp.defaultWindowName)
                        showsAppWindow(splitScreenApp.defaultWindowName)
                                .and().showsAppWindow(secondaryApp.defaultWindowName)
                                .and().showsAppWindow(secondaryApp.defaultWindowName)
                    }
                    }
                    visibleWindowsShownMoreThanOneConsecutiveEntry(listOf(LAUNCHER_PACKAGE_NAME))
                }
                }
            }
            }
        }
        }
@@ -181,85 +180,14 @@ class EnterLegacySplitScreenTest(
                layersTrace {
                layersTrace {
                    dockedStackDividerIsInvisible()
                    dockedStackDividerIsInvisible()
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                            listOf(launcherPackageName, nonResizeableApp.defaultWindowName)
                            listOf(LAUNCHER_PACKAGE_NAME, nonResizeableApp.defaultWindowName)
                    )
                    )
                }
                }
                windowManagerTrace {
                windowManagerTrace {
                    end {
                    end {
                        hidesAppWindow(nonResizeableApp.defaultWindowName)
                        hidesAppWindow(nonResizeableApp.defaultWindowName)
                    }
                    }
                }
                    visibleWindowsShownMoreThanOneConsecutiveEntry(listOf(LAUNCHER_PACKAGE_NAME))
            }
        }
    }

    @Test
    fun testNonResizeableWhenAlreadyInSplitScreenPrimary() {
        val testTag = "testNonResizeableWhenAlreadyInSplitScreenPrimary"
        runWithFlicker(splitScreenSetup) {
            withTestName { testTag }
            repeat {
                TEST_REPETITIONS
            }
            transitions {
                nonResizeableApp.launchViaIntent()
                splitScreenApp.launchViaIntent()
                uiDevice.launchSplitScreen()
                nonResizeableApp.reopenAppFromOverview()
            }
            assertions {
                layersTrace {
                    dockedStackDividerIsInvisible()
                    end("appsEndingBounds", enabled = false) {
                        val displayBounds = WindowUtils.getDisplayBounds(rotation)
                        this.hasVisibleRegion(nonResizeableApp.defaultWindowName, displayBounds)
                    }
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                            listOf(launcherPackageName, splitScreenApp.defaultWindowName,
                                    nonResizeableApp.defaultWindowName, letterBox)
                    )
                }
                windowManagerTrace {
                    end {
                        showsAppWindow(nonResizeableApp.defaultWindowName)
                        hidesAppWindow(splitScreenApp.defaultWindowName)
                    }
                }
            }
        }
    }

    @Test
    fun testNonResizeableWhenAlreadyInSplitScreenSecondary() {
        val testTag = "testNonResizeableWhenAlreadyInSplitScreenSecondary"
        runWithFlicker(splitScreenSetup) {
            withTestName { testTag }
            repeat {
                TEST_REPETITIONS
            }
            transitions {
                splitScreenApp.launchViaIntent()
                uiDevice.launchSplitScreen()
                uiDevice.pressBack()
                nonResizeableApp.launchViaIntent()
            }
            assertions {
                layersTrace {
                    dockedStackDividerIsInvisible()
                    end("appsEndingBounds", enabled = false) {
                        val displayBounds = WindowUtils.getDisplayBounds(rotation)
                        this.hasVisibleRegion(nonResizeableApp.defaultWindowName, displayBounds)
                    }
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                            listOf(launcherPackageName, splitScreenApp.defaultWindowName,
                                    nonResizeableApp.defaultWindowName, letterBox)
                    )
                }
                windowManagerTrace {
                    end {
                        showsAppWindow(nonResizeableApp.defaultWindowName)
                        hidesAppWindow(splitScreenApp.defaultWindowName)
                    }
                }
                }
            }
            }
        }
        }
+16 −13
Original line number Original line Diff line number Diff line
@@ -22,16 +22,20 @@ import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.Flicker
import com.android.server.wm.flicker.Flicker
import com.android.server.wm.flicker.FlickerTestRunner
import com.android.server.wm.flicker.FlickerTestRunner
import com.android.server.wm.flicker.FlickerTestRunnerFactory
import com.android.server.wm.flicker.FlickerTestRunnerFactory
import com.android.server.wm.flicker.helpers.StandardAppHelper
import com.android.server.wm.flicker.endRotation
import com.android.server.wm.flicker.endRotation
import com.android.server.wm.flicker.helpers.buildTestTag
import com.android.server.wm.flicker.helpers.buildTestTag
import com.android.server.wm.flicker.helpers.exitSplitScreen
import com.android.server.wm.flicker.helpers.exitSplitScreen
import com.android.server.wm.flicker.helpers.exitSplitScreenFromBottom
import com.android.server.wm.flicker.helpers.exitSplitScreenFromBottom
import com.android.server.wm.flicker.helpers.isInSplitScreen
import com.android.server.wm.flicker.helpers.isInSplitScreen
import com.android.server.wm.flicker.helpers.launchSplitScreen
import com.android.server.wm.flicker.helpers.launchSplitScreen
import com.android.server.wm.flicker.helpers.openQuickStepAndClearRecentAppsFromOverview
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen

import com.android.server.wm.flicker.repetitions
import com.android.server.wm.flicker.repetitions
import com.android.wm.shell.flicker.TEST_APP_SPLITSCREEN_PRIMARY_LABEL
import com.android.wm.shell.flicker.helpers.SplitScreenHelper
import com.android.wm.shell.flicker.testapp.Components
import org.junit.FixMethodOrder
import org.junit.FixMethodOrder
import org.junit.runner.RunWith
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.MethodSorters
@@ -53,23 +57,24 @@ class ExitLegacySplitScreenFromBottomTest(
        @JvmStatic
        @JvmStatic
        fun getParams(): Collection<Array<Any>> {
        fun getParams(): Collection<Array<Any>> {
            val instrumentation = InstrumentationRegistry.getInstrumentation()
            val instrumentation = InstrumentationRegistry.getInstrumentation()
            val testApp = StandardAppHelper(instrumentation,
            val splitScreenApp = SplitScreenHelper(instrumentation,
                    "com.android.wm.shell.flicker.testapp", "SimpleApp")
                    TEST_APP_SPLITSCREEN_PRIMARY_LABEL,
                    Components.SplitScreenActivity())


            // b/161435597 causes the test not to work on 90 degrees
            // TODO(b/162923992) Use of multiple segments of flicker spec for testing
            return FlickerTestRunnerFactory(instrumentation, listOf(Surface.ROTATION_0))
            return FlickerTestRunnerFactory(instrumentation,
                    listOf(Surface.ROTATION_0, Surface.ROTATION_90))
                    .buildTest { configuration ->
                    .buildTest { configuration ->
                        withTestName {
                        withTestName {
                            buildTestTag("exitSplitScreenFromBottom", testApp,
                            buildTestTag("exitSplitScreenFromBottom", splitScreenApp,
                                    configuration)
                                    configuration)
                        }
                        }
                        repeat { configuration.repetitions }
                        repeat { configuration.repetitions }
                        setup {
                        setup {
                            test {
                                device.wakeUpAndGoToHomeScreen()
                            }
                            eachRun {
                            eachRun {
                                testApp.open()
                                device.wakeUpAndGoToHomeScreen()
                                device.openQuickStepAndClearRecentAppsFromOverview()
                                splitScreenApp.launchViaIntent()
                                device.launchSplitScreen()
                                device.launchSplitScreen()
                                device.waitForIdle()
                                device.waitForIdle()
                                this.setRotation(configuration.endRotation)
                                this.setRotation(configuration.endRotation)
@@ -77,12 +82,10 @@ class ExitLegacySplitScreenFromBottomTest(
                        }
                        }
                        teardown {
                        teardown {
                            eachRun {
                            eachRun {
                                testApp.exit()
                            }
                            test {
                                if (device.isInSplitScreen()) {
                                if (device.isInSplitScreen()) {
                                    device.exitSplitScreen()
                                    device.exitSplitScreen()
                                }
                                }
                                splitScreenApp.exit()
                            }
                            }
                        }
                        }
                        transitions {
                        transitions {
+1 −1
Original line number Original line Diff line number Diff line
@@ -82,7 +82,7 @@ class ExitLegacySplitScreenTest(
                }
                }
                layersTrace {
                layersTrace {
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                            listOf(launcherPackageName))
                            listOf(LAUNCHER_PACKAGE_NAME))
                }
                }
            }
            }
        }
        }
+88 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 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.legacysplitscreen

import android.view.Surface
import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.dsl.runWithFlicker
import com.android.server.wm.flicker.helpers.WindowUtils
import com.android.server.wm.flicker.helpers.launchSplitScreen
import com.android.server.wm.flicker.visibleLayersShownMoreThanOneConsecutiveEntry
import com.android.wm.shell.flicker.dockedStackDividerIsInvisible
import com.android.wm.shell.flicker.helpers.SplitScreenHelper
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized

/**
 * Test open app to split screen.
 * To run this test: `atest WMShellFlickerTests:NonResizableDismissInLegacySplitScreenTest`
 */
@RequiresDevice
@RunWith(Parameterized::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class NonResizableDismissInLegacySplitScreenTest(
    rotationName: String,
    rotation: Int
) : SplitScreenTestBase(rotationName, rotation) {

    @Test
    fun testNonResizableDismissInLegacySplitScreenTest() {
        val testTag = "testNonResizableDismissInLegacySplitScreenTest"

        runWithFlicker(transitionSetup) {
            withTestName { testTag }
            repeat { SplitScreenHelper.TEST_REPETITIONS }
            transitions {
                nonResizeableApp.launchViaIntent()
                splitScreenApp.launchViaIntent()
                device.launchSplitScreen()
                nonResizeableApp.reopenAppFromOverview()
            }
            assertions {
                layersTrace {
                    dockedStackDividerIsInvisible()
                    end("appsEndingBounds", enabled = false) {
                        val displayBounds = WindowUtils.getDisplayBounds(rotation)
                        this.hasVisibleRegion(nonResizeableApp.defaultWindowName, displayBounds)
                    }
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                            listOf(LAUNCHER_PACKAGE_NAME, splitScreenApp.defaultWindowName,
                                    nonResizeableApp.defaultWindowName, LETTER_BOX_NAME)
                    )
                }
                windowManagerTrace {
                    end {
                        showsAppWindow(nonResizeableApp.defaultWindowName)
                        hidesAppWindow(splitScreenApp.defaultWindowName)
                    }
                }
            }
        }
    }

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): Collection<Array<Any>> {
            val supportedRotations = intArrayOf(Surface.ROTATION_0, Surface.ROTATION_90)
            return supportedRotations.map { arrayOf(Surface.rotationToString(it), it) }
        }
    }
}
 No newline at end of file
Loading