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.Companion.ResponsiveSpecType 25 import com.android.launcher3.util.TestResourceHelper 26 import com.google.common.truth.Truth.assertThat 27 import org.junit.Before 28 import org.junit.Test 29 import org.junit.runner.RunWith 30 31 @SmallTest 32 @RunWith(AndroidJUnit4::class) 33 class AllAppsSpecsTest : AbstractDeviceProfileTest() { 34 override val runningContext: Context = InstrumentationRegistry.getInstrumentation().context 35 val deviceSpec = deviceSpecs["phone"]!! 36 val aspectRatio = deviceSpec.naturalSize.first.toFloat() / deviceSpec.naturalSize.second 37 38 @Before setupnull39 fun setup() { 40 initializeVarsForPhone(deviceSpec) 41 } 42 43 @Test parseValidFilenull44 fun parseValidFile() { 45 val allAppsSpecs = 46 ResponsiveSpecsProvider.create( 47 TestResourceHelper(context, "valid_all_apps_file".xmlToId()), 48 ResponsiveSpecType.AllApps 49 ) 50 51 val specs = allAppsSpecs.getSpecsByAspectRatio(aspectRatio) 52 assertThat(specs.heightSpecs.size).isEqualTo(1) 53 assertThat(specs.heightSpecs[0].toString()) 54 .isEqualTo( 55 "ResponsiveSpec(" + 56 "maxAvailableSize=26247, " + 57 "dimensionType=HEIGHT, " + 58 "specType=AllApps, " + 59 "startPadding=SizeSpec(fixedSize=0.0, " + 60 "ofAvailableSpace=0.0, " + 61 "ofRemainderSpace=0.0, " + 62 "matchWorkspace=false, " + 63 "maxSize=2147483647), " + 64 "endPadding=SizeSpec(fixedSize=0.0, " + 65 "ofAvailableSpace=0.0, " + 66 "ofRemainderSpace=0.0, " + 67 "matchWorkspace=false, " + 68 "maxSize=2147483647), " + 69 "gutter=SizeSpec(fixedSize=0.0, " + 70 "ofAvailableSpace=0.0, " + 71 "ofRemainderSpace=0.0, " + 72 "matchWorkspace=true, " + 73 "maxSize=2147483647), " + 74 "cellSize=SizeSpec(fixedSize=0.0, " + 75 "ofAvailableSpace=0.0, " + 76 "ofRemainderSpace=0.0, " + 77 "matchWorkspace=true, " + 78 "maxSize=2147483647)" + 79 ")" 80 ) 81 82 assertThat(specs.widthSpecs.size).isEqualTo(1) 83 assertThat(specs.widthSpecs[0].toString()) 84 .isEqualTo( 85 "ResponsiveSpec(" + 86 "maxAvailableSize=26247, " + 87 "dimensionType=WIDTH, " + 88 "specType=AllApps, " + 89 "startPadding=SizeSpec(fixedSize=0.0, " + 90 "ofAvailableSpace=0.0, " + 91 "ofRemainderSpace=0.0, " + 92 "matchWorkspace=true, " + 93 "maxSize=2147483647), " + 94 "endPadding=SizeSpec(fixedSize=0.0, " + 95 "ofAvailableSpace=0.0, " + 96 "ofRemainderSpace=0.0, " + 97 "matchWorkspace=true, " + 98 "maxSize=2147483647), " + 99 "gutter=SizeSpec(fixedSize=0.0, " + 100 "ofAvailableSpace=0.0, " + 101 "ofRemainderSpace=0.0, " + 102 "matchWorkspace=true, " + 103 "maxSize=2147483647), " + 104 "cellSize=SizeSpec(fixedSize=0.0, " + 105 "ofAvailableSpace=0.0, " + 106 "ofRemainderSpace=0.0, " + 107 "matchWorkspace=true, " + 108 "maxSize=2147483647)" + 109 ")" 110 ) 111 } 112 113 @Test(expected = IllegalStateException::class) parseInvalidFile_missingTag_throwsErrornull114 fun parseInvalidFile_missingTag_throwsError() { 115 ResponsiveSpecsProvider.create( 116 TestResourceHelper(context, "invalid_all_apps_file_case_1".xmlToId()), 117 ResponsiveSpecType.AllApps 118 ) 119 } 120 121 @Test(expected = IllegalStateException::class) parseInvalidFile_moreThanOneValuePerTag_throwsErrornull122 fun parseInvalidFile_moreThanOneValuePerTag_throwsError() { 123 ResponsiveSpecsProvider.create( 124 TestResourceHelper(context, "invalid_all_apps_file_case_2".xmlToId()), 125 ResponsiveSpecType.AllApps 126 ) 127 } 128 129 @Test(expected = IllegalStateException::class) parseInvalidFile_valueBiggerThan1_throwsErrornull130 fun parseInvalidFile_valueBiggerThan1_throwsError() { 131 ResponsiveSpecsProvider.create( 132 TestResourceHelper(context, "invalid_all_apps_file_case_3".xmlToId()), 133 ResponsiveSpecType.AllApps 134 ) 135 } 136 } 137