• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.launcher3.nonquickstep
17 
18 import androidx.test.filters.SmallTest
19 import com.android.launcher3.AbstractDeviceProfileTest
20 import com.android.launcher3.DeviceProfile
21 import com.android.launcher3.Flags
22 import com.android.launcher3.InvariantDeviceProfile
23 import org.junit.Before
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 import org.junit.runners.Parameterized
27 
28 /** Tests for DeviceProfile. */
29 @SmallTest
30 @RunWith(Parameterized::class)
31 class DeviceProfileDumpTest : AbstractDeviceProfileTest() {
32     private val folderName: String = "DeviceProfileDumpTest"
33 
34     @Parameterized.Parameter lateinit var instance: TestCase
35 
36     @Before
setUpnull37     fun setUp() {
38         if (instance.decoupleDepth) {
39             setFlagsRule.enableFlags(Flags.FLAG_ENABLE_SCALING_REVEAL_HOME_ANIMATION)
40         } else {
41             setFlagsRule.disableFlags(Flags.FLAG_ENABLE_SCALING_REVEAL_HOME_ANIMATION)
42         }
43     }
44 
45     @Test
dumpPortraitGesturenull46     fun dumpPortraitGesture() {
47         initializeDevice(instance.deviceName, isGestureMode = true, isLandscape = false)
48         val dp = getDeviceProfileForGrid(instance.gridName)
49         dp.isTaskbarPresentInApps = instance.isTaskbarPresentInApps
50 
51         assertDump(dp, instance.filename("Portrait"))
52     }
53 
54     @Test
dumpPortrait3Buttonnull55     fun dumpPortrait3Button() {
56         initializeDevice(instance.deviceName, isGestureMode = false, isLandscape = false)
57         val dp = getDeviceProfileForGrid(instance.gridName)
58         dp.isTaskbarPresentInApps = instance.isTaskbarPresentInApps
59 
60         assertDump(dp, instance.filename("Portrait3Button"))
61     }
62 
63     @Test
dumpLandscapeGesturenull64     fun dumpLandscapeGesture() {
65         initializeDevice(instance.deviceName, isGestureMode = true, isLandscape = true)
66         val dp = getDeviceProfileForGrid(instance.gridName)
67         dp.isTaskbarPresentInApps = instance.isTaskbarPresentInApps
68 
69         val testName =
70             if (instance.deviceName == "phone") {
71                 "VerticalBar"
72             } else {
73                 "Landscape"
74             }
75         assertDump(dp, instance.filename(testName))
76     }
77 
78     @Test
dumpLandscape3Buttonnull79     fun dumpLandscape3Button() {
80         initializeDevice(instance.deviceName, isGestureMode = false, isLandscape = true)
81         val dp = getDeviceProfileForGrid(instance.gridName)
82         dp.isTaskbarPresentInApps = instance.isTaskbarPresentInApps
83 
84         val testName =
85             if (instance.deviceName == "phone") {
86                 "VerticalBar3Button"
87             } else {
88                 "Landscape3Button"
89             }
90         assertDump(dp, instance.filename(testName))
91     }
92 
initializeDevicenull93     private fun initializeDevice(deviceName: String, isGestureMode: Boolean, isLandscape: Boolean) {
94         val deviceSpec = deviceSpecs[instance.deviceName]!!
95         when (deviceName) {
96             "twopanel-phone",
97             "twopanel-tablet" ->
98                 initializeVarsForTwoPanel(
99                     deviceSpecUnfolded = deviceSpecs["twopanel-tablet"]!!,
100                     deviceSpecFolded = deviceSpecs["twopanel-phone"]!!,
101                     isLandscape = isLandscape,
102                     isGestureMode = isGestureMode,
103                 )
104             "tablet" ->
105                 initializeVarsForTablet(
106                     deviceSpec = deviceSpec,
107                     isLandscape = isLandscape,
108                     isGestureMode = isGestureMode
109                 )
110             else ->
111                 initializeVarsForPhone(
112                     deviceSpec = deviceSpec,
113                     isVerticalBar = isLandscape,
114                     isGestureMode = isGestureMode
115                 )
116         }
117     }
118 
getDeviceProfileForGridnull119     private fun getDeviceProfileForGrid(gridName: String): DeviceProfile {
120         return InvariantDeviceProfile(context, gridName).getDeviceProfile(context)
121     }
122 
assertDumpnull123     private fun assertDump(dp: DeviceProfile, filename: String) {
124         assertDump(dp, folderName, filename)
125     }
126 
127     companion object {
128         @Parameterized.Parameters(name = "{0}")
129         @JvmStatic
getInstancesnull130         fun getInstances(): List<TestCase> {
131             return listOf(
132                 TestCase("phone", gridName = "5_by_5"),
133                 TestCase("tablet", gridName = "6_by_5", isTaskbarPresentInApps = true),
134                 TestCase("twopanel-tablet", gridName = "4_by_4", isTaskbarPresentInApps = true),
135                 TestCase(
136                     "twopanel-tablet",
137                     gridName = "4_by_4",
138                     isTaskbarPresentInApps = true,
139                     decoupleDepth = true
140                 ),
141             )
142         }
143 
144         data class TestCase(
145             val deviceName: String,
146             val gridName: String,
147             val isTaskbarPresentInApps: Boolean = false,
148             val decoupleDepth: Boolean = false
149         ) {
filenamenull150             fun filename(testName: String = ""): String {
151                 val device =
152                     when (deviceName) {
153                         "tablet" -> "tablet"
154                         "twopanel-tablet" -> "twoPanel"
155                         "twopanel-phone" -> "twoPanelFolded"
156                         else -> "phone"
157                     }
158                 val depth =
159                     if (decoupleDepth) {
160                         "_decoupleDepth"
161                     } else {
162                         ""
163                     }
164                 return "$device$testName$depth"
165             }
166         }
167     }
168 }
169