Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop into release 2 12 0 #2148

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ internal class DefaultImageWireframeHelper(
if (imagePrivacy == ImagePrivacy.MASK_ALL) {
return createContentPlaceholderWireframe(
id = id,
x = x,
y = y,
view = view,
density = density,
drawableProperties = drawableProperties,
label = MASK_ALL_CONTENT_LABEL
)
}
Expand All @@ -106,10 +104,8 @@ internal class DefaultImageWireframeHelper(
if (shouldMaskContextualImage(imagePrivacy, usePIIPlaceholder, drawable, density)) {
return createContentPlaceholderWireframe(
id = id,
x = x,
y = y,
view = view,
density = density,
drawableProperties = drawableProperties,
label = MASK_CONTEXTUAL_CONTENT_LABEL
)
}
Expand Down Expand Up @@ -241,19 +237,23 @@ internal class DefaultImageWireframeHelper(
}

private fun createContentPlaceholderWireframe(
view: View,
id: Long,
x: Long,
y: Long,
density: Float,
drawableProperties: DrawableProperties,
label: String
): MobileSegment.Wireframe.PlaceholderWireframe {
val coordinates = IntArray(2)
@Suppress("UnsafeThirdPartyFunctionCall") // this will always have size >= 2
view.getLocationOnScreen(coordinates)
val viewX = coordinates[0].densityNormalized(density).toLong()
val viewY = coordinates[1].densityNormalized(density).toLong()

return MobileSegment.Wireframe.PlaceholderWireframe(
id,
x,
y,
drawableProperties.drawableWidth.densityNormalized(density).toLong(),
drawableProperties.drawableHeight.densityNormalized(density).toLong(),
viewX,
viewY,
view.width.densityNormalized(density).toLong(),
view.height.densityNormalized(density).toLong(),
label = label
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.datadog.android.sessionreplay.utils.GlobalBounds
import com.datadog.android.sessionreplay.utils.ImageWireframeHelper
import com.datadog.android.sessionreplay.utils.ImageWireframeHelper.Companion.DRAWABLE_CHILD_NAME
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver
import com.datadog.android.utils.isCloseTo
import com.datadog.android.utils.verifyLog
import fr.xgouchet.elmyr.Forge
import fr.xgouchet.elmyr.annotation.IntForgery
Expand Down Expand Up @@ -663,12 +664,19 @@ internal class DefaultImageWireframeHelperTest {
// Given
whenever(mockImageTypeResolver.isDrawablePII(any(), any())).thenReturn(true)

val fakeGlobalX = forge.aPositiveLong()
val fakeGlobalY = forge.aPositiveLong()
val fakeGlobalX = forge.aPositiveInt()
val fakeGlobalY = forge.aPositiveInt()
whenever(mockResources.displayMetrics).thenReturn(mockDisplayMetrics)
mockDisplayMetrics.density = 1f
whenever(mockContext.applicationContext).thenReturn(mockContext)
val mockView: View = mock {
whenever(it.getLocationOnScreen(any())).thenAnswer { location ->
val coords = location.arguments[0] as IntArray
coords[0] = fakeGlobalX
coords[1] = fakeGlobalY
null
}

whenever(it.resources).thenReturn(mockResources)
whenever(it.context).thenReturn(mockContext)
}
Expand All @@ -678,8 +686,8 @@ internal class DefaultImageWireframeHelperTest {
view = mockView,
imagePrivacy = ImagePrivacy.MASK_LARGE_ONLY,
currentWireframeIndex = forge.aPositiveInt(),
x = fakeGlobalX,
y = fakeGlobalY,
x = forge.aPositiveLong(),
y = forge.aPositiveLong(),
width = forge.aPositiveInt(),
height = forge.aPositiveInt(),
drawable = mockDrawable,
Expand All @@ -691,8 +699,8 @@ internal class DefaultImageWireframeHelperTest {

// Then
verifyNoInteractions(mockResourceResolver)
assertThat(result.x).isEqualTo(fakeGlobalX)
assertThat(result.y).isEqualTo(fakeGlobalY)
assertThat(isCloseTo(result.x.toInt(), fakeGlobalX)).isTrue
assertThat(isCloseTo(result.y.toInt(), fakeGlobalY)).isTrue
}

@Test
Expand Down