• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.server.wm.flicker.service.processors
18 
19 import com.android.server.wm.flicker.readLayerTraceFromFile
20 import com.android.server.wm.flicker.readWmTraceFromFile
21 import com.android.server.wm.traces.common.service.processors.AppCloseProcessor
22 import com.google.common.truth.Truth
23 import org.junit.FixMethodOrder
24 import org.junit.Test
25 import org.junit.runners.MethodSorters
26 
27 /**
28  * Contains [AppCloseProcessor] tests. To run this test:
29  * `atest FlickerLibTest:AppCloseProcessorTest`
30  */
31 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
32 class AppCloseProcessorTest {
<lambda>null33     private val processor = AppCloseProcessor { }
34 
<lambda>null35     private val tagAppCloseByBackButton by lazy {
36         val wmTrace = readWmTraceFromFile(
37             "tagprocessors/appclose/backbutton/WindowManagerTrace.winscope"
38         )
39         val layersTrace = readLayerTraceFromFile(
40             "tagprocessors/appclose/backbutton/SurfaceFlingerTrace.winscope"
41         )
42         processor.generateTags(wmTrace, layersTrace)
43     }
44 
<lambda>null45     private val tagAppCloseBySwipeUp by lazy {
46         val wmTrace = readWmTraceFromFile(
47             "tagprocessors/appclose/swipeup/WindowManagerTrace.winscope"
48         )
49         val layersTrace = readLayerTraceFromFile(
50             "tagprocessors/appclose/swipeup/SurfaceFlingerTrace.winscope"
51         )
52         processor.generateTags(wmTrace, layersTrace)
53     }
54 
<lambda>null55     private val tagAppCloseBySwitchingApps by lazy {
56         val wmTrace = readWmTraceFromFile(
57             "tagprocessors/appclose/switchapp/WindowManagerTrace.winscope"
58         )
59         val layersTrace = readLayerTraceFromFile(
60             "tagprocessors/appclose/switchapp/SurfaceFlingerTrace.winscope"
61         )
62         processor.generateTags(wmTrace, layersTrace)
63     }
64 
<lambda>null65     private val tagsAppCloseByClosingRotatedApp by lazy {
66         val wmTrace = readWmTraceFromFile(
67             "tagprocessors/appclose/rotated/WindowManagerTrace.winscope"
68         )
69         val layersTrace = readLayerTraceFromFile(
70             "tagprocessors/appclose/rotated/SurfaceFlingerTrace.winscope"
71         )
72         processor.generateTags(wmTrace, layersTrace)
73     }
74 
<lambda>null75     private val tagsColdAppLaunch by lazy {
76         val wmTrace = readWmTraceFromFile(
77             "tagprocessors/applaunch/cold/WindowManagerTrace.winscope"
78         )
79         val layersTrace = readLayerTraceFromFile(
80             "tagprocessors/applaunch/cold/SurfaceFlingerTrace.winscope"
81         )
82         processor.generateTags(wmTrace, layersTrace)
83     }
84 
<lambda>null85     private val tagsWarmAppLaunch by lazy {
86         val wmTrace = readWmTraceFromFile(
87             "tagprocessors/applaunch/warm/WindowManagerTrace.winscope"
88         )
89         val layersTrace = readLayerTraceFromFile(
90             "tagprocessors/applaunch/warm/SurfaceFlingerTrace.winscope"
91         )
92         processor.generateTags(wmTrace, layersTrace)
93     }
94 
95     @Test
generatesAppCloseTagsByPressingBackButtonnull96     fun generatesAppCloseTagsByPressingBackButton() {
97         val tagTrace = tagAppCloseByBackButton
98         Truth.assertWithMessage("Should have 2 app close tags")
99             .that(tagTrace)
100             .hasSize(2)
101         val startTagTimestamp = 9295108146952 // 0d2h34m55s108ms
102         val endTagTimestamp = 9295480256103 // 0d2h34m55s480ms
103         Truth.assertThat(tagTrace.first().timestamp).isEqualTo(startTagTimestamp)
104         Truth.assertThat(tagTrace.last().timestamp).isEqualTo(endTagTimestamp)
105     }
106 
107     @Test
generatesAppCloseTagsBySwipenull108     fun generatesAppCloseTagsBySwipe() {
109         val tagTrace = tagAppCloseBySwipeUp
110         Truth.assertWithMessage("Should have 2 app close tags")
111             .that(tagTrace)
112             .hasSize(2)
113         val startTagTimestamp = 9320574596259 // 0d2h35m20s578ms
114         val endTagTimestamp = 9321301178051 // 0d2h35m21s301ms
115         Truth.assertThat(tagTrace.first().timestamp).isEqualTo(startTagTimestamp)
116         Truth.assertThat(tagTrace.last().timestamp).isEqualTo(endTagTimestamp)
117     }
118 
119     @Test
generatesAppCloseTagsBySwitchingAppsnull120     fun generatesAppCloseTagsBySwitchingApps() {
121         val tagTrace = tagAppCloseBySwitchingApps
122         Truth.assertWithMessage("Should have 2 app close tags")
123             .that(tagTrace)
124             .hasSize(2)
125         val startTagTimestamp = 4129701437903 // 0d1h8m49s701ms
126         val endTagTimestamp = 4132063745690 // 0d1h8m52s52ms
127         Truth.assertThat(tagTrace.first().timestamp).isEqualTo(startTagTimestamp)
128         Truth.assertThat(tagTrace.last().timestamp).isEqualTo(endTagTimestamp)
129     }
130 
131     @Test
generatesAppCloseTagsWhenAppRotated90null132     fun generatesAppCloseTagsWhenAppRotated90() {
133         val tagTrace = tagsAppCloseByClosingRotatedApp
134         Truth.assertWithMessage("Should have 2 app close tags")
135             .that(tagTrace)
136             .hasSize(2)
137         val startTagTimestamp = 343127388040903 // 3d23h18m47s388ms
138         val endTagTimestamp = 343128129419414 // 3d23h18m48s129ms
139         Truth.assertThat(tagTrace.first().timestamp).isEqualTo(startTagTimestamp)
140         Truth.assertThat(tagTrace.last().timestamp).isEqualTo(endTagTimestamp)
141     }
142 
143     @Test
generatesNoTagsOnColdAppLaunchnull144     fun generatesNoTagsOnColdAppLaunch() {
145         val tagTrace = tagsColdAppLaunch
146         Truth.assertWithMessage("Should have 0 app launch tags")
147             .that(tagTrace)
148             .hasSize(0)
149     }
150 
151     @Test
generatesNoTagsOnWarmAppLaunchnull152     fun generatesNoTagsOnWarmAppLaunch() {
153         val tagTrace = tagsWarmAppLaunch
154         Truth.assertWithMessage("Should have 0 app launch tags")
155             .that(tagTrace)
156             .hasSize(0)
157     }
158 }