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

Commit 87e222e4 authored by Josh Chien's avatar Josh Chien
Browse files

Add gone to AoD integration tests in FromAodTransitionInteractorTest.

For b/348583197, Gone -> AOD was cancelled errantly when occluded. Add 2
integration tests to increase test coverage.

Test: local test
Flag: EXEMPT tests
Bug: 406147641

Change-Id: Ie49463e8d4f12daf5566759d67ebd8bee1a62d88
parent 470f5318
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
@@ -463,4 +463,79 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
            assertThat(transitionRepository)
                .startedTransition(from = KeyguardState.AOD, to = KeyguardState.LOCKSCREEN)
        }

    /** Regression test for b/348583197. */
    @Test
    fun testTransitionToAod_ifOccludedDuringTransitingToAod_fromGone() =
        testScope.runTest {
            val isGone by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Gone, GONE)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.AOD,
                to = KeyguardState.GONE,
                testScope,
            )
            runCurrent()

            // Make sure we're GONE.
            Truth.assertThat(isGone).isTrue()

            // Get part way to AOD.
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
            runCurrent()

            transitionRepository.sendTransitionSteps(
                from = KeyguardState.GONE,
                to = KeyguardState.AOD,
                testScope = testScope,
                throughTransitionState = TransitionState.RUNNING,
            )

            // Set occluded.
            reset(transitionRepository)
            kosmos.fakeKeyguardRepository.setKeyguardOccluded(true)
            advanceTimeBy(100) // account for debouncing

            // Make sure stay at AoD.
            assertThat(transitionRepository).noTransitionsStarted()
        }

    /** Regression test for b/348583197. */
    @Test
    fun testTransitionToAod_ifOccludedAfterTransitingToAod_fromGone() =
        testScope.runTest {
            val isGone by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Gone, GONE)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.AOD,
                to = KeyguardState.GONE,
                testScope,
            )
            runCurrent()

            // Make sure we're GONE.
            Truth.assertThat(isGone).isTrue()

            // Get all the way to AOD.
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.GONE,
                to = KeyguardState.AOD,
                testScope = testScope,
            )

            // Set occluded.
            reset(transitionRepository)
            kosmos.fakeKeyguardRepository.setKeyguardOccluded(true)
            advanceTimeBy(100) // account for debouncing

            // Make sure stay at AoD.
            assertThat(transitionRepository).noTransitionsStarted()
        }
}