@@ -9,6 +9,8 @@ import io.sentry.ScopeCallback
99import io.sentry.SentryOptions
1010import io.sentry.SentryReplayEvent
1111import io.sentry.SentryReplayEvent.ReplayType
12+ import io.sentry.SentryReplayOptions.SentryReplayQuality.HIGH
13+ import io.sentry.android.replay.BuildConfig
1214import io.sentry.android.replay.DefaultReplayBreadcrumbConverter
1315import io.sentry.android.replay.GeneratedVideo
1416import io.sentry.android.replay.ReplayCache
@@ -22,9 +24,11 @@ import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_TIMESTAMP
2224import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_WIDTH
2325import io.sentry.android.replay.ReplayFrame
2426import io.sentry.android.replay.ScreenshotRecorderConfig
27+ import io.sentry.android.replay.maskAllImages
2528import io.sentry.protocol.SentryId
2629import io.sentry.rrweb.RRWebBreadcrumbEvent
2730import io.sentry.rrweb.RRWebMetaEvent
31+ import io.sentry.rrweb.RRWebOptionsEvent
2832import io.sentry.transport.CurrentDateProvider
2933import io.sentry.transport.ICurrentDateProvider
3034import org.junit.Rule
@@ -43,8 +47,10 @@ import org.mockito.kotlin.whenever
4347import java.io.File
4448import java.util.Date
4549import kotlin.test.Test
50+ import kotlin.test.assertContentEquals
4651import kotlin.test.assertEquals
4752import kotlin.test.assertFalse
53+ import kotlin.test.assertNull
4854import kotlin.test.assertTrue
4955
5056class SessionCaptureStrategyTest {
@@ -367,4 +373,81 @@ class SessionCaptureStrategyTest {
367373 " the current replay cache folder is not being deleted."
368374 )
369375 }
376+
377+ @Test
378+ fun `records replay options event for segment 0` () {
379+ fixture.options.experimental.sessionReplay.sessionSampleRate = 1.0
380+ fixture.options.experimental.sessionReplay.maskAllImages = false
381+ fixture.options.experimental.sessionReplay.quality = HIGH
382+ fixture.options.experimental.sessionReplay.addMaskViewClass(" my.custom.View" )
383+
384+ val now =
385+ System .currentTimeMillis() + (fixture.options.experimental.sessionReplay.sessionSegmentDuration * 5 )
386+ val strategy = fixture.getSut(dateProvider = { now })
387+ strategy.start(fixture.recorderConfig)
388+
389+ strategy.onScreenshotRecorded(mock<Bitmap >()) {}
390+
391+ verify(fixture.hub).captureReplay(
392+ argThat { event ->
393+ event is SentryReplayEvent && event.segmentId == 0
394+ },
395+ check {
396+ val optionsEvent =
397+ it.replayRecording?.payload?.filterIsInstance<RRWebOptionsEvent >()!!
398+ assertEquals(" sentry.java" , optionsEvent[0 ].optionsPayload[" nativeSdkName" ])
399+ assertEquals(BuildConfig .VERSION_NAME , optionsEvent[0 ].optionsPayload[" nativeSdkVersion" ])
400+
401+ assertEquals(null , optionsEvent[0 ].optionsPayload[" errorSampleRate" ])
402+ assertEquals(1.0 , optionsEvent[0 ].optionsPayload[" sessionSampleRate" ])
403+ assertEquals(true , optionsEvent[0 ].optionsPayload[" maskAllText" ])
404+ assertEquals(false , optionsEvent[0 ].optionsPayload[" maskAllImages" ])
405+ assertEquals(" high" , optionsEvent[0 ].optionsPayload[" quality" ])
406+ assertContentEquals(
407+ listOf (
408+ " android.widget.TextView" ,
409+ " android.webkit.WebView" ,
410+ " android.widget.VideoView" ,
411+ " androidx.media3.ui.PlayerView" ,
412+ " com.google.android.exoplayer2.ui.PlayerView" ,
413+ " com.google.android.exoplayer2.ui.StyledPlayerView" ,
414+ " my.custom.View"
415+ ),
416+ optionsEvent[0 ].optionsPayload[" maskedViewClasses" ] as Collection <* >
417+ )
418+ assertContentEquals(
419+ listOf (" android.widget.ImageView" ),
420+ optionsEvent[0 ].optionsPayload[" unmaskedViewClasses" ] as Collection <* >
421+ )
422+ }
423+ )
424+ }
425+
426+ @Test
427+ fun `does not record replay options event for segment above 0` () {
428+ val now =
429+ System .currentTimeMillis() + (fixture.options.experimental.sessionReplay.sessionSegmentDuration * 5 )
430+ val strategy = fixture.getSut(dateProvider = { now })
431+ strategy.start(fixture.recorderConfig)
432+
433+ strategy.onScreenshotRecorded(mock<Bitmap >()) {}
434+ verify(fixture.hub).captureReplay(
435+ argThat { event ->
436+ event is SentryReplayEvent && event.segmentId == 0
437+ },
438+ any()
439+ )
440+
441+ strategy.onScreenshotRecorded(mock<Bitmap >()) {}
442+ verify(fixture.hub).captureReplay(
443+ argThat { event ->
444+ event is SentryReplayEvent && event.segmentId == 1
445+ },
446+ check {
447+ val optionsEvent =
448+ it.replayRecording?.payload?.find { it is RRWebOptionsEvent }
449+ assertNull(optionsEvent)
450+ }
451+ )
452+ }
370453}
0 commit comments