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.testing.AndroidTestingRunner 20 import android.util.Size 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 31 import org.mockito.Mockito.spy 32 33 @RunWith(AndroidTestingRunner::class) 34 @SmallTest 35 class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() { 36 37 @Mock private lateinit var roundedCornerResDelegate: RoundedCornerResDelegate 38 private lateinit var roundedCornerDecorProviderFactory: RoundedCornerDecorProviderFactory 39 40 @Before 41 fun setUp() { 42 roundedCornerResDelegate = spy(RoundedCornerResDelegateImpl(mContext.resources, null)) 43 } 44 45 @Test 46 fun testNoRoundedCorners() { 47 Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasTop 48 Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasBottom 49 50 roundedCornerDecorProviderFactory = 51 RoundedCornerDecorProviderFactory(roundedCornerResDelegate) 52 53 Assert.assertEquals(false, roundedCornerDecorProviderFactory.hasProviders) 54 Assert.assertEquals(0, roundedCornerDecorProviderFactory.providers.size) 55 } 56 57 @Test 58 fun testOnlyHasTopRoundedCorners() { 59 Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasTop 60 Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasBottom 61 Mockito.doReturn(Size(1, 1)).`when`(roundedCornerResDelegate).topRoundedSize 62 63 roundedCornerDecorProviderFactory = 64 RoundedCornerDecorProviderFactory(roundedCornerResDelegate) 65 66 Assert.assertEquals(true, roundedCornerDecorProviderFactory.hasProviders) 67 roundedCornerDecorProviderFactory.providers.let { providers -> 68 Assert.assertEquals(2, providers.size) 69 Assert.assertEquals(1, providers.count { 70 ((it.viewId == R.id.rounded_corner_top_left) 71 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_TOP) 72 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_LEFT)) 73 }) 74 Assert.assertEquals(1, providers.count { 75 ((it.viewId == R.id.rounded_corner_top_right) 76 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_TOP) 77 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_RIGHT)) 78 }) 79 } 80 } 81 82 @Test 83 fun testHasRoundedCornersIfBottomWidthLargerThan0() { 84 Mockito.doReturn(false).`when`(roundedCornerResDelegate).hasTop 85 Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasBottom 86 Mockito.doReturn(Size(1, 1)).`when`(roundedCornerResDelegate).bottomRoundedSize 87 88 roundedCornerDecorProviderFactory = 89 RoundedCornerDecorProviderFactory(roundedCornerResDelegate) 90 91 Assert.assertEquals(true, roundedCornerDecorProviderFactory.hasProviders) 92 roundedCornerDecorProviderFactory.providers.let { providers -> 93 Assert.assertEquals(2, providers.size) 94 Assert.assertEquals(1, providers.count { 95 ((it.viewId == R.id.rounded_corner_bottom_left) 96 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_BOTTOM) 97 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_LEFT)) 98 }) 99 Assert.assertEquals(1, providers.count { 100 ((it.viewId == R.id.rounded_corner_bottom_right) 101 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_BOTTOM) 102 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_RIGHT)) 103 }) 104 } 105 } 106 107 @Test 108 fun test4CornerDecorProvidersInfo() { 109 Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasTop 110 Mockito.doReturn(true).`when`(roundedCornerResDelegate).hasBottom 111 Mockito.doReturn(Size(10, 10)).`when`(roundedCornerResDelegate).topRoundedSize 112 Mockito.doReturn(Size(10, 10)).`when`(roundedCornerResDelegate).bottomRoundedSize 113 114 roundedCornerDecorProviderFactory = 115 RoundedCornerDecorProviderFactory(roundedCornerResDelegate) 116 117 Assert.assertEquals(true, roundedCornerDecorProviderFactory.hasProviders) 118 roundedCornerDecorProviderFactory.providers.let { providers -> 119 Assert.assertEquals(4, providers.size) 120 Assert.assertEquals(1, providers.count { 121 ((it.viewId == R.id.rounded_corner_top_left) 122 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_TOP) 123 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_LEFT)) 124 }) 125 Assert.assertEquals(1, providers.count { 126 ((it.viewId == R.id.rounded_corner_top_right) 127 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_TOP) 128 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_RIGHT)) 129 }) 130 Assert.assertEquals(1, providers.count { 131 ((it.viewId == R.id.rounded_corner_bottom_left) 132 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_BOTTOM) 133 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_LEFT)) 134 }) 135 Assert.assertEquals(1, providers.count { 136 ((it.viewId == R.id.rounded_corner_bottom_right) 137 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_BOTTOM) 138 and it.alignedBounds.contains(DisplayCutout.BOUNDS_POSITION_RIGHT)) 139 }) 140 } 141 } 142 }