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

Commit b9e7f761 authored by Michael Mikhail's avatar Michael Mikhail Committed by Android (Google) Code Review
Browse files

Merge "Add test for different pendingIntents" into main

parents a9ff07df 3040a776
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -235,6 +235,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()
            }
@@ -2156,6 +2157,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()) {
@@ -2235,4 +2258,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
@@ -251,6 +251,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))
@@ -258,6 +259,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()
            }
@@ -2250,6 +2252,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()) {
@@ -2329,4 +2358,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,
        )
    }
}