Skip to content

Commit 5ddd387

Browse files
markushiclaude
andcommitted
Add snapshot tests for non-ellipsized multi-line text masking
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2e7b083 commit 5ddd387

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed

sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,42 @@ class ScreenshotEventProcessorTest {
467467
assertNotNull(bytes)
468468
}
469469

470+
@Test
471+
fun `snapshot - multiline view text no masking`() {
472+
fixture.activity = buildActivity(MultiLineTextActivity::class.java, null).setup().get()
473+
val bytes =
474+
processEventForSnapshots("screenshot_multiline_view_unmasked", isReplayAvailable = false)
475+
assertNotNull(bytes)
476+
}
477+
478+
@Test
479+
fun `snapshot - multiline view text with masking`() {
480+
fixture.activity = buildActivity(MultiLineTextActivity::class.java, null).setup().get()
481+
val bytes =
482+
processEventForSnapshots("screenshot_multiline_view_masked") {
483+
it.screenshot.setMaskAllText(true)
484+
}
485+
assertNotNull(bytes)
486+
}
487+
488+
@Test
489+
fun `snapshot - multiline compose text no masking`() {
490+
fixture.activity = buildActivity(ComposeMultiLineTextActivity::class.java, null).setup().get()
491+
val bytes =
492+
processEventForSnapshots("screenshot_multiline_compose_unmasked", isReplayAvailable = false)
493+
assertNotNull(bytes)
494+
}
495+
496+
@Test
497+
fun `snapshot - multiline compose text with masking`() {
498+
fixture.activity = buildActivity(ComposeMultiLineTextActivity::class.java, null).setup().get()
499+
val bytes =
500+
processEventForSnapshots("screenshot_multiline_compose_masked") {
501+
it.screenshot.setMaskAllText(true)
502+
}
503+
assertNotNull(bytes)
504+
}
505+
470506
// endregion
471507

472508
private fun getEvent(): SentryEvent = SentryEvent(Throwable("Throwable"))
@@ -724,6 +760,122 @@ private class ComposeTextActivity : ComponentActivity() {
724760
}
725761
}
726762

763+
private class MultiLineTextActivity : Activity() {
764+
765+
override fun onCreate(savedInstanceState: Bundle?) {
766+
super.onCreate(savedInstanceState)
767+
val multiLineText =
768+
"This is a long text that will wrap across multiple lines without being ellipsized. " +
769+
"It should continue to flow naturally within the available width of the view."
770+
771+
val linearLayout =
772+
LinearLayout(this).apply {
773+
setBackgroundColor(Color.WHITE)
774+
orientation = LinearLayout.VERTICAL
775+
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
776+
setPadding(10, 10, 10, 10)
777+
}
778+
779+
// Multi-line wrapping text (no maxLines, no ellipsize)
780+
linearLayout.addView(
781+
TextView(this).apply {
782+
text = multiLineText
783+
setTextColor(Color.BLACK)
784+
textSize = 16f
785+
setBackgroundColor(Color.LTGRAY)
786+
layoutParams =
787+
LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT).apply {
788+
setMargins(0, 8, 0, 0)
789+
}
790+
}
791+
)
792+
793+
// Multi-line text with maxLines = 3 (wraps but capped)
794+
linearLayout.addView(
795+
TextView(this).apply {
796+
text = multiLineText
797+
setTextColor(Color.BLACK)
798+
textSize = 16f
799+
maxLines = 3
800+
setBackgroundColor(Color.LTGRAY)
801+
layoutParams =
802+
LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT).apply {
803+
setMargins(0, 8, 0, 0)
804+
}
805+
}
806+
)
807+
808+
// Short single-line text for comparison
809+
linearLayout.addView(
810+
TextView(this).apply {
811+
text = "Short text"
812+
setTextColor(Color.BLACK)
813+
textSize = 16f
814+
setBackgroundColor(Color.LTGRAY)
815+
layoutParams =
816+
LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT).apply {
817+
setMargins(0, 8, 0, 0)
818+
}
819+
}
820+
)
821+
822+
setContentView(linearLayout)
823+
}
824+
}
825+
826+
private class ComposeMultiLineTextActivity : ComponentActivity() {
827+
828+
override fun onCreate(savedInstanceState: Bundle?) {
829+
super.onCreate(savedInstanceState)
830+
val multiLineText =
831+
"This is a long text that will wrap across multiple lines without being ellipsized. " +
832+
"It should continue to flow naturally within the available width of the view."
833+
834+
setContent {
835+
Column(
836+
modifier =
837+
Modifier.fillMaxWidth()
838+
.background(androidx.compose.ui.graphics.Color.White)
839+
.padding(10.dp),
840+
verticalArrangement = Arrangement.spacedBy(8.dp),
841+
) {
842+
// Multi-line wrapping text (no maxLines, no overflow)
843+
Text(
844+
multiLineText,
845+
fontSize = 16.sp,
846+
modifier =
847+
Modifier.fillMaxWidth().background(androidx.compose.ui.graphics.Color.LightGray),
848+
)
849+
850+
// Multi-line text with maxLines = 3
851+
Text(
852+
multiLineText,
853+
maxLines = 3,
854+
fontSize = 16.sp,
855+
modifier =
856+
Modifier.fillMaxWidth().background(androidx.compose.ui.graphics.Color.LightGray),
857+
)
858+
859+
// Multi-line centered text
860+
Text(
861+
multiLineText,
862+
textAlign = TextAlign.Center,
863+
fontSize = 16.sp,
864+
modifier =
865+
Modifier.fillMaxWidth().background(androidx.compose.ui.graphics.Color.LightGray),
866+
)
867+
868+
// Short text for comparison
869+
Text(
870+
"Short text",
871+
fontSize = 16.sp,
872+
modifier = Modifier.background(androidx.compose.ui.graphics.Color.LightGray),
873+
)
874+
}
875+
}
876+
}
877+
}
878+
727879
private class MaskingActivity : Activity() {
728880

729881
override fun onCreate(savedInstanceState: Bundle?) {
3.2 KB
Loading
28 KB
Loading
2.86 KB
Loading
20.4 KB
Loading

0 commit comments

Comments
 (0)