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.app.Activity 20 import android.platform.test.annotations.FlakyTest 21 import android.platform.test.annotations.Postsubmit 22 import android.platform.test.annotations.Presubmit 23 import android.platform.test.annotations.RequiresDevice 24 import android.platform.test.annotations.RequiresFlagsDisabled 25 import android.tools.Rotation 26 import android.tools.flicker.assertions.FlickerTest 27 import android.tools.flicker.junit.FlickerParametersRunnerFactory 28 import android.tools.flicker.legacy.FlickerBuilder 29 import android.tools.flicker.legacy.LegacyFlickerTest 30 import android.tools.flicker.legacy.LegacyFlickerTestFactory 31 import android.tools.helpers.WindowUtils 32 import com.android.server.wm.flicker.testapp.ActivityOptions 33 import com.android.server.wm.flicker.testapp.ActivityOptions.PortraitOnlyActivity.EXTRA_FIXED_ORIENTATION 34 import com.android.wm.shell.Flags 35 import com.android.wm.shell.flicker.pip.common.PipTransition 36 import com.android.wm.shell.flicker.pip.common.PipTransition.BroadcastActionTrigger.Companion.ORIENTATION_LANDSCAPE 37 import org.junit.Assume 38 import org.junit.Before 39 import org.junit.FixMethodOrder 40 import org.junit.Test 41 import org.junit.runner.RunWith 42 import org.junit.runners.MethodSorters 43 import org.junit.runners.Parameterized 44 45 /** 46 * Test exiting Pip with orientation changes. To run this test: 47 * `atest WMShellFlickerTestsPip1:SetRequestedOrientationWhilePinned` 48 */ 49 @RequiresDevice 50 @RunWith(Parameterized::class) 51 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) 52 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 53 @RequiresFlagsDisabled(Flags.FLAG_ENABLE_PIP2) 54 open class SetRequestedOrientationWhilePinned(flicker: LegacyFlickerTest) : PipTransition(flicker) { 55 private val startingBounds = WindowUtils.getDisplayBounds(Rotation.ROTATION_0) 56 private val endingBounds = WindowUtils.getDisplayBounds(Rotation.ROTATION_90) 57 <lambda>null58 override val thisTransition: FlickerBuilder.() -> Unit = { 59 transitions { 60 // Launch the activity back into fullscreen and ensure that it is now in landscape 61 pipApp.launchViaIntent(wmHelper) 62 // System bar may fade out during fixed rotation. 63 wmHelper 64 .StateSyncBuilder() 65 .withFullScreenApp(pipApp) 66 .withRotation(Rotation.ROTATION_90) 67 .withNavOrTaskBarVisible() 68 .withStatusBarVisible() 69 .waitForAndVerify() 70 } 71 } 72 <lambda>null73 override val defaultEnterPip: FlickerBuilder.() -> Unit = { 74 setup { 75 // Launch the PiP activity fixed as landscape. 76 pipApp.launchViaIntent( 77 wmHelper, 78 stringExtras = mapOf(EXTRA_FIXED_ORIENTATION to ORIENTATION_LANDSCAPE.toString()) 79 ) 80 // Enter PiP. 81 broadcastActionTrigger.doAction(ActivityOptions.Pip.ACTION_ENTER_PIP) 82 // System bar may fade out during fixed rotation. 83 wmHelper 84 .StateSyncBuilder() 85 .withPipShown() 86 .withRotation(Rotation.ROTATION_0) 87 .withNavOrTaskBarVisible() 88 .withStatusBarVisible() 89 .waitForAndVerify() 90 } 91 } 92 93 /** 94 * This test is not compatible with Tablets. When using [Activity.setRequestedOrientation] to 95 * fix a orientation, Tablets instead keep the same orientation and add letterboxes 96 */ 97 @Before setupnull98 fun setup() { 99 Assume.assumeFalse(tapl.isTablet) 100 } 101 102 @Presubmit 103 @Test displayEndsAt90Degreesnull104 fun displayEndsAt90Degrees() { 105 flicker.assertWmEnd { hasRotation(Rotation.ROTATION_90) } 106 } 107 108 @Presubmit 109 @Test pipWindowInsideDisplaynull110 fun pipWindowInsideDisplay() { 111 flicker.assertWmStart { visibleRegion(pipApp).coversAtMost(startingBounds) } 112 } 113 114 @Presubmit 115 @Test pipAppShowsOnTopnull116 fun pipAppShowsOnTop() { 117 flicker.assertWmEnd { isAppWindowOnTop(pipApp) } 118 } 119 120 @Presubmit 121 @Test pipLayerInsideDisplaynull122 fun pipLayerInsideDisplay() { 123 flicker.assertLayersStart { visibleRegion(pipApp).coversAtMost(startingBounds) } 124 } 125 126 @Presubmit 127 @Test pipAlwaysVisiblenull128 fun pipAlwaysVisible() { 129 flicker.assertWm { this.isAppWindowVisible(pipApp) } 130 } 131 132 @Presubmit 133 @Test pipAppLayerCoversFullScreennull134 fun pipAppLayerCoversFullScreen() { 135 flicker.assertLayersEnd { visibleRegion(pipApp).coversExactly(endingBounds) } 136 } 137 138 /** {@inheritDoc} */ 139 @Postsubmit 140 @Test taskBarLayerIsVisibleAtStartAndEndnull141 override fun taskBarLayerIsVisibleAtStartAndEnd() = super.taskBarLayerIsVisibleAtStartAndEnd() 142 143 /** {@inheritDoc} */ 144 @Postsubmit 145 @Test 146 override fun taskBarWindowIsAlwaysVisible() = super.taskBarWindowIsAlwaysVisible() 147 148 /** {@inheritDoc} */ 149 @FlakyTest(bugId = 264243884) 150 @Test 151 override fun entireScreenCovered() = super.entireScreenCovered() 152 153 @Postsubmit 154 @Test 155 override fun pipLayerHasCorrectCornersAtEnd() { 156 flicker.assertLayersEnd { hasNoRoundedCorners(pipApp) } 157 } 158 159 companion object { 160 @Parameterized.Parameters(name = "{0}") 161 @JvmStatic getParamsnull162 fun getParams(): Collection<FlickerTest> { 163 return LegacyFlickerTestFactory.nonRotationTests( 164 supportedRotations = listOf(Rotation.ROTATION_0) 165 ) 166 } 167 } 168 } 169