• 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.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 CalculatedAllAppsSpecTest : AbstractDeviceProfileTest() {
33     override val runningContext: Context = InstrumentationRegistry.getInstrumentation().context
34 
35     /**
36      * This test tests:
37      * - (height spec) copy values from workspace
38      * - (width spec) copy values from workspace
39      */
40     @Test
normalPhone_copiesFromWorkspacenull41     fun normalPhone_copiesFromWorkspace() {
42         val deviceSpec = deviceSpecs["phone"]!!
43         initializeVarsForPhone(deviceSpec)
44 
45         val availableWidth = deviceSpec.naturalSize.first
46         // Hotseat size is roughly 495px on a real device,
47         // it doesn't need to be precise on unit tests
48         val availableHeight = deviceSpec.naturalSize.second - deviceSpec.statusBarNaturalPx - 495
49 
50         val workspaceSpecs =
51             WorkspaceSpecs.create(TestResourceHelper(context!!, TestR.xml.valid_workspace_file))
52         val widthSpec = workspaceSpecs.getCalculatedWidthSpec(4, availableWidth)
53         val heightSpec = workspaceSpecs.getCalculatedHeightSpec(5, availableHeight)
54 
55         val allAppsSpecs =
56             AllAppsSpecs.create(TestResourceHelper(context!!, TestR.xml.valid_all_apps_file))
57 
58         with(allAppsSpecs.getCalculatedWidthSpec(4, availableWidth, widthSpec)) {
59             assertThat(availableSpace).isEqualTo(availableWidth)
60             assertThat(cells).isEqualTo(4)
61             assertThat(startPaddingPx).isEqualTo(widthSpec.startPaddingPx)
62             assertThat(endPaddingPx).isEqualTo(widthSpec.endPaddingPx)
63             assertThat(gutterPx).isEqualTo(widthSpec.gutterPx)
64             assertThat(cellSizePx).isEqualTo(widthSpec.cellSizePx)
65         }
66 
67         with(allAppsSpecs.getCalculatedHeightSpec(5, availableHeight, heightSpec)) {
68             assertThat(availableSpace).isEqualTo(availableHeight)
69             assertThat(cells).isEqualTo(5)
70             assertThat(startPaddingPx).isEqualTo(0)
71             assertThat(endPaddingPx).isEqualTo(0)
72             assertThat(gutterPx).isEqualTo(heightSpec.gutterPx)
73             assertThat(cellSizePx).isEqualTo(heightSpec.cellSizePx)
74         }
75     }
76 }
77