1 /* <lambda>null2 * 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.Postsubmit 21 import android.platform.test.annotations.Presubmit 22 import android.platform.test.annotations.RequiresDevice 23 import android.platform.test.annotations.RequiresFlagsDisabled 24 import android.tools.flicker.junit.FlickerParametersRunnerFactory 25 import android.tools.flicker.legacy.FlickerBuilder 26 import android.tools.flicker.legacy.LegacyFlickerTest 27 import com.android.server.wm.flicker.helpers.PipAppHelper 28 import com.android.wm.shell.Flags 29 import com.android.wm.shell.flicker.pip.common.EnterPipTransition 30 import com.android.wm.shell.flicker.pip.common.widthNotSmallerThan 31 import org.junit.Assume 32 import org.junit.FixMethodOrder 33 import org.junit.Test 34 import org.junit.runner.RunWith 35 import org.junit.runners.MethodSorters 36 import org.junit.runners.Parameterized 37 38 /** 39 * Test entering pip from an app via auto-enter property when navigating to home. 40 * 41 * To run this test: `atest WMShellFlickerTestsPip:AutoEnterPipOnGoToHomeTest` 42 * 43 * Actions: 44 * ``` 45 * Launch an app in full screen 46 * Select "Auto-enter PiP" radio button 47 * Press Home button or swipe up to go Home and put [pipApp] in pip mode 48 * ``` 49 * 50 * Notes: 51 * ``` 52 * 1. All assertions are inherited from [EnterPipTest] 53 * 2. Part of the test setup occurs automatically via 54 * [android.tools.flicker.legacy.runner.TransitionRunner], 55 * including configuring navigation mode, initial orientation and ensuring no 56 * apps are running before setup 57 * ``` 58 */ 59 @RequiresDevice 60 @RunWith(Parameterized::class) 61 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) 62 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 63 @RequiresFlagsDisabled(Flags.FLAG_ENABLE_PIP2) 64 open class AutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : EnterPipTransition(flicker) { 65 override val pipApp: PipAppHelper = PipAppHelper(instrumentation) 66 67 override val thisTransition: FlickerBuilder.() -> Unit = { transitions { tapl.goHome() } } 68 69 override val defaultEnterPip: FlickerBuilder.() -> Unit = { 70 setup { 71 pipApp.launchViaIntent(wmHelper) 72 pipApp.enableAutoEnterForPipActivity() 73 } 74 } 75 76 @Postsubmit 77 @Test 78 override fun pipLayerReduces() { 79 Assume.assumeFalse(flicker.scenario.isGesturalNavigation) 80 flicker.assertLayers { 81 val pipLayerList = this.layers { pipApp.layerMatchesAnyOf(it) && it.isVisible } 82 pipLayerList.zipWithNext { previous, current -> 83 current.visibleRegion.notBiggerThan(previous.visibleRegion.region) 84 } 85 } 86 } 87 88 /** Checks that [pipApp] window's width is first decreasing then increasing. */ 89 @Postsubmit 90 @Test 91 fun pipLayerWidthDecreasesThenIncreases() { 92 Assume.assumeTrue(flicker.scenario.isGesturalNavigation) 93 flicker.assertLayers { 94 val pipLayerList = this.layers { pipApp.layerMatchesAnyOf(it) && it.isVisible } 95 var previousLayer = pipLayerList[0] 96 var currentLayer = previousLayer 97 var i = 0 98 invoke("layer area is decreasing") { 99 if (i < pipLayerList.size - 1) { 100 previousLayer = currentLayer 101 currentLayer = pipLayerList[++i] 102 previousLayer.widthNotSmallerThan(currentLayer) 103 } 104 }.then().invoke("layer are is increasing", true /* isOptional */) { 105 if (i < pipLayerList.size - 1) { 106 previousLayer = currentLayer 107 currentLayer = pipLayerList[++i] 108 currentLayer.widthNotSmallerThan(previousLayer) 109 } 110 } 111 } 112 } 113 114 /** Checks that [pipApp] window is animated towards default position in right bottom corner */ 115 @FlakyTest(bugId = 255578530) 116 @Test 117 open fun pipLayerMovesTowardsRightBottomCorner() { 118 // in gestural nav the swipe makes PiP first go upwards 119 Assume.assumeFalse(flicker.scenario.isGesturalNavigation) 120 flicker.assertLayers { 121 val pipLayerList = this.layers { pipApp.layerMatchesAnyOf(it) && it.isVisible } 122 // Pip animates towards the right bottom corner, but because it is being resized at the 123 // same time, it is possible it shrinks first quickly below the default position and get 124 // moved up after that in just few last frames 125 pipLayerList.zipWithNext { previous, current -> 126 current.visibleRegion.isToTheRightBottom(previous.visibleRegion.region, 3) 127 } 128 } 129 } 130 131 @Presubmit 132 @Test 133 override fun focusChanges() { 134 // in gestural nav the focus goes to different activity on swipe up 135 Assume.assumeFalse(flicker.scenario.isGesturalNavigation) 136 super.focusChanges() 137 } 138 139 @FlakyTest(bugId = 289943985) 140 @Test 141 override fun visibleLayersShownMoreThanOneConsecutiveEntry() { 142 super.visibleLayersShownMoreThanOneConsecutiveEntry() 143 } 144 } 145