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.tests.R as TestR 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 35 /** 36 * This test tests: 37 * - (height spec) gets the correct breakpoint from the XML - skips the first breakpoint 38 */ 39 @Test normalPhone_returnsSecondBreakpointSpecnull40 fun normalPhone_returnsSecondBreakpointSpec() { 41 val deviceSpec = deviceSpecs["phone"]!! 42 initializeVarsForPhone(deviceSpec) 43 44 // Hotseat uses the whole device height 45 val availableHeight = deviceSpec.naturalSize.second 46 47 val hotseatSpecs = 48 HotseatSpecs.create(TestResourceHelper(context!!, TestR.xml.valid_hotseat_file)) 49 val heightSpec = hotseatSpecs.getCalculatedHeightSpec(availableHeight) 50 51 assertThat(heightSpec.availableSpace).isEqualTo(availableHeight) 52 assertThat(heightSpec.hotseatQsbSpace).isEqualTo(95) 53 } 54 55 /** 56 * This test tests: 57 * - (height spec) gets the correct breakpoint from the XML - use the first breakpoint 58 */ 59 @Test smallPhone_returnsFirstBreakpointSpecnull60 fun smallPhone_returnsFirstBreakpointSpec() { 61 val deviceSpec = deviceSpecs["phone"]!! 62 deviceSpec.densityDpi = 540 // larger display size 63 initializeVarsForPhone(deviceSpec) 64 65 // Hotseat uses the whole device height 66 val availableHeight = deviceSpec.naturalSize.second 67 68 val hotseatSpecs = 69 HotseatSpecs.create(TestResourceHelper(context!!, TestR.xml.valid_hotseat_file)) 70 val heightSpec = hotseatSpecs.getCalculatedHeightSpec(availableHeight) 71 72 assertThat(heightSpec.availableSpace).isEqualTo(availableHeight) 73 assertThat(heightSpec.hotseatQsbSpace).isEqualTo(81) 74 } 75 } 76