Merge "Add tests for configuaration changes on media carousel." into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
024acf1349
@@ -17,6 +17,7 @@
|
||||
package com.android.systemui.media.controls.ui
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.testing.AndroidTestingRunner
|
||||
import android.testing.TestableLooper
|
||||
@@ -26,6 +27,7 @@ import androidx.test.filters.SmallTest
|
||||
import com.android.internal.logging.InstanceId
|
||||
import com.android.keyguard.KeyguardUpdateMonitor
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback
|
||||
import com.android.systemui.R
|
||||
import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.classifier.FalsingCollector
|
||||
import com.android.systemui.dagger.qualifiers.Main
|
||||
@@ -50,6 +52,7 @@ import com.android.systemui.statusbar.notification.collection.provider.OnReorder
|
||||
import com.android.systemui.statusbar.notification.collection.provider.VisualStabilityProvider
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController
|
||||
import com.android.systemui.util.concurrency.DelayableExecutor
|
||||
import com.android.systemui.util.mockito.any
|
||||
import com.android.systemui.util.mockito.capture
|
||||
import com.android.systemui.util.mockito.eq
|
||||
import com.android.systemui.util.time.FakeSystemClock
|
||||
@@ -77,6 +80,8 @@ import org.mockito.MockitoAnnotations
|
||||
private val DATA = MediaTestUtils.emptyMediaData
|
||||
|
||||
private val SMARTSPACE_KEY = "smartspace"
|
||||
private const val PAUSED_LOCAL = "paused local"
|
||||
private const val PLAYING_LOCAL = "playing local"
|
||||
|
||||
@SmallTest
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
@@ -157,7 +162,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
// Test values: key, data, last active time
|
||||
val playingLocal =
|
||||
Triple(
|
||||
"playing local",
|
||||
PLAYING_LOCAL,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = true,
|
||||
@@ -181,7 +186,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
|
||||
val pausedLocal =
|
||||
Triple(
|
||||
"paused local",
|
||||
PAUSED_LOCAL,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = false,
|
||||
@@ -384,8 +389,8 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
testPlayerOrdering()
|
||||
// playing paused player
|
||||
listener.value.onMediaDataLoaded(
|
||||
"paused local",
|
||||
"paused local",
|
||||
PAUSED_LOCAL,
|
||||
PAUSED_LOCAL,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = true,
|
||||
@@ -394,8 +399,8 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
)
|
||||
)
|
||||
listener.value.onMediaDataLoaded(
|
||||
"playing local",
|
||||
"playing local",
|
||||
PLAYING_LOCAL,
|
||||
PLAYING_LOCAL,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = false,
|
||||
@@ -405,7 +410,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
MediaPlayerData.getMediaPlayerIndex("paused local"),
|
||||
MediaPlayerData.getMediaPlayerIndex(PAUSED_LOCAL),
|
||||
mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
|
||||
)
|
||||
// paused player order should stays the same in visibleMediaPLayer map.
|
||||
@@ -486,7 +491,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
@Test
|
||||
fun testMediaLoaded_ScrollToActivePlayer() {
|
||||
listener.value.onMediaDataLoaded(
|
||||
"playing local",
|
||||
PLAYING_LOCAL,
|
||||
null,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
@@ -496,7 +501,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
)
|
||||
)
|
||||
listener.value.onMediaDataLoaded(
|
||||
"paused local",
|
||||
PAUSED_LOCAL,
|
||||
null,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
@@ -514,8 +519,8 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
mediaCarouselController.shouldScrollToKey = true
|
||||
// switching between media players.
|
||||
listener.value.onMediaDataLoaded(
|
||||
"playing local",
|
||||
"playing local",
|
||||
PLAYING_LOCAL,
|
||||
PLAYING_LOCAL,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = false,
|
||||
@@ -524,8 +529,8 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
)
|
||||
)
|
||||
listener.value.onMediaDataLoaded(
|
||||
"paused local",
|
||||
"paused local",
|
||||
PAUSED_LOCAL,
|
||||
PAUSED_LOCAL,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = true,
|
||||
@@ -535,7 +540,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
MediaPlayerData.getMediaPlayerIndex("paused local"),
|
||||
MediaPlayerData.getMediaPlayerIndex(PAUSED_LOCAL),
|
||||
mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
|
||||
)
|
||||
}
|
||||
@@ -548,7 +553,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
false
|
||||
)
|
||||
listener.value.onMediaDataLoaded(
|
||||
"playing local",
|
||||
PLAYING_LOCAL,
|
||||
null,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
@@ -558,7 +563,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
)
|
||||
)
|
||||
|
||||
var playerIndex = MediaPlayerData.getMediaPlayerIndex("playing local")
|
||||
var playerIndex = MediaPlayerData.getMediaPlayerIndex(PLAYING_LOCAL)
|
||||
assertEquals(
|
||||
playerIndex,
|
||||
mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
|
||||
@@ -569,7 +574,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
// And check that the card stays in its position.
|
||||
mediaCarouselController.shouldScrollToKey = true
|
||||
listener.value.onMediaDataLoaded(
|
||||
"playing local",
|
||||
PLAYING_LOCAL,
|
||||
null,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
@@ -579,7 +584,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
packageName = "PACKAGE_NAME"
|
||||
)
|
||||
)
|
||||
playerIndex = MediaPlayerData.getMediaPlayerIndex("playing local")
|
||||
playerIndex = MediaPlayerData.getMediaPlayerIndex(PLAYING_LOCAL)
|
||||
assertEquals(playerIndex, 0)
|
||||
}
|
||||
|
||||
@@ -676,36 +681,35 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun testOnConfigChanged_playersAreAddedBack() {
|
||||
listener.value.onMediaDataLoaded(
|
||||
"playing local",
|
||||
null,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = true,
|
||||
playbackLocation = MediaData.PLAYBACK_LOCAL,
|
||||
resumption = false
|
||||
)
|
||||
)
|
||||
listener.value.onMediaDataLoaded(
|
||||
"paused local",
|
||||
null,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = false,
|
||||
playbackLocation = MediaData.PLAYBACK_LOCAL,
|
||||
resumption = false
|
||||
)
|
||||
)
|
||||
testConfigurationChange { configListener.value.onConfigChanged(Configuration()) }
|
||||
}
|
||||
|
||||
val playersSize = MediaPlayerData.players().size
|
||||
@Test
|
||||
fun testOnUiModeChanged_playersAreAddedBack() {
|
||||
testConfigurationChange(configListener.value::onUiModeChanged)
|
||||
|
||||
configListener.value.onConfigChanged(Configuration())
|
||||
verify(pageIndicator).tintList =
|
||||
ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator))
|
||||
verify(pageIndicator, times(2)).setNumPages(any())
|
||||
}
|
||||
|
||||
assertEquals(playersSize, MediaPlayerData.players().size)
|
||||
assertEquals(
|
||||
MediaPlayerData.getMediaPlayerIndex("playing local"),
|
||||
mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
|
||||
)
|
||||
@Test
|
||||
fun testOnDensityOrFontScaleChanged_playersAreAddedBack() {
|
||||
testConfigurationChange(configListener.value::onDensityOrFontScaleChanged)
|
||||
|
||||
verify(pageIndicator).tintList =
|
||||
ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator))
|
||||
// when recreateMedia is set to true, page indicator is updated on removal and addition.
|
||||
verify(pageIndicator, times(4)).setNumPages(any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnThemeChanged_playersAreAddedBack() {
|
||||
testConfigurationChange(configListener.value::onThemeChanged)
|
||||
|
||||
verify(pageIndicator).tintList =
|
||||
ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator))
|
||||
verify(pageIndicator, times(2)).setNumPages(any())
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -846,4 +850,43 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
||||
// Then the carousel visibility is updated
|
||||
assertTrue(stateUpdated)
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method when a configuration change occurs.
|
||||
*
|
||||
* @param function called when a certain configuration change occurs.
|
||||
*/
|
||||
private fun testConfigurationChange(function: () -> Unit) {
|
||||
mediaCarouselController.pageIndicator = pageIndicator
|
||||
listener.value.onMediaDataLoaded(
|
||||
PLAYING_LOCAL,
|
||||
null,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = true,
|
||||
playbackLocation = MediaData.PLAYBACK_LOCAL,
|
||||
resumption = false
|
||||
)
|
||||
)
|
||||
listener.value.onMediaDataLoaded(
|
||||
PAUSED_LOCAL,
|
||||
null,
|
||||
DATA.copy(
|
||||
active = true,
|
||||
isPlaying = false,
|
||||
playbackLocation = MediaData.PLAYBACK_LOCAL,
|
||||
resumption = false
|
||||
)
|
||||
)
|
||||
|
||||
val playersSize = MediaPlayerData.players().size
|
||||
reset(pageIndicator)
|
||||
function()
|
||||
|
||||
assertEquals(playersSize, MediaPlayerData.players().size)
|
||||
assertEquals(
|
||||
MediaPlayerData.getMediaPlayerIndex(PLAYING_LOCAL),
|
||||
mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user