1 /* 2 * Copyright (C) 2020 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.wm.shell.flicker.pip 18 19 import android.platform.test.annotations.Presubmit 20 import android.platform.test.annotations.RequiresFlagsDisabled 21 import android.tools.flicker.assertions.FlickerTest 22 import android.tools.flicker.junit.FlickerParametersRunnerFactory 23 import android.tools.flicker.legacy.FlickerBuilder 24 import android.tools.flicker.legacy.LegacyFlickerTest 25 import android.tools.flicker.legacy.LegacyFlickerTestFactory 26 import android.tools.helpers.WindowUtils 27 import com.android.server.wm.flicker.helpers.SimpleAppHelper 28 import com.android.server.wm.flicker.helpers.setRotation 29 import com.android.wm.shell.Flags 30 import com.android.wm.shell.flicker.pip.common.PipTransition 31 import org.junit.FixMethodOrder 32 import org.junit.Test 33 import org.junit.runner.RunWith 34 import org.junit.runners.MethodSorters 35 import org.junit.runners.Parameterized 36 37 /** 38 * Test Pip Stack in bounds after rotations. 39 * 40 * To run this test: `atest WMShellFlickerTestsPip:ShowPipAndRotateDisplay` 41 * 42 * Actions: 43 * ``` 44 * Launch a [pipApp] in pip mode 45 * Launch another app [fixedApp] (appears below pip) 46 * Rotate the screen from [flicker.scenario.startRotation] to [flicker.scenario.endRotation] 47 * (usually, 0->90 and 90->0) 48 * ``` 49 * 50 * Notes: 51 * ``` 52 * 1. Some default assertions (e.g., nav bar, status bar and screen covered) 53 * are inherited from [PipTransition] 54 * 2. Part of the test setup occurs automatically via 55 * [android.tools.flicker.legacy.runner.TransitionRunner], 56 * including configuring navigation mode, initial orientation and ensuring no 57 * apps are running before setup 58 * ``` 59 */ 60 @RunWith(Parameterized::class) 61 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) 62 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 63 @RequiresFlagsDisabled(Flags.FLAG_ENABLE_PIP2) 64 class ShowPipAndRotateDisplay(flicker: LegacyFlickerTest) : PipTransition(flicker) { 65 private val testApp = SimpleAppHelper(instrumentation) 66 private val screenBoundsStart = WindowUtils.getDisplayBounds(flicker.scenario.startRotation) 67 private val screenBoundsEnd = WindowUtils.getDisplayBounds(flicker.scenario.endRotation) 68 <lambda>null69 override val thisTransition: FlickerBuilder.() -> Unit = { 70 setup { 71 testApp.launchViaIntent(wmHelper) 72 setRotation(flicker.scenario.startRotation) 73 } 74 transitions { setRotation(flicker.scenario.endRotation) } 75 } 76 77 /** Checks that [testApp] layer is within [screenBoundsStart] at the start of the transition */ 78 @Presubmit 79 @Test fixedAppLayer_StartingBoundsnull80 fun fixedAppLayer_StartingBounds() { 81 flicker.assertLayersStart { visibleRegion(testApp).coversAtMost(screenBoundsStart) } 82 } 83 84 /** Checks that [testApp] layer is within [screenBoundsEnd] at the end of the transition */ 85 @Presubmit 86 @Test fixedAppLayer_EndingBoundsnull87 fun fixedAppLayer_EndingBounds() { 88 flicker.assertLayersEnd { visibleRegion(testApp).coversAtMost(screenBoundsEnd) } 89 } 90 91 /** 92 * Checks that [testApp] plus [pipApp] layers are within [screenBoundsEnd] at the start of the 93 * transition 94 */ 95 @Presubmit 96 @Test appLayers_StartingBoundsnull97 fun appLayers_StartingBounds() { 98 flicker.assertLayersStart { 99 visibleRegion(testApp.or(pipApp)).coversExactly(screenBoundsStart) 100 } 101 } 102 103 /** 104 * Checks that [testApp] plus [pipApp] layers are within [screenBoundsEnd] at the end of the 105 * transition 106 */ 107 @Presubmit 108 @Test appLayers_EndingBoundsnull109 fun appLayers_EndingBounds() { 110 flicker.assertLayersEnd { visibleRegion(testApp.or(pipApp)).coversExactly(screenBoundsEnd) } 111 } 112 113 /** Checks that [pipApp] layer is within [screenBoundsStart] at the start of the transition */ pipLayerRotates_StartingBounds_internalnull114 private fun pipLayerRotates_StartingBounds_internal() { 115 flicker.assertLayersStart { visibleRegion(pipApp).coversAtMost(screenBoundsStart) } 116 } 117 118 /** Checks that [pipApp] layer is within [screenBoundsStart] at the start of the transition */ 119 @Presubmit 120 @Test pipLayerRotates_StartingBoundsnull121 fun pipLayerRotates_StartingBounds() { 122 pipLayerRotates_StartingBounds_internal() 123 } 124 125 /** Checks that [pipApp] layer is within [screenBoundsEnd] at the end of the transition */ 126 @Presubmit 127 @Test pipLayerRotates_EndingBoundsnull128 fun pipLayerRotates_EndingBounds() { 129 flicker.assertLayersEnd { visibleRegion(pipApp).coversAtMost(screenBoundsEnd) } 130 } 131 132 /** 133 * Ensure that the [pipApp] window does not obscure the [testApp] at the start of the transition 134 */ 135 @Presubmit 136 @Test pipIsAboveFixedAppWindow_Startnull137 fun pipIsAboveFixedAppWindow_Start() { 138 flicker.assertWmStart { isAboveWindow(pipApp, testApp) } 139 } 140 141 /** 142 * Ensure that the [pipApp] window does not obscure the [testApp] at the end of the transition 143 */ 144 @Presubmit 145 @Test pipIsAboveFixedAppWindow_Endnull146 fun pipIsAboveFixedAppWindow_End() { 147 flicker.assertWmEnd { isAboveWindow(pipApp, testApp) } 148 } 149 150 @Presubmit 151 @Test navBarLayerIsVisibleAtStartAndEndnull152 override fun navBarLayerIsVisibleAtStartAndEnd() { 153 super.navBarLayerIsVisibleAtStartAndEnd() 154 } 155 156 companion object { 157 /** 158 * Creates the test configurations. 159 * 160 * See [LegacyFlickerTestFactory.nonRotationTests] for configuring repetitions, screen 161 * orientation and navigation modes. 162 */ 163 @Parameterized.Parameters(name = "{0}") 164 @JvmStatic getParamsnull165 fun getParams(): Collection<FlickerTest> { 166 return LegacyFlickerTestFactory.rotationTests() 167 } 168 } 169 } 170