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

Commit e4606a15 authored by AI test gen's avatar AI test gen Committed by Ang Li
Browse files

Add test for starting a bubble session when one is active


Please help fill out the survey for feedback: https://docs.google.com/forms/d/e/1FAIpQLSeKFKpHImCAqZIa_OR801cw72HQUreM2oGM25C3mKKT2tBFnw/viewform?usp=pp_url&entry.1586624956=ag/35498577

Please feel free to make changes to the generated tests based on your domain knowledge. More context about the project please see go/ai-testgen

Original Change: ag/35390097 (Note tests are based on the original CL but may add coverage beyond the specific changes to improve overall code health)

Test: ATP tests passed http://go/forrest-run/L40600030017639478
Bug: 431235865
Flag: TEST_ONLY



Change-Id: Id57f7a429a6f7547bcec0d5fe88e51ad25e9c4e3
parent dfb0e6a0
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -170,6 +170,43 @@ class BubbleSessionTrackerImplTest {
        assertThat(uiEventLoggerFake.logs).isEmpty()
    }

    @Test
    fun startSession_whenSessionActive_startsNewSession() {
        // Start a session.
        bubbleSessionTracker.log(
            SessionEvent.Started(forBubbleBar = true, selectedBubblePackage = "app.package1")
        )

        // Without ending the first session, start another one.
        // This should log an error but still proceed to start a new session, overwriting the old one.
        bubbleSessionTracker.log(
            SessionEvent.Started(forBubbleBar = true, selectedBubblePackage = "app.package2")
        )

        // Now, end the session.
        bubbleSessionTracker.log(SessionEvent.Ended(forBubbleBar = true))

        // Verify the logs.
        assertThat(uiEventLoggerFake.numLogs()).isEqualTo(3)

        // The first log should be the start of the first session.
        val firstSessionStart = uiEventLoggerFake.logs[0]
        assertThat(firstSessionStart.eventId).isEqualTo(BUBBLE_BAR_SESSION_STARTED.id)
        assertThat(firstSessionStart.packageName).isEqualTo("app.package1")

        // The second log should be the start of the second session.
        val secondSessionStart = uiEventLoggerFake.logs[1]
        assertThat(secondSessionStart.eventId).isEqualTo(BUBBLE_BAR_SESSION_STARTED.id)
        assertThat(secondSessionStart.packageName).isEqualTo("app.package2")
        assertThat(firstSessionStart.instanceId).isNotEqualTo(secondSessionStart.instanceId)

        // The third log should be the end of the *second* session.
        val sessionEnd = uiEventLoggerFake.logs[2]
        assertThat(sessionEnd.eventId).isEqualTo(BUBBLE_BAR_SESSION_ENDED.id)
        assertThat(sessionEnd.packageName).isEqualTo("app.package2")
        assertThat(sessionEnd.instanceId).isEqualTo(secondSessionStart.instanceId)
    }

    class FakeInstanceIdSequence : InstanceIdSequence(/* instanceIdMax= */ 10) {

        var id = -1