Create base test class with general assertions

Also, move common pip tv test class to tv package

Bug: 234735502
Test: atest FlickerTests
Change-Id: Id3219cf44cb9a117efc5408afd957841b1ad76ed
This commit is contained in:
Nataniel Borges
2022-07-10 17:08:11 +00:00
parent e172dbcc45
commit e5b727ad38
4 changed files with 175 additions and 59 deletions

View File

@@ -0,0 +1,161 @@
/*
* Copyright (C) 2022 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
import android.app.Instrumentation
import androidx.test.platform.app.InstrumentationRegistry
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.entireScreenCovered
import com.android.server.wm.flicker.navBarLayerIsVisibleAtStartAndEnd
import com.android.server.wm.flicker.navBarLayerPositionAtStartAndEnd
import com.android.server.wm.flicker.navBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.statusBarLayerIsVisibleAtStartAndEnd
import com.android.server.wm.flicker.statusBarLayerPositionAtStartAndEnd
import com.android.server.wm.flicker.statusBarWindowIsAlwaysVisible
import com.android.server.wm.flicker.taskBarLayerIsVisibleAtStartAndEnd
import com.android.server.wm.flicker.taskBarWindowIsAlwaysVisible
import com.android.server.wm.traces.common.ComponentMatcher
import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper
import org.junit.Assume
/**
* Base test class containing common assertions for [ComponentMatcher.NAV_BAR],
* [ComponentMatcher.TASK_BAR], [ComponentMatcher.STATUS_BAR], and general assertions
* (layers visible in consecutive states, entire screen covered, etc.)
*/
abstract class BaseTest @JvmOverloads constructor(
protected val testSpec: FlickerTestParameter,
protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation(),
protected val tapl: LauncherInstrumentation = LauncherInstrumentation()
) {
init {
testSpec.setIsTablet(
WindowManagerStateHelper(instrumentation).currentState.wmState.isTablet
)
}
/**
* Specification of the test transition to execute
*/
abstract val transition: FlickerBuilder.() -> Unit
/**
* Entry point for the test runner. It will use this method to initialize and cache
* flicker executions
*/
@FlickerBuilderProvider
fun buildFlicker(): FlickerBuilder {
return FlickerBuilder(instrumentation).apply {
setup {
test {
testSpec.setIsTablet(wmHelper.currentState.wmState.isTablet)
}
}
transition()
}
}
/**
* Checks that all parts of the screen are covered during the transition
*/
open fun entireScreenCovered() = testSpec.entireScreenCovered()
/**
* Checks that the [ComponentMatcher.NAV_BAR] layer is visible during the whole transition
*/
open fun navBarLayerIsVisibleAtStartAndEnd() {
Assume.assumeFalse(testSpec.isTablet)
testSpec.navBarLayerIsVisibleAtStartAndEnd()
}
/**
* Checks the position of the [ComponentMatcher.NAV_BAR] at the start and end of the transition
*/
open fun navBarLayerPositionAtStartAndEnd() {
Assume.assumeFalse(testSpec.isTablet)
testSpec.navBarLayerPositionAtStartAndEnd()
}
/**
* Checks that the [ComponentMatcher.NAV_BAR] window is visible during the whole transition
*
* Note: Phones only
*/
open fun navBarWindowIsAlwaysVisible() {
Assume.assumeFalse(testSpec.isTablet)
testSpec.navBarWindowIsAlwaysVisible()
}
/**
* Checks that the [ComponentMatcher.TASK_BAR] layer is visible during the whole transition
*/
open fun taskBarLayerIsVisibleAtStartAndEnd() {
Assume.assumeTrue(testSpec.isTablet)
testSpec.taskBarLayerIsVisibleAtStartAndEnd()
}
/**
* Checks that the [ComponentMatcher.TASK_BAR] window is visible during the whole transition
*
* Note: Large screen only
*/
open fun taskBarWindowIsAlwaysVisible() {
Assume.assumeTrue(testSpec.isTablet)
testSpec.taskBarWindowIsAlwaysVisible()
}
/**
* Checks that the [ComponentMatcher.STATUS_BAR] layer is visible during the whole transition
*/
open fun statusBarLayerIsVisibleAtStartAndEnd() =
testSpec.statusBarLayerIsVisibleAtStartAndEnd()
/**
* Checks the position of the [ComponentMatcher.STATUS_BAR] at the start and end of the transition
*/
open fun statusBarLayerPositionAtStartAndEnd() = testSpec.statusBarLayerPositionAtStartAndEnd()
/**
* Checks that the [ComponentMatcher.STATUS_BAR] window is visible during the whole transition
*/
open fun statusBarWindowIsAlwaysVisible() {
testSpec.statusBarWindowIsAlwaysVisible()
}
/**
* Checks that all layers that are visible on the trace, are visible for at least 2
* consecutive entries.
*/
open fun visibleLayersShownMoreThanOneConsecutiveEntry() {
testSpec.assertLayers {
this.visibleLayersShownMoreThanOneConsecutiveEntry()
}
}
/**
* Checks that all windows that are visible on the trace, are visible for at least 2
* consecutive entries.
*/
open fun visibleWindowsShownMoreThanOneConsecutiveEntry() {
testSpec.assertWm {
this.visibleWindowsShownMoreThanOneConsecutiveEntry()
}
}
}

View File

@@ -1,37 +0,0 @@
/*
* 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.pip
import com.android.wm.shell.flicker.FlickerTestBase
import com.android.wm.shell.flicker.helpers.PipAppHelper
import org.junit.Before
abstract class PipTestBase(
rotationName: String,
rotation: Int
) : FlickerTestBase(rotationName, rotation) {
protected val testApp = PipAppHelper(instrumentation)
@Before
override fun televisionSetUp() {
/**
* The super implementation assumes ([org.junit.Assume]) that not running on TV, thus
* disabling the test on TV. This test, however, *should run on TV*, so we overriding this
* method and simply leaving it blank.
*/
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 The Android Open Source Project
* Copyright (C) 2022 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.
@@ -14,29 +14,18 @@
* limitations under the License.
*/
package com.android.wm.shell.flicker
package com.android.wm.shell.flicker.pip.tv
import android.app.Instrumentation
import android.content.pm.PackageManager
import android.content.pm.PackageManager.FEATURE_LEANBACK
import android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY
import android.view.Surface
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.junit.Assume.assumeFalse
import com.android.wm.shell.flicker.helpers.PipAppHelper
import org.junit.Before
import org.junit.runners.Parameterized
/**
* Base class of all Flicker test that performs common functions for all flicker tests:
*
* - Caches transitions so that a transition is run once and the transition results are used by
* tests multiple times. This is needed for parameterized tests which call the BeforeClass methods
* multiple times.
* - Keeps track of all test artifacts and deletes ones which do not need to be reviewed.
* - Fails tests if results are not available for any test due to jank.
*/
abstract class FlickerTestBase(
abstract class PipTestBase(
protected val rotationName: String,
protected val rotation: Int
) {
@@ -45,16 +34,20 @@ abstract class FlickerTestBase(
val packageManager: PackageManager = instrumentation.context.packageManager
protected val isTelevision: Boolean by lazy {
packageManager.run {
hasSystemFeature(FEATURE_LEANBACK) || hasSystemFeature(FEATURE_LEANBACK_ONLY)
hasSystemFeature(PackageManager.FEATURE_LEANBACK) ||
hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY)
}
}
protected val testApp = PipAppHelper(instrumentation)
/**
* By default WmShellFlickerTests do not run on TV devices.
* If the test should run on TV - it should override this method.
*/
@Before
open fun televisionSetUp() = assumeFalse(isTelevision)
open fun televisionSetUp() {
/**
* The super implementation assumes ([org.junit.Assume]) that not running on TV, thus
* disabling the test on TV. This test, however, *should run on TV*, so we overriding this
* method and simply leaving it blank.
*/
}
companion object {
@Parameterized.Parameters(name = "{0}")

View File

@@ -25,7 +25,6 @@ import android.view.Surface.rotationToString
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper
import com.android.wm.shell.flicker.SYSTEM_UI_PACKAGE_NAME
import com.android.wm.shell.flicker.pip.PipTestBase
import org.junit.After
import org.junit.Assert.assertFalse
import org.junit.Assume.assumeTrue