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

Commit a4c06d8a authored by Ang Li's avatar Ang Li Committed by Android (Google) Code Review
Browse files

Merge "Add test for starting a bubble session when one is active" into main

parents e3292e1d e4606a15
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