f8bfb036ba
Some attributes of hotseat change depending on the size of the device. In the future more attributes could be moved to the spec, e.g. hotseat icons. Fix: 292204436 Test: CalculatedHotseatSpecTest Test: HotseatSpecsTest Test: SizeSpecTest Test: DeviceProfileResponsiveDumpTest Test: DeviceProfileResponsiveAlternativeDisplaysDumpTest Flag: ENABLE_RESPONSIVE_WORKSPACE Change-Id: I6a4e05d75af819dbf1444a5ca45c2080f55dc203
159 lines
5.4 KiB
Kotlin
159 lines
5.4 KiB
Kotlin
/*
|
|
* Copyright (C) 2023 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.android.launcher3.responsive
|
|
|
|
import android.content.Context
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
import androidx.test.filters.SmallTest
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
import com.android.launcher3.AbstractDeviceProfileTest
|
|
import com.google.common.truth.Truth.assertThat
|
|
import kotlin.math.roundToInt
|
|
import org.junit.Before
|
|
import org.junit.Test
|
|
import org.junit.runner.RunWith
|
|
|
|
@SmallTest
|
|
@RunWith(AndroidJUnit4::class)
|
|
class SizeSpecTest : AbstractDeviceProfileTest() {
|
|
override val runningContext: Context = InstrumentationRegistry.getInstrumentation().context
|
|
|
|
@Before
|
|
fun setup() {
|
|
initializeVarsForPhone(deviceSpecs["phone"]!!)
|
|
}
|
|
|
|
@Test
|
|
fun valid_values() {
|
|
val combinations =
|
|
listOf(
|
|
SizeSpec(100f, 0f, 0f, false),
|
|
SizeSpec(0f, 1f, 0f, false),
|
|
SizeSpec(0f, 0f, 1f, false),
|
|
SizeSpec(0f, 0f, 0f, false),
|
|
SizeSpec(0f, 0f, 0f, true),
|
|
SizeSpec(100f, 0f, 0f, false, 100),
|
|
SizeSpec(0f, 1f, 0f, false, 100),
|
|
SizeSpec(0f, 0f, 1f, false, 100),
|
|
SizeSpec(0f, 0f, 0f, false, 100),
|
|
SizeSpec(0f, 0f, 0f, true, 100)
|
|
)
|
|
|
|
for (instance in combinations) {
|
|
assertThat(instance.isValid()).isEqualTo(true)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun validate_getCalculatedValue() {
|
|
val availableSpace = 100
|
|
val matchWorkspaceValue = 101
|
|
val combinations =
|
|
listOf(
|
|
SizeSpec(100f) to 100,
|
|
SizeSpec(ofAvailableSpace = .5f) to (availableSpace * .5f).roundToInt(),
|
|
SizeSpec(ofRemainderSpace = .5f) to 0,
|
|
SizeSpec(matchWorkspace = true) to matchWorkspaceValue,
|
|
// Restricts max size up to 10 (calculated value > 10)
|
|
SizeSpec(100f, maxSize = 10) to 10,
|
|
SizeSpec(ofAvailableSpace = .5f, maxSize = 10) to 10,
|
|
SizeSpec(ofRemainderSpace = .5f, maxSize = 10) to 0,
|
|
SizeSpec(matchWorkspace = true, maxSize = 10) to 10
|
|
)
|
|
|
|
for ((sizeSpec, expectedValue) in combinations) {
|
|
val value = sizeSpec.getCalculatedValue(availableSpace, matchWorkspaceValue)
|
|
assertThat(value).isEqualTo(expectedValue)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun validate_getRemainderSpaceValue() {
|
|
val remainderSpace = 100
|
|
val defaultValue = 50
|
|
val combinations =
|
|
listOf(
|
|
SizeSpec(100f) to defaultValue,
|
|
SizeSpec(ofAvailableSpace = .5f) to defaultValue,
|
|
SizeSpec(ofRemainderSpace = .5f) to (remainderSpace * .5f).roundToInt(),
|
|
SizeSpec(matchWorkspace = true) to defaultValue,
|
|
// Restricts max size up to 10 (defaultValue > 10)
|
|
SizeSpec(100f, maxSize = 10) to 10,
|
|
SizeSpec(ofAvailableSpace = .5f, maxSize = 10) to 10,
|
|
SizeSpec(ofRemainderSpace = .5f, maxSize = 10) to 10,
|
|
SizeSpec(matchWorkspace = true, maxSize = 10) to 10,
|
|
)
|
|
|
|
for ((sizeSpec, expectedValue) in combinations) {
|
|
val value = sizeSpec.getRemainderSpaceValue(remainderSpace, defaultValue)
|
|
assertThat(value).isEqualTo(expectedValue)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun multiple_values_assigned() {
|
|
val combinations =
|
|
listOf(
|
|
SizeSpec(1f, 1f, 0f, false),
|
|
SizeSpec(1f, 0f, 1f, false),
|
|
SizeSpec(1f, 0f, 0f, true),
|
|
SizeSpec(0f, 1f, 1f, false),
|
|
SizeSpec(0f, 1f, 0f, true),
|
|
SizeSpec(0f, 0f, 1f, true),
|
|
SizeSpec(1f, 1f, 1f, true)
|
|
)
|
|
|
|
for (instance in combinations) {
|
|
assertThat(instance.isValid()).isEqualTo(false)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun invalid_values() {
|
|
val combinations =
|
|
listOf(
|
|
SizeSpec(-1f, 0f, 0f, false),
|
|
SizeSpec(0f, 1.1f, 0f, false),
|
|
SizeSpec(0f, -0.1f, 0f, false),
|
|
SizeSpec(0f, 0f, 1.1f, false),
|
|
SizeSpec(0f, 0f, -0.1f, false),
|
|
SizeSpec(0f, 0f, 0f, false, -10),
|
|
SizeSpec(50f, 0f, 0f, false, 10)
|
|
)
|
|
|
|
for (instance in combinations) {
|
|
assertThat(instance.isValid()).isEqualTo(false)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun onlyFixedSize() {
|
|
assertThat(SizeSpec(fixedSize = 16f).onlyFixedSize()).isEqualTo(true)
|
|
|
|
val combinations =
|
|
listOf(
|
|
SizeSpec(0f, 1.1f, 0f, false),
|
|
SizeSpec(0f, 0f, 1.1f, false),
|
|
SizeSpec(0f, 0f, 0f, true)
|
|
)
|
|
|
|
for (instance in combinations) {
|
|
assertThat(instance.onlyFixedSize()).isEqualTo(false)
|
|
}
|
|
}
|
|
}
|