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.launcher3.util.window 18 19 import android.graphics.Rect 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import androidx.test.filters.SmallTest 22 import com.android.launcher3.util.window.WindowManagerProxy.areBottomDisplayCutoutsSmallAndAtCorners 23 import junit.framework.Assert.assertFalse 24 import junit.framework.Assert.assertTrue 25 import org.junit.Test 26 import org.junit.runner.RunWith 27 28 /** Unit test for [WindowManagerProxy] */ 29 @SmallTest 30 @RunWith(AndroidJUnit4::class) 31 class WindowManagerProxyTest { 32 33 private val windowWidthPx = 2000 34 35 private val bottomLeftCutout = Rect(0, 2364, 136, 2500) 36 private val bottomRightCutout = Rect(1864, 2364, 2000, 2500) 37 38 private val bottomLeftCutoutWithOffset = Rect(10, 2364, 136, 2500) 39 private val bottomRightCutoutWithOffset = Rect(1864, 2364, 1990, 2500) 40 41 private val maxWidthAndHeightOfSmallCutoutPx = 136 42 43 @Test cutout_at_bottom_right_cornernull44 fun cutout_at_bottom_right_corner() { 45 assertTrue( 46 areBottomDisplayCutoutsSmallAndAtCorners( 47 bottomRightCutout, 48 windowWidthPx, 49 maxWidthAndHeightOfSmallCutoutPx 50 ) 51 ) 52 } 53 54 @Test cutout_at_bottom_left_corner_with_offsetnull55 fun cutout_at_bottom_left_corner_with_offset() { 56 assertTrue( 57 areBottomDisplayCutoutsSmallAndAtCorners( 58 bottomLeftCutoutWithOffset, 59 windowWidthPx, 60 maxWidthAndHeightOfSmallCutoutPx 61 ) 62 ) 63 } 64 65 @Test cutout_at_bottom_right_corner_with_offsetnull66 fun cutout_at_bottom_right_corner_with_offset() { 67 assertTrue( 68 areBottomDisplayCutoutsSmallAndAtCorners( 69 bottomRightCutoutWithOffset, 70 windowWidthPx, 71 maxWidthAndHeightOfSmallCutoutPx 72 ) 73 ) 74 } 75 76 @Test cutout_at_bottom_left_cornernull77 fun cutout_at_bottom_left_corner() { 78 assertTrue( 79 areBottomDisplayCutoutsSmallAndAtCorners( 80 bottomLeftCutout, 81 windowWidthPx, 82 maxWidthAndHeightOfSmallCutoutPx 83 ) 84 ) 85 } 86 87 @Test cutout_at_bottom_edge_at_bottom_cornersnull88 fun cutout_at_bottom_edge_at_bottom_corners() { 89 assertTrue( 90 areBottomDisplayCutoutsSmallAndAtCorners( 91 bottomLeftCutout, 92 windowWidthPx, 93 maxWidthAndHeightOfSmallCutoutPx 94 ) 95 ) 96 } 97 98 @Test cutout_too_big_not_at_bottom_cornersnull99 fun cutout_too_big_not_at_bottom_corners() { 100 // Rect in size of 200px 101 val bigBottomLeftCutout = Rect(0, 2300, 200, 2500) 102 103 assertFalse( 104 areBottomDisplayCutoutsSmallAndAtCorners( 105 bigBottomLeftCutout, 106 windowWidthPx, 107 maxWidthAndHeightOfSmallCutoutPx 108 ) 109 ) 110 } 111 112 @Test cutout_too_small_at_bottom_cornersnull113 fun cutout_too_small_at_bottom_corners() { 114 // Rect in size of 100px 115 val smallBottomLeft = Rect(0, 2400, 100, 2500) 116 117 assertTrue( 118 areBottomDisplayCutoutsSmallAndAtCorners( 119 smallBottomLeft, 120 windowWidthPx, 121 maxWidthAndHeightOfSmallCutoutPx 122 ) 123 ) 124 } 125 126 @Test cutout_empty_not_at_bottom_cornersnull127 fun cutout_empty_not_at_bottom_corners() { 128 val emptyRect = Rect(0, 0, 0, 0) 129 130 assertFalse( 131 areBottomDisplayCutoutsSmallAndAtCorners( 132 emptyRect, 133 windowWidthPx, 134 maxWidthAndHeightOfSmallCutoutPx 135 ) 136 ) 137 } 138 } 139