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.systemui.shade 18 19 import android.testing.AndroidTestingRunner 20 import android.view.View 21 import android.view.ViewGroup 22 import android.widget.FrameLayout 23 import androidx.constraintlayout.widget.ConstraintLayout 24 import androidx.test.filters.SmallTest 25 import com.android.systemui.R 26 import com.android.systemui.SysuiTestCase 27 import com.android.systemui.qs.QSFragment 28 import com.android.systemui.util.mockito.whenever 29 import com.google.common.truth.Truth.assertThat 30 import org.junit.Before 31 import org.junit.Test 32 import org.junit.runner.RunWith 33 import org.mockito.Mock 34 import org.mockito.MockitoAnnotations 35 36 @SmallTest 37 @RunWith(AndroidTestingRunner::class) 38 class NotificationsQuickSettingsContainerTest : SysuiTestCase() { 39 40 @Mock private lateinit var qsFrame: View 41 @Mock private lateinit var stackScroller: View 42 @Mock private lateinit var keyguardStatusBar: View 43 @Mock private lateinit var qsFragment: QSFragment 44 45 private lateinit var qsView: ViewGroup 46 private lateinit var qsContainer: View 47 48 private lateinit var underTest: NotificationsQuickSettingsContainer 49 50 @Before 51 fun setUp() { 52 MockitoAnnotations.initMocks(this) 53 54 underTest = NotificationsQuickSettingsContainer(context, null) 55 56 setUpViews() 57 underTest.onFinishInflate() 58 underTest.onFragmentViewCreated("QS", qsFragment) 59 } 60 61 @Test 62 fun qsContainerPaddingSetAgainAfterQsRecreated() { 63 val padding = 100 64 underTest.setQSContainerPaddingBottom(padding) 65 66 assertThat(qsContainer.paddingBottom).isEqualTo(padding) 67 68 // We reset the padding before "creating" a new QSFragment 69 qsContainer.setPadding(0, 0, 0, 0) 70 underTest.onFragmentViewCreated("QS", qsFragment) 71 72 assertThat(qsContainer.paddingBottom).isEqualTo(padding) 73 } 74 75 private fun setUpViews() { 76 qsView = FrameLayout(context) 77 qsContainer = View(context) 78 qsContainer.id = R.id.quick_settings_container 79 qsView.addView(qsContainer) 80 81 whenever(qsFrame.findViewById<View>(R.id.qs_frame)).thenReturn(qsFrame) 82 whenever(stackScroller.findViewById<View>(R.id.notification_stack_scroller)) 83 .thenReturn(stackScroller) 84 whenever(keyguardStatusBar.findViewById<View>(R.id.keyguard_header)) 85 .thenReturn(keyguardStatusBar) 86 whenever(qsFragment.view).thenReturn(qsView) 87 88 val layoutParams = ConstraintLayout.LayoutParams(0, 0) 89 whenever(qsFrame.layoutParams).thenReturn(layoutParams) 90 whenever(stackScroller.layoutParams).thenReturn(layoutParams) 91 whenever(keyguardStatusBar.layoutParams).thenReturn(layoutParams) 92 93 underTest.addView(qsFrame) 94 underTest.addView(stackScroller) 95 underTest.addView(keyguardStatusBar) 96 } 97 } 98