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

Commit 3040a776 authored by Michael Mikhail's avatar Michael Mikhail
Browse files

Add test for different pendingIntents

Flag: TEST_ONLY
Fixes: 376445089
Test: atest MediaDataProcessorTest
Test: atest LegacyMediaDataManagerImplTest
Change-Id: I8da77a8207e5142cfd2d16f4ee900d7149bd7dab
parent 5b25a727
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -236,6 +236,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
                modifyNotification(context).also {
                    it.setSmallIcon(android.R.drawable.ic_media_pause)
                    it.setStyle(MediaStyle().apply { setMediaSession(session.sessionToken) })
                    it.setContentIntent(getNewPendingIntent())
                }
                build()
            }
@@ -2158,6 +2159,28 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
        verify(kosmos.mediaLogger, never()).logDuplicateMediaNotification(eq(KEY))
    }

    @Test
    @EnableFlags(Flags.FLAG_MEDIA_CONTROLS_POSTS_OPTIMIZATION)
    fun postDifferentIntentNotifications_CallsListeners() {
        addNotificationAndLoad()
        reset(listener)
        mediaNotification =
            mediaNotification.also { it.notification.contentIntent = getNewPendingIntent() }
        mediaDataManager.onNotificationAdded(KEY, mediaNotification)

        testScope.assertRunAllReady(foreground = 1, background = 1)
        verify(listener)
            .onMediaDataLoaded(
                eq(KEY),
                eq(KEY),
                capture(mediaDataCaptor),
                eq(true),
                eq(0),
                eq(false),
            )
        verify(kosmos.mediaLogger, never()).logDuplicateMediaNotification(eq(KEY))
    }

    private fun TestScope.assertRunAllReady(foreground: Int = 0, background: Int = 0) {
        runCurrent()
        if (Flags.mediaLoadMetadataViaMediaDataLoader()) {
@@ -2237,4 +2260,14 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
        backgroundExecutor.runAllReady()
        foregroundExecutor.runAllReady()
    }

    private fun getNewPendingIntent(): PendingIntent {
        val intent = Intent().setAction(null)
        return PendingIntent.getBroadcast(
            mContext,
            1,
            intent,
            PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE,
        )
    }
}
+39 −0
Original line number Diff line number Diff line
@@ -252,6 +252,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        verify(mediaTimeoutListener).stateCallback = capture(stateCallbackCaptor)
        verify(mediaTimeoutListener).sessionCallback = capture(sessionCallbackCaptor)
        session = MediaSession(context, "MediaDataProcessorTestSession")

        mediaNotification =
            SbnBuilder().run {
                setUser(UserHandle(USER_ID))
@@ -259,6 +260,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
                modifyNotification(context).also {
                    it.setSmallIcon(android.R.drawable.ic_media_pause)
                    it.setStyle(MediaStyle().apply { setMediaSession(session.sessionToken) })
                    it.setContentIntent(getNewPendingIntent())
                }
                build()
            }
@@ -2252,6 +2254,33 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        verify(kosmos.mediaLogger, never()).logDuplicateMediaNotification(eq(KEY))
    }

    @Test
    @EnableFlags(Flags.FLAG_MEDIA_CONTROLS_POSTS_OPTIMIZATION)
    fun postDifferentIntentNotifications_CallsListeners() {
        whenever(notificationLockscreenUserManager.isCurrentProfile(USER_ID)).thenReturn(true)
        whenever(notificationLockscreenUserManager.isProfileAvailable(USER_ID)).thenReturn(true)

        mediaDataProcessor.addInternalListener(mediaDataFilter)
        mediaDataFilter.mediaDataProcessor = mediaDataProcessor
        addNotificationAndLoad()
        reset(listener)
        mediaNotification =
            mediaNotification.also { it.notification.contentIntent = getNewPendingIntent() }
        mediaDataProcessor.onNotificationAdded(KEY, mediaNotification)

        testScope.assertRunAllReady(foreground = 1, background = 1)
        verify(listener)
            .onMediaDataLoaded(
                eq(KEY),
                eq(KEY),
                capture(mediaDataCaptor),
                eq(true),
                eq(0),
                eq(false),
            )
        verify(kosmos.mediaLogger, never()).logDuplicateMediaNotification(eq(KEY))
    }

    private fun TestScope.assertRunAllReady(foreground: Int = 0, background: Int = 0) {
        runCurrent()
        if (Flags.mediaLoadMetadataViaMediaDataLoader()) {
@@ -2331,4 +2360,14 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        runCurrent()
        advanceUntilIdle()
    }

    private fun getNewPendingIntent(): PendingIntent {
        val intent = Intent().setAction(null)
        return PendingIntent.getBroadcast(
            mContext,
            1,
            intent,
            PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE,
        )
    }
}