1 /* 2 * Copyright (C) 2022 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.FlakyTest 20 import android.platform.test.annotations.Presubmit 21 import android.platform.test.annotations.RequiresDevice 22 import android.platform.test.annotations.RequiresFlagsDisabled 23 import android.tools.Rotation 24 import android.tools.flicker.junit.FlickerParametersRunnerFactory 25 import android.tools.flicker.legacy.FlickerBuilder 26 import android.tools.flicker.legacy.LegacyFlickerTest 27 import android.tools.flicker.legacy.LegacyFlickerTestFactory 28 import android.tools.helpers.WindowUtils 29 import android.tools.traces.parsers.toFlickerComponent 30 import com.android.server.wm.flicker.helpers.SimpleAppHelper 31 import com.android.server.wm.flicker.testapp.ActivityOptions 32 import com.android.wm.shell.Flags 33 import com.android.wm.shell.flicker.utils.SplitScreenUtils 34 import org.junit.Assume 35 import org.junit.FixMethodOrder 36 import org.junit.Test 37 import org.junit.runner.RunWith 38 import org.junit.runners.MethodSorters 39 import org.junit.runners.Parameterized 40 41 /** 42 * Test entering pip from an app via auto-enter property when navigating to home from split screen. 43 * 44 * To run this test: `atest WMShellFlickerTestsPip:FromSplitScreenAutoEnterPipOnGoToHomeTest` 45 * 46 * Actions: 47 * ``` 48 * Launch an app in full screen 49 * Select "Auto-enter PiP" radio button 50 * Open all apps and drag another app icon to enter split screen 51 * Press Home button or swipe up to go Home and put [pipApp] in pip mode 52 * ``` 53 * 54 * Notes: 55 * ``` 56 * 1. All assertions are inherited from [EnterPipTest] 57 * 2. Part of the test setup occurs automatically via 58 * [android.tools.flicker.legacy.runner.TransitionRunner], 59 * including configuring navigation mode, initial orientation and ensuring no 60 * apps are running before setup 61 * ``` 62 */ 63 @RequiresDevice 64 @RunWith(Parameterized::class) 65 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) 66 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 67 @RequiresFlagsDisabled(Flags.FLAG_ENABLE_PIP2) 68 class FromSplitScreenAutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : 69 AutoEnterPipOnGoToHomeTest(flicker) { 70 private val portraitDisplayBounds = WindowUtils.getDisplayBounds(Rotation.ROTATION_0) 71 /** Second app used to enter split screen mode */ 72 private val secondAppForSplitScreen = 73 SimpleAppHelper( 74 instrumentation, 75 ActivityOptions.SplitScreen.Primary.LABEL, 76 ActivityOptions.SplitScreen.Primary.COMPONENT.toFlickerComponent() 77 ) 78 79 /** Defines the transition used to run the test */ 80 override val transition: FlickerBuilder.() -> Unit <lambda>null81 get() = { 82 setup { 83 secondAppForSplitScreen.launchViaIntent(wmHelper) 84 pipApp.launchViaIntent(wmHelper) 85 tapl.goHome() 86 SplitScreenUtils.enterSplit( 87 wmHelper, 88 tapl, 89 device, 90 pipApp, 91 secondAppForSplitScreen, 92 flicker.scenario.startRotation 93 ) 94 pipApp.enableAutoEnterForPipActivity() 95 } 96 teardown { 97 pipApp.exit(wmHelper) 98 secondAppForSplitScreen.exit(wmHelper) 99 } 100 transitions { tapl.goHome() } 101 } 102 103 @Presubmit 104 @Test pipOverlayLayerAppearThenDisappearnull105 override fun pipOverlayLayerAppearThenDisappear() { 106 // when entering from split screen we use alpha animation, without overlay 107 } 108 109 @Presubmit 110 @Test pipLayerOrOverlayRemainInsideVisibleBoundsnull111 override fun pipLayerOrOverlayRemainInsideVisibleBounds() { 112 // when entering from split screen we use alpha animation, without overlay 113 } 114 115 @Presubmit 116 @Test pipLayerReducesnull117 override fun pipLayerReduces() { 118 // when entering from split screen we use alpha animation, so there is no size change 119 Assume.assumeFalse(flicker.scenario.isGesturalNavigation) 120 super.pipLayerReduces() 121 } 122 123 @Presubmit 124 @Test pipAppLayerAlwaysVisiblenull125 override fun pipAppLayerAlwaysVisible() { 126 // pip layer in should disappear during transition with alpha animation 127 } 128 129 @Presubmit 130 @Test pipWindowRemainInsideVisibleBoundsnull131 override fun pipWindowRemainInsideVisibleBounds() { 132 if (tapl.isTablet) { 133 flicker.assertWmVisibleRegion(pipApp) { coversAtMost(displayBounds) } 134 } else { 135 // on phones home screen does not rotate in landscape, PiP enters back to portrait 136 // orientation - if we go from landscape to portrait it should switch between the bounds 137 // otherwise it should be the same as tablet (i.e. portrait to portrait) 138 if (flicker.scenario.isLandscapeOrSeascapeAtStart) { 139 flicker.assertWmVisibleRegion(pipApp) { 140 // first check against landscape bounds then against portrait bounds 141 coversAtMost(displayBounds).then().coversAtMost(portraitDisplayBounds) 142 } 143 } else { 144 // always check against the display bounds which do not change during transition 145 flicker.assertWmVisibleRegion(pipApp) { coversAtMost(displayBounds) } 146 } 147 } 148 } 149 150 @FlakyTest(bugId = 293133362) 151 @Test entireScreenCoverednull152 override fun entireScreenCovered() = super.entireScreenCovered() 153 154 companion object { 155 @Parameterized.Parameters(name = "{0}") 156 @JvmStatic 157 fun getParams() = 158 LegacyFlickerTestFactory.nonRotationTests( 159 supportedRotations = listOf(Rotation.ROTATION_0) 160 ) 161 } 162 } 163