• 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 
17 package android.tools.common
18 
19 /**
20  * Legacy flicker test scenario
21  *
22  * @param testClass
23  * @param startRotation Initial screen rotation
24  * @param endRotation Final screen rotation
25  * @param navBarMode Navigation mode, such as 3 button or gestural.
26  * @param config Additional configurations
27  *
28  * Defaults to [startRotation]
29  */
30 class ScenarioImpl
31 internal constructor(
32     val testClass: String,
33     override val startRotation: Rotation,
34     override val endRotation: Rotation,
35     override val navBarMode: NavBar,
36     config: Map<String, Any?>,
37     override val description: String
38 ) : Scenario {
39     private val _extraConfig = config.toMutableMap()
40 
41     val extraConfig: Map<String, Any?>
42         get() = _extraConfig
43 
44     override val isEmpty = testClass.isEmpty()
45 
46     override val key = if (isEmpty) "empty" else "${testClass}_$description"
47 
48     /** If the initial screen rotation is 90 (landscape) or 180 (seascape) degrees */
49     val isLandscapeOrSeascapeAtStart: Boolean =
50         startRotation == Rotation.ROTATION_90 || startRotation == Rotation.ROTATION_270
51 
52     val isGesturalNavigation = navBarMode == NavBar.MODE_GESTURAL
53 
54     val isTablet: Boolean
55         get() =
56             extraConfig[IS_TABLET] as Boolean?
57                 ?: error("$IS_TABLET property not initialized. Use [setIsTablet] to initialize ")
58 
setIsTabletnull59     fun setIsTablet(isTablet: Boolean) {
60         _extraConfig[IS_TABLET] = isTablet
61     }
62 
getConfigValuenull63     override fun <T> getConfigValue(key: String): T? = extraConfig[key] as T?
64 
65     override fun toString(): String = key
66 
67     override fun equals(other: Any?): Boolean {
68         if (this === other) return true
69         if (other !is ScenarioImpl) return false
70 
71         if (testClass != other.testClass) return false
72         if (startRotation != other.startRotation) return false
73         if (endRotation != other.endRotation) return false
74         if (navBarMode != other.navBarMode) return false
75         if (description != other.description) return false
76         if (extraConfig != other.extraConfig) return false
77 
78         return true
79     }
80 
hashCodenull81     override fun hashCode(): Int {
82         var result = testClass.hashCode()
83         result = 31 * result + startRotation.hashCode()
84         result = 31 * result + endRotation.hashCode()
85         result = 31 * result + navBarMode.hashCode()
86         result = 31 * result + description.hashCode()
87         result = 31 * result + extraConfig.hashCode()
88         return result
89     }
90 
91     companion object {
92         internal const val IS_TABLET = "isTablet"
93     }
94 }
95