| 1 |
/* |
| 2 |
* Copyright (C) 2021 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package com.android.server.wm.flicker.rotation |
| 18 |
|
| 19 |
import android.app.Instrumentation |
| 20 |
import android.platform.test.annotations.Presubmit |
| 21 |
import androidx.test.platform.app.InstrumentationRegistry |
| 22 |
import com.android.server.wm.flicker.FlickerBuilderProvider |
| 23 |
import com.android.server.wm.flicker.FlickerTestParameter |
| 24 |
import com.android.server.wm.flicker.dsl.FlickerBuilder |
| 25 |
import com.android.server.wm.flicker.helpers.StandardAppHelper |
| 26 |
import com.android.server.wm.flicker.helpers.setRotation |
| 27 |
import com.android.server.wm.flicker.navBarLayerIsVisible |
| 28 |
import com.android.server.wm.flicker.navBarLayerRotatesAndScales |
| 29 |
import com.android.server.wm.flicker.navBarWindowIsVisible |
| 30 |
import com.android.server.wm.flicker.entireScreenCovered |
| 31 |
import com.android.server.wm.traces.common.FlickerComponentName |
| 32 |
import org.junit.Test |
| 33 |
|
| 34 |
/** |
| 35 |
* Base class for app rotation tests |
| 36 |
*/ |
| 37 |
abstract class RotationTransition(protected val testSpec: FlickerTestParameter) { |
| 38 |
protected abstract val testApp: StandardAppHelper |
| 39 |
|
| 40 |
protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() |
| 41 |
|
| 42 |
protected open val transition: FlickerBuilder.() -> Unit = { |
| 43 |
setup { |
| 44 |
eachRun { |
| 45 |
this.setRotation(testSpec.startRotation) |
| 46 |
} |
| 47 |
} |
| 48 |
teardown { |
| 49 |
test { |
| 50 |
testApp.exit() |
| 51 |
} |
| 52 |
} |
| 53 |
transitions { |
| 54 |
this.setRotation(testSpec.endRotation) |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Entry point for the test runner. It will use this method to initialize and cache |
| 60 |
* flicker executions |
| 61 |
*/ |
| 62 |
@FlickerBuilderProvider |
| 63 |
fun buildFlicker(): FlickerBuilder { |
| 64 |
return FlickerBuilder(instrumentation).apply { |
| 65 |
transition() |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Checks that the navigation bar window is visible and above the app windows in all WM |
| 71 |
* trace entries |
| 72 |
*/ |
| 73 |
@Presubmit |
| 74 |
@Test |
| 75 |
open fun navBarWindowIsVisible() { |
| 76 |
testSpec.navBarWindowIsVisible() |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Checks that the navigation bar layer is visible at the start and end of the transition |
| 81 |
*/ |
| 82 |
@Presubmit |
| 83 |
@Test |
| 84 |
open fun navBarLayerIsVisible() { |
| 85 |
testSpec.navBarLayerIsVisible() |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Checks the position of the navigation bar at the start and end of the transition |
| 90 |
*/ |
| 91 |
@Presubmit |
| 92 |
@Test |
| 93 |
open fun navBarLayerRotatesAndScales() = testSpec.navBarLayerRotatesAndScales() |
| 94 |
|
| 95 |
/** |
| 96 |
* Checks that all layers that are visible on the trace, are visible for at least 2 |
| 97 |
* consecutive entries. |
| 98 |
*/ |
| 99 |
@Presubmit |
| 100 |
@Test |
| 101 |
open fun visibleLayersShownMoreThanOneConsecutiveEntry() { |
| 102 |
testSpec.assertLayers { |
| 103 |
this.visibleLayersShownMoreThanOneConsecutiveEntry( |
| 104 |
ignoreLayers = listOf(FlickerComponentName.SPLASH_SCREEN, |
| 105 |
FlickerComponentName.SNAPSHOT, |
| 106 |
FlickerComponentName("", "SecondaryHomeHandle") |
| 107 |
) |
| 108 |
) |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Checks that all windows that are visible on the trace, are visible for at least 2 |
| 114 |
* consecutive entries. |
| 115 |
*/ |
| 116 |
@Presubmit |
| 117 |
@Test |
| 118 |
open fun visibleWindowsShownMoreThanOneConsecutiveEntry() { |
| 119 |
testSpec.assertWm { |
| 120 |
this.visibleWindowsShownMoreThanOneConsecutiveEntry() |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Checks that all parts of the screen are covered during the transition |
| 126 |
*/ |
| 127 |
@Presubmit |
| 128 |
@Test |
| 129 |
open fun entireScreenCovered() = testSpec.entireScreenCovered() |
| 130 |
|
| 131 |
/** |
| 132 |
* Checks that [testApp] layer covers the entire screen at the start of the transition |
| 133 |
*/ |
| 134 |
@Presubmit |
| 135 |
@Test |
| 136 |
open fun appLayerRotates_StartingPos() { |
| 137 |
testSpec.assertLayersStart { |
| 138 |
this.entry.displays.map { display -> |
| 139 |
this.visibleRegion(testApp.component).coversExactly(display.layerStackSpace) |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Checks that [testApp] layer covers the entire screen at the end of the transition |
| 146 |
*/ |
| 147 |
@Presubmit |
| 148 |
@Test |
| 149 |
open fun appLayerRotates_EndingPos() { |
| 150 |
testSpec.assertLayersEnd { |
| 151 |
this.entry.displays.map { display -> |
| 152 |
this.visibleRegion(testApp.component).coversExactly(display.layerStackSpace) |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
} |