1 package com.android.systemui.navigationbar.gestural 2 3 import android.view.Gravity 4 import android.view.Surface 5 import androidx.test.filters.SmallTest 6 import com.android.systemui.SysuiTestCase 7 import com.android.systemui.shared.rotation.FloatingRotationButtonPositionCalculator 8 import com.android.systemui.shared.rotation.FloatingRotationButtonPositionCalculator.Position 9 import com.google.common.truth.Truth.assertThat 10 import org.junit.Test 11 import org.junit.runner.RunWith 12 import platform.test.runner.parameterized.ParameterizedAndroidJunit4 13 import platform.test.runner.parameterized.Parameters 14 15 @RunWith(ParameterizedAndroidJunit4::class) 16 @SmallTest 17 internal class FloatingRotationButtonPositionCalculatorTest(private val testCase: TestCase) : 18 SysuiTestCase() { 19 20 @Test calculatePositionnull21 fun calculatePosition() { 22 val position = 23 testCase.calculator.calculatePosition( 24 testCase.rotation, 25 testCase.taskbarVisible, 26 testCase.taskbarStashed, 27 ) 28 assertThat(position).isEqualTo(testCase.expectedPosition) 29 } 30 31 internal class TestCase( 32 val calculator: FloatingRotationButtonPositionCalculator, 33 val rotation: Int, 34 val taskbarVisible: Boolean, 35 val taskbarStashed: Boolean, 36 val expectedPosition: Position, 37 ) { <lambda>null38 override fun toString(): String = buildString { 39 append("when calculator = ") 40 append( 41 when (calculator) { 42 posLeftCalculator -> "LEFT" 43 posRightCalculator -> "RIGHT" 44 else -> error("Unknown calculator: $calculator") 45 } 46 ) 47 append(", rotation = $rotation") 48 append(", taskbarVisible = $taskbarVisible") 49 append(", taskbarStashed = $taskbarStashed") 50 append(" - expected $expectedPosition") 51 } 52 } 53 54 companion object { 55 private const val MARGIN_DEFAULT = 10 56 private const val MARGIN_TASKBAR_LEFT = 20 57 private const val MARGIN_TASKBAR_BOTTOM = 30 58 59 private val posLeftCalculator = 60 FloatingRotationButtonPositionCalculator( 61 MARGIN_DEFAULT, 62 MARGIN_TASKBAR_LEFT, 63 MARGIN_TASKBAR_BOTTOM, 64 true, 65 ) 66 private val posRightCalculator = 67 FloatingRotationButtonPositionCalculator( 68 MARGIN_DEFAULT, 69 MARGIN_TASKBAR_LEFT, 70 MARGIN_TASKBAR_BOTTOM, 71 false, 72 ) 73 74 @Parameters(name = "{0}") 75 @JvmStatic getParamsnull76 fun getParams(): Collection<TestCase> = 77 listOf( 78 // Position left 79 TestCase( 80 calculator = posLeftCalculator, 81 rotation = Surface.ROTATION_0, 82 taskbarVisible = false, 83 taskbarStashed = false, 84 expectedPosition = 85 Position( 86 gravity = Gravity.BOTTOM or Gravity.LEFT, 87 translationX = MARGIN_DEFAULT, 88 translationY = -MARGIN_DEFAULT, 89 ), 90 ), 91 TestCase( 92 calculator = posLeftCalculator, 93 rotation = Surface.ROTATION_90, 94 taskbarVisible = false, 95 taskbarStashed = false, 96 expectedPosition = 97 Position( 98 gravity = Gravity.BOTTOM or Gravity.RIGHT, 99 translationX = -MARGIN_DEFAULT, 100 translationY = -MARGIN_DEFAULT, 101 ), 102 ), 103 TestCase( 104 calculator = posLeftCalculator, 105 rotation = Surface.ROTATION_180, 106 taskbarVisible = false, 107 taskbarStashed = false, 108 expectedPosition = 109 Position( 110 gravity = Gravity.TOP or Gravity.RIGHT, 111 translationX = -MARGIN_DEFAULT, 112 translationY = MARGIN_DEFAULT, 113 ), 114 ), 115 TestCase( 116 calculator = posLeftCalculator, 117 rotation = Surface.ROTATION_270, 118 taskbarVisible = false, 119 taskbarStashed = false, 120 expectedPosition = 121 Position( 122 gravity = Gravity.TOP or Gravity.LEFT, 123 translationX = MARGIN_DEFAULT, 124 translationY = MARGIN_DEFAULT, 125 ), 126 ), 127 TestCase( 128 calculator = posLeftCalculator, 129 rotation = Surface.ROTATION_0, 130 taskbarVisible = true, 131 taskbarStashed = false, 132 expectedPosition = 133 Position( 134 gravity = Gravity.BOTTOM or Gravity.LEFT, 135 translationX = MARGIN_TASKBAR_LEFT, 136 translationY = -MARGIN_TASKBAR_BOTTOM, 137 ), 138 ), 139 TestCase( 140 calculator = posLeftCalculator, 141 rotation = Surface.ROTATION_0, 142 taskbarVisible = true, 143 taskbarStashed = true, 144 expectedPosition = 145 Position( 146 gravity = Gravity.BOTTOM or Gravity.LEFT, 147 translationX = MARGIN_DEFAULT, 148 translationY = -MARGIN_DEFAULT, 149 ), 150 ), 151 TestCase( 152 calculator = posLeftCalculator, 153 rotation = Surface.ROTATION_90, 154 taskbarVisible = true, 155 taskbarStashed = false, 156 expectedPosition = 157 Position( 158 gravity = Gravity.BOTTOM or Gravity.RIGHT, 159 translationX = -MARGIN_TASKBAR_LEFT, 160 translationY = -MARGIN_TASKBAR_BOTTOM, 161 ), 162 ), 163 164 // Position right 165 TestCase( 166 calculator = posRightCalculator, 167 rotation = Surface.ROTATION_0, 168 taskbarVisible = false, 169 taskbarStashed = false, 170 expectedPosition = 171 Position( 172 gravity = Gravity.BOTTOM or Gravity.RIGHT, 173 translationX = -MARGIN_DEFAULT, 174 translationY = -MARGIN_DEFAULT, 175 ), 176 ), 177 TestCase( 178 calculator = posRightCalculator, 179 rotation = Surface.ROTATION_90, 180 taskbarVisible = false, 181 taskbarStashed = false, 182 expectedPosition = 183 Position( 184 gravity = Gravity.TOP or Gravity.RIGHT, 185 translationX = -MARGIN_DEFAULT, 186 translationY = MARGIN_DEFAULT, 187 ), 188 ), 189 TestCase( 190 calculator = posRightCalculator, 191 rotation = Surface.ROTATION_180, 192 taskbarVisible = false, 193 taskbarStashed = false, 194 expectedPosition = 195 Position( 196 gravity = Gravity.TOP or Gravity.LEFT, 197 translationX = MARGIN_DEFAULT, 198 translationY = MARGIN_DEFAULT, 199 ), 200 ), 201 TestCase( 202 calculator = posRightCalculator, 203 rotation = Surface.ROTATION_270, 204 taskbarVisible = false, 205 taskbarStashed = false, 206 expectedPosition = 207 Position( 208 gravity = Gravity.BOTTOM or Gravity.LEFT, 209 translationX = MARGIN_DEFAULT, 210 translationY = -MARGIN_DEFAULT, 211 ), 212 ), 213 TestCase( 214 calculator = posRightCalculator, 215 rotation = Surface.ROTATION_0, 216 taskbarVisible = true, 217 taskbarStashed = false, 218 expectedPosition = 219 Position( 220 gravity = Gravity.BOTTOM or Gravity.RIGHT, 221 translationX = -MARGIN_TASKBAR_LEFT, 222 translationY = -MARGIN_TASKBAR_BOTTOM, 223 ), 224 ), 225 TestCase( 226 calculator = posRightCalculator, 227 rotation = Surface.ROTATION_0, 228 taskbarVisible = true, 229 taskbarStashed = true, 230 expectedPosition = 231 Position( 232 gravity = Gravity.BOTTOM or Gravity.RIGHT, 233 translationX = -MARGIN_DEFAULT, 234 translationY = -MARGIN_DEFAULT, 235 ), 236 ), 237 TestCase( 238 calculator = posRightCalculator, 239 rotation = Surface.ROTATION_90, 240 taskbarVisible = true, 241 taskbarStashed = false, 242 expectedPosition = 243 Position( 244 gravity = Gravity.TOP or Gravity.RIGHT, 245 translationX = -MARGIN_TASKBAR_LEFT, 246 translationY = MARGIN_TASKBAR_BOTTOM, 247 ), 248 ), 249 ) 250 } 251 } 252