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.ExpandHelper 24 import com.android.systemui.SysuiTestCase 25 import com.android.systemui.classifier.FalsingCollector 26 import com.android.systemui.plugins.FalsingManager 27 import com.android.systemui.statusbar.notification.row.ExpandableView 28 import com.android.systemui.util.mockito.mock 29 import org.junit.Before 30 import org.junit.Test 31 import org.junit.runner.RunWith 32 import org.mockito.Mockito.anyInt 33 import org.mockito.Mockito.atLeast 34 import org.mockito.Mockito.never 35 import org.mockito.Mockito.verify 36 import org.mockito.Mockito.`when` as whenever 37 38 @SmallTest 39 @TestableLooper.RunWithLooper 40 @RunWith(AndroidTestingRunner::class) 41 class DragDownHelperTest : SysuiTestCase() { 42 43 private lateinit var dragDownHelper: DragDownHelper 44 45 private val collapsedHeight = 300 46 private val falsingManager: FalsingManager = mock() 47 private val falsingCollector: FalsingCollector = mock() 48 private val dragDownloadCallback: LockscreenShadeTransitionController = mock() 49 private val expandableView: ExpandableView = mock() 50 private val expandCallback: ExpandHelper.Callback = mock() 51 52 @Before 53 fun setUp() { 54 whenever(expandableView.collapsedHeight).thenReturn(collapsedHeight) 55 56 dragDownHelper = DragDownHelper( 57 falsingManager, 58 falsingCollector, 59 dragDownloadCallback, 60 mContext 61 ).also { 62 it.expandCallback = expandCallback 63 } 64 } 65 66 @Test 67 fun cancelChildExpansion_updateHeight() { 68 whenever(expandableView.actualHeight).thenReturn(500) 69 70 dragDownHelper.cancelChildExpansion(expandableView, animationDuration = 0) 71 72 verify(expandableView, atLeast(1)).actualHeight = collapsedHeight 73 } 74 75 @Test 76 fun cancelChildExpansion_dontUpdateHeight() { 77 whenever(expandableView.actualHeight).thenReturn(collapsedHeight) 78 79 dragDownHelper.cancelChildExpansion(expandableView, animationDuration = 0) 80 81 verify(expandableView, never()).actualHeight = anyInt() 82 } 83 } 84