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

RUM-3532 keep webview wireframe hidden #1949

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions features/dd-sdk-android-session-replay/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ data class com.datadog.android.sessionreplay.model.MobileSegment
fun fromJson(kotlin.String): PlaceholderWireframe
fun fromJsonObject(com.google.gson.JsonObject): PlaceholderWireframe
data class WebviewWireframe : Wireframe
constructor(kotlin.Long, kotlin.Long, kotlin.Long, kotlin.Long, kotlin.Long, WireframeClip? = null, ShapeStyle? = null, ShapeBorder? = null, kotlin.String)
constructor(kotlin.Long, kotlin.Long, kotlin.Long, kotlin.Long, kotlin.Long, WireframeClip? = null, ShapeStyle? = null, ShapeBorder? = null, kotlin.String, kotlin.Boolean? = null)
val type: kotlin.String
override fun toJson(): com.google.gson.JsonElement
companion object
Expand Down Expand Up @@ -295,7 +295,7 @@ data class com.datadog.android.sessionreplay.model.MobileSegment
fun fromJson(kotlin.String): PlaceholderWireframeUpdate
fun fromJsonObject(com.google.gson.JsonObject): PlaceholderWireframeUpdate
data class WebviewWireframeUpdate : WireframeUpdateMutation
constructor(kotlin.Long, kotlin.Long? = null, kotlin.Long? = null, kotlin.Long? = null, kotlin.Long? = null, WireframeClip? = null, ShapeStyle? = null, ShapeBorder? = null, kotlin.String)
constructor(kotlin.Long, kotlin.Long? = null, kotlin.Long? = null, kotlin.Long? = null, kotlin.Long? = null, WireframeClip? = null, ShapeStyle? = null, ShapeBorder? = null, kotlin.String, kotlin.Boolean? = null)
val type: kotlin.String
override fun toJson(): com.google.gson.JsonElement
companion object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1059,9 +1059,10 @@ public final class com/datadog/android/sessionreplay/model/MobileSegment$Wirefra

public final class com/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe : com/datadog/android/sessionreplay/model/MobileSegment$Wireframe {
public static final field Companion Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe$Companion;
public fun <init> (JJJJJLcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;)V
public synthetic fun <init> (JJJJJLcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (JJJJJLcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;Ljava/lang/Boolean;)V
public synthetic fun <init> (JJJJJLcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;Ljava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()J
public final fun component10 ()Ljava/lang/Boolean;
public final fun component2 ()J
public final fun component3 ()J
public final fun component4 ()J
Expand All @@ -1070,8 +1071,8 @@ public final class com/datadog/android/sessionreplay/model/MobileSegment$Wirefra
public final fun component7 ()Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;
public final fun component8 ()Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;
public final fun component9 ()Ljava/lang/String;
public final fun copy (JJJJJLcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;)Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe;
public static synthetic fun copy$default (Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe;JJJJJLcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;ILjava/lang/Object;)Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe;
public final fun copy (JJJJJLcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;Ljava/lang/Boolean;)Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe;
public static synthetic fun copy$default (Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe;JJJJJLcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;Ljava/lang/Boolean;ILjava/lang/Object;)Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe;
public fun equals (Ljava/lang/Object;)Z
public static final fun fromJson (Ljava/lang/String;)Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe;
public static final fun fromJsonObject (Lcom/google/gson/JsonObject;)Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$WebviewWireframe;
Expand All @@ -1086,6 +1087,7 @@ public final class com/datadog/android/sessionreplay/model/MobileSegment$Wirefra
public final fun getX ()J
public final fun getY ()J
public fun hashCode ()I
public final fun isVisible ()Ljava/lang/Boolean;
public fun toJson ()Lcom/google/gson/JsonElement;
public fun toString ()Ljava/lang/String;
}
Expand Down Expand Up @@ -1299,9 +1301,10 @@ public final class com/datadog/android/sessionreplay/model/MobileSegment$Wirefra

public final class com/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate : com/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation {
public static final field Companion Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate$Companion;
public fun <init> (JLjava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;)V
public synthetic fun <init> (JLjava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (JLjava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;Ljava/lang/Boolean;)V
public synthetic fun <init> (JLjava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;Ljava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()J
public final fun component10 ()Ljava/lang/Boolean;
public final fun component2 ()Ljava/lang/Long;
public final fun component3 ()Ljava/lang/Long;
public final fun component4 ()Ljava/lang/Long;
Expand All @@ -1310,8 +1313,8 @@ public final class com/datadog/android/sessionreplay/model/MobileSegment$Wirefra
public final fun component7 ()Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;
public final fun component8 ()Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;
public final fun component9 ()Ljava/lang/String;
public final fun copy (JLjava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;)Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate;
public static synthetic fun copy$default (Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate;JLjava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;ILjava/lang/Object;)Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate;
public final fun copy (JLjava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;Ljava/lang/Boolean;)Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate;
public static synthetic fun copy$default (Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate;JLjava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeClip;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeStyle;Lcom/datadog/android/sessionreplay/model/MobileSegment$ShapeBorder;Ljava/lang/String;Ljava/lang/Boolean;ILjava/lang/Object;)Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate;
public fun equals (Ljava/lang/Object;)Z
public static final fun fromJson (Ljava/lang/String;)Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate;
public static final fun fromJsonObject (Lcom/google/gson/JsonObject;)Lcom/datadog/android/sessionreplay/model/MobileSegment$WireframeUpdateMutation$WebviewWireframeUpdate;
Expand All @@ -1326,6 +1329,7 @@ public final class com/datadog/android/sessionreplay/model/MobileSegment$Wirefra
public final fun getX ()Ljava/lang/Long;
public final fun getY ()Ljava/lang/Long;
public fun hashCode ()I
public final fun isVisible ()Ljava/lang/Boolean;
public fun toJson ()Lcom/google/gson/JsonElement;
public fun toString ()Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"type": "string",
"description": "Unique Id of the slot containing this webview.",
"readOnly": true
},
"isVisible": {
"type": "boolean",
"description": "Whether this web-view is visible or not.",
"readOnly": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"type": "string",
"description": "Unique Id of the slot containing this webview.",
"readOnly": true
},
"isVisible": {
"type": "boolean",
"description": "Whether this web-view is visible or not.",
"readOnly": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,21 @@ internal class MutationResolver(private val internalLogger: InternalLogger) {
oa.forEachIndexed { index, entry ->
removalOffsets[index] = runningOffset
if (entry is Entry.Reference) {
// Old element was removed
removes.add(MobileSegment.Remove(oldSnapshot[index].id()))
val oldWireframe = oldSnapshot[index]
if (oldWireframe is MobileSegment.Wireframe.WebviewWireframe) {
if (oldWireframe.isVisible != false) {
updates.add(
MobileSegment.WireframeUpdateMutation.WebviewWireframeUpdate(
id = oldWireframe.id,
slotId = oldWireframe.slotId,
isVisible = false
)
)
}
} else {
// Old element was removed
removes.add(MobileSegment.Remove(oldWireframe.id()))
}
runningOffset++
}
}
Expand Down Expand Up @@ -169,6 +182,7 @@ internal class MutationResolver(private val internalLogger: InternalLogger) {
}
} // else - element was not moved and not changed, so: skip
}

is Entry.Reference -> {
// New element was added:
val previousId = if (index > 0) newSnapshot[index - 1].id() else null
Expand Down Expand Up @@ -366,18 +380,22 @@ internal class MutationResolver(private val internalLogger: InternalLogger) {
prevWireframe,
currentWireframe as MobileSegment.Wireframe.TextWireframe
)

is MobileSegment.Wireframe.ShapeWireframe -> resolveShapeMutation(
prevWireframe,
currentWireframe as MobileSegment.Wireframe.ShapeWireframe
)

is MobileSegment.Wireframe.ImageWireframe -> resolveImageMutation(
prevWireframe,
currentWireframe as MobileSegment.Wireframe.ImageWireframe
)

is MobileSegment.Wireframe.PlaceholderWireframe -> resolvePlaceholderMutation(
prevWireframe,
currentWireframe as MobileSegment.Wireframe.PlaceholderWireframe
)

is MobileSegment.Wireframe.WebviewWireframe -> resolveWebViewWireframeMutation(
prevWireframe,
currentWireframe as MobileSegment.Wireframe.WebviewWireframe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ internal class WebViewWireframeMapper(
viewGlobalBounds.y,
viewGlobalBounds.width,
viewGlobalBounds.height,
slotId = webViewId.toString()
slotId = webViewId.toString(),
isVisible = true
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.mockito.kotlin.eq
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.quality.Strictness
import java.util.ArrayList
import java.util.LinkedList
import java.util.Locale

Expand Down Expand Up @@ -523,6 +522,66 @@ internal class MutationResolverTest {

// endregion

// region WebView "remove" mutations

@Test
fun `M identify the updated wireframes W resolveMutations {WebView removed at beginning}`(forge: Forge) {
// Given
val fakePrevSnapshot = forge.aList(size = forge.anInt(min = 3, max = 10)) {
forge.getForgery(MobileSegment.Wireframe.WebviewWireframe::class.java)
}
val fakeHiddenWebViews = forge.anInt(min = 1, max = fakePrevSnapshot.size - 1)
val fakeCurrentSnapshot = fakePrevSnapshot.drop(fakeHiddenWebViews)
val expectedUpdates = fakePrevSnapshot.take(fakeHiddenWebViews).map {
MobileSegment.WireframeUpdateMutation.WebviewWireframeUpdate(
id = it.id(),
slotId = it.slotId,
isVisible = false
)
}

// When
val mutations = testedMutationResolver.resolveMutations(
fakePrevSnapshot,
fakeCurrentSnapshot
)

// Then
assertThat(mutations?.adds).isNullOrEmpty()
assertThat(mutations?.removes).isNullOrEmpty()
assertThat(mutations?.updates).isEqualTo(expectedUpdates)
}

@Test
fun `M identify the updated wireframes W resolveMutations {WebView removed at end}`(forge: Forge) {
// Given
val fakePrevSnapshot = forge.aList(size = forge.anInt(min = 3, max = 10)) {
forge.getForgery(MobileSegment.Wireframe.WebviewWireframe::class.java)
}
val fakeHiddenWebViews = forge.anInt(min = 1, max = fakePrevSnapshot.size - 1)
val fakeCurrentSnapshot = fakePrevSnapshot.dropLast(fakeHiddenWebViews)
val expectedUpdates = fakePrevSnapshot.takeLast(fakeHiddenWebViews).map {
MobileSegment.WireframeUpdateMutation.WebviewWireframeUpdate(
id = it.id(),
slotId = it.slotId,
isVisible = false
)
}

// When
val mutations = testedMutationResolver.resolveMutations(
fakePrevSnapshot,
fakeCurrentSnapshot
)

// Then
assertThat(mutations?.adds).isNullOrEmpty()
assertThat(mutations?.removes).isNullOrEmpty()
assertThat(mutations?.updates).isEqualTo(expectedUpdates)
}

// endregion

// region no mutation

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ internal class WebViewWireframeMapperTest : BaseWireframeMapperTest() {
y = fakeViewGlobalBounds.y,
width = fakeViewGlobalBounds.width,
height = fakeViewGlobalBounds.height,
slotId = fakeWireframeId.toString()
slotId = fakeWireframeId.toString(),
isVisible = true
)

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class SampleApplication : Application() {

companion object {
private const val SAMPLE_IN_ALL_SESSIONS = 100f

init {
System.loadLibrary("datadog-native-sample-lib")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,9 @@ class ViewPagerFragment : Fragment() {

override fun createFragment(position: Int): Fragment {
return when (position) {
0 -> FragmentA()
1 -> FragmentB()
else -> FragmentC()
}.apply {
val args = Bundle().apply {
putString("fragmentClassName", this::class.java.simpleName)
putInt("adapterPosition", position)
}
arguments = args
0 -> FragmentA.newInstance()
1 -> FragmentB.newInstance()
else -> FragmentC.newInstance()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal class PictureFragment :
}
}

@Deprecated("Deprecated in Java")
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
val currentType = viewModel.getImageLoader()
inflater.inflate(R.menu.image_loader, menu)
Expand All @@ -65,6 +66,7 @@ internal class PictureFragment :
menu.findItem(disabled).isEnabled = false
}

@Deprecated("Deprecated in Java")
override fun onOptionsItemSelected(item: MenuItem): Boolean {
val type = when (item.itemId) {
R.id.image_loader_coil -> ImageLoaderType.COIL
Expand Down