• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.responsive.ResponsiveSpec.DimensionType
26 import com.android.launcher3.util.TestResourceHelper
27 import com.google.common.truth.Truth.assertThat
28 import org.junit.Test
29 import org.junit.runner.RunWith
30 
31 @SmallTest
32 @RunWith(AndroidJUnit4::class)
33 class CalculatedAllAppsSpecTest : AbstractDeviceProfileTest() {
34     override val runningContext: Context = InstrumentationRegistry.getInstrumentation().context
35 
36     /**
37      * This test tests:
38      * - (height spec) copy values from workspace
39      * - (width spec) copy values from workspace
40      */
41     @Test
normalPhone_copiesFromWorkspacenull42     fun normalPhone_copiesFromWorkspace() {
43         val deviceSpec = deviceSpecs["phone"]!!
44         val aspectRatio = deviceSpec.naturalSize.first.toFloat() / deviceSpec.naturalSize.second
45         initializeVarsForPhone(deviceSpec)
46 
47         val availableWidth = deviceSpec.naturalSize.first
48         // Hotseat size is roughly 495px on a real device,
49         // it doesn't need to be precise on unit tests
50         val availableHeight = deviceSpec.naturalSize.second - deviceSpec.statusBarNaturalPx - 495
51 
52         val workspaceSpecs =
53             ResponsiveSpecsProvider.create(
54                 TestResourceHelper(context, "valid_workspace_file".xmlToId()),
55                 ResponsiveSpecType.Workspace
56             )
57         val widthSpec =
58             workspaceSpecs.getCalculatedSpec(aspectRatio, DimensionType.WIDTH, 4, availableWidth)
59         val heightSpec =
60             workspaceSpecs.getCalculatedSpec(aspectRatio, DimensionType.HEIGHT, 5, availableHeight)
61 
62         val allAppsSpecs =
63             ResponsiveSpecsProvider.create(
64                 TestResourceHelper(context, "valid_all_apps_file".xmlToId()),
65                 ResponsiveSpecType.AllApps
66             )
67 
68         with(
69             allAppsSpecs.getCalculatedSpec(
70                 aspectRatio,
71                 DimensionType.WIDTH,
72                 4,
73                 availableWidth,
74                 widthSpec
75             )
76         ) {
77             assertThat(availableSpace).isEqualTo(availableWidth)
78             assertThat(cells).isEqualTo(4)
79             assertThat(startPaddingPx).isEqualTo(widthSpec.startPaddingPx)
80             assertThat(endPaddingPx).isEqualTo(widthSpec.endPaddingPx)
81             assertThat(gutterPx).isEqualTo(widthSpec.gutterPx)
82             assertThat(cellSizePx).isEqualTo(widthSpec.cellSizePx)
83         }
84 
85         with(
86             allAppsSpecs.getCalculatedSpec(
87                 aspectRatio,
88                 DimensionType.HEIGHT,
89                 5,
90                 availableHeight,
91                 heightSpec
92             )
93         ) {
94             assertThat(availableSpace).isEqualTo(availableHeight)
95             assertThat(cells).isEqualTo(5)
96             assertThat(startPaddingPx).isEqualTo(0)
97             assertThat(endPaddingPx).isEqualTo(0)
98             assertThat(gutterPx).isEqualTo(heightSpec.gutterPx)
99             assertThat(cellSizePx).isEqualTo(heightSpec.cellSizePx)
100         }
101     }
102 }
103