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.splitscreen
18 
19 import android.platform.test.annotations.Presubmit
20 import android.tools.NavBar
21 import android.tools.flicker.junit.FlickerParametersRunnerFactory
22 import android.tools.flicker.legacy.FlickerBuilder
23 import android.tools.flicker.legacy.LegacyFlickerTest
24 import android.tools.flicker.legacy.LegacyFlickerTestFactory
25 import android.tools.flicker.subject.layers.LayersTraceSubject
26 import android.tools.flicker.subject.region.RegionSubject
27 import android.tools.traces.component.ComponentNameMatcher.Companion.WALLPAPER_BBQ_WRAPPER
28 import androidx.test.filters.FlakyTest
29 import androidx.test.filters.RequiresDevice
30 import com.android.wm.shell.flicker.splitscreen.benchmark.UnlockKeyguardToSplitScreenBenchmark
31 import com.android.wm.shell.flicker.utils.ICommonAssertions
32 import com.android.wm.shell.flicker.utils.SPLIT_SCREEN_DIVIDER_COMPONENT
33 import com.android.wm.shell.flicker.utils.appWindowIsVisibleAtEnd
34 import com.android.wm.shell.flicker.utils.layerIsVisibleAtEnd
35 import com.android.wm.shell.flicker.utils.splitAppLayerBoundsIsVisibleAtEnd
36 import org.junit.FixMethodOrder
37 import org.junit.Test
38 import org.junit.runner.RunWith
39 import org.junit.runners.MethodSorters
40 import org.junit.runners.Parameterized
41 
42 /**
43  * Test unlocking insecure keyguard to back to split screen tasks and verify the transition
44  * behavior.
45  *
46  * To run this test: `atest WMShellFlickerTestsSplitScreen:UnlockKeyguardToSplitScreen`
47  */
48 @RequiresDevice
49 @FlakyTest(bugId = 293578017)
50 @RunWith(Parameterized::class)
51 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
52 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
53 class UnlockKeyguardToSplitScreen(override val flicker: LegacyFlickerTest) :
54     UnlockKeyguardToSplitScreenBenchmark(flicker), ICommonAssertions {
55     /** {@inheritDoc} */
56     override val transition: FlickerBuilder.() -> Unit
57         get() = {
58             defaultTeardown(this)
59             thisTransition(this)
60         }
61 
62     @Test
63     override fun visibleLayersShownMoreThanOneConsecutiveEntry() =
64         super.visibleLayersShownMoreThanOneConsecutiveEntry()
65 
66     // TODO(b/293578017) remove once that bug is resolve
67     @Test
68     @Presubmit
69     fun visibleLayersShownMoreThanOneConsecutiveEntry_withoutWallpaper() =
70         flicker.assertLayers {
71             this.visibleLayersShownMoreThanOneConsecutiveEntry(
72                 LayersTraceSubject.VISIBLE_FOR_MORE_THAN_ONE_ENTRY_IGNORE_LAYERS +
73                     listOf(WALLPAPER_BBQ_WRAPPER)
74             )
75         }
76 
77     @Test
78     fun splitScreenDividerIsVisibleAtEnd() {
79         flicker.assertLayersEnd { this.isVisible(SPLIT_SCREEN_DIVIDER_COMPONENT) }
80     }
81 
82     @Test fun primaryAppLayerIsVisibleAtEnd() = flicker.layerIsVisibleAtEnd(primaryApp)
83 
84     @Test
85     fun primaryAppBoundsIsVisibleAtEnd() =
86         flicker.splitAppLayerBoundsIsVisibleAtEnd(
87             primaryApp,
88             landscapePosLeft = false,
89             portraitPosTop = false
90         )
91 
92     @Test
93     fun secondaryAppBoundsIsVisibleAtEnd() =
94         flicker.splitAppLayerBoundsIsVisibleAtEnd(
95             secondaryApp,
96             landscapePosLeft = true,
97             portraitPosTop = true
98         )
99 
100     @Test fun primaryAppWindowIsVisibleAtEnd() = flicker.appWindowIsVisibleAtEnd(primaryApp)
101 
102     @Test fun secondaryAppWindowIsVisibleAtEnd() = flicker.appWindowIsVisibleAtEnd(secondaryApp)
103 
104     @Test
105     fun notOverlapsForPrimaryAndSecondaryAppLayers() {
106         flicker.assertLayers {
107             this.invoke("notOverlapsForPrimaryAndSecondaryLayers") {
108                 val primaryAppRegions =
109                     it.subjects
110                         .filter { subject ->
111                             subject.name.contains(primaryApp.toLayerName()) && subject.isVisible
112                         }
113                         .mapNotNull { primaryApp -> primaryApp.layer.visibleRegion }
114 
115                 val primaryAppRegionArea = RegionSubject(primaryAppRegions, it.timestamp)
116                 it.visibleRegion(secondaryApp).notOverlaps(primaryAppRegionArea.region)
117             }
118         }
119     }
120 
121     companion object {
122         @Parameterized.Parameters(name = "{0}")
123         @JvmStatic
124         fun getParams() =
125             LegacyFlickerTestFactory.nonRotationTests(
126                 supportedNavigationModes = listOf(NavBar.MODE_GESTURAL)
127             )
128     }
129 }
130