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

Commit 02dd8a34 authored by Justin Weir's avatar Justin Weir
Browse files

Parameterize AuthDialogPanelInteractionDetectorTest

Parameterize AuthDialogPanelInteractionDetectorTest for the scene
container flag. Also migrates it to Kosmos.

Bug: 334874076
Test: yes
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT
Change-Id: I3dd37666d4c9bf92255cd83485345f916cc78068
parent fc7d2084
Loading
Loading
Loading
Loading
+53 −58
Original line number Diff line number Diff line
@@ -16,80 +16,73 @@

package com.android.systemui.biometrics

import android.platform.test.flag.junit.FlagsParameterization
import androidx.test.filters.SmallTest
import com.android.systemui.SysUITestComponent
import com.android.systemui.SysUITestModule
import com.android.systemui.SysuiTestCase
import com.android.systemui.biometrics.domain.BiometricsDomainLayerModule
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.flags.FakeFeatureFlagsClassicModule
import com.android.systemui.flags.Flags
import com.android.systemui.runCurrent
import com.android.systemui.runTest
import com.android.systemui.shade.data.repository.FakeShadeRepository
import com.android.systemui.user.domain.UserDomainLayerModule
import dagger.BindsInstance
import dagger.Component
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.testScope
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.testKosmos
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyZeroInteractions
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.verifyZeroInteractions
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@SmallTest
class AuthDialogPanelInteractionDetectorTest : SysuiTestCase() {

    @SysUISingleton
    @Component(
        modules =
            [
                SysUITestModule::class,
                UserDomainLayerModule::class,
                BiometricsDomainLayerModule::class,
            ]
    )
    interface TestComponent : SysUITestComponent<AuthDialogPanelInteractionDetector> {

        val shadeRepository: FakeShadeRepository

        @Component.Factory
        interface Factory {
            fun create(
                @BindsInstance test: SysuiTestCase,
                featureFlags: FakeFeatureFlagsClassicModule,
            ): TestComponent
@RunWith(ParameterizedAndroidJunit4::class)
class AuthDialogPanelInteractionDetectorTest(flags: FlagsParameterization?) : SysuiTestCase() {

    companion object {
        @JvmStatic
        @Parameters(name = "{0}")
        fun getParams(): List<FlagsParameterization> {
            return FlagsParameterization.allCombinationsOf().andSceneContainer()
        }
    }

    private val testComponent: TestComponent =
        DaggerAuthDialogPanelInteractionDetectorTest_TestComponent.factory()
            .create(
                test = this,
                featureFlags =
                    FakeFeatureFlagsClassicModule { set(Flags.FULL_SCREEN_USER_SWITCHER, true) },
            )
    init {
        mSetFlagsRule.setFlagsParameterization(flags!!)
    }

    private val detector: AuthDialogPanelInteractionDetector = testComponent.underTest
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope

    private val shadeTestUtil by lazy { kosmos.shadeTestUtil }

    @Mock private lateinit var action: Runnable

    lateinit var detector: AuthDialogPanelInteractionDetector

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        detector =
            AuthDialogPanelInteractionDetector(
                kosmos.applicationCoroutineScope,
                { kosmos.shadeInteractor },
            )
    }

    @Test
    fun enableDetector_expand_shouldRunAction() =
        testComponent.runTest {
        testScope.runTest {
            // GIVEN shade is closed and detector is enabled
            shadeRepository.setLegacyShadeExpansion(0f)
            shadeTestUtil.setShadeExpansion(0f)
            detector.enable(action)
            runCurrent()

            // WHEN shade expands
            shadeRepository.setLegacyShadeTracking(true)
            shadeRepository.setLegacyShadeExpansion(.5f)
            shadeTestUtil.setTracking(true)
            shadeTestUtil.setShadeExpansion(.5f)
            runCurrent()

            // THEN action was run
@@ -98,9 +91,9 @@ class AuthDialogPanelInteractionDetectorTest : SysuiTestCase() {

    @Test
    fun enableDetector_isUserInteractingTrue_shouldNotPostRunnable() =
        testComponent.runTest {
        testScope.runTest {
            // GIVEN isInteracting starts true
            shadeRepository.setLegacyShadeTracking(true)
            shadeTestUtil.setTracking(true)
            runCurrent()
            detector.enable(action)

@@ -110,33 +103,34 @@ class AuthDialogPanelInteractionDetectorTest : SysuiTestCase() {

    @Test
    fun enableDetector_shadeExpandImmediate_shouldNotPostRunnable() =
        testComponent.runTest {
        testScope.runTest {
            // GIVEN shade is closed and detector is enabled
            shadeRepository.setLegacyShadeExpansion(0f)
            shadeTestUtil.setShadeExpansion(0f)
            detector.enable(action)
            runCurrent()

            // WHEN shade expands fully instantly
            shadeRepository.setLegacyShadeExpansion(1f)
            shadeTestUtil.setShadeExpansion(1f)
            runCurrent()

            // THEN action not run
            verifyZeroInteractions(action)
            detector.disable()
        }

    @Test
    fun disableDetector_shouldNotPostRunnable() =
        testComponent.runTest {
        testScope.runTest {
            // GIVEN shade is closed and detector is enabled
            shadeRepository.setLegacyShadeExpansion(0f)
            shadeTestUtil.setShadeExpansion(0f)
            detector.enable(action)
            runCurrent()

            // WHEN detector is disabled and shade opens
            detector.disable()
            runCurrent()
            shadeRepository.setLegacyShadeTracking(true)
            shadeRepository.setLegacyShadeExpansion(.5f)
            shadeTestUtil.setTracking(true)
            shadeTestUtil.setShadeExpansion(.5f)
            runCurrent()

            // THEN action not run
@@ -145,17 +139,18 @@ class AuthDialogPanelInteractionDetectorTest : SysuiTestCase() {

    @Test
    fun enableDetector_beginCollapse_shouldNotPostRunnable() =
        testComponent.runTest {
        testScope.runTest {
            // GIVEN shade is open and detector is enabled
            shadeRepository.setLegacyShadeExpansion(1f)
            shadeTestUtil.setShadeExpansion(1f)
            detector.enable(action)
            runCurrent()

            // WHEN shade begins to collapse
            shadeRepository.setLegacyShadeExpansion(.5f)
            shadeTestUtil.programmaticCollapseShade()
            runCurrent()

            // THEN action not run
            verifyZeroInteractions(action)
            detector.disable()
        }
}
+51 −9
Original line number Diff line number Diff line
@@ -58,11 +58,23 @@ class ShadeTestUtil constructor(val delegate: ShadeTestUtilDelegate) {
        delegate.setLockscreenShadeExpansion(lockscreenShadeExpansion)
    }

    /** Sets whether the user is moving the shade with touch input. */
    /** Sets whether the user is moving the shade with touch input on Lockscreen. */
    fun setLockscreenShadeTracking(lockscreenShadeTracking: Boolean) {
        delegate.assertFlagValid()
        delegate.setLockscreenShadeTracking(lockscreenShadeTracking)
    }

    /** Sets whether the user is moving the shade with touch input. */
    fun setTracking(tracking: Boolean) {
        delegate.assertFlagValid()
        delegate.setTracking(tracking)
    }

    /** Sets the shade to half collapsed with no touch input. */
    fun programmaticCollapseShade() {
        delegate.assertFlagValid()
        delegate.programmaticCollapseShade()
    }
}

/** Sets up shade state for tests for a specific value of the scene container flag. */
@@ -79,11 +91,17 @@ interface ShadeTestUtilDelegate {
    /** Sets whether the user is moving the shade with touch input. */
    fun setLockscreenShadeTracking(lockscreenShadeTracking: Boolean)

    /** Sets whether the user is moving the shade with touch input. */
    fun setTracking(tracking: Boolean)

    /** Sets shade expansion to a value between 0-1. */
    fun setShadeExpansion(shadeExpansion: Float)

    /** Sets QS expansion to a value between 0-1. */
    fun setQsExpansion(qsExpansion: Float)

    /** Sets the shade to half collapsed with no touch input. */
    fun programmaticCollapseShade()
}

/** Sets up shade state for tests when the scene container flag is disabled. */
@@ -103,6 +121,10 @@ class ShadeTestUtilLegacyImpl(val testScope: TestScope, val shadeRepository: Fak
        shadeRepository.setLegacyLockscreenShadeTracking(lockscreenShadeTracking)
    }

    override fun setTracking(tracking: Boolean) {
        shadeRepository.setLegacyShadeTracking(tracking)
    }

    override fun assertFlagValid() {
        Assert.assertFalse(SceneContainerFlag.isEnabled)
    }
@@ -118,6 +140,11 @@ class ShadeTestUtilLegacyImpl(val testScope: TestScope, val shadeRepository: Fak
        shadeRepository.setQsExpansion(qsExpansion)
        testScope.runCurrent()
    }

    override fun programmaticCollapseShade() {
        shadeRepository.setLegacyShadeExpansion(.5f)
        testScope.runCurrent()
    }
}

/** Sets up shade state for tests when the scene container flag is enabled. */
@@ -126,14 +153,16 @@ class ShadeTestUtilSceneImpl(val testScope: TestScope, val sceneInteractor: Scen
    val isUserInputOngoing = MutableStateFlow(true)

    override fun setShadeAndQsExpansion(shadeExpansion: Float, qsExpansion: Float) {
        if (shadeExpansion == 0f) {
            setTransitionProgress(Scenes.Lockscreen, Scenes.QuickSettings, qsExpansion)
        } else if (qsExpansion == 0f) {
            setTransitionProgress(Scenes.Lockscreen, Scenes.Shade, shadeExpansion)
        } else if (shadeExpansion == 1f) {
        if (shadeExpansion == 1f) {
            setIdleScene(Scenes.Shade)
        } else if (qsExpansion == 1f) {
            setIdleScene(Scenes.QuickSettings)
        } else if (shadeExpansion == 0f && qsExpansion == 0f) {
            setIdleScene(Scenes.Lockscreen)
        } else if (shadeExpansion == 0f) {
            setTransitionProgress(Scenes.Lockscreen, Scenes.QuickSettings, qsExpansion)
        } else if (qsExpansion == 0f) {
            setTransitionProgress(Scenes.Lockscreen, Scenes.Shade, shadeExpansion)
        } else {
            setTransitionProgress(Scenes.Shade, Scenes.QuickSettings, qsExpansion)
        }
@@ -149,6 +178,10 @@ class ShadeTestUtilSceneImpl(val testScope: TestScope, val sceneInteractor: Scen
        setShadeAndQsExpansion(0f, qsExpansion)
    }

    override fun programmaticCollapseShade() {
        setTransitionProgress(Scenes.Shade, Scenes.Lockscreen, .5f, false)
    }

    override fun setLockscreenShadeExpansion(lockscreenShadeExpansion: Float) {
        if (lockscreenShadeExpansion == 0f) {
            setIdleScene(Scenes.Lockscreen)
@@ -160,7 +193,11 @@ class ShadeTestUtilSceneImpl(val testScope: TestScope, val sceneInteractor: Scen
    }

    override fun setLockscreenShadeTracking(lockscreenShadeTracking: Boolean) {
        isUserInputOngoing.value = lockscreenShadeTracking
        setTracking(lockscreenShadeTracking)
    }

    override fun setTracking(tracking: Boolean) {
        isUserInputOngoing.value = tracking
    }

    private fun setIdleScene(scene: SceneKey) {
@@ -171,7 +208,12 @@ class ShadeTestUtilSceneImpl(val testScope: TestScope, val sceneInteractor: Scen
        testScope.runCurrent()
    }

    private fun setTransitionProgress(from: SceneKey, to: SceneKey, progress: Float) {
    private fun setTransitionProgress(
        from: SceneKey,
        to: SceneKey,
        progress: Float,
        isInitiatedByUserInput: Boolean = true
    ) {
        sceneInteractor.changeScene(from, "test")
        val transitionState =
            MutableStateFlow<ObservableTransitionState>(
@@ -179,7 +221,7 @@ class ShadeTestUtilSceneImpl(val testScope: TestScope, val sceneInteractor: Scen
                    fromScene = from,
                    toScene = to,
                    progress = MutableStateFlow(progress),
                    isInitiatedByUserInput = true,
                    isInitiatedByUserInput = isInitiatedByUserInput,
                    isUserInputOngoing = isUserInputOngoing,
                )
            )