• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.allapps
18 
19 import android.content.Context
20 import android.platform.test.annotations.DisableFlags
21 import android.platform.test.annotations.EnableFlags
22 import android.platform.test.flag.junit.SetFlagsRule
23 import androidx.test.core.app.ApplicationProvider.getApplicationContext
24 import androidx.test.ext.junit.runners.AndroidJUnit4
25 import com.android.launcher3.Flags
26 import com.android.launcher3.util.ActivityContextWrapper
27 import com.google.common.truth.Truth.assertThat
28 import org.junit.Before
29 import org.junit.Rule
30 import org.junit.Test
31 import org.junit.runner.RunWith
32 
33 @RunWith(AndroidJUnit4::class)
34 class FloatingHeaderViewTest {
35 
36     @get:Rule val mSetFlagsRule = SetFlagsRule()
37 
38     private lateinit var context: Context
39     private lateinit var vut: FloatingHeaderView
40 
41     @Before
setUpnull42     fun setUp() {
43         context = ActivityContextWrapper(getApplicationContext())
44         // TODO(b/352161553): Inflate FloatingHeaderView or R.layout.all_apps_content with proper
45         // FloatingHeaderView#setup
46         vut = FloatingHeaderView(context)
47         vut.onFinishInflate()
48     }
49 
50     @Test
51     @DisableFlags(Flags.FLAG_FLOATING_SEARCH_BAR, Flags.FLAG_MULTILINE_SEARCH_BAR)
onHeightUpdated_whenNotMultiline_thenZeroHeightnull52     fun onHeightUpdated_whenNotMultiline_thenZeroHeight() {
53         vut.setFloatingRowsCollapsed(true)
54         val beforeHeight = vut.maxTranslation
55         vut.updateSearchBarOffset(HEADER_HEIGHT_OFFSET)
56 
57         vut.onHeightUpdated()
58 
59         assertThat(vut.maxTranslation).isEqualTo(beforeHeight)
60     }
61 
62     @Test
63     @EnableFlags(Flags.FLAG_MULTILINE_SEARCH_BAR)
64     @DisableFlags(Flags.FLAG_FLOATING_SEARCH_BAR)
onHeightUpdated_whenMultiline_thenHeightIsOffsetnull65     fun onHeightUpdated_whenMultiline_thenHeightIsOffset() {
66         vut.setFloatingRowsCollapsed(true)
67         vut.updateSearchBarOffset(HEADER_HEIGHT_OFFSET)
68 
69         vut.onHeightUpdated()
70 
71         assertThat(vut.maxTranslation).isEqualTo(HEADER_HEIGHT_OFFSET)
72     }
73 
74     @Test
75     @DisableFlags(Flags.FLAG_MULTILINE_SEARCH_BAR)
76     @EnableFlags(Flags.FLAG_FLOATING_SEARCH_BAR)
onHeightUpdated_whenFloatingRowsShownAndNotMultiline_thenAddsOnlyFloatingRownull77     fun onHeightUpdated_whenFloatingRowsShownAndNotMultiline_thenAddsOnlyFloatingRow() {
78         // Collapse floating rows and expand to trigger header height calculation
79         vut.setFloatingRowsCollapsed(true)
80         vut.setFloatingRowsCollapsed(false)
81         val defaultHeight = vut.maxTranslation
82         vut.updateSearchBarOffset(HEADER_HEIGHT_OFFSET)
83 
84         vut.onHeightUpdated()
85 
86         assertThat(vut.maxTranslation).isEqualTo(defaultHeight)
87     }
88 
89     companion object {
90         private const val HEADER_HEIGHT_OFFSET = 50
91     }
92 }
93