Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53ec1aca authored by Anton Potapov's avatar Anton Potapov
Browse files

Add FakeDevicePostureController

Flag: EXEMPT TEST_ONLY
Fixes: 369993864
Test: atest VolumeDialogScreenshotTest
Test: presubmits
Change-Id: I41572fc2f9c97289fa26aa805061f3d47df53c51
parent ef515d32
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
/*
 * 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)
        }
}
+2 −0
Original line number Diff line number Diff line
@@ -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>
+1 −1
Original line number Diff line number Diff line
@@ -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,
+2 −1
Original line number Diff line number Diff line
@@ -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>() }
+39 −0
Original line number Diff line number Diff line
/*
 * 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
}
Loading