Merge "6-2/ Integrate AppPairs flicker rotation tests"

This commit is contained in:
Bill Lin
2020-12-24 03:13:41 +00:00
committed by Android (Google) Code Review
5 changed files with 277 additions and 64 deletions

View File

@@ -17,10 +17,11 @@
package com.android.wm.shell.flicker
import android.graphics.Region
import com.android.server.wm.flicker.DOCKED_STACK_DIVIDER
import android.view.Surface
import com.android.server.wm.flicker.dsl.EventLogAssertion
import com.android.server.wm.flicker.dsl.LayersAssertion
import com.android.server.wm.flicker.helpers.WindowUtils
import com.android.wm.shell.flicker.FlickerTestBase.Companion.DOCKED_STACK_DIVIDER
@JvmOverloads
fun LayersAssertion.appPairsDividerIsVisible(
@@ -86,6 +87,36 @@ fun LayersAssertion.dockedStackDividerIsInvisible(
}
}
@JvmOverloads
fun LayersAssertion.appPairsPrimaryBoundsIsVisible(
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.SPLIT_DIVIDER)
this.hasVisibleRegion(primaryLayerName, getPrimaryRegion(dividerRegion, rotation))
}
}
@JvmOverloads
fun LayersAssertion.appPairsSecondaryBoundsIsVisible(
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.SPLIT_DIVIDER)
this.hasVisibleRegion(secondaryLayerName, getSecondaryRegion(dividerRegion, rotation))
}
}
@JvmOverloads
fun LayersAssertion.dockedStackPrimaryBoundsIsVisible(
rotation: Int,
@@ -118,16 +149,27 @@ fun LayersAssertion.dockedStackSecondaryBoundsIsVisible(
fun getPrimaryRegion(dividerRegion: Region, rotation: Int): Region {
val displayBounds = WindowUtils.getDisplayBounds(rotation)
return Region(0, 0, displayBounds.getBounds().right,
dividerRegion.getBounds().bottom - WindowUtils.dockedStackDividerInset)
return if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
Region(0, 0, displayBounds.getBounds().right,
dividerRegion.getBounds().bottom - WindowUtils.dockedStackDividerInset)
} else {
Region(0, 0, dividerRegion.getBounds().left,
dividerRegion.getBounds().right - 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)
return if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
Region(0,
dividerRegion.getBounds().bottom - WindowUtils.dockedStackDividerInset,
displayBounds.getBounds().right,
displayBounds.getBounds().bottom - WindowUtils.dockedStackDividerInset)
} else {
Region(dividerRegion.getBounds().right, 0,
displayBounds.getBounds().right,
displayBounds.getBounds().bottom - WindowUtils.dockedStackDividerInset)
}
}
fun EventLogAssertion.focusChanges(

View File

@@ -16,29 +16,26 @@
package com.android.wm.shell.flicker.apppairs
import android.platform.test.annotations.Presubmit
import android.os.SystemClock
import android.util.Log
import android.platform.test.annotations.Presubmit
import android.view.Surface
import androidx.test.filters.RequiresDevice
import com.android.compatibility.common.util.SystemUtil
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.dsl.runWithFlicker
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.wm.shell.flicker.helpers.AppPairsHelper
import com.android.wm.shell.flicker.helpers.AppPairsHelper.Companion.TEST_REPETITIONS
import com.android.wm.shell.flicker.appPairsDividerIsInvisible
import com.android.wm.shell.flicker.appPairsDividerIsVisible
import com.android.server.wm.flicker.navBarLayerIsAlwaysVisible
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.appPairsDividerIsInvisible
import com.android.wm.shell.flicker.appPairsDividerIsVisible
import com.android.wm.shell.flicker.helpers.AppPairsHelper
import com.android.wm.shell.flicker.helpers.AppPairsHelper.Companion.TEST_REPETITIONS
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized
import java.io.IOException
/**
* Test AppPairs launch.
@@ -64,15 +61,18 @@ class AppPairsTest(
primaryApp.launchViaIntent()
secondaryApp.launchViaIntent()
nonResizeableApp.launchViaIntent()
updateTaskId()
updateTasksId()
}
}
teardown {
eachRun {
executeShellCommand(composePairsCommand(
primaryTaskId, secondaryTaskId, false /* pair */))
executeShellCommand(composePairsCommand(
primaryTaskId, nonResizeableTaskId, false /* pair */))
primaryApp.exit()
secondaryApp.exit()
nonResizeableApp.exit()
}
}
assertions {
@@ -184,12 +184,12 @@ class AppPairsTest(
TEST_REPETITIONS
}
transitions {
nonResizeableApp.launchViaIntent()
// TODO pair apps through normal UX flow
executeShellCommand(composePairsCommand(
primaryTaskId, nonResizeableTaskId, true /* pair */))
SystemClock.sleep(AppPairsHelper.TIMEOUT_MS)
}
assertions {
layersTrace {
appPairsDividerIsInvisible()
@@ -205,52 +205,23 @@ class AppPairsTest(
}
}
private fun composePairsCommand(
primaryApp: String,
secondaryApp: String,
pair: Boolean
): String = buildString {
// dumpsys activity service SystemUIService WMShell {pair|unpair} ${TASK_ID_1} ${TASK_ID_2}
append("dumpsys activity service SystemUIService WMShell ")
if (pair) {
append("pair ")
} else {
append("unpair ")
}
append(primaryApp + " " + secondaryApp)
}
private fun executeShellCommand(cmd: String) {
try {
SystemUtil.runShellCommand(instrumentation, cmd)
} catch (e: IOException) {
Log.d("AppPairsTest", "executeShellCommand error!" + e)
}
}
private fun updateTaskId() {
val primaryAppComponent = primaryApp.openAppIntent.component
val secondaryAppComponent = secondaryApp.openAppIntent.component
val nonResizeableAppComponent = nonResizeableApp.openAppIntent.component
fun updateTasksId() {
if (primaryAppComponent != null) {
primaryTaskId = appPairsHelper.getTaskIdForActivity(
primaryTaskId = getTaskIdForActivity(
primaryAppComponent.packageName, primaryAppComponent.className).toString()
}
if (secondaryAppComponent != null) {
secondaryTaskId = appPairsHelper.getTaskIdForActivity(
secondaryTaskId = getTaskIdForActivity(
secondaryAppComponent.packageName, secondaryAppComponent.className).toString()
}
if (nonResizeableAppComponent != null) {
nonResizeableTaskId = appPairsHelper.getTaskIdForActivity(
nonResizeableAppComponent.packageName,
nonResizeableAppComponent.className).toString()
nonResizeableTaskId = getTaskIdForActivity(
nonResizeableAppComponent.packageName,
nonResizeableAppComponent.className).toString()
}
}
companion object {
var primaryTaskId = ""
var secondaryTaskId = ""
var nonResizeableTaskId = ""
@Parameterized.Parameters(name = "{0}")
@JvmStatic
fun getParams(): Collection<Array<Any>> {

View File

@@ -16,6 +16,9 @@
package com.android.wm.shell.flicker.apppairs
import android.system.helpers.ActivityHelper
import android.util.Log
import com.android.compatibility.common.util.SystemUtil
import com.android.wm.shell.flicker.NonRotationTestBase
import com.android.wm.shell.flicker.TEST_APP_NONRESIZEABLE_LABEL
import com.android.wm.shell.flicker.TEST_APP_SPLITSCREEN_PRIMARY_LABEL
@@ -23,21 +26,59 @@ import com.android.wm.shell.flicker.TEST_APP_SPLITSCREEN_SECONDARY_LABEL
import com.android.wm.shell.flicker.helpers.AppPairsHelper
import com.android.wm.shell.flicker.helpers.SplitScreenHelper
import com.android.wm.shell.flicker.testapp.Components
import java.io.IOException
abstract class AppPairsTestBase(
rotationName: String,
rotation: Int
) : NonRotationTestBase(rotationName, rotation) {
protected val appPairsHelper = AppPairsHelper(instrumentation,
val activityHelper = ActivityHelper.getInstance()
val appPairsHelper = AppPairsHelper(instrumentation,
TEST_APP_SPLITSCREEN_PRIMARY_LABEL,
Components.SplitScreenActivity())
protected val primaryApp = SplitScreenHelper(instrumentation,
val primaryApp = SplitScreenHelper(instrumentation,
TEST_APP_SPLITSCREEN_PRIMARY_LABEL,
Components.SplitScreenActivity())
protected val secondaryApp = SplitScreenHelper(instrumentation,
val secondaryApp = SplitScreenHelper(instrumentation,
TEST_APP_SPLITSCREEN_SECONDARY_LABEL,
Components.SplitScreenSecondaryActivity())
protected val nonResizeableApp = SplitScreenHelper(instrumentation,
val nonResizeableApp = SplitScreenHelper(instrumentation,
TEST_APP_NONRESIZEABLE_LABEL,
Components.NonResizeableActivity())
val primaryAppComponent = primaryApp.openAppIntent.component
val secondaryAppComponent = secondaryApp.openAppIntent.component
val nonResizeableAppComponent = nonResizeableApp.openAppIntent.component
var primaryTaskId = ""
var secondaryTaskId = ""
var nonResizeableTaskId = ""
fun composePairsCommand(
primaryApp: String,
secondaryApp: String,
pair: Boolean
): String = buildString {
// dumpsys activity service SystemUIService WMShell {pair|unpair} ${TASK_ID_1} ${TASK_ID_2}
append("dumpsys activity service SystemUIService WMShell ")
if (pair) {
append("pair ")
} else {
append("unpair ")
}
append(primaryApp + " " + secondaryApp)
}
fun executeShellCommand(cmd: String) {
try {
SystemUtil.runShellCommand(instrumentation, cmd)
} catch (e: IOException) {
Log.d("AppPairsTest", "executeShellCommand error!" + e)
}
}
fun getTaskIdForActivity(pkgName: String, activityName: String): Int {
return activityHelper.getTaskIdForActivity(pkgName, activityName)
}
}

View File

@@ -0,0 +1,166 @@
/*
* 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.apppairs
import android.os.SystemClock
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.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.appPairsDividerIsVisible
import com.android.wm.shell.flicker.appPairsPrimaryBoundsIsVisible
import com.android.wm.shell.flicker.appPairsSecondaryBoundsIsVisible
import com.android.wm.shell.flicker.helpers.AppPairsHelper
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 apps to app pairs and rotate.
* To run this test: `atest WMShellFlickerTests:RotateTwoLaunchedAppTest`
*/
@RequiresDevice
@RunWith(Parameterized::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class RotateTwoLaunchedAppTest(
rotationName: String,
rotation: Int
) : AppPairsTestBase(rotationName, rotation) {
private val appPairsRotationSetup: FlickerBuilder
get() = FlickerBuilder(instrumentation).apply {
val testSetupRotation = "testSetupRotation"
withTestName {
testSetupRotation
}
setup {
test {
uiDevice.wakeUpAndGoToHomeScreen()
primaryApp.launchViaIntent()
secondaryApp.launchViaIntent()
updateTasksId()
}
}
teardown {
eachRun {
executeShellCommand(composePairsCommand(
primaryTaskId, secondaryTaskId, false /* pair */))
primaryApp.exit()
secondaryApp.exit()
}
}
}
@Test
fun testRotateInAppPairsMode() {
val testTag = "testRotateInAppPairsMode"
runWithFlicker(appPairsRotationSetup) {
withTestName { testTag }
repeat {
SplitScreenHelper.TEST_REPETITIONS
}
transitions {
executeShellCommand(composePairsCommand(
primaryTaskId, secondaryTaskId, true /* pair */))
SystemClock.sleep(AppPairsHelper.TIMEOUT_MS)
setRotation(rotation)
}
assertions {
layersTrace {
navBarLayerRotatesAndScales(Surface.ROTATION_0, rotation)
statusBarLayerRotatesScales(Surface.ROTATION_0, rotation)
appPairsDividerIsVisible()
appPairsPrimaryBoundsIsVisible(
rotation, primaryApp.defaultWindowName, 172776659)
appPairsSecondaryBoundsIsVisible(
rotation, secondaryApp.defaultWindowName, 172776659)
}
windowManagerTrace {
navBarWindowIsAlwaysVisible()
statusBarWindowIsAlwaysVisible()
end {
showsAppWindow(primaryApp.defaultWindowName)
.and().showsAppWindow(secondaryApp.defaultWindowName)
}
}
}
}
}
@Test
fun testRotateAndEnterAppPairsMode() {
val testTag = "testRotateAndEnterAppPairsMode"
runWithFlicker(appPairsRotationSetup) {
withTestName { testTag }
repeat {
SplitScreenHelper.TEST_REPETITIONS
}
transitions {
setRotation(rotation)
executeShellCommand(composePairsCommand(
primaryTaskId, secondaryTaskId, true /* pair */))
SystemClock.sleep(AppPairsHelper.TIMEOUT_MS)
}
assertions {
layersTrace {
navBarLayerRotatesAndScales(Surface.ROTATION_0, rotation)
statusBarLayerRotatesScales(Surface.ROTATION_0, rotation)
appPairsDividerIsVisible()
appPairsPrimaryBoundsIsVisible(
rotation, primaryApp.defaultWindowName, 172776659)
appPairsSecondaryBoundsIsVisible(
rotation, secondaryApp.defaultWindowName, 172776659)
}
windowManagerTrace {
navBarWindowIsAlwaysVisible()
statusBarWindowIsAlwaysVisible()
end {
showsAppWindow(primaryApp.defaultWindowName)
.and().showsAppWindow(secondaryApp.defaultWindowName)
}
}
}
}
}
fun updateTasksId() {
if (primaryAppComponent != null) {
primaryTaskId = getTaskIdForActivity(
primaryAppComponent.packageName, primaryAppComponent.className).toString()
}
if (secondaryAppComponent != null) {
secondaryTaskId = getTaskIdForActivity(
secondaryAppComponent.packageName, secondaryAppComponent.className).toString()
}
}
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) }
}
}
}

View File

@@ -18,7 +18,6 @@ package com.android.wm.shell.flicker.helpers
import android.app.Instrumentation
import android.graphics.Region
import android.system.helpers.ActivityHelper
import com.android.server.wm.flicker.helpers.WindowUtils
import com.android.wm.shell.flicker.testapp.Components
@@ -31,8 +30,6 @@ class AppPairsHelper(
activityLabel,
componentsInfo
) {
val activityHelper = ActivityHelper.getInstance()
fun getPrimaryBounds(dividerBounds: Region): android.graphics.Region {
val primaryAppBounds = Region(0, 0, dividerBounds.bounds.right,
dividerBounds.bounds.bottom + WindowUtils.dockedStackDividerInset)
@@ -47,10 +44,6 @@ class AppPairsHelper(
return secondaryAppBounds
}
fun getTaskIdForActivity(pkgName: String, activityName: String): Int {
return activityHelper.getTaskIdForActivity(pkgName, activityName)
}
companion object {
const val TEST_REPETITIONS = 1
const val TIMEOUT_MS = 3_000L