1 /*
2  * Copyright (c) 2022 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 
18 package com.android.systemui.statusbar
19 
20 import android.testing.AndroidTestingRunner
21 import android.testing.TestableLooper
22 import androidx.test.filters.SmallTest
23 import com.android.systemui.SysuiTestCase
24 import com.android.systemui.classifier.FalsingCollector
25 import com.android.systemui.dump.DumpManager
26 import com.android.systemui.plugins.FalsingManager
27 import com.android.systemui.plugins.statusbar.StatusBarStateController
28 import com.android.systemui.shade.ShadeExpansionStateManager
29 import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator
30 import com.android.systemui.statusbar.notification.row.ExpandableView
31 import com.android.systemui.statusbar.notification.stack.NotificationRoundnessManager
32 import com.android.systemui.statusbar.phone.HeadsUpManagerPhone
33 import com.android.systemui.statusbar.phone.KeyguardBypassController
34 import com.android.systemui.statusbar.policy.ConfigurationController
35 import com.android.systemui.util.mockito.mock
36 import org.junit.Before
37 import org.junit.Test
38 import org.junit.runner.RunWith
39 import org.mockito.Mockito.anyInt
40 import org.mockito.Mockito.atLeast
41 import org.mockito.Mockito.never
42 import org.mockito.Mockito.verify
43 import org.mockito.Mockito.`when` as whenever
44 
45 @SmallTest
46 @TestableLooper.RunWithLooper
47 @RunWith(AndroidTestingRunner::class)
48 class PulseExpansionHandlerTest : SysuiTestCase() {
49 
50     private lateinit var pulseExpansionHandler: PulseExpansionHandler
51 
52     private val collapsedHeight = 300
53     private val wakeUpCoordinator: NotificationWakeUpCoordinator = mock()
54     private val bypassController: KeyguardBypassController = mock()
55     private val headsUpManager: HeadsUpManagerPhone = mock()
56     private val roundnessManager: NotificationRoundnessManager = mock()
57     private val configurationController: ConfigurationController = mock()
58     private val statusBarStateController: StatusBarStateController = mock()
59     private val falsingManager: FalsingManager = mock()
60     private val shadeExpansionStateManager: ShadeExpansionStateManager = mock()
61     private val lockscreenShadeTransitionController: LockscreenShadeTransitionController = mock()
62     private val falsingCollector: FalsingCollector = mock()
63     private val dumpManager: DumpManager = mock()
64     private val expandableView: ExpandableView = mock()
65 
66     @Before
67     fun setUp() {
68         whenever(expandableView.collapsedHeight).thenReturn(collapsedHeight)
69 
70         pulseExpansionHandler =
71             PulseExpansionHandler(
72                 mContext,
73                 wakeUpCoordinator,
74                 bypassController,
75                 headsUpManager,
76                 roundnessManager,
77                 configurationController,
78                 statusBarStateController,
79                 falsingManager,
80                 shadeExpansionStateManager,
81                 lockscreenShadeTransitionController,
82                 falsingCollector,
83                 dumpManager
84             )
85     }
86 
87     @Test
88     fun resetChild_updateHeight() {
89         whenever(expandableView.actualHeight).thenReturn(500)
90 
91         pulseExpansionHandler.reset(expandableView, animationDuration = 0)
92 
93         verify(expandableView, atLeast(1)).actualHeight = collapsedHeight
94     }
95 
96     @Test
97     fun resetChild_dontUpdateHeight() {
98         whenever(expandableView.actualHeight).thenReturn(collapsedHeight)
99 
100         pulseExpansionHandler.reset(expandableView, animationDuration = 0)
101 
102         verify(expandableView, never()).actualHeight = anyInt()
103     }
104 }
105