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

Commit 341ab179 authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge "[RONs] Modernize the PromotedNotificationContentExtractorImplTest" into main

parents a8f4747e dd2151a1
Loading
Loading
Loading
Loading
+380 −332
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.runTest
import com.android.systemui.statusbar.NotificationLockscreenUserManager.REDACTION_TYPE_NONE
import com.android.systemui.statusbar.NotificationLockscreenUserManager.REDACTION_TYPE_PUBLIC
import com.android.systemui.statusbar.chips.notification.shared.StatusBarNotifChips
@@ -58,15 +60,16 @@ import org.junit.runner.RunWith
class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
    private val kosmos = testKosmos().apply { systemClock = fakeSystemClock }

    private val underTest = kosmos.promotedNotificationContentExtractor
    private val systemClock = kosmos.fakeSystemClock
    private val rowImageInflater =
        RowImageInflater.newInstance(previousIndex = null, reinflating = false)
    private val imageModelProvider by lazy { rowImageInflater.useForContentModel() }
    private val Kosmos.underTest by Kosmos.Fixture { promotedNotificationContentExtractor }
    private val Kosmos.rowImageInflater by
        Kosmos.Fixture { RowImageInflater.newInstance(previousIndex = null, reinflating = false) }
    private val Kosmos.imageModelProvider by
        Kosmos.Fixture { rowImageInflater.useForContentModel() }

    @Test
    @DisableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun shouldNotExtract_bothFlagsDisabled() {
    fun shouldNotExtract_bothFlagsDisabled() =
        kosmos.runTest {
            val notif = createEntry()
            val content = extractContent(notif)
            assertThat(content).isNull()
@@ -75,7 +78,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    @DisableFlags(StatusBarNotifChips.FLAG_NAME)
    fun shouldExtract_promotedNotificationUiFlagEnabled() {
    fun shouldExtract_promotedNotificationUiFlagEnabled() =
        kosmos.runTest {
            val entry = createEntry()
            val content = extractContent(entry)
            assertThat(content).isNotNull()
@@ -84,7 +88,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
    @Test
    @EnableFlags(StatusBarNotifChips.FLAG_NAME)
    @DisableFlags(PromotedNotificationUi.FLAG_NAME)
    fun shouldExtract_statusBarNotifChipsFlagEnabled() {
    fun shouldExtract_statusBarNotifChipsFlagEnabled() =
        kosmos.runTest {
            val entry = createEntry()
            val content = extractContent(entry)
            assertThat(content).isNotNull()
@@ -92,7 +97,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun shouldExtract_bothFlagsEnabled() {
    fun shouldExtract_bothFlagsEnabled() =
        kosmos.runTest {
            val entry = createEntry()
            val content = extractContent(entry)
            assertThat(content).isNotNull()
@@ -100,7 +106,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun shouldNotExtract_becauseNotPromoted() {
    fun shouldNotExtract_becauseNotPromoted() =
        kosmos.runTest {
            val entry = createEntry(promoted = false)
            val content = extractContent(entry)
            assertThat(content).isNull()
@@ -108,7 +115,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractsContent_commonFields() {
    fun extractsContent_commonFields() =
        kosmos.runTest {
            val entry = createEntry {
                setSubText(TEST_SUB_TEXT)
                setContentTitle(TEST_CONTENT_TITLE)
@@ -132,7 +140,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractsContent_commonFields_noRedaction() {
    fun extractsContent_commonFields_noRedaction() =
        kosmos.runTest {
            val entry = createEntry {
                setSubText(TEST_SUB_TEXT)
                setContentTitle(TEST_CONTENT_TITLE)
@@ -156,7 +165,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_wasPromotedAutomatically_false() {
    fun extractContent_wasPromotedAutomatically_false() =
        kosmos.runTest {
            val entry = createEntry { extras.putBoolean(EXTRA_WAS_AUTOMATICALLY_PROMOTED, false) }

            val content = requireContent(entry).privateVersion
@@ -166,7 +176,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_wasPromotedAutomatically_true() {
    fun extractContent_wasPromotedAutomatically_true() =
        kosmos.runTest {
            val entry = createEntry { extras.putBoolean(EXTRA_WAS_AUTOMATICALLY_PROMOTED, true) }

            val content = requireContent(entry).privateVersion
@@ -177,7 +188,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    @DisableFlags(android.app.Flags.FLAG_API_RICH_ONGOING)
    fun extractContent_apiFlagOff_shortCriticalTextNotExtracted() {
    fun extractContent_apiFlagOff_shortCriticalTextNotExtracted() =
        kosmos.runTest {
            val entry = createEntry { setShortCriticalText(TEST_SHORT_CRITICAL_TEXT) }

            val content = requireContent(entry).privateVersion
@@ -191,7 +203,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
        StatusBarNotifChips.FLAG_NAME,
        android.app.Flags.FLAG_API_RICH_ONGOING,
    )
    fun extractContent_apiFlagOn_shortCriticalTextExtracted() {
    fun extractContent_apiFlagOn_shortCriticalTextExtracted() =
        kosmos.runTest {
            val entry = createEntry { setShortCriticalText(TEST_SHORT_CRITICAL_TEXT) }

            val content = requireContent(entry).privateVersion
@@ -205,7 +218,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
        StatusBarNotifChips.FLAG_NAME,
        android.app.Flags.FLAG_API_RICH_ONGOING,
    )
    fun extractContent_noShortCriticalTextSet_textIsNull() {
    fun extractContent_noShortCriticalTextSet_textIsNull() =
        kosmos.runTest {
            val entry = createEntry { setShortCriticalText(null) }

            val content = requireContent(entry).privateVersion
@@ -215,13 +229,19 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_none() {
        assertExtractedTime(hasTime = false, hasChronometer = false, expected = ExpectedTime.Null)
    fun extractTime_none() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = false,
                expected = ExpectedTime.Null,
            )
        }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_basicTimeZero() {
    fun extractTime_basicTimeZero() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = true,
                hasChronometer = false,
@@ -232,7 +252,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_basicTimeNow() {
    fun extractTime_basicTimeNow() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = true,
                hasChronometer = false,
@@ -243,7 +264,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_basicTimePast() {
    fun extractTime_basicTimePast() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = true,
                hasChronometer = false,
@@ -254,7 +276,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_basicTimeFuture() {
    fun extractTime_basicTimeFuture() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = true,
                hasChronometer = false,
@@ -265,7 +288,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_countUpZero() {
    fun extractTime_countUpZero() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = true,
@@ -277,7 +301,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_countUpNow() {
    fun extractTime_countUpNow() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = true,
@@ -289,7 +314,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_countUpPast() {
    fun extractTime_countUpPast() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = true,
@@ -301,7 +327,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_countUpFuture() {
    fun extractTime_countUpFuture() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = true,
@@ -313,7 +340,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_countDownZero() {
    fun extractTime_countDownZero() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = true,
@@ -325,7 +353,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_countDownNow() {
    fun extractTime_countDownNow() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = true,
@@ -337,7 +366,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_countDownPast() {
    fun extractTime_countDownPast() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = true,
@@ -349,7 +379,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_countDownFuture() {
    fun extractTime_countDownFuture() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = false,
                hasChronometer = true,
@@ -361,8 +392,13 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractTime_prefersChronometerToWhen() {
        assertExtractedTime(hasTime = true, hasChronometer = true, expected = ExpectedTime.CountUp)
    fun extractTime_prefersChronometerToWhen() =
        kosmos.runTest {
            assertExtractedTime(
                hasTime = true,
                hasChronometer = true,
                expected = ExpectedTime.CountUp,
            )
        }

    private sealed class ProvidedTime {
@@ -378,7 +414,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
        CountDown,
    }

    private fun assertExtractedTime(
    private fun Kosmos.assertExtractedTime(
        hasTime: Boolean = false,
        hasChronometer: Boolean = false,
        isCountDown: Boolean = false,
@@ -387,8 +423,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
    ) {
        // Set the two timebases to different (arbitrary) numbers, so we can verify whether the
        // extractor is doing the timebase adjustment correctly.
        systemClock.setCurrentTimeMillis(1_739_570_992_579L)
        systemClock.setElapsedRealtime(1_380_967_080L)
        fakeSystemClock.setCurrentTimeMillis(1_739_570_992_579L)
        fakeSystemClock.setElapsedRealtime(1_380_967_080L)

        val providedCurrentTime =
            when (provided) {
@@ -437,7 +473,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromBaseStyle() {
    fun extractContent_fromBaseStyle() =
        kosmos.runTest {
            val entry = createEntry { setStyle(null) }

            val content = requireContent(entry)
@@ -448,7 +485,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromBigPictureStyle() {
    fun extractContent_fromBigPictureStyle() =
        kosmos.runTest {
            val entry = createEntry { setStyle(BigPictureStyle()) }

            val content = requireContent(entry)
@@ -459,7 +497,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromBigTextStyle() {
    fun extractContent_fromBigTextStyle() =
        kosmos.runTest {
            val entry = createEntry {
                setContentTitle(TEST_CONTENT_TITLE)
                setContentText(TEST_CONTENT_TEXT)
@@ -484,7 +523,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromBigTextStyle_fallbackToContentTitle() {
    fun extractContent_fromBigTextStyle_fallbackToContentTitle() =
        kosmos.runTest {
            val entry = createEntry {
                setContentTitle(TEST_CONTENT_TITLE)
                setContentText(TEST_CONTENT_TEXT)
@@ -509,7 +549,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromBigTextStyle_fallbackToContentText() {
    fun extractContent_fromBigTextStyle_fallbackToContentText() =
        kosmos.runTest {
            val entry = createEntry {
                setContentTitle(TEST_CONTENT_TITLE)
                setContentText(TEST_CONTENT_TEXT)
@@ -534,7 +575,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromCallStyle() {
    fun extractContent_fromCallStyle() =
        kosmos.runTest {
            val hangUpIntent =
                PendingIntent.getBroadcast(
                    context,
@@ -542,7 +584,9 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
                    Intent("hangup_action"),
                    PendingIntent.FLAG_IMMUTABLE,
                )
        val entry = createEntry { setStyle(CallStyle.forOngoingCall(TEST_PERSON, hangUpIntent)) }
            val entry = createEntry {
                setStyle(CallStyle.forOngoingCall(TEST_PERSON, hangUpIntent))
            }

            val content = requireContent(entry)

@@ -560,7 +604,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
        StatusBarNotifChips.FLAG_NAME,
        android.app.Flags.FLAG_API_RICH_ONGOING,
    )
    fun extractContent_fromProgressStyle() {
    fun extractContent_fromProgressStyle() =
        kosmos.runTest {
            val entry = createEntry {
                setStyle(ProgressStyle().addProgressSegment(Segment(100)).setProgress(75))
            }
@@ -580,7 +625,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromIneligibleStyle() {
    fun extractContent_fromIneligibleStyle() =
        kosmos.runTest {
            val entry = createEntry {
                setStyle(MessagingStyle(TEST_PERSON).addMessage("message text", 0L, TEST_PERSON))
            }
@@ -594,7 +640,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromOldProgressDeterminate() {
    fun extractContent_fromOldProgressDeterminate() =
        kosmos.runTest {
            val entry = createEntry {
                setProgress(TEST_PROGRESS_MAX, TEST_PROGRESS, /* indeterminate= */ false)
            }
@@ -610,7 +657,8 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromOldProgressIndeterminate() {
    fun extractContent_fromOldProgressIndeterminate() =
        kosmos.runTest {
            val entry = createEntry {
                setProgress(TEST_PROGRESS_MAX, TEST_PROGRESS, /* indeterminate= */ true)
            }
@@ -623,12 +671,12 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
            assertThat(oldProgress.isIndeterminate).isTrue()
        }

    private fun requireContent(
    private fun Kosmos.requireContent(
        entry: NotificationEntry,
        redactionType: Int = REDACTION_TYPE_PUBLIC,
    ): PromotedNotificationContentModels = assertNotNull(extractContent(entry, redactionType))

    private fun extractContent(
    private fun Kosmos.extractContent(
        entry: NotificationEntry,
        redactionType: Int = REDACTION_TYPE_PUBLIC,
    ): PromotedNotificationContentModels? {
@@ -636,7 +684,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
        return underTest.extractContent(entry, recoveredBuilder, redactionType, imageModelProvider)
    }

    private fun createEntry(
    private fun Kosmos.createEntry(
        promoted: Boolean = true,
        builderBlock: Notification.Builder.() -> Unit = {},
    ): NotificationEntry {