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

Commit 3407c387 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Call] Fix `assertIsCallChip` helper method in tests.

If StatusBarConnectedDisplays is disabled but the call interactor does
provide a `StatusBarIconView`, then we use the `StatusBarIconView`
instead of a hard-coded phone icon. Also, `OngoingCallTestHelper`
provides a `StatusBarIconView` by default, which is what caused these
tests to start failing (because these tests still expected a hard-coded
phone icon).

Fixes: 394948482
Bug: 364653005
Flag: TEST_ONLY
Test: atest OngoingActivityChipsWithNotifsViewModelTest
Change-Id: Ibf4ddb09c741beed8be45a8634812aaac46220e3
parent dc09df61
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -16,18 +16,19 @@

package com.android.systemui.statusbar.chips.ui.viewmodel

import android.content.Context
import android.content.DialogInterface
import android.content.packageManager
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectLastValue
@@ -181,7 +182,7 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() {

            val latest by collectLastValue(underTest.primaryChip)

            assertIsCallChip(latest, notificationKey)
            assertIsCallChip(latest, notificationKey, context)
        }

    @Test
@@ -196,7 +197,7 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() {

            val latest by collectLastValue(underTest.primaryChip)

            assertIsCallChip(latest, callNotificationKey)
            assertIsCallChip(latest, callNotificationKey, context)

            // WHEN the higher priority media projection chip is added
            mediaProjectionState.value =
@@ -241,7 +242,7 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() {
            mediaProjectionState.value = MediaProjectionState.NotProjecting

            // THEN the lower priority call is used
            assertIsCallChip(latest, callNotificationKey)
            assertIsCallChip(latest, callNotificationKey, context)
        }

    /** Regression test for b/347726238. */
@@ -395,18 +396,29 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() {
            assertThat(icon.res).isEqualTo(R.drawable.ic_present_to_all)
        }

        fun assertIsCallChip(latest: OngoingActivityChipModel?, notificationKey: String) {
        fun assertIsCallChip(
            latest: OngoingActivityChipModel?,
            notificationKey: String,
            context: Context,
        ) {
            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Active::class.java)
            assertThat((latest as OngoingActivityChipModel.Active).key).isEqualTo(notificationKey)

            if (StatusBarConnectedDisplays.isEnabled) {
                assertNotificationIcon(latest, notificationKey)
                return
            } else {
                val contentDescription =
                    if (latest.icon is OngoingActivityChipModel.ChipIcon.SingleColorIcon) {
                        ((latest.icon) as OngoingActivityChipModel.ChipIcon.SingleColorIcon)
                            .impl
                            .contentDescription
                    } else {
                        (latest.icon as OngoingActivityChipModel.ChipIcon.StatusBarView)
                            .contentDescription
                    }
                assertThat(contentDescription.loadContentDescription(context))
                    .contains(context.getString(R.string.ongoing_call_content_description))
            }
            val icon =
                ((latest.icon) as OngoingActivityChipModel.ChipIcon.SingleColorIcon).impl
                    as Icon.Resource
            assertThat(icon.res).isEqualTo(com.android.internal.R.drawable.ic_phone)
        }

        private fun assertNotificationIcon(
+18 −18
Original line number Diff line number Diff line
@@ -241,7 +241,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            val unused by collectLastValue(underTest.chips)

            assertIsScreenRecordChip(latest!!.primary)
            assertIsCallChip(latest!!.secondary, callNotificationKey)
            assertIsCallChip(latest!!.secondary, callNotificationKey, context)
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModel())
        }

@@ -258,7 +258,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            assertThat(latest!!.active.size).isEqualTo(2)
            assertIsScreenRecordChip(latest!!.active[0])
            assertIsCallChip(latest!!.active[1], callNotificationKey)
            assertIsCallChip(latest!!.active[1], callNotificationKey, context)
            assertThat(latest!!.overflow).isEmpty()
            assertThat(latest!!.inactive.size).isEqualTo(2)
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModelLegacy())
@@ -590,7 +590,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            val unused by collectLastValue(underTest.chips)

            assertIsShareToAppChip(latest!!.primary)
            assertIsCallChip(latest!!.secondary, callNotificationKey)
            assertIsCallChip(latest!!.secondary, callNotificationKey, context)
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModel())
        }

@@ -609,7 +609,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            assertThat(latest!!.active.size).isEqualTo(2)
            assertIsShareToAppChip(latest!!.active[0])
            assertIsCallChip(latest!!.active[1], callNotificationKey)
            assertIsCallChip(latest!!.active[1], callNotificationKey, context)
            assertThat(latest!!.overflow).isEmpty()
            assertThat(latest!!.inactive.size).isEqualTo(2)
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModelLegacy())
@@ -627,7 +627,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            val latest by collectLastValue(underTest.primaryChip)

            assertIsCallChip(latest, callNotificationKey)
            assertIsCallChip(latest, callNotificationKey, context)
        }

    @DisableChipsModernization
@@ -644,7 +644,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            val latest by collectLastValue(underTest.chipsLegacy)
            val unused by collectLastValue(underTest.chips)

            assertIsCallChip(latest!!.primary, callNotificationKey)
            assertIsCallChip(latest!!.primary, callNotificationKey, context)
            assertThat(latest!!.secondary)
                .isInstanceOf(OngoingActivityChipModel.Inactive::class.java)
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModel())
@@ -664,7 +664,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            val unused by collectLastValue(underTest.chipsLegacy)

            assertThat(latest!!.active.size).isEqualTo(1)
            assertIsCallChip(latest!!.active[0], callNotificationKey)
            assertIsCallChip(latest!!.active[0], callNotificationKey, context)
            assertThat(latest!!.overflow).isEmpty()
            assertThat(latest!!.inactive.size).isEqualTo(3)
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModelLegacy())
@@ -892,7 +892,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                )
            )

            assertIsCallChip(latest!!.primary, callNotificationKey)
            assertIsCallChip(latest!!.primary, callNotificationKey, context)
            assertIsNotifChip(latest!!.secondary, context, firstIcon, "firstNotif")
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModel())
        }
@@ -926,7 +926,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            )

            assertThat(latest!!.active.size).isEqualTo(2)
            assertIsCallChip(latest!!.active[0], callNotificationKey)
            assertIsCallChip(latest!!.active[0], callNotificationKey, context)
            assertIsNotifChip(latest!!.active[1], context, firstIcon, "firstNotif")
            assertThat(latest!!.overflow.size).isEqualTo(1)
            assertIsNotifChip(latest!!.overflow[0], context, secondIcon, "secondNotif")
@@ -953,7 +953,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            )

            assertIsScreenRecordChip(latest!!.primary)
            assertIsCallChip(latest!!.secondary, callNotificationKey)
            assertIsCallChip(latest!!.secondary, callNotificationKey, context)
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModel())
        }

@@ -978,7 +978,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            assertThat(latest!!.active.size).isEqualTo(2)
            assertIsScreenRecordChip(latest!!.active[0])
            assertIsCallChip(latest!!.active[1], callNotificationKey)
            assertIsCallChip(latest!!.active[1], callNotificationKey, context)
            assertThat(latest!!.overflow.size).isEqualTo(1)
            assertIsNotifChip(latest!!.overflow[0], context, notifIcon, "notif")
            assertThat(latest!!.inactive.size).isEqualTo(2)
@@ -1013,7 +1013,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            addOngoingCallState(callNotificationKey)

            // THEN the higher priority call chip is used
            assertIsCallChip(latest, callNotificationKey)
            assertIsCallChip(latest, callNotificationKey, context)

            // WHEN the higher priority media projection chip is added
            mediaProjectionState.value =
@@ -1066,7 +1066,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            mediaProjectionState.value = MediaProjectionState.NotProjecting

            // THEN the lower priority call is used
            assertIsCallChip(latest, callNotificationKey)
            assertIsCallChip(latest, callNotificationKey, context)

            // WHEN the higher priority call is removed
            removeOngoingCallState(key = callNotificationKey)
@@ -1107,7 +1107,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            // THEN the higher priority call chip is used as primary and notif is demoted to
            // secondary
            assertIsCallChip(latest!!.primary, callNotificationKey)
            assertIsCallChip(latest!!.primary, callNotificationKey, context)
            assertIsNotifChip(latest!!.secondary, context, notifIcon, "notif")
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModel())

@@ -1122,7 +1122,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            // THEN the higher priority media projection chip is used as primary and call is demoted
            // to secondary (and notif is dropped altogether)
            assertIsShareToAppChip(latest!!.primary)
            assertIsCallChip(latest!!.secondary, callNotificationKey)
            assertIsCallChip(latest!!.secondary, callNotificationKey, context)
            assertThat(unused).isEqualTo(MultipleOngoingActivityChipsModel())

            // WHEN the higher priority screen record chip is added
@@ -1185,7 +1185,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            // THEN the higher priority call chip and notif are active in that order
            assertThat(latest!!.active.size).isEqualTo(2)
            assertIsCallChip(latest!!.active[0], callNotificationKey)
            assertIsCallChip(latest!!.active[0], callNotificationKey, context)
            assertIsNotifChip(latest!!.active[1], context, notifIcon, "notif")
            assertThat(latest!!.overflow).isEmpty()
            assertThat(latest!!.inactive.size).isEqualTo(3)
@@ -1203,7 +1203,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            // notif is demoted to overflow
            assertThat(latest!!.active.size).isEqualTo(2)
            assertIsShareToAppChip(latest!!.active[0])
            assertIsCallChip(latest!!.active[1], callNotificationKey)
            assertIsCallChip(latest!!.active[1], callNotificationKey, context)
            assertThat(latest!!.overflow.size).isEqualTo(1)
            assertIsNotifChip(latest!!.overflow[0], context, notifIcon, "notif")
            assertThat(latest!!.inactive.size).isEqualTo(2)
@@ -1216,7 +1216,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            // media projection and notif are demoted in overflow
            assertThat(latest!!.active.size).isEqualTo(2)
            assertIsScreenRecordChip(latest!!.active[0])
            assertIsCallChip(latest!!.active[1], callNotificationKey)
            assertIsCallChip(latest!!.active[1], callNotificationKey, context)
            assertThat(latest!!.overflow.size).isEqualTo(2)
            assertIsShareToAppChip(latest!!.overflow[0])
            assertIsNotifChip(latest!!.overflow[1], context, notifIcon, "notif")
+1 −1
Original line number Diff line number Diff line
@@ -920,7 +920,7 @@ class HomeStatusBarViewModelImplTest : SysuiTestCase() {
            addOngoingCallState(key = "call")

            assertIsScreenRecordChip(latest!!.chips.active[0])
            assertIsCallChip(latest!!.chips.active[1], "call")
            assertIsCallChip(latest!!.chips.active[1], "call", context)
        }

    @Test