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

Commit 5cbcf761 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "6-1/ Integrate SplitScreen rotation flicker tests"

parents 331168f1 60ae7ac3
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package com.android.wm.shell.flicker

import android.graphics.Region
import com.android.server.wm.flicker.dsl.EventLogAssertion
import com.android.server.wm.flicker.dsl.LayersAssertion
import com.android.server.wm.flicker.helpers.WindowUtils

@JvmOverloads
fun LayersAssertion.appPairsDividerIsVisible(
@@ -59,6 +61,50 @@ fun LayersAssertion.dockedStackDividerIsInvisible(
    }
}

@JvmOverloads
fun LayersAssertion.dockedStackPrimaryBoundsIsVisible(
    rotation: Int,
    primaryLayerName: String,
    bugId: Int = 0,
    enabled: Boolean = bugId == 0
) {
    end("PrimaryAppBounds", bugId, enabled) {
        val entry = this.trace.entries.firstOrNull()
                ?: throw IllegalStateException("Trace is empty")
        val dividerRegion = entry.getVisibleBounds(FlickerTestBase.DOCKED_STACK_DIVIDER)
        this.hasVisibleRegion(primaryLayerName, getPrimaryRegion(dividerRegion, rotation))
    }
}

@JvmOverloads
fun LayersAssertion.dockedStackSecondaryBoundsIsVisible(
    rotation: Int,
    secondaryLayerName: String,
    bugId: Int = 0,
    enabled: Boolean = bugId == 0
) {
    end("SecondaryAppBounds", bugId, enabled) {
        val entry = this.trace.entries.firstOrNull()
                ?: throw IllegalStateException("Trace is empty")
        val dividerRegion = entry.getVisibleBounds(FlickerTestBase.DOCKED_STACK_DIVIDER)
        this.hasVisibleRegion(secondaryLayerName, getSecondaryRegion(dividerRegion, rotation))
    }
}

fun getPrimaryRegion(dividerRegion: Region, rotation: Int): Region {
    val displayBounds = WindowUtils.getDisplayBounds(rotation)
    return Region(0, 0, displayBounds.getBounds().right,
            dividerRegion.getBounds().bottom - WindowUtils.dockedStackDividerInset)
}

fun getSecondaryRegion(dividerRegion: Region, rotation: Int): Region {
    val displayBounds = WindowUtils.getDisplayBounds(rotation)
    return Region(0,
            dividerRegion.getBounds().bottom - WindowUtils.dockedStackDividerInset,
            displayBounds.getBounds().right,
            displayBounds.getBounds().bottom - WindowUtils.navigationBarHeight)
}

fun EventLogAssertion.focusChanges(
    vararg windows: String,
    bugId: Int = 0,
+0 −16
Original line number Diff line number Diff line
@@ -17,9 +17,7 @@
package com.android.wm.shell.flicker.helpers

import android.app.Instrumentation
import android.graphics.Region
import android.os.SystemClock
import com.android.server.wm.flicker.helpers.WindowUtils
import com.android.wm.shell.flicker.testapp.Components

class SplitScreenHelper(
@@ -43,20 +41,6 @@ class SplitScreenHelper(
        SystemClock.sleep(TIMEOUT_MS)
    }

    fun getPrimaryBounds(dividerBounds: Region): android.graphics.Region {
        val primaryAppBounds = Region(0, 0, dividerBounds.bounds.right,
                dividerBounds.bounds.bottom + WindowUtils.dockedStackDividerInset)
        return primaryAppBounds
    }

    fun getSecondaryBounds(dividerBounds: Region): android.graphics.Region {
        val displayBounds = WindowUtils.displayBounds
        val secondaryAppBounds = Region(0,
                dividerBounds.bounds.bottom - WindowUtils.dockedStackDividerInset,
                displayBounds.right, displayBounds.bottom - WindowUtils.navigationBarHeight)
        return secondaryAppBounds
    }

    companion object {
        const val TEST_REPETITIONS = 1
        const val TIMEOUT_MS = 3_000L
+8 −18
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ 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 org.junit.FixMethodOrder
import org.junit.Test
@@ -102,13 +104,8 @@ class EnterSplitScreenTest(
            assertions {
                layersTrace {
                    dockedStackDividerIsVisible()
                    end("appsEndingBounds", enabled = false) {
                        val entry = this.trace.entries.firstOrNull()
                                ?: throw IllegalStateException("Trace is empty")
                        this.hasVisibleRegion(splitScreenApp.defaultWindowName,
                                splitScreenApp.getPrimaryBounds(
                                        entry.getVisibleBounds(DOCKED_STACK_DIVIDER)))
                    }
                    dockedStackPrimaryBoundsIsVisible(
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                }
                windowManagerTrace {
                    end {
@@ -136,17 +133,10 @@ class EnterSplitScreenTest(
            assertions {
                layersTrace {
                    dockedStackDividerIsVisible()
                    end("appsEndingBounds", enabled = false) {
                        val entry = this.trace.entries.firstOrNull()
                                ?: throw IllegalStateException("Trace is empty")
                        this.hasVisibleRegion(splitScreenApp.defaultWindowName,
                                splitScreenApp.getPrimaryBounds(
                                        entry.getVisibleBounds(DOCKED_STACK_DIVIDER)))
                                .and()
                                .hasVisibleRegion(secondaryApp.defaultWindowName,
                                        splitScreenApp.getSecondaryBounds(
                                        entry.getVisibleBounds(DOCKED_STACK_DIVIDER)))
                    }
                    dockedStackPrimaryBoundsIsVisible(
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                    dockedStackSecondaryBoundsIsVisible(
                            rotation, secondaryApp.defaultWindowName, 169271943)
                }
                windowManagerTrace {
                    end {
+146 −0
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.splitscreen

import android.view.Surface
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.exitSplitScreen
import com.android.server.wm.flicker.helpers.isInSplitScreen
import com.android.server.wm.flicker.helpers.launchSplitScreen
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.server.wm.flicker.navBarLayerRotatesAndScales
import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerRotatesScales
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.wm.shell.flicker.dockedStackDividerIsVisible
import com.android.wm.shell.flicker.dockedStackPrimaryBoundsIsVisible
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:RotateOneLaunchedAppTest`
 */
@RequiresDevice
@RunWith(Parameterized::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class RotateOneLaunchedAppTest(
    rotationName: String,
    rotation: Int
) : SplitScreenTestBase(rotationName, rotation) {
    private val splitScreenRotationSetup: FlickerBuilder
        get() = FlickerBuilder(instrumentation).apply {
            val testSetupRotation = "testSetupRotation"
            withTestName {
                testSetupRotation
            }
            setup {
                test {
                    device.wakeUpAndGoToHomeScreen()
                }
            }
            teardown {
                eachRun {
                    if (uiDevice.isInSplitScreen()) {
                        uiDevice.exitSplitScreen()
                    }
                    setRotation(Surface.ROTATION_0)
                    splitScreenApp.exit()
                    secondaryApp.exit()
                }
            }
        }

    @Test
    fun testRotateInSplitScreenMode() {
        val testTag = "testEnterSplitScreen_launchToSide"
        runWithFlicker(splitScreenRotationSetup) {
            withTestName { testTag }
            repeat {
                SplitScreenHelper.TEST_REPETITIONS
            }
            transitions {
                splitScreenApp.launchViaIntent()
                device.launchSplitScreen()
                setRotation(rotation)
            }
            assertions {
                layersTrace {
                    navBarLayerRotatesAndScales(Surface.ROTATION_0, rotation, 169271943)
                    statusBarLayerRotatesScales(Surface.ROTATION_0, rotation, 169271943)
                    dockedStackDividerIsVisible()
                    dockedStackPrimaryBoundsIsVisible(
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                }
                windowManagerTrace {
                    navBarWindowIsAlwaysVisible()
                    statusBarWindowIsAlwaysVisible()
                    end {
                        showsAppWindow(splitScreenApp.defaultWindowName)
                    }
                }
            }
        }
    }

    @Test
    fun testRotateAndEnterSplitScreenMode() {
        val testTag = "testRotateAndEnterSplitScreenMode"
        runWithFlicker(splitScreenRotationSetup) {
            withTestName { testTag }
            repeat {
                SplitScreenHelper.TEST_REPETITIONS
            }
            transitions {
                splitScreenApp.launchViaIntent()
                setRotation(rotation)
                device.launchSplitScreen()
            }
            assertions {
                layersTrace {
                    navBarLayerRotatesAndScales(Surface.ROTATION_0, rotation, 169271943)
                    statusBarLayerRotatesScales(Surface.ROTATION_0, rotation, 169271943)
                    dockedStackDividerIsVisible()
                    dockedStackPrimaryBoundsIsVisible(
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                }
                windowManagerTrace {
                    navBarWindowIsAlwaysVisible()
                    statusBarWindowIsAlwaysVisible()
                    end {
                        showsAppWindow(splitScreenApp.defaultWindowName)
                    }
                }
            }
        }
    }

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): Collection<Array<Any>> {
            val supportedRotations = intArrayOf(Surface.ROTATION_90, Surface.ROTATION_270)
            return supportedRotations.map { arrayOf(Surface.rotationToString(it), it) }
        }
    }
}
 No newline at end of file
+157 −0
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.splitscreen

import android.view.Surface
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.exitSplitScreen
import com.android.server.wm.flicker.helpers.isInSplitScreen
import com.android.server.wm.flicker.helpers.launchSplitScreen
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.server.wm.flicker.navBarLayerRotatesAndScales
import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerRotatesScales
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.wm.shell.flicker.dockedStackDividerIsVisible
import com.android.wm.shell.flicker.dockedStackPrimaryBoundsIsVisible
import com.android.wm.shell.flicker.dockedStackSecondaryBoundsIsVisible
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:RotateTwoLaunchedAppTest`
 */
@RequiresDevice
@RunWith(Parameterized::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class RotateTwoLaunchedAppTest(
    rotationName: String,
    rotation: Int
) : SplitScreenTestBase(rotationName, rotation) {
    private val splitScreenRotationSetup: FlickerBuilder
        get() = FlickerBuilder(instrumentation).apply {
            val testSetupRotation = "testSetupRotation"
            withTestName {
                testSetupRotation
            }
            setup {
                test {
                    device.wakeUpAndGoToHomeScreen()
                }
            }
            teardown {
                eachRun {
                    if (uiDevice.isInSplitScreen()) {
                        uiDevice.exitSplitScreen()
                    }
                    setRotation(Surface.ROTATION_0)
                    splitScreenApp.exit()
                    secondaryApp.exit()
                }
            }
        }

    @Test
    fun testRotateInSplitScreenMode() {
        val testTag = "testRotateInSplitScreenMode"
        runWithFlicker(splitScreenRotationSetup) {
            withTestName { testTag }
            repeat {
                SplitScreenHelper.TEST_REPETITIONS
            }
            transitions {
                secondaryApp.launchViaIntent()
                splitScreenApp.launchViaIntent()
                device.launchSplitScreen()
                splitScreenApp.reopenAppFromOverview()
                setRotation(rotation)
            }
            assertions {
                layersTrace {
                    navBarLayerRotatesAndScales(Surface.ROTATION_0, rotation, 169271943)
                    statusBarLayerRotatesScales(Surface.ROTATION_0, rotation, 169271943)
                    dockedStackDividerIsVisible()
                    dockedStackPrimaryBoundsIsVisible(
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                    dockedStackSecondaryBoundsIsVisible(
                            rotation, secondaryApp.defaultWindowName, 169271943)
                }
                windowManagerTrace {
                    navBarWindowIsAlwaysVisible()
                    statusBarWindowIsAlwaysVisible()
                    end {
                        showsAppWindow(splitScreenApp.defaultWindowName)
                                .and().showsAppWindow(secondaryApp.defaultWindowName)
                    }
                }
            }
        }
    }

    @Test
    fun testRotateAndEnterSplitScreenMode() {
        val testTag = "testRotateAndEnterSplitScreenMode"
        runWithFlicker(splitScreenRotationSetup) {
            withTestName { testTag }
            repeat {
                SplitScreenHelper.TEST_REPETITIONS
            }
            transitions {
                secondaryApp.launchViaIntent()
                splitScreenApp.launchViaIntent()
                setRotation(rotation)
                device.launchSplitScreen()
                splitScreenApp.reopenAppFromOverview()
            }
            assertions {
                layersTrace {
                    navBarLayerRotatesAndScales(Surface.ROTATION_0, rotation, 169271943)
                    statusBarLayerRotatesScales(Surface.ROTATION_0, rotation, 169271943)
                    dockedStackDividerIsVisible()
                    dockedStackPrimaryBoundsIsVisible(
                            rotation, splitScreenApp.defaultWindowName, 169271943)
                    dockedStackSecondaryBoundsIsVisible(
                            rotation, secondaryApp.defaultWindowName, 169271943)
                }
                windowManagerTrace {
                    navBarWindowIsAlwaysVisible()
                    statusBarWindowIsAlwaysVisible()
                    end {
                        showsAppWindow(splitScreenApp.defaultWindowName)
                                .and().showsAppWindow(secondaryApp.defaultWindowName)
                    }
                }
            }
        }
    }

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