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

Commit f7d30bfb authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Dual Shade] Fix KeyguardBypassInteractorTest for DualShade on." into main

parents e17d2099 68026030
Loading
Loading
Loading
Loading
+56 −96
Original line number Diff line number Diff line
@@ -20,22 +20,23 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.bouncer.data.repository.keyguardBouncerRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.configureKeyguardBypass
import com.android.systemui.keyguard.domain.interactor.KeyguardBypassInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardBypassInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardQuickAffordanceInteractor
import com.android.systemui.keyguard.domain.interactor.pulseExpansionInteractor
import com.android.systemui.kosmos.testScope
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.Overlays
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.domain.interactor.enableSingleShade
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@@ -43,134 +44,93 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@EnableSceneContainer
class KeyguardBypassInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private lateinit var underTest: KeyguardBypassInteractor

    private val kosmos = testKosmos().useUnconfinedTestDispatcher()

    private val underTest: KeyguardBypassInteractor by lazy { kosmos.keyguardBypassInteractor }

    @Before
    fun setUp() {
        kosmos.configureKeyguardBypass(isBypassAvailable = true)
    }

    @Test
    fun canBypassFalseWhenBypassAvailableFalse() =
        testScope.runTest {
            initializeDependenciesForCanBypass(skipIsBypassAvailableCheck = false)
    fun canBypass_bypassNotAvailable_isFalse() =
        kosmos.runTest {
            configureKeyguardBypass(isBypassAvailable = false)
            val canBypass by collectLastValue(underTest.canBypass)
            runCurrent()

            sceneInteractor.changeScene(Scenes.Lockscreen, "reason")

            assertThat(canBypass).isFalse()
        }

    @Test
    fun canBypassTrueOnPrimaryBouncerShowing() =
        testScope.runTest {
            initializeDependenciesForCanBypass(skipBouncerShowingCheck = false)
    fun canBypass_onPrimaryBouncerShowing_isTrue() =
        kosmos.runTest {
            val canBypass by collectLastValue(underTest.canBypass)
            runCurrent()

            sceneInteractor.changeScene(Scenes.Lockscreen, "reason")
            sceneInteractor.showOverlay(Overlays.Bouncer, "reason")

            assertThat(canBypass).isTrue()
        }

    @Test
    fun canBypassTrueOnAlternateBouncerShowing() =
        testScope.runTest {
            initializeDependenciesForCanBypass(skipAlternateBouncerShowingCheck = false)
    fun canBypass_onAlternateBouncerShowing_isTrue() =
        kosmos.runTest {
            val canBypass by collectLastValue(underTest.canBypass)
            runCurrent()

            sceneInteractor.changeScene(Scenes.Lockscreen, "reason")
            keyguardBouncerRepository.setAlternateVisible(true)

            assertThat(canBypass).isTrue()
        }

    @Test
    fun canBypassFalseWhenNotOnLockscreenScene() =
        testScope.runTest {
            initializeDependenciesForCanBypass(skipOnLockscreenSceneCheck = false)
    fun canBypass_notOnLockscreenScene_isFalse() =
        kosmos.runTest {
            enableSingleShade()
            val canBypass by collectLastValue(underTest.canBypass)
            val currentScene by collectLastValue(kosmos.sceneInteractor.currentScene)
            runCurrent()

            sceneInteractor.changeScene(Scenes.Shade, "reason")

            assertThat(currentScene).isNotEqualTo(Scenes.Lockscreen)
            assertThat(canBypass).isFalse()
        }

    @Test
    fun canBypassFalseOnLaunchingAffordance() =
        testScope.runTest {
            initializeDependenciesForCanBypass(skipLaunchingAffordanceCheck = false)
    fun canBypass_onLaunchingAffordance_isFalse() =
        kosmos.runTest {
            val canBypass by collectLastValue(underTest.canBypass)
            runCurrent()
            assertThat(canBypass).isFalse()
        }

    @Test
    fun canBypassFalseOnPulseExpanding() =
        testScope.runTest {
            initializeDependenciesForCanBypass(skipPulseExpandingCheck = false)
            val canBypass by collectLastValue(underTest.canBypass)
            runCurrent()
            sceneInteractor.changeScene(Scenes.Lockscreen, "reason")
            keyguardQuickAffordanceInteractor.setLaunchingAffordance(true)

            assertThat(canBypass).isFalse()
        }

    @Test
    fun canBypassFalseOnQsExpanded() =
        testScope.runTest {
            initializeDependenciesForCanBypass(skipQsExpandedCheck = false)
    fun canBypass_onPulseExpanding_isFalse() =
        kosmos.runTest {
            val canBypass by collectLastValue(underTest.canBypass)
            runCurrent()
            assertThat(canBypass).isFalse()
        }

    // Initializes all canBypass dependencies to opposite of value needed to return
    private fun initializeDependenciesForCanBypass(
        skipIsBypassAvailableCheck: Boolean = true,
        skipBouncerShowingCheck: Boolean = true,
        skipAlternateBouncerShowingCheck: Boolean = true,
        skipOnLockscreenSceneCheck: Boolean = true,
        skipLaunchingAffordanceCheck: Boolean = true,
        skipPulseExpandingCheck: Boolean = true,
        skipQsExpandedCheck: Boolean = true,
    ) {
        // !isBypassAvailable false
        kosmos.configureKeyguardBypass(isBypassAvailable = skipIsBypassAvailableCheck)
        underTest = kosmos.keyguardBypassInteractor

        // alternateBouncerShowing false
        setAlternateBouncerShowing(!skipAlternateBouncerShowingCheck)
        // launchingAffordance false
        setLaunchingAffordance(!skipLaunchingAffordanceCheck)
        // pulseExpanding false
        setPulseExpanding(!skipPulseExpandingCheck)
        // qsExpanding false
        setQsExpanded(!skipQsExpandedCheck)

        // bouncerShowing false, !onLockscreenScene false
        // !onLockscreenScene false
        setScene(
            bouncerShowing = !skipBouncerShowingCheck,
            onLockscreenScene = skipOnLockscreenSceneCheck,
        )
    }

    private fun setAlternateBouncerShowing(alternateBouncerVisible: Boolean) {
        kosmos.keyguardBouncerRepository.setAlternateVisible(alternateBouncerVisible)
    }
            sceneInteractor.changeScene(Scenes.Lockscreen, "reason")
            pulseExpansionInteractor.setPulseExpanding(true)

    private fun setScene(bouncerShowing: Boolean, onLockscreenScene: Boolean) {
        if (onLockscreenScene) {
            kosmos.sceneInteractor.changeScene(Scenes.Lockscreen, "reason")
            if (bouncerShowing) {
                kosmos.sceneInteractor.showOverlay(Overlays.Bouncer, "reason")
            }
        } else {
            kosmos.sceneInteractor.changeScene(Scenes.Shade, "reason")
        }
            assertThat(canBypass).isFalse()
        }

    private fun setLaunchingAffordance(launchingAffordance: Boolean) {
        kosmos.keyguardQuickAffordanceInteractor.setLaunchingAffordance(launchingAffordance)
    }
    @Test
    fun canBypass_onQsExpanded_isFalse() =
        kosmos.runTest {
            enableSingleShade()
            val canBypass by collectLastValue(underTest.canBypass)

    private fun setPulseExpanding(pulseExpanding: Boolean) {
        kosmos.pulseExpansionInteractor.setPulseExpanding(pulseExpanding)
    }
            sceneInteractor.changeScene(Scenes.QuickSettings, "reason")
            shadeTestUtil.setQsExpansion(1f)

    private fun setQsExpanded(qsExpanded: Boolean) {
        if (qsExpanded) {
            kosmos.shadeTestUtil.setQsExpansion(1f)
        } else {
            kosmos.shadeTestUtil.setQsExpansion(0f)
        }
            assertThat(canBypass).isFalse()
        }
}