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 com.android.server.wm.flicker.activityembedding.rtl
18 
19 import android.platform.test.annotations.Presubmit
20 import android.tools.flicker.junit.FlickerParametersRunnerFactory
21 import android.tools.flicker.legacy.FlickerBuilder
22 import android.tools.flicker.legacy.LegacyFlickerTest
23 import android.tools.flicker.legacy.LegacyFlickerTestFactory
24 import androidx.test.filters.RequiresDevice
25 import com.android.server.wm.flicker.activityembedding.ActivityEmbeddingTestBase
26 import com.android.server.wm.flicker.helpers.ActivityEmbeddingAppHelper
27 import org.junit.FixMethodOrder
28 import org.junit.Test
29 import org.junit.runner.RunWith
30 import org.junit.runners.MethodSorters
31 import org.junit.runners.Parameterized
32 
33 /**
34  * Test launching a placeholder split over a normal split, both splits are configured in RTL.
35  *
36  * Setup: From A launch a split in RTL - resulting in B|A. Transitions: From A start
37  * PlaceholderPrimary, which is configured to launch with PlaceholderSecondary in RTL. Expect split
38  * PlaceholderSecondary|PlaceholderPrimary covering split B|A.
39  *
40  * To run this test: `atest FlickerTestsOther:RTLStartSecondaryWithPlaceholderTest`
41  */
42 @RequiresDevice
43 @RunWith(Parameterized::class)
44 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
45 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
46 class RTLStartSecondaryWithPlaceholderTest(flicker: LegacyFlickerTest) :
47     ActivityEmbeddingTestBase(flicker) {
48 
49     /** {@inheritDoc} */
<lambda>null50     override val transition: FlickerBuilder.() -> Unit = {
51         setup {
52             tapl.setExpectedRotationCheckEnabled(false)
53             testApp.launchViaIntent(wmHelper)
54             testApp.launchSecondaryActivityRTL(wmHelper)
55         }
56         transitions { testApp.launchPlaceholderSplitRTL(wmHelper) }
57         teardown {
58             tapl.goHome()
59             testApp.exit(wmHelper)
60         }
61     }
62 
63     /**
64      * Main activity and Secondary activity will become invisible because they are covered by
65      * PlaceholderPrimary activity and PlaceholderSecondary activity.
66      */
67     @Presubmit
68     @Test
assertWindowVisibilitiesnull69     fun assertWindowVisibilities() {
70         flicker.assertWm {
71             isAppWindowVisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
72                 .then()
73                 .isAppWindowInvisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
74         }
75         flicker.assertWm {
76             isAppWindowVisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
77                 .then()
78                 .isAppWindowInvisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
79         }
80         flicker.assertWm {
81             isAppWindowInvisible(ActivityEmbeddingAppHelper.PLACEHOLDER_PRIMARY_COMPONENT)
82                 .then()
83                 .isAppWindowVisible(ActivityEmbeddingAppHelper.PLACEHOLDER_PRIMARY_COMPONENT)
84         }
85         flicker.assertWm {
86             isAppWindowInvisible(ActivityEmbeddingAppHelper.PLACEHOLDER_SECONDARY_COMPONENT)
87                 .then()
88                 .isAppWindowVisible(ActivityEmbeddingAppHelper.PLACEHOLDER_SECONDARY_COMPONENT)
89         }
90     }
91 
92     /**
93      * Main activity and Secondary activity will become invisible because they are covered by
94      * PlaceholderPrimary activity and PlaceholderSecondary activity.
95      */
96     @Presubmit
97     @Test
assertLayerVisibilitiesnull98     fun assertLayerVisibilities() {
99         flicker.assertLayers {
100             this.isVisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
101                 .then()
102                 .isInvisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
103         }
104         flicker.assertLayers {
105             this.isVisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
106                 .then()
107                 .isInvisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
108         }
109         flicker.assertLayers {
110             isInvisible(ActivityEmbeddingAppHelper.PLACEHOLDER_PRIMARY_COMPONENT)
111                 .then()
112                 .isVisible(ActivityEmbeddingAppHelper.PLACEHOLDER_PRIMARY_COMPONENT)
113         }
114         flicker.assertLayers {
115             isInvisible(ActivityEmbeddingAppHelper.PLACEHOLDER_SECONDARY_COMPONENT)
116                 .then()
117                 .isVisible(ActivityEmbeddingAppHelper.PLACEHOLDER_SECONDARY_COMPONENT)
118         }
119     }
120 
121     /** Main activity and Secondary activity split is in right-to-left layout direction. */
122     @Presubmit
123     @Test
assertWMRTLBeforeTransitionnull124     fun assertWMRTLBeforeTransition() {
125         flicker.assertWmStart {
126             val mainActivityRegion =
127                 this.visibleRegion(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
128             val secondaryActivityRegion =
129                 this.visibleRegion(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
130             mainActivityRegion.notOverlaps(secondaryActivityRegion.region)
131             // secondary activity is on the left, main activity is on the right.
132             check { "isRTLBeforeTransition" }
133                 .that(mainActivityRegion.region.bounds.left)
134                 .isEqual(secondaryActivityRegion.region.bounds.right)
135         }
136     }
137 
138     /** Main activity and Secondary activity split is in right-to-left layout direction. */
139     @Presubmit
140     @Test
assertLayerRTLBeforeTransitionnull141     fun assertLayerRTLBeforeTransition() {
142         flicker.assertLayersStart {
143             val mainActivityRegion =
144                 this.visibleRegion(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
145             val secondaryActivityRegion =
146                 this.visibleRegion(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
147             mainActivityRegion.notOverlaps(secondaryActivityRegion.region)
148             // secondary activity is on the left, main activity is on the right.
149             check { "isRTLBeforeTransition" }
150                 .that(mainActivityRegion.region.bounds.left)
151                 .isEqual(secondaryActivityRegion.region.bounds.right)
152         }
153     }
154 
155     /**
156      * PlaceholderPrimary activity and PlaceholderSecondary activity split are in right-to-left
157      * layout direction.
158      */
159     @Presubmit
160     @Test
assertWMRTLAfterTransitionnull161     fun assertWMRTLAfterTransition() {
162         flicker.assertWmEnd {
163             val mainActivityRegion =
164                 this.visibleRegion(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
165             val secondaryActivityRegion =
166                 this.visibleRegion(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT)
167             mainActivityRegion.notOverlaps(secondaryActivityRegion.region)
168             // secondary activity is on the left, main activity is on the right.
169             check { "isRTLBeforeTransition" }
170                 .that(mainActivityRegion.region.bounds.left)
171                 .isEqual(secondaryActivityRegion.region.bounds.right)
172         }
173     }
174 
175     /**
176      * PlaceholderPrimary activity and PlaceholderSecondary activity split are in right-to-left
177      * layout direction.
178      */
179     @Presubmit
180     @Test
assertLayerRTLAfterTransitionnull181     fun assertLayerRTLAfterTransition() {
182         flicker.assertLayersEnd {
183             val mainActivityRegion =
184                 this.visibleRegion(ActivityEmbeddingAppHelper.PLACEHOLDER_PRIMARY_COMPONENT)
185             val secondaryActivityRegion =
186                 this.visibleRegion(ActivityEmbeddingAppHelper.PLACEHOLDER_SECONDARY_COMPONENT)
187             mainActivityRegion.notOverlaps(secondaryActivityRegion.region)
188             // Placeholder secondary activity is on the left, placeholder primary activity is on the
189             // right.
190             check { "isRTLAfterTransition" }
191                 .that(mainActivityRegion.region.bounds.left)
192                 .isEqual(secondaryActivityRegion.region.bounds.right)
193         }
194     }
195 
196     companion object {
197         /**
198          * Creates the test configurations.
199          *
200          * See [LegacyFlickerTestFactory.nonRotationTests] for configuring screen orientation and
201          * navigation modes.
202          */
203         @Parameterized.Parameters(name = "{0}")
204         @JvmStatic
getParamsnull205         fun getParams() = LegacyFlickerTestFactory.nonRotationTests()
206     }
207 }
208