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.systemui.settings.brightness.ui.binder
18 
19 import android.content.applicationContext
20 import android.view.ContextThemeWrapper
21 import android.view.View
22 import androidx.test.ext.junit.runners.AndroidJUnit4
23 import androidx.test.filters.SmallTest
24 import com.android.systemui.SysuiTestCase
25 import com.android.systemui.res.R
26 import com.android.systemui.settings.brightnessSliderControllerFactory
27 import com.android.systemui.testKosmos
28 import com.android.systemui.util.Assert
29 import com.google.common.truth.Truth.assertThat
30 import org.junit.Test
31 import org.junit.runner.RunWith
32 
33 @SmallTest
34 @RunWith(AndroidJUnit4::class)
35 class BrightnessMirrorInflaterTest : SysuiTestCase() {
36     private val kosmos = testKosmos()
37 
38     private val themedContext =
39         ContextThemeWrapper(kosmos.applicationContext, R.style.Theme_SystemUI_QuickSettings)
40 
41     @Test
inflate_sliderViewAddedToFramenull42     fun inflate_sliderViewAddedToFrame() {
43         Assert.setTestThread(Thread.currentThread())
44 
45         val (frame, sliderController) =
46             BrightnessMirrorInflater.inflate(
47                 themedContext,
48                 kosmos.brightnessSliderControllerFactory
49             )
50 
51         assertThat(sliderController.rootView.parent).isSameInstanceAs(frame)
52 
53         Assert.setTestThread(null)
54     }
55 
56     @Test
inflate_frameAndSliderViewVisiblenull57     fun inflate_frameAndSliderViewVisible() {
58         Assert.setTestThread(Thread.currentThread())
59 
60         val (frame, sliderController) =
61             BrightnessMirrorInflater.inflate(
62                 themedContext,
63                 kosmos.brightnessSliderControllerFactory,
64             )
65 
66         assertThat(frame.visibility).isEqualTo(View.VISIBLE)
67         assertThat(sliderController.rootView.visibility).isEqualTo(View.VISIBLE)
68 
69         Assert.setTestThread(null)
70     }
71 
72     @Test
inflate_frameHasPaddingnull73     fun inflate_frameHasPadding() {
74         Assert.setTestThread(Thread.currentThread())
75 
76         val (frame, _) =
77             BrightnessMirrorInflater.inflate(
78                 themedContext,
79                 kosmos.brightnessSliderControllerFactory,
80             )
81 
82         assertThat(frame.visibility).isEqualTo(View.VISIBLE)
83 
84         val padding =
85             context.resources.getDimensionPixelSize(R.dimen.rounded_slider_background_padding)
86 
87         assertThat(frame.paddingLeft).isEqualTo(padding)
88         assertThat(frame.paddingTop).isEqualTo(padding)
89         assertThat(frame.paddingRight).isEqualTo(padding)
90         assertThat(frame.paddingBottom).isEqualTo(padding)
91 
92         Assert.setTestThread(null)
93     }
94 }
95