Loading packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/startable/ShadeStartableTest.kt +77 −58 Original line number Diff line number Diff line Loading @@ -24,13 +24,14 @@ import com.android.compose.animation.scene.SceneKey import com.android.systemui.SysuiTestCase import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository import com.android.systemui.authentication.shared.model.AuthenticationMethodModel import com.android.systemui.coroutines.collectLastValue import com.android.systemui.display.data.repository.displayStateRepository import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.flags.parameterizeSceneContainerFlag import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.scene.domain.interactor.sceneInteractor import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.scene.shared.model.fakeSceneDataSource Loading @@ -54,9 +55,6 @@ import kotlin.math.max import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -70,16 +68,9 @@ import platform.test.runner.parameterized.Parameters @RunWith(ParameterizedAndroidJunit4::class) class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val sceneInteractor by lazy { kosmos.sceneInteractor } private val fakeSceneDataSource by lazy { kosmos.fakeSceneDataSource } private val shadeDepthController by lazy { kosmos.notificationShadeDepthController } private val shadeExpansionStateManager by lazy { kosmos.shadeExpansionStateManager.also { it.addExpansionListener(shadeDepthController) } } private val kosmos = testKosmos().useUnconfinedTestDispatcher() private lateinit var underTest: ShadeStartable private val underTest: ShadeStartable by lazy { kosmos.shadeStartable } companion object { @JvmStatic Loading @@ -95,25 +86,27 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { @Before fun setUp() { underTest = kosmos.shadeStartable kosmos.shadeExpansionStateManager.addExpansionListener( kosmos.notificationShadeDepthController ) } @Test fun hydrateShadeMode_dualShadeDisabled() = testScope.runTest { val shadeMode by collectLastValue(kosmos.shadeMode) val isShadeLayoutWide by collectLastValue(kosmos.shadeModeInteractor.isShadeLayoutWide) kosmos.runTest { val shadeMode by collectLastValue(shadeMode) val isShadeLayoutWide by collectLastValue(shadeModeInteractor.isShadeLayoutWide) underTest.start() kosmos.enableSingleShade() enableSingleShade() assertThat(shadeMode).isEqualTo(ShadeMode.Single) assertThat(isShadeLayoutWide).isFalse() kosmos.enableSplitShade() enableSplitShade() assertThat(shadeMode).isEqualTo(ShadeMode.Split) assertThat(isShadeLayoutWide).isTrue() kosmos.enableSingleShade() enableSingleShade() assertThat(shadeMode).isEqualTo(ShadeMode.Single) assertThat(isShadeLayoutWide).isFalse() } Loading @@ -121,20 +114,20 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { @Test @EnableSceneContainer fun hydrateShadeMode_dualShadeEnabled() = testScope.runTest { val shadeMode by collectLastValue(kosmos.shadeMode) val isShadeLayoutWide by collectLastValue(kosmos.shadeModeInteractor.isShadeLayoutWide) kosmos.runTest { val shadeMode by collectLastValue(shadeMode) val isShadeLayoutWide by collectLastValue(shadeModeInteractor.isShadeLayoutWide) underTest.start() kosmos.enableDualShade(wideLayout = false) enableDualShade(wideLayout = false) assertThat(shadeMode).isEqualTo(ShadeMode.Dual) assertThat(isShadeLayoutWide).isFalse() kosmos.enableDualShade(wideLayout = true) enableDualShade(wideLayout = true) assertThat(shadeMode).isEqualTo(ShadeMode.Dual) assertThat(isShadeLayoutWide).isTrue() kosmos.enableDualShade(wideLayout = false) enableDualShade(wideLayout = false) assertThat(shadeMode).isEqualTo(ShadeMode.Dual) assertThat(isShadeLayoutWide).isFalse() } Loading @@ -142,7 +135,8 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { @Test @EnableSceneContainer fun hydrateShadeExpansionStateManager() = testScope.runTest { kosmos.runTest { enableSingleShade() val expansionListener = mock<ShadeExpansionListener>() var latestChangeEvent: ShadeExpansionChangeEvent? = null whenever(expansionListener.onPanelExpansionChanged(any())).thenAnswer { Loading @@ -153,14 +147,10 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { underTest.start() kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) runCurrent() kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( SuccessFingerprintAuthenticationStatus(0, true) ) runCurrent() val transitionState = MutableStateFlow<ObservableTransitionState>( ObservableTransitionState.Idle(Scenes.Gone) Loading @@ -178,21 +168,22 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { changeScene(Scenes.Shade, transitionState) { progress -> assertThat(latestChangeEvent?.fraction).isEqualTo(progress) assertThat(shadeDepthController.qsPanelExpansion).isZero() assertThat(shadeDepthController.shadeExpansion).isEqualTo(progress) assertThat(shadeDepthController.transitionToFullShadeProgress).isEqualTo(progress) assertThat(notificationShadeDepthController.qsPanelExpansion).isZero() assertThat(notificationShadeDepthController.shadeExpansion).isEqualTo(progress) assertThat(notificationShadeDepthController.transitionToFullShadeProgress) .isEqualTo(progress) } assertThat(currentScene).isEqualTo(Scenes.Shade) changeScene(Scenes.QuickSettings, transitionState) { progress -> assertThat(latestChangeEvent?.fraction).isEqualTo(1 - progress) assertThat(shadeDepthController.qsPanelExpansion).isEqualTo(progress) assertThat(shadeDepthController.shadeExpansion).isEqualTo(1 - progress) assertThat(shadeDepthController.transitionToFullShadeProgress) assertThat(notificationShadeDepthController.qsPanelExpansion).isEqualTo(progress) assertThat(notificationShadeDepthController.shadeExpansion).isEqualTo(1 - progress) assertThat(notificationShadeDepthController.transitionToFullShadeProgress) .isEqualTo( max( shadeDepthController.qsPanelExpansion, shadeDepthController.shadeExpansion, notificationShadeDepthController.qsPanelExpansion, notificationShadeDepthController.shadeExpansion, ) ) } Loading @@ -200,9 +191,10 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { changeScene(Scenes.Lockscreen, transitionState) { progress -> assertThat(latestChangeEvent?.fraction).isZero() assertThat(shadeDepthController.qsPanelExpansion).isEqualTo(1 - progress) assertThat(shadeDepthController.shadeExpansion).isZero() assertThat(shadeDepthController.transitionToFullShadeProgress) assertThat(notificationShadeDepthController.qsPanelExpansion) .isEqualTo(1 - progress) assertThat(notificationShadeDepthController.shadeExpansion).isZero() assertThat(notificationShadeDepthController.transitionToFullShadeProgress) .isEqualTo(1 - progress) } assertThat(currentScene).isEqualTo(Scenes.Lockscreen) Loading @@ -210,17 +202,49 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { @Test @EnableSceneContainer fun hydrateFullWidth() = testScope.runTest { fun hydrateFullWidth_singleShade() = kosmos.runTest { enableSingleShade() underTest.start() verify(notificationStackScrollLayoutController).setIsFullWidth(true) assertThat(scrimController.clipQsScrim).isFalse() } @Test @EnableSceneContainer fun hydrateFullWidth_splitShade() = kosmos.runTest { enableSplitShade() underTest.start() verify(notificationStackScrollLayoutController).setIsFullWidth(false) assertThat(scrimController.clipQsScrim).isFalse() } @Test @EnableSceneContainer fun hydrateFullWidth_dualShade_narrowScreen() = kosmos.runTest { enableDualShade(wideLayout = false) underTest.start() verify(notificationStackScrollLayoutController).setIsFullWidth(true) assertThat(scrimController.clipQsScrim).isFalse() } @Test @EnableSceneContainer fun hydrateFullWidth_dualShade_wideScreen() = kosmos.runTest { enableDualShade(wideLayout = true) underTest.start() kosmos.displayStateRepository.setIsWideScreen(true) runCurrent() verify(kosmos.notificationStackScrollLayoutController).setIsFullWidth(false) assertThat(kosmos.scrimController.clipQsScrim).isFalse() verify(notificationStackScrollLayoutController).setIsFullWidth(false) assertThat(scrimController.clipQsScrim).isFalse() } private fun TestScope.changeScene( private fun Kosmos.changeScene( toScene: SceneKey, transitionState: MutableStateFlow<ObservableTransitionState>, assertDuringProgress: ((progress: Float) -> Unit) = {}, Loading @@ -236,24 +260,19 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { isInitiatedByUserInput = true, isUserInputOngoing = flowOf(true), ) runCurrent() assertDuringProgress(progressFlow.value) progressFlow.value = 0.2f runCurrent() assertDuringProgress(progressFlow.value) progressFlow.value = 0.6f runCurrent() assertDuringProgress(progressFlow.value) progressFlow.value = 1f runCurrent() assertDuringProgress(progressFlow.value) transitionState.value = ObservableTransitionState.Idle(toScene) fakeSceneDataSource.changeScene(toScene) runCurrent() assertDuringProgress(progressFlow.value) assertThat(currentScene).isEqualTo(toScene) Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/startable/ShadeStartableTest.kt +77 −58 Original line number Diff line number Diff line Loading @@ -24,13 +24,14 @@ import com.android.compose.animation.scene.SceneKey import com.android.systemui.SysuiTestCase import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository import com.android.systemui.authentication.shared.model.AuthenticationMethodModel import com.android.systemui.coroutines.collectLastValue import com.android.systemui.display.data.repository.displayStateRepository import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.flags.parameterizeSceneContainerFlag import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.scene.domain.interactor.sceneInteractor import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.scene.shared.model.fakeSceneDataSource Loading @@ -54,9 +55,6 @@ import kotlin.math.max import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -70,16 +68,9 @@ import platform.test.runner.parameterized.Parameters @RunWith(ParameterizedAndroidJunit4::class) class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val sceneInteractor by lazy { kosmos.sceneInteractor } private val fakeSceneDataSource by lazy { kosmos.fakeSceneDataSource } private val shadeDepthController by lazy { kosmos.notificationShadeDepthController } private val shadeExpansionStateManager by lazy { kosmos.shadeExpansionStateManager.also { it.addExpansionListener(shadeDepthController) } } private val kosmos = testKosmos().useUnconfinedTestDispatcher() private lateinit var underTest: ShadeStartable private val underTest: ShadeStartable by lazy { kosmos.shadeStartable } companion object { @JvmStatic Loading @@ -95,25 +86,27 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { @Before fun setUp() { underTest = kosmos.shadeStartable kosmos.shadeExpansionStateManager.addExpansionListener( kosmos.notificationShadeDepthController ) } @Test fun hydrateShadeMode_dualShadeDisabled() = testScope.runTest { val shadeMode by collectLastValue(kosmos.shadeMode) val isShadeLayoutWide by collectLastValue(kosmos.shadeModeInteractor.isShadeLayoutWide) kosmos.runTest { val shadeMode by collectLastValue(shadeMode) val isShadeLayoutWide by collectLastValue(shadeModeInteractor.isShadeLayoutWide) underTest.start() kosmos.enableSingleShade() enableSingleShade() assertThat(shadeMode).isEqualTo(ShadeMode.Single) assertThat(isShadeLayoutWide).isFalse() kosmos.enableSplitShade() enableSplitShade() assertThat(shadeMode).isEqualTo(ShadeMode.Split) assertThat(isShadeLayoutWide).isTrue() kosmos.enableSingleShade() enableSingleShade() assertThat(shadeMode).isEqualTo(ShadeMode.Single) assertThat(isShadeLayoutWide).isFalse() } Loading @@ -121,20 +114,20 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { @Test @EnableSceneContainer fun hydrateShadeMode_dualShadeEnabled() = testScope.runTest { val shadeMode by collectLastValue(kosmos.shadeMode) val isShadeLayoutWide by collectLastValue(kosmos.shadeModeInteractor.isShadeLayoutWide) kosmos.runTest { val shadeMode by collectLastValue(shadeMode) val isShadeLayoutWide by collectLastValue(shadeModeInteractor.isShadeLayoutWide) underTest.start() kosmos.enableDualShade(wideLayout = false) enableDualShade(wideLayout = false) assertThat(shadeMode).isEqualTo(ShadeMode.Dual) assertThat(isShadeLayoutWide).isFalse() kosmos.enableDualShade(wideLayout = true) enableDualShade(wideLayout = true) assertThat(shadeMode).isEqualTo(ShadeMode.Dual) assertThat(isShadeLayoutWide).isTrue() kosmos.enableDualShade(wideLayout = false) enableDualShade(wideLayout = false) assertThat(shadeMode).isEqualTo(ShadeMode.Dual) assertThat(isShadeLayoutWide).isFalse() } Loading @@ -142,7 +135,8 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { @Test @EnableSceneContainer fun hydrateShadeExpansionStateManager() = testScope.runTest { kosmos.runTest { enableSingleShade() val expansionListener = mock<ShadeExpansionListener>() var latestChangeEvent: ShadeExpansionChangeEvent? = null whenever(expansionListener.onPanelExpansionChanged(any())).thenAnswer { Loading @@ -153,14 +147,10 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { underTest.start() kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) runCurrent() kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( SuccessFingerprintAuthenticationStatus(0, true) ) runCurrent() val transitionState = MutableStateFlow<ObservableTransitionState>( ObservableTransitionState.Idle(Scenes.Gone) Loading @@ -178,21 +168,22 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { changeScene(Scenes.Shade, transitionState) { progress -> assertThat(latestChangeEvent?.fraction).isEqualTo(progress) assertThat(shadeDepthController.qsPanelExpansion).isZero() assertThat(shadeDepthController.shadeExpansion).isEqualTo(progress) assertThat(shadeDepthController.transitionToFullShadeProgress).isEqualTo(progress) assertThat(notificationShadeDepthController.qsPanelExpansion).isZero() assertThat(notificationShadeDepthController.shadeExpansion).isEqualTo(progress) assertThat(notificationShadeDepthController.transitionToFullShadeProgress) .isEqualTo(progress) } assertThat(currentScene).isEqualTo(Scenes.Shade) changeScene(Scenes.QuickSettings, transitionState) { progress -> assertThat(latestChangeEvent?.fraction).isEqualTo(1 - progress) assertThat(shadeDepthController.qsPanelExpansion).isEqualTo(progress) assertThat(shadeDepthController.shadeExpansion).isEqualTo(1 - progress) assertThat(shadeDepthController.transitionToFullShadeProgress) assertThat(notificationShadeDepthController.qsPanelExpansion).isEqualTo(progress) assertThat(notificationShadeDepthController.shadeExpansion).isEqualTo(1 - progress) assertThat(notificationShadeDepthController.transitionToFullShadeProgress) .isEqualTo( max( shadeDepthController.qsPanelExpansion, shadeDepthController.shadeExpansion, notificationShadeDepthController.qsPanelExpansion, notificationShadeDepthController.shadeExpansion, ) ) } Loading @@ -200,9 +191,10 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { changeScene(Scenes.Lockscreen, transitionState) { progress -> assertThat(latestChangeEvent?.fraction).isZero() assertThat(shadeDepthController.qsPanelExpansion).isEqualTo(1 - progress) assertThat(shadeDepthController.shadeExpansion).isZero() assertThat(shadeDepthController.transitionToFullShadeProgress) assertThat(notificationShadeDepthController.qsPanelExpansion) .isEqualTo(1 - progress) assertThat(notificationShadeDepthController.shadeExpansion).isZero() assertThat(notificationShadeDepthController.transitionToFullShadeProgress) .isEqualTo(1 - progress) } assertThat(currentScene).isEqualTo(Scenes.Lockscreen) Loading @@ -210,17 +202,49 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { @Test @EnableSceneContainer fun hydrateFullWidth() = testScope.runTest { fun hydrateFullWidth_singleShade() = kosmos.runTest { enableSingleShade() underTest.start() verify(notificationStackScrollLayoutController).setIsFullWidth(true) assertThat(scrimController.clipQsScrim).isFalse() } @Test @EnableSceneContainer fun hydrateFullWidth_splitShade() = kosmos.runTest { enableSplitShade() underTest.start() verify(notificationStackScrollLayoutController).setIsFullWidth(false) assertThat(scrimController.clipQsScrim).isFalse() } @Test @EnableSceneContainer fun hydrateFullWidth_dualShade_narrowScreen() = kosmos.runTest { enableDualShade(wideLayout = false) underTest.start() verify(notificationStackScrollLayoutController).setIsFullWidth(true) assertThat(scrimController.clipQsScrim).isFalse() } @Test @EnableSceneContainer fun hydrateFullWidth_dualShade_wideScreen() = kosmos.runTest { enableDualShade(wideLayout = true) underTest.start() kosmos.displayStateRepository.setIsWideScreen(true) runCurrent() verify(kosmos.notificationStackScrollLayoutController).setIsFullWidth(false) assertThat(kosmos.scrimController.clipQsScrim).isFalse() verify(notificationStackScrollLayoutController).setIsFullWidth(false) assertThat(scrimController.clipQsScrim).isFalse() } private fun TestScope.changeScene( private fun Kosmos.changeScene( toScene: SceneKey, transitionState: MutableStateFlow<ObservableTransitionState>, assertDuringProgress: ((progress: Float) -> Unit) = {}, Loading @@ -236,24 +260,19 @@ class ShadeStartableTest(flags: FlagsParameterization) : SysuiTestCase() { isInitiatedByUserInput = true, isUserInputOngoing = flowOf(true), ) runCurrent() assertDuringProgress(progressFlow.value) progressFlow.value = 0.2f runCurrent() assertDuringProgress(progressFlow.value) progressFlow.value = 0.6f runCurrent() assertDuringProgress(progressFlow.value) progressFlow.value = 1f runCurrent() assertDuringProgress(progressFlow.value) transitionState.value = ObservableTransitionState.Idle(toScene) fakeSceneDataSource.changeScene(toScene) runCurrent() assertDuringProgress(progressFlow.value) assertThat(currentScene).isEqualTo(toScene) Loading