Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/chips/ui/viewmodel/OngoingActivityChipsViewModelTest.kt +32 −43 Original line number Diff line number Diff line Loading @@ -22,15 +22,18 @@ 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.Icon import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.mediaprojection.data.model.MediaProjectionState import com.android.systemui.mediaprojection.data.repository.fakeMediaProjectionRepository import com.android.systemui.mediaprojection.taskswitcher.FakeActivityTaskManager.Companion.createTask Loading @@ -48,16 +51,13 @@ import com.android.systemui.statusbar.core.StatusBarConnectedDisplays import com.android.systemui.statusbar.phone.SystemUIDialog import com.android.systemui.statusbar.phone.mockSystemUIDialogFactory import com.android.systemui.statusbar.phone.ongoingcall.StatusBarChipsModernization import com.android.systemui.statusbar.phone.ongoingcall.data.repository.ongoingCallRepository import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallModel import com.android.systemui.statusbar.phone.ongoingcall.shared.model.inCallModel import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallTestHelper.addOngoingCallState import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallTestHelper.removeOngoingCallState import com.android.systemui.testKosmos import com.android.systemui.util.time.fakeSystemClock import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -72,15 +72,14 @@ import org.mockito.kotlin.whenever /** Tests for [OngoingActivityChipsViewModel] when the [StatusBarNotifChips] flag is disabled. */ @SmallTest @RunWith(AndroidJUnit4::class) @EnableFlags(StatusBarChipsModernization.FLAG_NAME) @DisableFlags(StatusBarNotifChips.FLAG_NAME) class OngoingActivityChipsViewModelTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val systemClock = kosmos.fakeSystemClock private val screenRecordState = kosmos.screenRecordRepository.screenRecordState private val mediaProjectionState = kosmos.fakeMediaProjectionRepository.mediaProjectionState private val callRepo = kosmos.ongoingCallRepository private val mockSystemUIDialog = mock<SystemUIDialog>() private val chipBackgroundView = mock<ChipBackgroundContainer>() Loading @@ -96,7 +95,7 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { private val mockExpandable: Expandable = mock<Expandable>().apply { whenever(dialogTransitionController(any())).thenReturn(mock()) } private val underTest = kosmos.ongoingActivityChipsViewModel private val Kosmos.underTest by Kosmos.Fixture { ongoingActivityChipsViewModel } @Before fun setUp() { Loading @@ -111,10 +110,10 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_allHidden_hidden() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.DoingNothing mediaProjectionState.value = MediaProjectionState.NotProjecting callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading @@ -123,10 +122,10 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordShow_restHidden_screenRecordShown() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.Recording mediaProjectionState.value = MediaProjectionState.NotProjecting callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading @@ -135,10 +134,10 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordShowAndCallShow_screenRecordShown() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.Recording callRepo.setOngoingCallState(inCallModel(startTimeMs = 34)) addOngoingCallState() val latest by collectLastValue(underTest.primaryChip) Loading @@ -147,11 +146,11 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordShowAndShareToAppShow_screenRecordShown() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.Recording mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading @@ -160,11 +159,11 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_shareToAppShowAndCallShow_shareToAppShown() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.DoingNothing mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) callRepo.setOngoingCallState(inCallModel(startTimeMs = 34)) addOngoingCallState() val latest by collectLastValue(underTest.primaryChip) Loading @@ -173,15 +172,13 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordAndShareToAppAndCastToOtherHideAndCallShown_callShown() = testScope.runTest { kosmos.runTest { val notificationKey = "call" screenRecordState.value = ScreenRecordModel.DoingNothing // MediaProjection covers both share-to-app and cast-to-other-device mediaProjectionState.value = MediaProjectionState.NotProjecting callRepo.setOngoingCallState( inCallModel(startTimeMs = 34, notificationKey = notificationKey) ) addOngoingCallState(key = notificationKey) val latest by collectLastValue(underTest.primaryChip) Loading @@ -190,12 +187,10 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_higherPriorityChipAdded_lowerPriorityChipReplaced() = testScope.runTest { kosmos.runTest { // Start with just the lowest priority chip shown val callNotificationKey = "call" callRepo.setOngoingCallState( inCallModel(startTimeMs = 34, notificationKey = callNotificationKey) ) addOngoingCallState(key = callNotificationKey) // And everything else hidden mediaProjectionState.value = MediaProjectionState.NotProjecting screenRecordState.value = ScreenRecordModel.DoingNothing Loading Loading @@ -224,15 +219,13 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_highestPriorityChipRemoved_showsNextPriorityChip() = testScope.runTest { kosmos.runTest { // WHEN all chips are active screenRecordState.value = ScreenRecordModel.Recording mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) val callNotificationKey = "call" callRepo.setOngoingCallState( inCallModel(startTimeMs = 34, notificationKey = callNotificationKey) ) addOngoingCallState(key = callNotificationKey) val latest by collectLastValue(underTest.primaryChip) Loading @@ -255,17 +248,15 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { /** Regression test for b/347726238. */ @Test fun primaryChip_timerDoesNotResetAfterSubscribersRestart() = testScope.runTest { kosmos.runTest { var latest: OngoingActivityChipModel? = null val job1 = underTest.primaryChip.onEach { latest = it }.launchIn(this) val job1 = underTest.primaryChip.onEach { latest = it }.launchIn(kosmos.testScope) // Start a chip with a timer systemClock.setElapsedRealtime(1234) screenRecordState.value = ScreenRecordModel.Recording runCurrent() assertThat((latest as OngoingActivityChipModel.Active.Timer).startTimeMs) .isEqualTo(1234) Loading @@ -276,9 +267,7 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { systemClock.setElapsedRealtime(5678) // WHEN we re-subscribe to the chip flow val job2 = underTest.primaryChip.onEach { latest = it }.launchIn(this) runCurrent() val job2 = underTest.primaryChip.onEach { latest = it }.launchIn(kosmos.testScope) // THEN the old start time is still used assertThat((latest as OngoingActivityChipModel.Active.Timer).startTimeMs) Loading @@ -289,14 +278,14 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordStoppedViaDialog_chipHiddenWithoutAnimation() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.Recording mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen( NORMAL_PACKAGE, hostDeviceName = "Recording Display", ) callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading @@ -319,11 +308,11 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_projectionStoppedViaDialog_chipHiddenWithoutAnimation() = testScope.runTest { kosmos.runTest { mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) screenRecordState.value = ScreenRecordModel.DoingNothing callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/chips/ui/viewmodel/OngoingActivityChipsViewModelTest.kt +32 −43 Original line number Diff line number Diff line Loading @@ -22,15 +22,18 @@ 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.Icon import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.mediaprojection.data.model.MediaProjectionState import com.android.systemui.mediaprojection.data.repository.fakeMediaProjectionRepository import com.android.systemui.mediaprojection.taskswitcher.FakeActivityTaskManager.Companion.createTask Loading @@ -48,16 +51,13 @@ import com.android.systemui.statusbar.core.StatusBarConnectedDisplays import com.android.systemui.statusbar.phone.SystemUIDialog import com.android.systemui.statusbar.phone.mockSystemUIDialogFactory import com.android.systemui.statusbar.phone.ongoingcall.StatusBarChipsModernization import com.android.systemui.statusbar.phone.ongoingcall.data.repository.ongoingCallRepository import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallModel import com.android.systemui.statusbar.phone.ongoingcall.shared.model.inCallModel import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallTestHelper.addOngoingCallState import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallTestHelper.removeOngoingCallState import com.android.systemui.testKosmos import com.android.systemui.util.time.fakeSystemClock import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -72,15 +72,14 @@ import org.mockito.kotlin.whenever /** Tests for [OngoingActivityChipsViewModel] when the [StatusBarNotifChips] flag is disabled. */ @SmallTest @RunWith(AndroidJUnit4::class) @EnableFlags(StatusBarChipsModernization.FLAG_NAME) @DisableFlags(StatusBarNotifChips.FLAG_NAME) class OngoingActivityChipsViewModelTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val systemClock = kosmos.fakeSystemClock private val screenRecordState = kosmos.screenRecordRepository.screenRecordState private val mediaProjectionState = kosmos.fakeMediaProjectionRepository.mediaProjectionState private val callRepo = kosmos.ongoingCallRepository private val mockSystemUIDialog = mock<SystemUIDialog>() private val chipBackgroundView = mock<ChipBackgroundContainer>() Loading @@ -96,7 +95,7 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { private val mockExpandable: Expandable = mock<Expandable>().apply { whenever(dialogTransitionController(any())).thenReturn(mock()) } private val underTest = kosmos.ongoingActivityChipsViewModel private val Kosmos.underTest by Kosmos.Fixture { ongoingActivityChipsViewModel } @Before fun setUp() { Loading @@ -111,10 +110,10 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_allHidden_hidden() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.DoingNothing mediaProjectionState.value = MediaProjectionState.NotProjecting callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading @@ -123,10 +122,10 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordShow_restHidden_screenRecordShown() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.Recording mediaProjectionState.value = MediaProjectionState.NotProjecting callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading @@ -135,10 +134,10 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordShowAndCallShow_screenRecordShown() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.Recording callRepo.setOngoingCallState(inCallModel(startTimeMs = 34)) addOngoingCallState() val latest by collectLastValue(underTest.primaryChip) Loading @@ -147,11 +146,11 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordShowAndShareToAppShow_screenRecordShown() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.Recording mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading @@ -160,11 +159,11 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_shareToAppShowAndCallShow_shareToAppShown() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.DoingNothing mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) callRepo.setOngoingCallState(inCallModel(startTimeMs = 34)) addOngoingCallState() val latest by collectLastValue(underTest.primaryChip) Loading @@ -173,15 +172,13 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordAndShareToAppAndCastToOtherHideAndCallShown_callShown() = testScope.runTest { kosmos.runTest { val notificationKey = "call" screenRecordState.value = ScreenRecordModel.DoingNothing // MediaProjection covers both share-to-app and cast-to-other-device mediaProjectionState.value = MediaProjectionState.NotProjecting callRepo.setOngoingCallState( inCallModel(startTimeMs = 34, notificationKey = notificationKey) ) addOngoingCallState(key = notificationKey) val latest by collectLastValue(underTest.primaryChip) Loading @@ -190,12 +187,10 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_higherPriorityChipAdded_lowerPriorityChipReplaced() = testScope.runTest { kosmos.runTest { // Start with just the lowest priority chip shown val callNotificationKey = "call" callRepo.setOngoingCallState( inCallModel(startTimeMs = 34, notificationKey = callNotificationKey) ) addOngoingCallState(key = callNotificationKey) // And everything else hidden mediaProjectionState.value = MediaProjectionState.NotProjecting screenRecordState.value = ScreenRecordModel.DoingNothing Loading Loading @@ -224,15 +219,13 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_highestPriorityChipRemoved_showsNextPriorityChip() = testScope.runTest { kosmos.runTest { // WHEN all chips are active screenRecordState.value = ScreenRecordModel.Recording mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) val callNotificationKey = "call" callRepo.setOngoingCallState( inCallModel(startTimeMs = 34, notificationKey = callNotificationKey) ) addOngoingCallState(key = callNotificationKey) val latest by collectLastValue(underTest.primaryChip) Loading @@ -255,17 +248,15 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { /** Regression test for b/347726238. */ @Test fun primaryChip_timerDoesNotResetAfterSubscribersRestart() = testScope.runTest { kosmos.runTest { var latest: OngoingActivityChipModel? = null val job1 = underTest.primaryChip.onEach { latest = it }.launchIn(this) val job1 = underTest.primaryChip.onEach { latest = it }.launchIn(kosmos.testScope) // Start a chip with a timer systemClock.setElapsedRealtime(1234) screenRecordState.value = ScreenRecordModel.Recording runCurrent() assertThat((latest as OngoingActivityChipModel.Active.Timer).startTimeMs) .isEqualTo(1234) Loading @@ -276,9 +267,7 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { systemClock.setElapsedRealtime(5678) // WHEN we re-subscribe to the chip flow val job2 = underTest.primaryChip.onEach { latest = it }.launchIn(this) runCurrent() val job2 = underTest.primaryChip.onEach { latest = it }.launchIn(kosmos.testScope) // THEN the old start time is still used assertThat((latest as OngoingActivityChipModel.Active.Timer).startTimeMs) Loading @@ -289,14 +278,14 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_screenRecordStoppedViaDialog_chipHiddenWithoutAnimation() = testScope.runTest { kosmos.runTest { screenRecordState.value = ScreenRecordModel.Recording mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen( NORMAL_PACKAGE, hostDeviceName = "Recording Display", ) callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading @@ -319,11 +308,11 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() { @Test fun primaryChip_projectionStoppedViaDialog_chipHiddenWithoutAnimation() = testScope.runTest { kosmos.runTest { mediaProjectionState.value = MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) screenRecordState.value = ScreenRecordModel.DoingNothing callRepo.setOngoingCallState(OngoingCallModel.NoCall) removeOngoingCallState("testKey") val latest by collectLastValue(underTest.primaryChip) Loading