@@ -9,6 +9,8 @@ import io.sentry.ScopeCallback
9
9
import io.sentry.SentryOptions
10
10
import io.sentry.SentryReplayEvent
11
11
import io.sentry.SentryReplayEvent.ReplayType
12
+ import io.sentry.SentryReplayOptions.SentryReplayQuality.HIGH
13
+ import io.sentry.android.replay.BuildConfig
12
14
import io.sentry.android.replay.DefaultReplayBreadcrumbConverter
13
15
import io.sentry.android.replay.GeneratedVideo
14
16
import io.sentry.android.replay.ReplayCache
@@ -22,9 +24,11 @@ import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_TIMESTAMP
22
24
import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_WIDTH
23
25
import io.sentry.android.replay.ReplayFrame
24
26
import io.sentry.android.replay.ScreenshotRecorderConfig
27
+ import io.sentry.android.replay.maskAllImages
25
28
import io.sentry.protocol.SentryId
26
29
import io.sentry.rrweb.RRWebBreadcrumbEvent
27
30
import io.sentry.rrweb.RRWebMetaEvent
31
+ import io.sentry.rrweb.RRWebOptionsEvent
28
32
import io.sentry.transport.CurrentDateProvider
29
33
import io.sentry.transport.ICurrentDateProvider
30
34
import org.junit.Rule
@@ -43,8 +47,10 @@ import org.mockito.kotlin.whenever
43
47
import java.io.File
44
48
import java.util.Date
45
49
import kotlin.test.Test
50
+ import kotlin.test.assertContentEquals
46
51
import kotlin.test.assertEquals
47
52
import kotlin.test.assertFalse
53
+ import kotlin.test.assertNull
48
54
import kotlin.test.assertTrue
49
55
50
56
class SessionCaptureStrategyTest {
@@ -367,4 +373,81 @@ class SessionCaptureStrategyTest {
367
373
" the current replay cache folder is not being deleted."
368
374
)
369
375
}
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
+ }
370
453
}
0 commit comments