From d7b23cadc6eade40c898b694f21b5034b8427ec4 Mon Sep 17 00:00:00 2001 From: Jorge Antonio Diaz-Benito Soriano Date: Tue, 25 Jun 2024 10:17:03 +0200 Subject: [PATCH] Add PlayLog test 6 --- .../playlog/SingleMediaProductPlayLogTest.kt | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) 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 64cf2b1e..356b3a47 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 @@ -420,6 +420,62 @@ internal class SingleMediaProductPlayLogTest(private val mediaProduct: MediaProd ) } + @Test + fun loadAndPlayThenSeekBackWhilePaused() = runTest { + val gson = Gson() + + player.playbackEngine.load(mediaProduct) + player.playbackEngine.play() + withContext(Dispatchers.Default.limitedParallelism(1)) { + withTimeout(4.seconds) { + player.playbackEngine.events.filter { it is Event.MediaProductTransition }.first() + } + delay(3.seconds) + while (player.playbackEngine.assetPosition < 3) { + delay(10.milliseconds) + } + player.playbackEngine.pause() + player.playbackEngine.seek(2_000F) + player.playbackEngine.play() + withTimeout(8.seconds) { + player.playbackEngine.events.filter { it is MediaProductEnded }.first() + } + } + + eventReporterCoroutineScope.advanceUntilIdle() + verify(eventSender).sendEvent( + eq("playback_session"), + eq(ConsentCategory.NECESSARY), + argThat { + with(gson.fromJson(this, JsonObject::class.java)["payload"].asJsonObject) { + assertThat(get("startAssetPosition").asDouble).isAssetPositionEqualTo(0.0) + assertThat(get("endAssetPosition").asDouble) + .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_SECONDS) + assertThat(get("actualProductId").asString).isEqualTo(mediaProduct.productId) + assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct.sourceType) + assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct.sourceId) + with(get("actions").asJsonArray) { + val stopAction = + gson.fromJson(this[0], PlaybackSession.Payload.Action::class.java) + assertThat(stopAction.actionType) + .isEqualTo(PlaybackSession.Payload.Action.Type.PLAYBACK_STOP) + assertThat(stopAction.assetPositionSeconds).isAssetPositionEqualTo(3.0) + val startAction = + gson.fromJson(this[1], PlaybackSession.Payload.Action::class.java) + assertThat(startAction.actionType) + .isEqualTo(PlaybackSession.Payload.Action.Type.PLAYBACK_START) + assertThat(startAction.assetPositionSeconds).isAssetPositionEqualTo(2.0) + val perfectResumeTimestamp = stopAction.timestamp + assertThat(startAction.timestamp) + .isBetween(perfectResumeTimestamp - 500, perfectResumeTimestamp + 500) + } + } + true + }, + eq(emptyMap()), + ) + } + private fun Assert.isAssetPositionEqualTo(targetPosition: Double) = run { isCloseTo(targetPosition, 0.5) }