1 /*
<lambda>null2  * Copyright (C) 2023 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.common
18 
19 import android.platform.test.annotations.Presubmit
20 import android.tools.Rotation
21 import android.tools.flicker.legacy.FlickerBuilder
22 import android.tools.flicker.legacy.LegacyFlickerTest
23 import android.tools.flicker.legacy.LegacyFlickerTestFactory
24 import android.tools.traces.component.ComponentNameMatcher
25 import org.junit.Test
26 import org.junit.runners.Parameterized
27 
28 abstract class EnterPipTransition(flicker: LegacyFlickerTest) : PipTransition(flicker) {
29     override val defaultEnterPip: FlickerBuilder.() -> Unit = {
30         setup { pipApp.launchViaIntent(wmHelper) }
31     }
32 
33     /** Checks [pipApp] window remains visible throughout the animation */
34     @Presubmit
35     @Test
36     open fun pipAppWindowAlwaysVisible() {
37         flicker.assertWm { this.isAppWindowVisible(pipApp) }
38     }
39 
40     /** Checks [pipApp] layer remains visible throughout the animation */
41     @Presubmit
42     @Test
43     open fun pipAppLayerAlwaysVisible() {
44         flicker.assertLayers { this.isVisible(pipApp) }
45     }
46 
47     /** Checks the content overlay appears then disappears during the animation */
48     @Presubmit
49     @Test
50     open fun pipOverlayLayerAppearThenDisappear() {
51         val overlay = ComponentNameMatcher.PIP_CONTENT_OVERLAY
52         flicker.assertLayers {
53             this.notContains(overlay).then().contains(overlay).then().notContains(overlay)
54         }
55     }
56 
57     /**
58      * Checks that the pip app window remains inside the display bounds throughout the whole
59      * animation
60      */
61     @Presubmit
62     @Test
63     open fun pipWindowRemainInsideVisibleBounds() {
64         flicker.assertWmVisibleRegion(pipApp) { coversAtMost(displayBounds) }
65     }
66 
67     /**
68      * Checks that the pip app layer remains inside the display bounds throughout the whole
69      * animation
70      */
71     @Presubmit
72     @Test
73     open fun pipLayerOrOverlayRemainInsideVisibleBounds() {
74         flicker.assertLayersVisibleRegion(
75             pipApp.or(ComponentNameMatcher.PIP_CONTENT_OVERLAY)
76         ) {
77             coversAtMost(displayBounds)
78         }
79     }
80 
81     /** Checks that the visible region of [pipApp] always reduces during the animation */
82     @Presubmit
83     @Test
84     open fun pipLayerReduces() {
85         flicker.assertLayers {
86             val pipLayerList = this.layers { pipApp.layerMatchesAnyOf(it) && it.isVisible }
87             pipLayerList.zipWithNext { previous, current ->
88                 current.visibleRegion.notBiggerThan(previous.visibleRegion.region)
89             }
90         }
91     }
92 
93     /** Checks that [pipApp] window becomes pinned */
94     @Presubmit
95     @Test
96     open fun pipWindowBecomesPinned() {
97         flicker.assertWm {
98             invoke("pipWindowIsNotPinned") { it.isNotPinned(pipApp) }
99                 .then()
100                 .invoke("pipWindowIsPinned") { it.isPinned(pipApp) }
101         }
102     }
103 
104     /** Checks [ComponentNameMatcher.LAUNCHER] layer remains visible throughout the animation */
105     @Presubmit
106     @Test
107     open fun launcherLayerBecomesVisible() {
108         flicker.assertLayers {
109             isInvisible(ComponentNameMatcher.LAUNCHER)
110                 .then()
111                 .isVisible(ComponentNameMatcher.LAUNCHER)
112         }
113     }
114 
115     /**
116      * Checks that the focus changes between the [pipApp] window and the launcher when closing the
117      * pip window
118      */
119     @Presubmit
120     @Test
121     open fun focusChanges() {
122         flicker.assertEventLog {
123             this.focusChanges(pipApp.packageName, "NexusLauncherActivity")
124         }
125     }
126 
127     companion object {
128         /**
129          * Creates the test configurations.
130          *
131          * See [LegacyFlickerTestFactory.nonRotationTests] for configuring repetitions, screen
132          * orientation and navigation modes.
133          */
134         @Parameterized.Parameters(name = "{0}")
135         @JvmStatic
136         fun getParams() =
137             LegacyFlickerTestFactory.nonRotationTests(
138                 supportedRotations = listOf(Rotation.ROTATION_0)
139             )
140     }
141 }
142