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

Commit 6ea20e07 authored by Bill Lin's avatar Bill Lin
Browse files

1/ Integrate legacySplitScreen Flicker tests into individual assertions

1) Integrate companion object inheritance and the default test runner
2) Move launch activity to setup: avoid noise of splash screen
3) Move setRotate() to setup: avoid noise of system windows
   (LetterBox, NavBar, StatusBar...) visibility changes
4) Reducing test time of each test case: remove redundant transition
5) Remve redundant val for readibility
6) Remove navBarLayerIsAlwaysVisible assertion from split test
   the rotation flow of enter split screen :
   Overview(land) -> enter split(portrait) -> split mode(land)
7) Partially enable ROTATION_90 tests
8) Bypass visibleLayersShownMoreThanOneConsecutiveEntry assertion
   for flaky reasons(Splash Screen, LetterBox, BackGestureSurface)

Test: atest WMShellFlickerTests
Bug: 176134495
Bug: 178685668
Bug: 178447631
Change-Id: I1d6153b987e5913a5d9a1fa5b72b9341b40db6fc
parent 9c4c2122
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -18,10 +18,11 @@ package com.android.wm.shell.flicker

import android.graphics.Region
import android.view.Surface
import com.android.server.wm.flicker.APP_PAIR_SPLIT_DIVIDER
import com.android.server.wm.flicker.DOCKED_STACK_DIVIDER
import com.android.server.wm.flicker.dsl.LayersAssertionBuilder
import com.android.server.wm.flicker.helpers.WindowUtils
import com.android.server.wm.flicker.traces.layers.getVisibleBounds
import com.android.wm.shell.flicker.FlickerTestBase.Companion.DOCKED_STACK_DIVIDER

@JvmOverloads
fun LayersAssertionBuilder.appPairsDividerIsVisible(
@@ -29,7 +30,7 @@ fun LayersAssertionBuilder.appPairsDividerIsVisible(
    enabled: Boolean = bugId == 0
) {
    end("appPairsDividerIsVisible", bugId, enabled) {
        this.isVisible(FlickerTestBase.APP_PAIR_SPLIT_DIVIDER)
        this.isVisible(APP_PAIR_SPLIT_DIVIDER)
    }
}

@@ -39,7 +40,7 @@ fun LayersAssertionBuilder.appPairsDividerIsInvisible(
    enabled: Boolean = bugId == 0
) {
    end("appPairsDividerIsInVisible", bugId, enabled) {
        this.notExists(FlickerTestBase.APP_PAIR_SPLIT_DIVIDER)
        this.notExists(APP_PAIR_SPLIT_DIVIDER)
    }
}

@@ -107,7 +108,7 @@ fun LayersAssertionBuilder.appPairsPrimaryBoundsIsVisible(
    enabled: Boolean = bugId == 0
) {
    end("PrimaryAppBounds", bugId, enabled) {
        val dividerRegion = entry.getVisibleBounds(FlickerTestBase.APP_PAIR_SPLIT_DIVIDER)
        val dividerRegion = entry.getVisibleBounds(APP_PAIR_SPLIT_DIVIDER)
        this.hasVisibleRegion(primaryLayerName, getPrimaryRegion(dividerRegion, rotation))
    }
}
@@ -120,7 +121,7 @@ fun LayersAssertionBuilder.appPairsSecondaryBoundsIsVisible(
    enabled: Boolean = bugId == 0
) {
    end("SecondaryAppBounds", bugId, enabled) {
        val dividerRegion = entry.getVisibleBounds(FlickerTestBase.APP_PAIR_SPLIT_DIVIDER)
        val dividerRegion = entry.getVisibleBounds(APP_PAIR_SPLIT_DIVIDER)
        this.hasVisibleRegion(secondaryLayerName, getSecondaryRegion(dividerRegion, rotation))
    }
}
+0 −8
Original line number Diff line number Diff line
@@ -135,12 +135,4 @@ abstract class FlickerTestBase {
            throw RuntimeException(e)
        }
    }

    companion object {
        const val NAVIGATION_BAR_WINDOW_TITLE = "NavigationBar"
        const val STATUS_BAR_WINDOW_TITLE = "StatusBar"
        const val DOCKED_STACK_DIVIDER = "DockedStackDivider"
        const val APP_PAIR_SPLIT_DIVIDER = "AppPairSplitDivider"
        const val IMAGE_WALLPAPER = "ImageWallpaper"
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -21,12 +21,12 @@ import android.os.SystemClock
import android.platform.test.annotations.Presubmit
import androidx.test.filters.RequiresDevice
import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.APP_PAIR_SPLIT_DIVIDER
import com.android.server.wm.flicker.FlickerTestRunner
import com.android.server.wm.flicker.FlickerTestRunnerFactory
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.buildTestTag
import com.android.server.wm.flicker.traces.layers.getVisibleBounds
import com.android.wm.shell.flicker.FlickerTestBase.Companion.APP_PAIR_SPLIT_DIVIDER
import com.android.wm.shell.flicker.appPairsDividerIsVisible
import com.android.wm.shell.flicker.helpers.AppPairsHelper
import org.junit.FixMethodOrder
+1 −1
Original line number Diff line number Diff line
@@ -21,12 +21,12 @@ import android.os.SystemClock
import android.platform.test.annotations.Presubmit
import androidx.test.filters.RequiresDevice
import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.APP_PAIR_SPLIT_DIVIDER
import com.android.server.wm.flicker.FlickerTestRunner
import com.android.server.wm.flicker.FlickerTestRunnerFactory
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.buildTestTag
import com.android.server.wm.flicker.traces.layers.getVisibleBounds
import com.android.wm.shell.flicker.FlickerTestBase.Companion.APP_PAIR_SPLIT_DIVIDER
import com.android.wm.shell.flicker.appPairsDividerIsInvisible
import com.android.wm.shell.flicker.helpers.AppPairsHelper
import org.junit.FixMethodOrder
+0 −208
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.platform.test.annotations.Presubmit
import android.view.Surface
import androidx.test.filters.FlakyTest
import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.dsl.runWithFlicker
import com.android.server.wm.flicker.helpers.canSplitScreen
import com.android.server.wm.flicker.helpers.exitSplitScreen
import com.android.server.wm.flicker.helpers.isInSplitScreen
import com.android.server.wm.flicker.helpers.launchSplitScreen
import com.android.server.wm.flicker.helpers.openQuickstep
import com.android.server.wm.flicker.helpers.openQuickStepAndClearRecentAppsFromOverview
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.wm.shell.flicker.dockedStackDividerIsInvisible
import com.android.wm.shell.flicker.helpers.SplitScreenHelper.Companion.TEST_REPETITIONS
import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.navBarLayerIsAlwaysVisible
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.wm.shell.flicker.dockedStackPrimaryBoundsIsVisible
import com.android.wm.shell.flicker.dockedStackSecondaryBoundsIsVisible
import org.junit.Assert
import com.android.wm.shell.flicker.dockedStackDividerBecomesVisible
import com.android.server.wm.flicker.visibleWindowsShownMoreThanOneConsecutiveEntry
import com.android.server.wm.flicker.visibleLayersShownMoreThanOneConsecutiveEntry
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized

/**
 * Test SplitScreen launch.
 * To run this test: `atest WMShellFlickerTests:EnterLegacySplitScreenTest`
 */
@Presubmit
@RequiresDevice
@RunWith(Parameterized::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class EnterLegacySplitScreenTest(
    rotationName: String,
    rotation: Int
) : SplitScreenTestBase(rotationName, rotation) {
    private val splitScreenSetup: FlickerBuilder
        get() = FlickerBuilder(instrumentation).apply {
            val testLaunchActivity = "launch_splitScreen_test_activity"
            withTestName {
                testLaunchActivity
            }
            setup {
                eachRun {
                    uiDevice.wakeUpAndGoToHomeScreen()
                    uiDevice.openQuickStepAndClearRecentAppsFromOverview()
                }
            }
            teardown {
                eachRun {
                    if (uiDevice.isInSplitScreen()) {
                        uiDevice.exitSplitScreen()
                    }
                    splitScreenApp.exit()
                    secondaryApp.exit()
                    nonResizeableApp.exit()
                }
            }
            assertions {
                layersTrace {
                    navBarLayerIsAlwaysVisible()
                    statusBarLayerIsAlwaysVisible()
                }
                windowManagerTrace {
                    navBarWindowIsAlwaysVisible()
                    statusBarWindowIsAlwaysVisible()
                }
            }
        }

    @Test
    fun testEnterSplitScreen_dockActivity() {
        val testTag = "testEnterSplitScreen_dockActivity"
        runWithFlicker(splitScreenSetup) {
            withTestName { testTag }
            repeat {
                TEST_REPETITIONS
            }
            transitions {
                splitScreenApp.launchViaIntent()
                uiDevice.launchSplitScreen()
            }
            assertions {
                layersTrace {
                    dockedStackPrimaryBoundsIsVisible(
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                    dockedStackDividerBecomesVisible()
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                            listOf(LAUNCHER_PACKAGE_NAME, splitScreenApp.defaultWindowName,
                                    LIVE_WALLPAPER_PACKAGE_NAME)
                    )
                }
                windowManagerTrace {
                    end("appWindowIsVisible") {
                        isVisible(splitScreenApp.defaultWindowName)
                    }
                }
            }
        }
    }

    @Test
    fun testEnterSplitScreen_launchToSide() {
        val testTag = "testEnterSplitScreen_launchToSide"
        runWithFlicker(splitScreenSetup) {
            withTestName { testTag }
            repeat {
                TEST_REPETITIONS
            }
            transitions {
                secondaryApp.launchViaIntent()
                splitScreenApp.launchViaIntent()
                uiDevice.launchSplitScreen()
                splitScreenApp.reopenAppFromOverview()
            }
            assertions {
                layersTrace {
                    dockedStackPrimaryBoundsIsVisible(
                        rotation, splitScreenApp.defaultWindowName, 169271943)
                    dockedStackSecondaryBoundsIsVisible(
                        rotation, secondaryApp.defaultWindowName, 169271943)
                    dockedStackDividerBecomesVisible()
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                        listOf(LAUNCHER_PACKAGE_NAME, splitScreenApp.defaultWindowName,
                            secondaryApp.defaultWindowName)
                    )
                }
                windowManagerTrace {
                    end("appWindowIsVisible") {
                        isVisible(splitScreenApp.defaultWindowName)
                            .isVisible(secondaryApp.defaultWindowName)
                    }
                    visibleWindowsShownMoreThanOneConsecutiveEntry(
                        listOf(LAUNCHER_PACKAGE_NAME, splitScreenApp.defaultWindowName,
                            secondaryApp.defaultWindowName))
                }
            }
        }
    }

    @FlakyTest(bugId = 173875043)
    @Test
    fun testNonResizeableNotDocked() {
        val testTag = "testNonResizeableNotDocked"
        runWithFlicker(splitScreenSetup) {
            withTestName { testTag }
            repeat {
                TEST_REPETITIONS
            }
            transitions {
                nonResizeableApp.launchViaIntent()
                uiDevice.openQuickstep()
                if (uiDevice.canSplitScreen()) {
                    Assert.fail("Non-resizeable app should not enter split screen")
                }
            }
            assertions {
                layersTrace {
                    dockedStackDividerIsInvisible()
                    visibleLayersShownMoreThanOneConsecutiveEntry(
                        listOf(LAUNCHER_PACKAGE_NAME, nonResizeableApp.defaultWindowName)
                    )
                }
                windowManagerTrace {
                    end("appWindowIsVisible") {
                        isInvisible(nonResizeableApp.defaultWindowName)
                    }
                    visibleWindowsShownMoreThanOneConsecutiveEntry(
                        listOf(LAUNCHER_PACKAGE_NAME, nonResizeableApp.defaultWindowName))
                }
            }
        }
    }

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