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.fold.ui.helper 18 19 import android.graphics.Rect 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import androidx.test.filters.SmallTest 22 import androidx.window.layout.FoldingFeature 23 import androidx.window.layout.WindowLayoutInfo 24 import com.android.systemui.SysuiTestCase 25 import com.google.common.truth.Truth.assertThat 26 import org.junit.Test 27 import org.junit.runner.RunWith 28 29 @SmallTest 30 @RunWith(AndroidJUnit4::class) 31 @android.platform.test.annotations.EnabledOnRavenwood 32 class FoldPostureTest : SysuiTestCase() { 33 34 @Test foldPosture_whenNull_returnsFoldednull35 fun foldPosture_whenNull_returnsFolded() { 36 assertThat(foldPostureInternal(null)).isEqualTo(FoldPosture.Folded) 37 } 38 39 @Test foldPosture_whenHalfOpenHorizontally_returnsTabletopnull40 fun foldPosture_whenHalfOpenHorizontally_returnsTabletop() { 41 assertThat( 42 foldPostureInternal( 43 createWindowLayoutInfo( 44 state = FoldingFeature.State.HALF_OPENED, 45 orientation = FoldingFeature.Orientation.HORIZONTAL, 46 ) 47 ) 48 ) 49 .isEqualTo(FoldPosture.Tabletop) 50 } 51 52 @Test foldPosture_whenHalfOpenVertically_returnsBooknull53 fun foldPosture_whenHalfOpenVertically_returnsBook() { 54 assertThat( 55 foldPostureInternal( 56 createWindowLayoutInfo( 57 state = FoldingFeature.State.HALF_OPENED, 58 orientation = FoldingFeature.Orientation.VERTICAL, 59 ) 60 ) 61 ) 62 .isEqualTo(FoldPosture.Book) 63 } 64 65 @Test foldPosture_whenFlatAndNotSeparating_returnsFullyUnfoldednull66 fun foldPosture_whenFlatAndNotSeparating_returnsFullyUnfolded() { 67 assertThat( 68 foldPostureInternal( 69 createWindowLayoutInfo( 70 state = FoldingFeature.State.FLAT, 71 orientation = FoldingFeature.Orientation.HORIZONTAL, 72 isSeparating = false, 73 ) 74 ) 75 ) 76 .isEqualTo(FoldPosture.FullyUnfolded) 77 } 78 79 @Test foldPosture_whenFlatAndSeparatingHorizontally_returnsTabletopnull80 fun foldPosture_whenFlatAndSeparatingHorizontally_returnsTabletop() { 81 assertThat( 82 foldPostureInternal( 83 createWindowLayoutInfo( 84 state = FoldingFeature.State.FLAT, 85 isSeparating = true, 86 orientation = FoldingFeature.Orientation.HORIZONTAL, 87 ) 88 ) 89 ) 90 .isEqualTo(FoldPosture.Tabletop) 91 } 92 93 @Test foldPosture_whenFlatAndSeparatingVertically_returnsBooknull94 fun foldPosture_whenFlatAndSeparatingVertically_returnsBook() { 95 assertThat( 96 foldPostureInternal( 97 createWindowLayoutInfo( 98 state = FoldingFeature.State.FLAT, 99 isSeparating = true, 100 orientation = FoldingFeature.Orientation.VERTICAL, 101 ) 102 ) 103 ) 104 .isEqualTo(FoldPosture.Book) 105 } 106 createWindowLayoutInfonull107 private fun createWindowLayoutInfo( 108 state: FoldingFeature.State, 109 orientation: FoldingFeature.Orientation = FoldingFeature.Orientation.VERTICAL, 110 isSeparating: Boolean = false, 111 occlusionType: FoldingFeature.OcclusionType = FoldingFeature.OcclusionType.NONE, 112 ): WindowLayoutInfo { 113 return WindowLayoutInfo( 114 listOf( 115 object : FoldingFeature { 116 override val bounds: Rect = Rect(0, 0, 100, 100) 117 override val isSeparating: Boolean = isSeparating 118 override val occlusionType: FoldingFeature.OcclusionType = occlusionType 119 override val orientation: FoldingFeature.Orientation = orientation 120 override val state: FoldingFeature.State = state 121 } 122 ) 123 ) 124 } 125 } 126