Skip to content

Commit

Permalink
Add an helper method to create an SRG test player
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Dec 18, 2024
1 parent 13cf17b commit b1ba2ce
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.core.business

import android.content.Context
import androidx.media3.common.C
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.test.utils.FakeClock
import androidx.test.core.app.ApplicationProvider
import ch.srgssr.pillarbox.player.PillarboxDsl
import ch.srgssr.pillarbox.player.PillarboxExoPlayer
import kotlin.coroutines.EmptyCoroutineContext

/**
* Pillarbox ExoPlayer
*
* @param context The [Context], by default [ApplicationProvider.getApplicationContext]
* @param block The block to further configure the [PillarboxExoPlayer].
* @return [PillarboxExoPlayer] configured for tests.
*/
@PillarboxDsl
fun PillarboxExoPlayer(context: Context = ApplicationProvider.getApplicationContext(), block: SRG.Builder.() -> Unit = {}): PillarboxExoPlayer {
return PillarboxExoPlayer(context, SRG) {
loadControl(DefaultLoadControl())
clock(FakeClock(true))
coroutineContext(EmptyCoroutineContext)
block()
}.apply {
// FIXME Investigate why we need to disable the image track in tests
trackSelectionParameters = trackSelectionParameters.buildUpon()
.setTrackTypeDisabled(C.TRACK_TYPE_IMAGE, true)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package ch.srgssr.pillarbox.core.business.tracker.commandersact

import android.content.Context
import android.os.Looper
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
Expand Down Expand Up @@ -42,7 +41,6 @@ import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runTest
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.math.abs
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
Expand Down Expand Up @@ -70,21 +68,13 @@ class CommandersActTrackerIntegrationTest {
testDispatcher = UnconfinedTestDispatcher()

val context = ApplicationProvider.getApplicationContext<Context>()
val mediaCompositionWithFallbackService = LocalMediaCompositionWithFallbackService(context)
player = PillarboxExoPlayer(context) {
player = PillarboxExoPlayer {
clock(clock)
srgAssetLoader(context) {
mediaCompositionService(mediaCompositionWithFallbackService)
mediaCompositionService(LocalMediaCompositionWithFallbackService(context))
commanderActTrackerFactory(CommandersActTracker.Factory(commandersAct = commandersAct, coroutineContext = testDispatcher))
comscoreTrackerFactory(mockk(relaxed = true))
}
clock(clock)
// Use other CoroutineContext to avoid infinite loop because Heartbeat is also running in Pillarbox.
coroutineContext(EmptyCoroutineContext)
}.apply {
// FIXME Investigate why we need to disable the image track in tests
trackSelectionParameters = trackSelectionParameters.buildUpon()
.setTrackTypeDisabled(C.TRACK_TYPE_IMAGE, true)
.build()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.os.Looper
import android.view.SurfaceView
import android.view.ViewGroup
import androidx.core.view.updateLayoutParams
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.test.utils.FakeClock
Expand All @@ -33,7 +32,6 @@ import io.mockk.verify
import io.mockk.verifyOrder
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Ignore
Expand All @@ -57,20 +55,13 @@ class ComScoreTrackerIntegrationTest {
ComScoreTracker(streamingAnalytics)
}
val context = ApplicationProvider.getApplicationContext<Context>()
val mediaCompositionWithFallbackService = LocalMediaCompositionWithFallbackService(context)
player = PillarboxExoPlayer(context) {
player = PillarboxExoPlayer {
clock(clock)
coroutineContext(EmptyCoroutineContext)
srgAssetLoader(context) {
mediaCompositionService(mediaCompositionWithFallbackService)
mediaCompositionService(LocalMediaCompositionWithFallbackService(context))
comscoreTrackerFactory(comScoreFactory)
commanderActTrackerFactory(mockk(relaxed = true))
}
}.apply {
// FIXME Investigate why we need to disable the image track in tests
trackSelectionParameters = trackSelectionParameters.buildUpon()
.setTrackTypeDisabled(C.TRACK_TYPE_IMAGE, true)
.build()
}
}

Expand Down

0 comments on commit b1ba2ce

Please sign in to comment.