xref: /aosp_15_r20/platform_testing/libraries/flicker/src/android/tools/flicker/config/AssertionTemplates.kt (revision dd0948b35e70be4c0246aabd6c72554a5eb8b22a)
1 /*
2  * 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 android.tools.flicker.config
18 
19 import android.tools.flicker.AssertionInvocationGroup
20 import android.tools.flicker.assertors.AssertionTemplate
21 import android.tools.flicker.assertors.assertions.AppLayerBecomesInvisible
22 import android.tools.flicker.assertors.assertions.AppLayerBecomesVisible
23 import android.tools.flicker.assertors.assertions.AppLayerCoversFullScreenAtEnd
24 import android.tools.flicker.assertors.assertions.AppLayerCoversFullScreenAtStart
25 import android.tools.flicker.assertors.assertions.AppLayerIsInvisibleAtEnd
26 import android.tools.flicker.assertors.assertions.AppLayerIsInvisibleAtStart
27 import android.tools.flicker.assertors.assertions.AppLayerIsVisibleAlways
28 import android.tools.flicker.assertors.assertions.AppLayerIsVisibleAtEnd
29 import android.tools.flicker.assertors.assertions.AppLayerIsVisibleAtStart
30 import android.tools.flicker.assertors.assertions.AppWindowBecomesInvisible
31 import android.tools.flicker.assertors.assertions.AppWindowBecomesTopWindow
32 import android.tools.flicker.assertors.assertions.AppWindowBecomesVisible
33 import android.tools.flicker.assertors.assertions.AppWindowIsInvisibleAtEnd
34 import android.tools.flicker.assertors.assertions.AppWindowIsInvisibleAtStart
35 import android.tools.flicker.assertors.assertions.AppWindowIsTopWindowAtStart
36 import android.tools.flicker.assertors.assertions.AppWindowIsVisibleAlways
37 import android.tools.flicker.assertors.assertions.AppWindowIsVisibleAtEnd
38 import android.tools.flicker.assertors.assertions.AppWindowIsVisibleAtStart
39 import android.tools.flicker.assertors.assertions.AppWindowOnTopAtEnd
40 import android.tools.flicker.assertors.assertions.AppWindowOnTopAtStart
41 import android.tools.flicker.assertors.assertions.AppWindowRemainInsideDisplayBounds
42 import android.tools.flicker.assertors.assertions.EntireScreenCoveredAlways
43 import android.tools.flicker.assertors.assertions.FocusChanges
44 import android.tools.flicker.assertors.assertions.HasAtMostOneWindowMatching
45 import android.tools.flicker.assertors.assertions.LayerBecomesInvisible
46 import android.tools.flicker.assertors.assertions.LayerBecomesVisible
47 import android.tools.flicker.assertors.assertions.LayerReduces
48 import android.tools.flicker.assertors.assertions.ScreenLockedAtStart
49 import android.tools.flicker.assertors.assertions.SplitAppLayerBoundsBecomesVisible
50 import android.tools.flicker.assertors.assertions.VisibleLayersShownMoreThanOneConsecutiveEntry
51 import android.tools.flicker.assertors.assertions.VisibleWindowsShownMoreThanOneConsecutiveEntry
52 import android.tools.flicker.assertors.assertions.WindowBecomesPinned
53 import android.tools.flicker.assertors.assertions.WindowRemainInsideVisibleBounds
54 import android.tools.flicker.config.appclose.Components.CLOSING_APPS
55 import android.tools.flicker.config.applaunch.Components.OPENING_APPS
56 import android.tools.flicker.config.common.Components.LAUNCHER
57 import android.tools.flicker.config.desktopmode.Components.DESKTOP_MODE_APP
58 import android.tools.flicker.config.pip.Components.PIP_APP
59 import android.tools.flicker.config.pip.Components.PIP_DISMISS_OVERLAY
60 import android.tools.flicker.config.splitscreen.Components.SPLIT_SCREEN_DIVIDER
61 import android.tools.flicker.config.splitscreen.Components.SPLIT_SCREEN_PRIMARY_APP
62 import android.tools.flicker.config.splitscreen.Components.SPLIT_SCREEN_SECONDARY_APP
63 import android.tools.traces.component.ComponentNameMatcher
64 
65 object AssertionTemplates {
66     val ENTIRE_TRACE_ASSERTIONS =
67         mapOf(
68             EntireScreenCoveredAlways() to AssertionInvocationGroup.NON_BLOCKING,
69             VisibleWindowsShownMoreThanOneConsecutiveEntry() to
70                 AssertionInvocationGroup.NON_BLOCKING,
71             // Temporarily ignore these layers which might be visible for a single entry
72             // and contain only view level changes during that entry (b/286054008)
73             VisibleLayersShownMoreThanOneConsecutiveEntry(
74                 ignore =
75                     listOf(
76                         ComponentNameMatcher.NOTIFICATION_SHADE,
77                         ComponentNameMatcher.VOLUME_DIALOG,
78                         ComponentNameMatcher.NAV_BAR,
79                     )
80             ) to AssertionInvocationGroup.NON_BLOCKING,
81         )
82 
83     val COMMON_ASSERTIONS =
84         listOf(
85                 EntireScreenCoveredAlways(),
86                 VisibleWindowsShownMoreThanOneConsecutiveEntry(),
87                 VisibleLayersShownMoreThanOneConsecutiveEntry(),
88             )
<lambda>null89             .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
90 
91     val APP_LAUNCH_ASSERTIONS =
92         COMMON_ASSERTIONS +
93             listOf(
94                     AppLayerIsInvisibleAtStart(OPENING_APPS),
95                     AppLayerIsVisibleAtEnd(OPENING_APPS),
96                     AppLayerBecomesVisible(OPENING_APPS),
97                     AppWindowBecomesVisible(OPENING_APPS),
98                     AppWindowBecomesTopWindow(OPENING_APPS),
99                 )
<lambda>null100                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
101 
102     val APP_CLOSE_ASSERTIONS =
<lambda>null103         COMMON_ASSERTIONS.toMutableMap().also {
104             it.remove(VisibleLayersShownMoreThanOneConsecutiveEntry())
105         } +
106             listOf(
107                     AppLayerIsVisibleAtStart(CLOSING_APPS),
108                     AppLayerIsInvisibleAtEnd(CLOSING_APPS),
109                     AppWindowIsVisibleAtStart(CLOSING_APPS),
110                     AppWindowIsInvisibleAtEnd(CLOSING_APPS),
111                     AppLayerBecomesInvisible(CLOSING_APPS),
112                     AppWindowBecomesInvisible(CLOSING_APPS),
113                     AppWindowIsTopWindowAtStart(CLOSING_APPS),
114                     VisibleLayersShownMoreThanOneConsecutiveEntry(
115                         listOf(ComponentNameMatcher.NAV_BAR)
116                     ),
117                 )
<lambda>null118                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
119 
120     val APP_LAUNCH_FROM_HOME_ASSERTIONS =
121         APP_LAUNCH_ASSERTIONS +
122             listOf(AppLayerIsVisibleAtStart(LAUNCHER), AppLayerIsInvisibleAtEnd(LAUNCHER))
<lambda>null123                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
124 
125     val APP_LAUNCH_FROM_LOCK_ASSERTIONS =
126         APP_LAUNCH_ASSERTIONS +
127             listOf(FocusChanges(toComponent = OPENING_APPS), ScreenLockedAtStart())
<lambda>null128                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
129 
130     val APP_CLOSE_TO_HOME_ASSERTIONS =
131         APP_CLOSE_ASSERTIONS +
132             listOf(
133                     AppLayerIsInvisibleAtStart(LAUNCHER),
134                     AppLayerIsVisibleAtEnd(LAUNCHER),
135                     AppWindowIsInvisibleAtStart(LAUNCHER),
136                     AppWindowIsVisibleAtEnd(LAUNCHER),
137                     AppWindowBecomesTopWindow(LAUNCHER),
138                 )
<lambda>null139                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
140 
141     val APP_LAUNCH_FROM_NOTIFICATION_ASSERTIONS = COMMON_ASSERTIONS + APP_LAUNCH_ASSERTIONS
142 
143     val LAUNCHER_QUICK_SWITCH_ASSERTIONS =
144         COMMON_ASSERTIONS +
145             APP_LAUNCH_ASSERTIONS +
146             APP_CLOSE_ASSERTIONS +
147             listOf(
148                     AppLayerCoversFullScreenAtStart(CLOSING_APPS),
149                     AppLayerCoversFullScreenAtEnd(OPENING_APPS),
150                     AppWindowOnTopAtStart(CLOSING_APPS),
151                     AppWindowOnTopAtEnd(OPENING_APPS),
152                     AppWindowBecomesInvisible(CLOSING_APPS),
153                     AppLayerBecomesInvisible(CLOSING_APPS),
154                     AppWindowBecomesVisible(OPENING_APPS),
155                     AppLayerBecomesVisible(OPENING_APPS),
156                 )
<lambda>null157                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
158 
159     val APP_CLOSE_TO_PIP_ASSERTIONS =
160         COMMON_ASSERTIONS +
161             listOf(
162                     LayerReduces(PIP_APP),
163                     FocusChanges(),
164                     AppWindowIsVisibleAlways(PIP_APP),
165                     WindowRemainInsideVisibleBounds(PIP_APP),
166                     WindowBecomesPinned(PIP_APP),
167                     LayerBecomesVisible(LAUNCHER),
168                     HasAtMostOneWindowMatching(PIP_DISMISS_OVERLAY),
169                 )
<lambda>null170                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
171 
172     val ENTER_SPLITSCREEN_ASSERTIONS =
173         COMMON_ASSERTIONS +
174             listOf(
175                     LayerBecomesVisible(SPLIT_SCREEN_DIVIDER),
176                     AppLayerIsVisibleAtEnd(SPLIT_SCREEN_PRIMARY_APP),
177                     AppLayerBecomesVisible(SPLIT_SCREEN_SECONDARY_APP),
178                     SplitAppLayerBoundsBecomesVisible(
179                         SPLIT_SCREEN_PRIMARY_APP,
180                         isPrimaryApp = true,
181                     ),
182                     SplitAppLayerBoundsBecomesVisible(
183                         SPLIT_SCREEN_SECONDARY_APP,
184                         isPrimaryApp = false,
185                     ),
186                     AppWindowBecomesVisible(SPLIT_SCREEN_PRIMARY_APP),
187                     AppWindowBecomesVisible(SPLIT_SCREEN_SECONDARY_APP),
188                 )
<lambda>null189                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
190 
191     val EXIT_SPLITSCREEN_ASSERTIONS =
192         COMMON_ASSERTIONS +
193             listOf(
194                     LayerBecomesInvisible(SPLIT_SCREEN_DIVIDER),
195                     AppLayerBecomesInvisible(SPLIT_SCREEN_PRIMARY_APP),
196                     AppLayerIsVisibleAlways(SPLIT_SCREEN_SECONDARY_APP),
197                     AppWindowBecomesInvisible(SPLIT_SCREEN_PRIMARY_APP),
198                     AppWindowIsVisibleAlways(SPLIT_SCREEN_SECONDARY_APP),
199                 )
<lambda>null200                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
201 
202     val RESIZE_SPLITSCREEN_ASSERTIONS =
203         COMMON_ASSERTIONS +
204             listOf(
205                     AppLayerIsVisibleAlways(SPLIT_SCREEN_PRIMARY_APP),
206                     AppLayerIsVisibleAlways(SPLIT_SCREEN_SECONDARY_APP),
207                     AppWindowIsVisibleAlways(SPLIT_SCREEN_PRIMARY_APP),
208                     AppWindowIsVisibleAlways(SPLIT_SCREEN_SECONDARY_APP),
209                 )
<lambda>null210                 .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
211 
212     val DESKTOP_MODE_APP_VISIBILITY_ASSERTIONS: Map<AssertionTemplate, AssertionInvocationGroup> =
213         listOf(
214                 AppWindowIsVisibleAlways(DESKTOP_MODE_APP),
215                 AppWindowOnTopAtEnd(DESKTOP_MODE_APP),
216                 AppWindowRemainInsideDisplayBounds(DESKTOP_MODE_APP),
217             )
<lambda>null218             .associateBy({ it }, { AssertionInvocationGroup.BLOCKING })
219 }
220