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 com.android.launcher3.responsive 18 19 import android.content.Context 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import androidx.test.filters.SmallTest 22 import androidx.test.platform.app.InstrumentationRegistry 23 import com.android.launcher3.AbstractDeviceProfileTest 24 import com.android.launcher3.responsive.ResponsiveSpec.DimensionType 25 import com.android.launcher3.util.TestResourceHelper 26 import com.google.common.truth.Truth.assertThat 27 import org.junit.Test 28 import org.junit.runner.RunWith 29 30 @SmallTest 31 @RunWith(AndroidJUnit4::class) 32 class CalculatedHotseatSpecTest : AbstractDeviceProfileTest() { 33 override val runningContext: Context = InstrumentationRegistry.getInstrumentation().context 34 val deviceSpec = deviceSpecs["phone"]!! 35 val aspectRatio = deviceSpec.naturalSize.first.toFloat() / deviceSpec.naturalSize.second 36 37 /** 38 * This test tests: 39 * - (height spec) gets the correct breakpoint from the XML - skips the first breakpoint 40 */ 41 @Test normalPhone_returnsSecondBreakpointSpecnull42 fun normalPhone_returnsSecondBreakpointSpec() { 43 initializeVarsForPhone(deviceSpec) 44 45 // Hotseat uses the whole device height 46 val availableHeight = deviceSpec.naturalSize.second 47 48 val hotseatSpecsProvider = 49 HotseatSpecsProvider.create(TestResourceHelper(context, "valid_hotseat_file".xmlToId())) 50 val heightSpec = 51 hotseatSpecsProvider.getCalculatedSpec( 52 aspectRatio, 53 DimensionType.HEIGHT, 54 availableHeight 55 ) 56 57 assertThat(heightSpec.availableSpace).isEqualTo(availableHeight) 58 assertThat(heightSpec.hotseatQsbSpace).isEqualTo(95) 59 assertThat(heightSpec.edgePadding).isEqualTo(126) 60 } 61 62 /** 63 * This test tests: 64 * - (height spec) gets the correct breakpoint from the XML - use the first breakpoint 65 */ 66 @Test smallPhone_returnsFirstBreakpointSpecnull67 fun smallPhone_returnsFirstBreakpointSpec() { 68 deviceSpec.densityDpi = 540 // larger display size 69 initializeVarsForPhone(deviceSpec) 70 71 // Hotseat uses the whole device height 72 val availableHeight = deviceSpec.naturalSize.second 73 74 val hotseatSpecsProvider = 75 HotseatSpecsProvider.create(TestResourceHelper(context, "valid_hotseat_file".xmlToId())) 76 val heightSpec = 77 hotseatSpecsProvider.getCalculatedSpec( 78 aspectRatio, 79 DimensionType.HEIGHT, 80 availableHeight 81 ) 82 83 assertThat(heightSpec.availableSpace).isEqualTo(availableHeight) 84 assertThat(heightSpec.hotseatQsbSpace).isEqualTo(81) 85 assertThat(heightSpec.edgePadding).isEqualTo(162) 86 } 87 88 /** 89 * This test tests: 90 * - (width spec) gets the correct breakpoint from the XML - skips the first breakpoint 91 */ 92 @Test normalPhoneLandscape_returnsSecondBreakpointSpecnull93 fun normalPhoneLandscape_returnsSecondBreakpointSpec() { 94 initializeVarsForPhone(deviceSpec, isVerticalBar = true) 95 96 // Hotseat uses the whole device width 97 val availableWidth = deviceSpec.naturalSize.second 98 99 val hotseatSpecsProvider = 100 HotseatSpecsProvider.create( 101 TestResourceHelper(context, "valid_hotseat_land_file".xmlToId()) 102 ) 103 val widthSpec = 104 hotseatSpecsProvider.getCalculatedSpec(aspectRatio, DimensionType.WIDTH, availableWidth) 105 106 assertThat(widthSpec.availableSpace).isEqualTo(availableWidth) 107 assertThat(widthSpec.hotseatQsbSpace).isEqualTo(0) 108 assertThat(widthSpec.edgePadding).isEqualTo(168) 109 } 110 } 111