diff --git a/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/Extensions.kt b/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/Extensions.kt index 4864d802..cdb07e3c 100644 --- a/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/Extensions.kt +++ b/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/Extensions.kt @@ -2,6 +2,10 @@ package com.tidal.sdk.player.playlog import assertk.Assert import assertk.assertions.isCloseTo +import kotlin.math.absoluteValue internal fun Assert.isAssetPositionEqualTo(targetPosition: Double) = isCloseTo(targetPosition, 0.5) + +internal fun Double.isAssetPositionEqualTo(targetPosition: Double) = + (this - targetPosition).absoluteValue < 0.5 diff --git a/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/SingleMediaProductPlayLogTest.kt b/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/SingleMediaProductPlayLogTest.kt index 7c33a5de..e4102ea8 100644 --- a/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/SingleMediaProductPlayLogTest.kt +++ b/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/SingleMediaProductPlayLogTest.kt @@ -825,6 +825,76 @@ internal class SingleMediaProductPlayLogTest { eq(emptyMap()), ) } + + @Suppress("CyclomaticComplexMethod", "LongMethod") + @Test + fun seekBeyondBoundsWithRepeatOne() = runTest { + val gson = Gson() + + player.playbackEngine.load(mediaProduct) + player.playbackEngine.setRepeatOne(true) + player.playbackEngine.play() + withContext(Dispatchers.Default.limitedParallelism(1)) { + delay(2.seconds) + while (player.playbackEngine.assetPosition < 2) { + delay(10.milliseconds) + } + player.playbackEngine.seek(10_000F) + delay(1.seconds) + while (player.playbackEngine.assetPosition < 1) { + delay(10.milliseconds) + } + player.playbackEngine.reset() + } + + eventReporterCoroutineScope.advanceUntilIdle() + verify(eventSender).sendEvent( + eq("playback_session"), + eq(ConsentCategory.NECESSARY), + argThat { + with(gson.fromJson(this, JsonObject::class.java)["payload"].asJsonObject) { + get("startAssetPosition").asDouble.isAssetPositionEqualTo(0.0) && + get("endAssetPosition").asDouble + .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_SECONDS) && + get("actualProductId")?.asString.contentEquals(mediaProduct.productId) && + get("sourceType")?.asString.contentEquals(mediaProduct.sourceType) && + get("sourceId")?.asString.contentEquals(mediaProduct.sourceId) && + get("actions").asJsonArray.run { + val stopAction = + gson.fromJson(this[0], PlaybackSession.Payload.Action::class.java) + val startAction = + gson.fromJson(this[1], PlaybackSession.Payload.Action::class.java) + val perfectResumeTimestamp = stopAction.timestamp + stopAction.actionType == + PlaybackSession.Payload.Action.Type.PLAYBACK_STOP && + stopAction.assetPositionSeconds.isAssetPositionEqualTo(2.0) && + startAction.actionType == + PlaybackSession.Payload.Action.Type.PLAYBACK_START && + startAction.assetPositionSeconds + .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_SECONDS) && + startAction.timestamp in + (perfectResumeTimestamp - 500)..(perfectResumeTimestamp + 500) + } + } + }, + eq(emptyMap()), + ) + verify(eventSender).sendEvent( + eq("playback_session"), + eq(ConsentCategory.NECESSARY), + argThat { + with(gson.fromJson(this, JsonObject::class.java)["payload"].asJsonObject) { + get("startAssetPosition").asDouble.isAssetPositionEqualTo(0.0) && + get("endAssetPosition").asDouble.isAssetPositionEqualTo(1.0) && + get("actualProductId")?.asString.contentEquals(mediaProduct.productId) && + get("sourceType")?.asString.contentEquals(mediaProduct.sourceType) && + get("sourceId")?.asString.contentEquals(mediaProduct.sourceId) && + get("actions").asJsonArray.isEmpty + } + }, + eq(emptyMap()), + ) + } } private const val MEDIA_PRODUCT_DURATION_SECONDS = 5.055 diff --git a/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/TwoMediaProductsPlayLogTest.kt b/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/TwoMediaProductsPlayLogTest.kt index 9ad46b9c..7ad53573 100644 --- a/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/TwoMediaProductsPlayLogTest.kt +++ b/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/TwoMediaProductsPlayLogTest.kt @@ -22,7 +22,6 @@ import com.tidal.sdk.player.playbackengine.model.Event import com.tidal.sdk.player.playbackengine.model.Event.MediaProductEnded import com.tidal.sdk.player.playbackengine.model.Event.Release import com.tidal.sdk.player.setBodyFromFile -import kotlin.math.absoluteValue import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -301,7 +300,4 @@ internal class TwoMediaProductsPlayLogTest { eq(emptyMap()), ) } - - private fun Double.isAssetPositionEqualTo(targetPosition: Double) = - (this - targetPosition).absoluteValue < 0.5 }