• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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
18 
19 import android.app.Activity
20 import android.platform.test.annotations.FlakyTest
21 import android.platform.test.annotations.Postsubmit
22 import android.platform.test.annotations.Presubmit
23 import android.platform.test.annotations.RequiresDevice
24 import android.platform.test.annotations.RequiresFlagsDisabled
25 import android.tools.Rotation
26 import android.tools.flicker.assertions.FlickerTest
27 import android.tools.flicker.junit.FlickerParametersRunnerFactory
28 import android.tools.flicker.legacy.FlickerBuilder
29 import android.tools.flicker.legacy.LegacyFlickerTest
30 import android.tools.flicker.legacy.LegacyFlickerTestFactory
31 import android.tools.helpers.WindowUtils
32 import com.android.server.wm.flicker.testapp.ActivityOptions
33 import com.android.server.wm.flicker.testapp.ActivityOptions.PortraitOnlyActivity.EXTRA_FIXED_ORIENTATION
34 import com.android.wm.shell.Flags
35 import com.android.wm.shell.flicker.pip.common.PipTransition
36 import com.android.wm.shell.flicker.pip.common.PipTransition.BroadcastActionTrigger.Companion.ORIENTATION_LANDSCAPE
37 import org.junit.Assume
38 import org.junit.Before
39 import org.junit.FixMethodOrder
40 import org.junit.Test
41 import org.junit.runner.RunWith
42 import org.junit.runners.MethodSorters
43 import org.junit.runners.Parameterized
44 
45 /**
46  * Test leaving pip while changing orientation (from pip window in portrait to app in landscape)
47  *
48  * To run this test: `atest WMShellFlickerTestsPip:SetRequestedOrientationWhilePinned`
49  *
50  * Actions:
51  * ```
52  *     Launch [pipApp] on a fixed landscape orientation
53  *     Broadcast action [ACTION_ENTER_PIP] to enter pip mode in portrait
54  *     Restore PIP from the original task to landscape
55  * ```
56  *
57  * Notes:
58  * ```
59  *     1. Some default assertions (e.g., nav bar, status bar and screen covered)
60  *        are inherited [PipTransition]
61  *     2. Part of the test setup occurs automatically via
62  *        [android.tools.flicker.legacy.runner.TransitionRunner],
63  *        including configuring navigation mode, initial orientation and ensuring no
64  *        apps are running before setup
65  * ```
66  */
67 @RequiresDevice
68 @RunWith(Parameterized::class)
69 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
70 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
71 @RequiresFlagsDisabled(Flags.FLAG_ENABLE_PIP2)
72 open class SetRequestedOrientationWhilePinned(flicker: LegacyFlickerTest) : PipTransition(flicker) {
73     private val startingBounds = WindowUtils.getDisplayBounds(Rotation.ROTATION_0)
74     internal open val endingBounds = WindowUtils.getDisplayBounds(Rotation.ROTATION_90)
75 
<lambda>null76     override val thisTransition: FlickerBuilder.() -> Unit = {
77         transitions {
78             // Launch the activity back into fullscreen and ensure that it is now in landscape
79             pipApp.launchViaIntent(wmHelper)
80             // System bar may fade out during fixed rotation.
81             wmHelper
82                 .StateSyncBuilder()
83                 .withFullScreenApp(pipApp)
84                 .withRotation(Rotation.ROTATION_90)
85                 .withNavOrTaskBarVisible()
86                 .withStatusBarVisible()
87                 .waitForAndVerify()
88         }
89     }
90 
<lambda>null91     override val defaultEnterPip: FlickerBuilder.() -> Unit = {
92         setup {
93             // Launch the PiP activity fixed as landscape.
94             pipApp.launchViaIntent(
95                 wmHelper,
96                 stringExtras = mapOf(EXTRA_FIXED_ORIENTATION to ORIENTATION_LANDSCAPE.toString())
97             )
98             // Enter PiP.
99             broadcastActionTrigger.doAction(ActivityOptions.Pip.ACTION_ENTER_PIP)
100             // System bar may fade out during fixed rotation.
101             wmHelper
102                 .StateSyncBuilder()
103                 .withPipShown()
104                 .withRotation(Rotation.ROTATION_0)
105                 .withNavOrTaskBarVisible()
106                 .withStatusBarVisible()
107                 .waitForAndVerify()
108         }
109     }
110 
111     /**
112      * This test is not compatible with Tablets. When using [Activity.setRequestedOrientation] to
113      * fix a orientation, Tablets instead keep the same orientation and add letterboxes
114      */
115     @Before
setupnull116     fun setup() {
117         Assume.assumeFalse(tapl.isTablet)
118     }
119 
120     @Presubmit
121     @Test
displayEndsAt90Degreesnull122     fun displayEndsAt90Degrees() {
123         flicker.assertWmEnd { hasRotation(Rotation.ROTATION_90) }
124     }
125 
126     @Presubmit
127     @Test
pipWindowInsideDisplaynull128     fun pipWindowInsideDisplay() {
129         flicker.assertWmStart { visibleRegion(pipApp).coversAtMost(startingBounds) }
130     }
131 
132     @Presubmit
133     @Test
pipAppShowsOnTopnull134     fun pipAppShowsOnTop() {
135         flicker.assertWmEnd { isAppWindowOnTop(pipApp) }
136     }
137 
138     @Presubmit
139     @Test
pipLayerInsideDisplaynull140     fun pipLayerInsideDisplay() {
141         flicker.assertLayersStart { visibleRegion(pipApp).coversAtMost(startingBounds) }
142     }
143 
144     @Presubmit
145     @Test
pipAlwaysVisiblenull146     fun pipAlwaysVisible() {
147         flicker.assertWm { this.isAppWindowVisible(pipApp) }
148     }
149 
150     @Presubmit
151     @Test
pipAppLayerCoversDisplayBoundsOnEndnull152     open fun pipAppLayerCoversDisplayBoundsOnEnd() {
153         flicker.assertLayersEnd { visibleRegion(pipApp).coversExactly(endingBounds) }
154     }
155 
156     /** {@inheritDoc} */
157     @Postsubmit
158     @Test
taskBarLayerIsVisibleAtStartAndEndnull159     override fun taskBarLayerIsVisibleAtStartAndEnd() = super.taskBarLayerIsVisibleAtStartAndEnd()
160 
161     /** {@inheritDoc} */
162     @Postsubmit
163     @Test
164     override fun taskBarWindowIsAlwaysVisible() = super.taskBarWindowIsAlwaysVisible()
165 
166     /** {@inheritDoc} */
167     @FlakyTest(bugId = 264243884)
168     @Test
169     override fun entireScreenCovered() = super.entireScreenCovered()
170 
171     @Postsubmit
172     @Test
173     override fun pipLayerHasCorrectCornersAtEnd() {
174         flicker.assertLayersEnd { hasNoRoundedCorners(pipApp) }
175     }
176 
177     companion object {
178         @Parameterized.Parameters(name = "{0}")
179         @JvmStatic
getParamsnull180         fun getParams(): Collection<FlickerTest> {
181             return LegacyFlickerTestFactory.nonRotationTests(
182                 supportedRotations = listOf(Rotation.ROTATION_0)
183             )
184         }
185     }
186 }
187