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 package com.android.systemui.decor 18 19 import android.content.res.Resources 20 import android.testing.AndroidTestingRunner 21 import android.view.DisplayCutout 22 import androidx.test.filters.SmallTest 23 import com.android.systemui.R 24 import com.android.systemui.SysuiTestCase 25 import org.junit.Assert 26 import org.junit.Before 27 import org.junit.Test 28 import org.junit.runner.RunWith 29 import org.mockito.Mock 30 import org.mockito.Mockito.spy 31 import org.mockito.Mockito.`when` as whenever 32 33 @RunWith(AndroidTestingRunner::class) 34 @SmallTest 35 class PrivacyDotDecorProviderFactoryTest : SysuiTestCase() { 36 private lateinit var mPrivacyDotDecorProviderFactory: PrivacyDotDecorProviderFactory 37 38 @Mock private lateinit var resources: Resources 39 40 @Before 41 fun setUp() { 42 resources = spy(mContext.resources) 43 mPrivacyDotDecorProviderFactory = PrivacyDotDecorProviderFactory(resources) 44 } 45 46 private fun setPrivacyDotResources(isEnable: Boolean) { 47 whenever(resources.getBoolean(R.bool.config_enablePrivacyDot)).thenReturn(isEnable) 48 } 49 50 @Test 51 fun testGetNoCornerDecorProviderWithNoPrivacyDot() { 52 setPrivacyDotResources(false) 53 54 Assert.assertEquals(false, mPrivacyDotDecorProviderFactory.hasProviders) 55 Assert.assertEquals(0, mPrivacyDotDecorProviderFactory.providers.size) 56 } 57 58 @Test 59 fun testGet4CornerDecorProvidersWithPrivacyDot() { 60 setPrivacyDotResources(true) 61 val providers = mPrivacyDotDecorProviderFactory.providers 62 63 Assert.assertEquals(true, mPrivacyDotDecorProviderFactory.hasProviders) 64 Assert.assertEquals(4, providers.size) 65 Assert.assertEquals(1, providers.count { 66 ((it.viewId == R.id.privacy_dot_top_left_container) 67 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_TOP) 68 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_LEFT)) 69 }) 70 Assert.assertEquals(1, providers.count { 71 ((it.viewId == R.id.privacy_dot_top_right_container) 72 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_TOP) 73 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_RIGHT)) 74 }) 75 Assert.assertEquals(1, providers.count { 76 ((it.viewId == R.id.privacy_dot_bottom_left_container) 77 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_BOTTOM) 78 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_LEFT)) 79 }) 80 Assert.assertEquals(1, providers.count { 81 ((it.viewId == R.id.privacy_dot_bottom_right_container) 82 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_BOTTOM) 83 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_RIGHT)) 84 }) 85 } 86 }