Skip to content

Commit

Permalink
Merge pull request #1223 from DataDog/mconstantin/fix-translucent-col…
Browse files Browse the repository at this point in the history
…or-verification

SR use case insensitive when checking wireframe background color opacity
  • Loading branch information
mariusc83 authored Jan 10, 2023
2 parents 04b24dc + 2f7ddb1 commit 8747487
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.datadog.android.sessionreplay.processor

import com.datadog.android.sessionreplay.model.MobileSegment
import java.util.Locale
import kotlin.math.max

internal class WireframeUtils {
Expand Down Expand Up @@ -86,7 +87,7 @@ internal class WireframeUtils {
private fun MobileSegment.ShapeStyle.isOpaque(): Boolean {
return this.opacity == FULL_OPACITY_ALPHA &&
this.backgroundColor != null &&
this.backgroundColor.takeLast(2) == FULL_OPACITY_ALPHA_AS_HEXA_STRING
this.backgroundColor.takeLast(2).lowercase(Locale.US) == FULL_OPACITY_STRING_HEXA
}

private fun MobileSegment.Wireframe.ShapeWireframe.bounds(): Bounds {
Expand Down Expand Up @@ -121,7 +122,7 @@ internal class WireframeUtils {
)

companion object {
const val FULL_OPACITY_ALPHA_AS_HEXA_STRING = "FF"
const val FULL_OPACITY_ALPHA = 1f
private const val FULL_OPACITY_STRING_HEXA = "ff"
private const val FULL_OPACITY_ALPHA = 1f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,11 @@ internal class WireframeUtilsTest {
width = fakeWidth,
height = fakeHeight,
shapeStyle = forge.forgeNonTransparentShapeStyle()
.copy(backgroundColor = forge.aStringMatching("#[0-9A-F]{6}[0-9A-E]{2}"))
.copy(
backgroundColor = forge.aStringMatching(
"#[0-9A-Fa-f]{6}[0-9A-Ea-e]{2}"
)
)
)
fakeCoverAllWireframe
}
Expand Down Expand Up @@ -736,7 +740,7 @@ internal class WireframeUtilsTest {

private fun Forge.forgeNonTransparentShapeStyle(): MobileSegment.ShapeStyle {
return MobileSegment.ShapeStyle(
backgroundColor = aStringMatching("#[0-9A-F]{6}FF"),
backgroundColor = aStringMatching("#[0-9A-Fa-f]{6}[fF]{2}"),
opacity = 1f,
cornerRadius = aPositiveLong()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class ShapeStyleForgeryFactory :
override fun getForgery(forge: Forge): MobileSegment.ShapeStyle {
return MobileSegment.ShapeStyle(
backgroundColor = forge.aNullable {
forge.aStringMatching("#[0-9A-F]{6}FF")
forge.aStringMatching("#[0-9A-Fa-f]{6}[fF]{2}")
},
opacity = forge.aFloat(min = 0f, max = 1f),
cornerRadius = forge.aPositiveLong()
Expand Down

0 comments on commit 8747487

Please sign in to comment.