diff options
| author | 2025-01-14 14:38:33 +0000 | |
|---|---|---|
| committer | 2025-01-17 11:16:54 +0000 | |
| commit | 53ec1aca4dafb25a035c784ebc481993fb9e8300 (patch) | |
| tree | f0885b9693649b3dd3377b92dbc217aee1bd4331 | |
| parent | ef515d32b3038ae6148078184435f861c0ca86b9 (diff) | |
Add FakeDevicePostureController
Flag: EXEMPT TEST_ONLY
Fixes: 369993864
Test: atest VolumeDialogScreenshotTest
Test: presubmits
Change-Id: I41572fc2f9c97289fa26aa805061f3d47df53c51
8 files changed, 116 insertions, 13 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/dialog/domain/interactor/VolumeDialogStateInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/dialog/domain/interactor/VolumeDialogStateInteractorTest.kt new file mode 100644 index 000000000000..a3b948e49e46 --- /dev/null +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/dialog/domain/interactor/VolumeDialogStateInteractorTest.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.volume.dialog.domain.interactor + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +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.plugins.fakeVolumeDialogController +import com.android.systemui.testKosmos +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith + +@SmallTest +@RunWith(AndroidJUnit4::class) +class VolumeDialogStateInteractorTest : SysuiTestCase() { + + private val kosmos: Kosmos = testKosmos().useUnconfinedTestDispatcher() + + private val underTest: VolumeDialogStateInteractor + get() = kosmos.volumeDialogStateInteractor + + @Test + fun dialogState_collectedEagerly() = + kosmos.runTest { + val nonDefaultActiveStream = 123 + fakeVolumeDialogController.setActiveStream(123) + + val volumeDialogStateModel by collectLastValue(underTest.volumeDialogState) + + assertThat(volumeDialogStateModel?.activeStream).isEqualTo(nonDefaultActiveStream) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/volume/dialog/domain/interactor/VolumeDialogCallbacksInteractor.kt b/packages/SystemUI/src/com/android/systemui/volume/dialog/domain/interactor/VolumeDialogCallbacksInteractor.kt index b52c1075e9f0..8c018606ebda 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/dialog/domain/interactor/VolumeDialogCallbacksInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/dialog/domain/interactor/VolumeDialogCallbacksInteractor.kt @@ -32,6 +32,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.buffer import kotlinx.coroutines.flow.callbackFlow +import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.shareIn private const val BUFFER_CAPACITY = 16 @@ -60,6 +61,7 @@ constructor( } .buffer(capacity = BUFFER_CAPACITY, onBufferOverflow = BufferOverflow.DROP_OLDEST) .shareIn(replay = 0, scope = coroutineScope, started = SharingStarted.WhileSubscribed()) + .onStart { emit(VolumeDialogEventModel.SubscribedToEvents) } private class VolumeDialogEventModelProducer( private val scope: ProducerScope<VolumeDialogEventModel> diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryKosmos.kt index 637385152a0a..5876290beca7 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryKosmos.kt @@ -22,7 +22,7 @@ import com.android.systemui.kosmos.testScope import com.android.systemui.shared.settings.data.repository.secureSettingsRepository import com.android.systemui.shared.settings.data.repository.systemSettingsRepository -val Kosmos.notificationSettingsRepository by +var Kosmos.notificationSettingsRepository by Kosmos.Fixture { NotificationSettingsRepository( backgroundScope = testScope.backgroundScope, diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/DevicePostureControllerKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/DevicePostureControllerKosmos.kt index 89eaf15a52d9..2c7e5a057729 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/DevicePostureControllerKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/DevicePostureControllerKosmos.kt @@ -19,4 +19,5 @@ package com.android.systemui.statusbar.policy import com.android.systemui.kosmos.Kosmos import com.android.systemui.util.mockito.mock -val Kosmos.devicePostureController by Kosmos.Fixture { mock<DevicePostureController>() } +val Kosmos.fakeDevicePostureController by Kosmos.Fixture { FakeDevicePostureController() } +var Kosmos.devicePostureController by Kosmos.Fixture { mock<DevicePostureController>() } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/FakeDevicePostureController.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/FakeDevicePostureController.kt new file mode 100644 index 000000000000..58fc31859223 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/FakeDevicePostureController.kt @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy + +import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt + +class FakeDevicePostureController : DevicePostureController { + + private var devicePosture: Int = DevicePostureController.DEVICE_POSTURE_OPENED + val callbacks: MutableCollection<DevicePostureController.Callback> = mutableSetOf() + + override fun addCallback(listener: DevicePostureController.Callback) { + callbacks.add(listener) + } + + override fun removeCallback(listener: DevicePostureController.Callback) { + callbacks.add(listener) + } + + fun setDevicePosture(@DevicePostureInt posture: Int) { + devicePosture = posture + } + + @DevicePostureInt override fun getDevicePosture(): Int = devicePosture +} diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/dagger/VolumeDialogComponentKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/dagger/VolumeDialogComponentKosmos.kt index 73e5d8d40985..87c382223939 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/dagger/VolumeDialogComponentKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/dagger/VolumeDialogComponentKosmos.kt @@ -27,15 +27,12 @@ val Kosmos.volumeDialogComponentFactory by Kosmos.Fixture { object : VolumeDialogComponent.Factory { override fun create(scope: CoroutineScope): VolumeDialogComponent = - volumeDialogComponent - } - } -val Kosmos.volumeDialogComponent by - Kosmos.Fixture { - object : VolumeDialogComponent { - override fun volumeDialogViewBinder(): VolumeDialogViewBinder = volumeDialogViewBinder + object : VolumeDialogComponent { + override fun volumeDialogViewBinder(): VolumeDialogViewBinder = + volumeDialogViewBinder - override fun sliderComponentFactory(): VolumeDialogSliderComponent.Factory = - volumeDialogSliderComponentFactory + override fun sliderComponentFactory(): VolumeDialogSliderComponent.Factory = + volumeDialogSliderComponentFactory + } } } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/data/repository/VolumeDialogStateRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/data/repository/VolumeDialogStateRepositoryKosmos.kt index 768111170f10..173e5a226879 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/data/repository/VolumeDialogStateRepositoryKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/data/repository/VolumeDialogStateRepositoryKosmos.kt @@ -18,5 +18,5 @@ package com.android.systemui.volume.dialog.data.repository import com.android.systemui.kosmos.Kosmos -val Kosmos.volumeDialogStateRepository: VolumeDialogStateRepository by +var Kosmos.volumeDialogStateRepository: VolumeDialogStateRepository by Kosmos.Fixture { VolumeDialogStateRepository() } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/sliders/dagger/VolumeDialogSliderComponentKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/sliders/dagger/VolumeDialogSliderComponentKosmos.kt index cb38cc3576ad..36fa82f82f0d 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/sliders/dagger/VolumeDialogSliderComponentKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/dialog/sliders/dagger/VolumeDialogSliderComponentKosmos.kt @@ -21,8 +21,13 @@ import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.plugins.volumeDialogController +import com.android.systemui.shared.notifications.data.repository.notificationSettingsRepository +import com.android.systemui.statusbar.policy.data.repository.deviceProvisioningRepository +import com.android.systemui.statusbar.policy.data.repository.userSetupRepository import com.android.systemui.statusbar.policy.data.repository.zenModeRepository +import com.android.systemui.statusbar.policy.devicePostureController import com.android.systemui.volume.data.repository.audioRepository +import com.android.systemui.volume.dialog.data.repository.volumeDialogStateRepository import com.android.systemui.volume.dialog.data.repository.volumeDialogVisibilityRepository import com.android.systemui.volume.dialog.sliders.domain.model.VolumeDialogSliderType import com.android.systemui.volume.dialog.sliders.domain.model.volumeDialogSliderType @@ -77,10 +82,18 @@ private fun Kosmos.setupVolumeDialogSliderComponent( testScope = parentKosmos.testScope testDispatcher = parentKosmos.testDispatcher + audioRepository = parentKosmos.audioRepository + devicePostureController = parentKosmos.devicePostureController + volumeDialogController = parentKosmos.volumeDialogController + volumeDialogStateRepository = parentKosmos.volumeDialogStateRepository + mediaControllerInteractor = parentKosmos.mediaControllerInteractor mediaControllerRepository = parentKosmos.mediaControllerRepository + zenModeRepository = parentKosmos.zenModeRepository volumeDialogVisibilityRepository = parentKosmos.volumeDialogVisibilityRepository - audioRepository = parentKosmos.audioRepository + notificationSettingsRepository = parentKosmos.notificationSettingsRepository + deviceProvisioningRepository = parentKosmos.deviceProvisioningRepository + userSetupRepository = parentKosmos.userSetupRepository } |