• 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.util.rule.setFlags
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         setFlagsRule.setFlags(
39             instance.decoupleDepth,
40             Flags.FLAG_ENABLE_SCALING_REVEAL_HOME_ANIMATION,
41         )
42         setFlagsRule.setFlags(false, Flags.FLAG_ONE_GRID_SPECS)
43     }
44 
45     @Test
dumpPortraitGesturenull46     fun dumpPortraitGesture() {
47         initializeDevice(instance.deviceName, isGestureMode = true, isLandscape = false)
48         val dp = context.appComponent.idp.getDeviceProfile(context)
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 = context.appComponent.idp.getDeviceProfile(context)
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 = context.appComponent.idp.getDeviceProfile(context)
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 = context.appComponent.idp.getDeviceProfile(context)
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                     gridName = instance.gridName,
104                 )
105             "tablet" ->
106                 initializeVarsForTablet(
107                     deviceSpec = deviceSpec,
108                     isLandscape = isLandscape,
109                     isGestureMode = isGestureMode,
110                     gridName = instance.gridName,
111                 )
112             else ->
113                 initializeVarsForPhone(
114                     deviceSpec = deviceSpec,
115                     isVerticalBar = isLandscape,
116                     isGestureMode = isGestureMode,
117                     gridName = instance.gridName,
118                 )
119         }
120     }
121 
assertDumpnull122     private fun assertDump(dp: DeviceProfile, filename: String) {
123         assertDump(dp, folderName, filename)
124     }
125 
126     companion object {
127         @Parameterized.Parameters(name = "{0}")
128         @JvmStatic
getInstancesnull129         fun getInstances(): List<TestCase> {
130             return listOf(
131                 TestCase("phone", gridName = "5_by_5"),
132                 TestCase("tablet", gridName = "6_by_5", isTaskbarPresentInApps = true),
133                 TestCase("twopanel-tablet", gridName = "4_by_4", isTaskbarPresentInApps = true),
134                 TestCase(
135                     "twopanel-tablet",
136                     gridName = "4_by_4",
137                     isTaskbarPresentInApps = true,
138                     decoupleDepth = true,
139                 ),
140             )
141         }
142 
143         data class TestCase(
144             val deviceName: String,
145             val gridName: String,
146             val isTaskbarPresentInApps: Boolean = false,
147             val decoupleDepth: Boolean = false,
148         ) {
filenamenull149             fun filename(testName: String = ""): String {
150                 val device =
151                     when (deviceName) {
152                         "tablet" -> "tablet"
153                         "twopanel-tablet" -> "twoPanel"
154                         "twopanel-phone" -> "twoPanelFolded"
155                         else -> "phone"
156                     }
157                 val depth =
158                     if (decoupleDepth) {
159                         "_decoupleDepth"
160                     } else {
161                         ""
162                     }
163                 return "$device$testName$depth"
164             }
165         }
166     }
167 }
168