|
| 1 | +package io.sentry.android.core.internal.gestures |
| 2 | + |
| 3 | +import android.app.Activity |
| 4 | +import android.view.MotionEvent |
| 5 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 6 | +import io.sentry.Breadcrumb |
| 7 | +import io.sentry.IScopes |
| 8 | +import io.sentry.android.core.SentryAndroidOptions |
| 9 | +import io.sentry.util.LazyEvaluator |
| 10 | +import kotlin.test.Test |
| 11 | +import kotlin.test.assertNull |
| 12 | +import org.junit.runner.RunWith |
| 13 | +import org.mockito.kotlin.any |
| 14 | +import org.mockito.kotlin.anyOrNull |
| 15 | +import org.mockito.kotlin.mock |
| 16 | +import org.mockito.kotlin.never |
| 17 | +import org.mockito.kotlin.verify |
| 18 | +import org.robolectric.Robolectric.buildActivity |
| 19 | + |
| 20 | +@RunWith(AndroidJUnit4::class) |
| 21 | +class SentryGestureListenerPeekDecorViewTest { |
| 22 | + |
| 23 | + @Test |
| 24 | + fun `does not force decor view creation when peekDecorView returns null`() { |
| 25 | + // A plain Activity that never calls setContentView — peekDecorView() should return null |
| 26 | + val activity = buildActivity(Activity::class.java).create().get() |
| 27 | + |
| 28 | + // Sanity check: decor view has not been created yet |
| 29 | + assertNull(activity.window.peekDecorView()) |
| 30 | + |
| 31 | + val scopes = mock<IScopes>() |
| 32 | + val options = |
| 33 | + SentryAndroidOptions().apply { |
| 34 | + isEnableUserInteractionBreadcrumbs = true |
| 35 | + gestureTargetLocators = listOf(AndroidViewGestureTargetLocator(LazyEvaluator { true })) |
| 36 | + dsn = "https://key@sentry.io/proj" |
| 37 | + } |
| 38 | + |
| 39 | + val sut = SentryGestureListener(activity, scopes, options) |
| 40 | + sut.onSingleTapUp(mock<MotionEvent>()) |
| 41 | + |
| 42 | + // The key assertion: peekDecorView is still null — we did not force view hierarchy creation |
| 43 | + assertNull(activity.window.peekDecorView()) |
| 44 | + |
| 45 | + // And no breadcrumb was captured |
| 46 | + verify(scopes, never()).addBreadcrumb(any<Breadcrumb>(), anyOrNull()) |
| 47 | + } |
| 48 | +} |
0 commit comments