Issue #16330: Remove remaining usages of Sentry.capture

upstream-sync
Christian Sadilek 3 years ago committed by mergify[bot]
parent a516bb6681
commit 589f166b29

@ -10,7 +10,6 @@ import android.content.res.Configuration
import android.os.Build
import android.os.StrictMode
import androidx.core.content.ContextCompat
import io.sentry.Sentry
import mozilla.components.browser.engine.gecko.GeckoEngine
import mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient
import mozilla.components.browser.engine.gecko.permission.GeckoSitePermissionsStorage
@ -85,6 +84,7 @@ import org.mozilla.fenix.telemetry.TelemetryMiddleware
import org.mozilla.fenix.utils.Mockable
import org.mozilla.fenix.utils.getUndoDelay
import org.mozilla.geckoview.GeckoRuntime
import java.lang.IllegalStateException
/**
* Component group for all core browser functionality.
@ -410,11 +410,13 @@ class Core(
private val passwordsEncryptionKey by lazyMonitored {
getSecureAbove22Preferences().getString(PASSWORDS_KEY)
?: generateEncryptionKey(KEY_STRENGTH).also {
if (context.settings().passwordsEncryptionKeyGenerated &&
isSentryEnabled()
) {
if (context.settings().passwordsEncryptionKeyGenerated) {
// We already had previously generated an encryption key, but we have lost it
Sentry.capture("Passwords encryption key for passwords storage was lost and we generated a new one")
crashReporter.submitCaughtException(
IllegalStateException(
"Passwords encryption key for passwords storage was lost and we generated a new one"
)
)
}
context.settings().recordPasswordsEncryptionKeyGenerated()
getSecureAbove22Preferences().putString(PASSWORDS_KEY, it)

@ -8,8 +8,7 @@ import androidx.annotation.IdRes
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import androidx.navigation.NavOptions
import io.sentry.Sentry
import org.mozilla.fenix.components.isSentryEnabled
import mozilla.components.support.base.log.logger.Logger
/**
* Navigate from the fragment with [id] using the given [directions].
@ -19,7 +18,7 @@ fun NavController.nav(@IdRes id: Int?, directions: NavDirections, navOptions: Na
if (id == null || this.currentDestination?.id == id) {
this.navigate(directions, navOptions)
} else {
recordIdException(this.currentDestination?.id, id)
Logger.error("Fragment id ${this.currentDestination?.id} did not match expected $id")
}
}
@ -27,12 +26,6 @@ fun NavController.alreadyOnDestination(@IdRes destId: Int?): Boolean {
return destId?.let { currentDestination?.id == it || popBackStack(it, false) } ?: false
}
fun recordIdException(actual: Int?, expected: Int?) {
if (isSentryEnabled()) {
Sentry.capture("Fragment id $actual did not match expected $expected")
}
}
fun NavController.navigateSafe(
@IdRes resId: Int,
directions: NavDirections

@ -9,17 +9,11 @@ import androidx.navigation.NavDestination
import androidx.navigation.NavDirections
import androidx.navigation.NavOptions
import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.confirmVerified
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.mockkStatic
import io.mockk.verify
import io.sentry.Sentry
import org.junit.Before
import org.junit.Test
import org.mozilla.fenix.components.isSentryEnabled
class NavControllerTest {
@ -32,12 +26,9 @@ class NavControllerTest {
@Before
fun setUp() {
MockKAnnotations.init(this)
mockkStatic("io.sentry.Sentry", "org.mozilla.fenix.components.AnalyticsKt")
every { navController.currentDestination } returns mockDestination
every { mockDestination.id } returns currentDestId
every { isSentryEnabled() } returns true
every { Sentry.capture(any<String>()) } just Runs
}
@Test
@ -53,21 +44,4 @@ class NavControllerTest {
verify { navController.currentDestination }
verify { navController.navigate(navDirections, mockOptions) }
}
@Test
fun `Test error response for id exception in-block`() {
navController.nav(7, navDirections)
verify { navController.currentDestination }
verify { Sentry.capture("Fragment id 4 did not match expected 7") }
confirmVerified(navController)
}
@Test
fun `Test record id exception fun`() {
val actual = 7
val expected = 4
recordIdException(actual, expected)
verify { Sentry.capture("Fragment id 7 did not match expected 4") }
}
}

Loading…
Cancel
Save