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

Commit 5b0de2e6 authored by Ale Nijamkin's avatar Ale Nijamkin
Browse files

[flexiglass] KeyguardTransitionAnimationFlowTest when flexi is on

1. Change GONE -> DREAMING to LOCKSCREREN -> DREAMING because GONE is
   not flexiglass-friendly
2. Disables cancellation-related test methods because cancel is ignored
when flexi is on

Bug: 283121968
Test: N/A
Flag: EXEMPT test only changes
Change-Id: I002ab0dfe48fa846b9c7b3f2e851dba1c8e46a6e
parent 90d0495b
Loading
Loading
Loading
Loading
+39 −36
Original line number Diff line number Diff line
@@ -20,22 +20,22 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.app.animation.Interpolators.EMPHASIZED_ACCELERATE
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.collectValues
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -43,34 +43,34 @@ import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    val animationFlow = kosmos.keyguardTransitionAnimationFlow
    val repository = kosmos.fakeKeyguardTransitionRepository
    val shadeTestUtil by lazy { kosmos.shadeTestUtil }
    private val kosmos = testKosmos()
    private lateinit var animationFlow: KeyguardTransitionAnimationFlow
    private lateinit var repository: FakeKeyguardTransitionRepository

    private lateinit var underTest: KeyguardTransitionAnimationFlow.FlowBuilder

    @Before
    fun setUp() {
        animationFlow = kosmos.keyguardTransitionAnimationFlow
        repository = kosmos.fakeKeyguardTransitionRepository
        underTest =
            animationFlow
                .setup(
                    duration = 1000.milliseconds,
                    edge = Edge.create(from = Scenes.Gone, to = DREAMING),
                    edge = Edge.create(from = LOCKSCREEN, to = DREAMING),
                )
                .setupWithoutSceneContainer(edge = Edge.create(from = GONE, to = DREAMING))
                .setupWithoutSceneContainer(edge = Edge.create(from = LOCKSCREEN, to = DREAMING))
    }

    @Test(expected = IllegalArgumentException::class)
    fun zeroDurationThrowsException() =
        testScope.runTest {
        kosmos.runTest {
            val flow = underTest.sharedFlow(duration = 0.milliseconds, onStep = { it })
        }

    @Test(expected = IllegalArgumentException::class)
    fun startTimePlusDurationGreaterThanTransitionDurationThrowsException() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlow(
                    startTime = 300.milliseconds,
@@ -81,7 +81,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun onFinishRunsWhenSpecified() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlow(
                    duration = 100.milliseconds,
@@ -96,8 +96,9 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer // CANCELED steps are filtered out when the scene framework is enabled.
    fun onCancelRunsWhenSpecified() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlow(
                    duration = 100.milliseconds,
@@ -113,7 +114,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun onStepReturnsNullEmitsNothing() =
        testScope.runTest {
        kosmos.runTest {
            val flow = underTest.sharedFlow(duration = 100.milliseconds, onStep = { null })
            var animationValues = collectLastValue(flow)
            runCurrent()
@@ -124,7 +125,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun usesStartTime() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlow(
                    startTime = 500.milliseconds,
@@ -152,7 +153,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun usesInterpolator() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlow(
                    duration = 1000.milliseconds,
@@ -176,7 +177,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun usesOnStepToDoubleValue() =
        testScope.runTest {
        kosmos.runTest {
            val flow = underTest.sharedFlow(duration = 1000.milliseconds, onStep = { it * 2 })
            val animationValues by collectLastValue(flow)
            runCurrent()
@@ -195,7 +196,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun usesOnStepToDoubleValueWithState() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlowWithState(duration = 1000.milliseconds, onStep = { it * 2 })
            val animationValues by collectLastValue(flow)
@@ -205,7 +206,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
            assertThat(animationValues)
                .isEqualTo(
                    StateToValue(
                        from = GONE,
                        from = LOCKSCREEN,
                        to = DREAMING,
                        transitionState = TransitionState.STARTED,
                        value = 0f,
@@ -215,7 +216,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
            assertThat(animationValues)
                .isEqualTo(
                    StateToValue(
                        from = GONE,
                        from = LOCKSCREEN,
                        to = DREAMING,
                        transitionState = TransitionState.RUNNING,
                        value = 0.6f,
@@ -225,7 +226,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
            assertThat(animationValues)
                .isEqualTo(
                    StateToValue(
                        from = GONE,
                        from = LOCKSCREEN,
                        to = DREAMING,
                        transitionState = TransitionState.RUNNING,
                        value = 1.2f,
@@ -235,7 +236,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
            assertThat(animationValues)
                .isEqualTo(
                    StateToValue(
                        from = GONE,
                        from = LOCKSCREEN,
                        to = DREAMING,
                        transitionState = TransitionState.RUNNING,
                        value = 1.6f,
@@ -245,7 +246,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
            assertThat(animationValues)
                .isEqualTo(
                    StateToValue(
                        from = GONE,
                        from = LOCKSCREEN,
                        to = DREAMING,
                        transitionState = TransitionState.RUNNING,
                        value = 2f,
@@ -255,7 +256,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
            assertThat(animationValues)
                .isEqualTo(
                    StateToValue(
                        from = GONE,
                        from = LOCKSCREEN,
                        to = DREAMING,
                        transitionState = TransitionState.FINISHED,
                        value = null,
@@ -265,7 +266,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun sameFloatValueWithTheSameTransitionStateDoesNotEmitTwice() =
        testScope.runTest {
        kosmos.runTest {
            val flow = underTest.sharedFlow(duration = 1000.milliseconds, onStep = { it })
            val values by collectValues(flow)
            runCurrent()
@@ -279,7 +280,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun sameFloatValueWithADifferentTransitionStateDoesEmitTwice() =
        testScope.runTest {
        kosmos.runTest {
            val flow = underTest.sharedFlow(duration = 1000.milliseconds, onStep = { it })
            val values by collectValues(flow)
            runCurrent()
@@ -294,7 +295,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun sharedFlowWithShadeExpanded() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlowWithShade(
                    duration = 1000.milliseconds,
@@ -313,7 +314,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {

    @Test
    fun sharedFlowWithShadeNotExpanded() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlowWithShade(
                    duration = 1000.milliseconds,
@@ -331,8 +332,9 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer // CANCELED steps are filtered out when the scene framework is enabled.
    fun sharedFlowWithShadeExpanded_onCancelRunsWhenSpecified() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlowWithShade(
                    duration = 100.milliseconds,
@@ -348,8 +350,9 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer // CANCELED steps are filtered out when the scene framework is enabled.
    fun sharedFlowWithShadeNotExpanded_onCancelRunsWhenSpecified() =
        testScope.runTest {
        kosmos.runTest {
            val flow =
                underTest.sharedFlowWithShade(
                    duration = 100.milliseconds,
@@ -373,7 +376,7 @@ class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
        state: TransitionState = TransitionState.RUNNING,
    ): TransitionStep {
        return TransitionStep(
            from = GONE,
            from = LOCKSCREEN,
            to = DREAMING,
            value = value,
            transitionState = state,