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.android.systemui.util.dpToPx 27 import com.google.common.truth.Truth.assertThat 28 import org.junit.Before 29 import org.junit.Test 30 import org.junit.runner.RunWith 31 32 @SmallTest 33 @RunWith(AndroidJUnit4::class) 34 class HotseatSpecsTest : AbstractDeviceProfileTest() { 35 override val runningContext: Context = InstrumentationRegistry.getInstrumentation().context 36 37 @Before setupnull38 fun setup() { 39 initializeVarsForPhone(deviceSpecs["phone"]!!) 40 } 41 42 @Test parseValidFilenull43 fun parseValidFile() { 44 val hotseatSpecs = 45 HotseatSpecs.create(TestResourceHelper(context!!, TestR.xml.valid_hotseat_file)) 46 assertThat(hotseatSpecs.specs.size).isEqualTo(2) 47 48 val expectedSpecs = 49 listOf( 50 HotseatSpec( 51 maxAvailableSize = 847.dpToPx(), 52 specType = ResponsiveSpec.SpecType.HEIGHT, 53 hotseatQsbSpace = SizeSpec(24f.dpToPx()) 54 ), 55 HotseatSpec( 56 maxAvailableSize = 9999.dpToPx(), 57 specType = ResponsiveSpec.SpecType.HEIGHT, 58 hotseatQsbSpace = SizeSpec(36f.dpToPx()) 59 ), 60 ) 61 62 assertThat(hotseatSpecs.specs.size).isEqualTo(expectedSpecs.size) 63 assertThat(hotseatSpecs.specs[0]).isEqualTo(expectedSpecs[0]) 64 assertThat(hotseatSpecs.specs[1]).isEqualTo(expectedSpecs[1]) 65 } 66 67 @Test(expected = IllegalStateException::class) parseInvalidFile_spaceIsNotFixedSize_throwsErrornull68 fun parseInvalidFile_spaceIsNotFixedSize_throwsError() { 69 HotseatSpecs.create(TestResourceHelper(context!!, TestR.xml.invalid_hotseat_file_case_1)) 70 } 71 } 72