diff --git a/android-components/components/feature/fxsuggest/src/main/java/mozilla/components/feature/fxsuggest/FxSuggestStorage.kt b/android-components/components/feature/fxsuggest/src/main/java/mozilla/components/feature/fxsuggest/FxSuggestStorage.kt index c48fecfa5872..48e80729cbe7 100644 --- a/android-components/components/feature/fxsuggest/src/main/java/mozilla/components/feature/fxsuggest/FxSuggestStorage.kt +++ b/android-components/components/feature/fxsuggest/src/main/java/mozilla/components/feature/fxsuggest/FxSuggestStorage.kt @@ -26,10 +26,7 @@ import java.io.File * @param crashReporter An optional [CrashReporting] instance for reporting unexpected caught * exceptions. */ -class FxSuggestStorage( - context: Context, - private val crashReporter: CrashReporting? = null, -) { +class FxSuggestStorage(context: Context) { // Lazily initializes the store on first use. `cacheDir` and using the `File` constructor // does I/O, so `store.value` should only be accessed from the read or write scope. @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @@ -99,7 +96,6 @@ class FxSuggestStorage( return try { operation() } catch (e: SuggestApiException) { - crashReporter?.submitCaughtException(e) logger.warn("Ignoring exception from `$name`", e) default } diff --git a/android-components/components/feature/fxsuggest/src/test/java/mozilla/components/feature/fxsuggest/FxSuggestStorageTest.kt b/android-components/components/feature/fxsuggest/src/test/java/mozilla/components/feature/fxsuggest/FxSuggestStorageTest.kt deleted file mode 100644 index 2ec69d31acab..000000000000 --- a/android-components/components/feature/fxsuggest/src/test/java/mozilla/components/feature/fxsuggest/FxSuggestStorageTest.kt +++ /dev/null @@ -1,98 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package mozilla.components.feature.fxsuggest - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import kotlinx.coroutines.test.runTest -import mozilla.appservices.suggest.SuggestApiException -import mozilla.appservices.suggest.SuggestStore -import mozilla.appservices.suggest.Suggestion -import mozilla.appservices.suggest.SuggestionQuery -import mozilla.components.concept.base.crash.CrashReporting -import mozilla.components.support.test.any -import mozilla.components.support.test.mock -import mozilla.components.support.test.robolectric.testContext -import mozilla.components.support.test.whenever -import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mockito.doNothing -import org.mockito.Mockito.never -import org.mockito.Mockito.spy -import org.mockito.Mockito.verify - -@RunWith(AndroidJUnit4::class) -class FxSuggestStorageTest { - @Test - fun `GIVEN an exception is thrown WHEN querying the store THEN the exception should be reported`() = runTest { - val store: SuggestStore = mock() - whenever(store.query(any())).then { - throw SuggestApiException.Other("Mercury in retrograde") - } - - val crashReporter: CrashReporting = mock() - val storage = spy(FxSuggestStorage(testContext, crashReporter)) - whenever(storage.store).thenReturn(lazy { store }) - - val suggestions = storage.query(SuggestionQuery("la", providers = emptyList())) - assertTrue(suggestions.isEmpty()) - verify(crashReporter).submitCaughtException(any()) - } - - @Test - fun `GIVEN an exception is not thrown WHEN querying the store THEN nothing should be reported`() = runTest { - val store: SuggestStore = mock() - whenever(store.query(any())).thenReturn( - listOf( - Suggestion.Wikipedia( - title = "Las Vegas", - url = "https://wikipedia.org/wiki/Las_Vegas", - icon = null, - fullKeyword = "las", - ), - ), - ) - - val crashReporter: CrashReporting = mock() - val storage = spy(FxSuggestStorage(testContext, crashReporter)) - whenever(storage.store).thenReturn(lazy { store }) - - val suggestions = storage.query(SuggestionQuery("la", providers = emptyList())) - assertEquals(1, suggestions.size) - verify(crashReporter, never()).submitCaughtException(any()) - } - - @Test - fun `GIVEN an exception is thrown WHEN ingesting THEN the exception should be reported`() = runTest { - val crashReporter: CrashReporting = mock() - val store: SuggestStore = mock() - whenever(store.ingest(any())).then { - throw SuggestApiException.Other("Mercury in retrograde") - } - - val storage = spy(FxSuggestStorage(testContext, crashReporter)) - whenever(storage.store).thenReturn(lazy { store }) - - val success = storage.ingest() - assertFalse(success) - verify(crashReporter).submitCaughtException(any()) - } - - @Test - fun `GIVEN an exception is not thrown WHEN ingesting THEN nothing should be reported`() = runTest { - val crashReporter: CrashReporting = mock() - val store: SuggestStore = mock() - doNothing().`when`(store).ingest(any()) - - val storage = spy(FxSuggestStorage(testContext, crashReporter)) - whenever(storage.store).thenReturn(lazy { store }) - - val success = storage.ingest() - assertTrue(success) - verify(crashReporter, never()).submitCaughtException(any()) - } -} diff --git a/fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt b/fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt index 40d316b8accd..6a4ea2328c2e 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt @@ -238,7 +238,7 @@ class Components(private val context: Context) { ) } - val fxSuggest by lazyMonitored { FxSuggest(context, analytics.crashReporter) } + val fxSuggest by lazyMonitored { FxSuggest(context) } } /** diff --git a/fenix/app/src/main/java/org/mozilla/fenix/components/FxSuggest.kt b/fenix/app/src/main/java/org/mozilla/fenix/components/FxSuggest.kt index 22a4444420bc..05593c97fc32 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/components/FxSuggest.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/components/FxSuggest.kt @@ -5,7 +5,6 @@ package org.mozilla.fenix.components import android.content.Context -import mozilla.components.concept.base.crash.CrashReporting import mozilla.components.feature.fxsuggest.FxSuggestIngestionScheduler import mozilla.components.feature.fxsuggest.FxSuggestStorage import org.mozilla.fenix.perf.lazyMonitored @@ -14,12 +13,10 @@ import org.mozilla.fenix.perf.lazyMonitored * Component group for Firefox Suggest. * * @param context The Android application context. - * @param crashReporter An optional [CrashReporting] instance for reporting unexpected caught - * exceptions. */ -class FxSuggest(context: Context, crashReporter: CrashReporting? = null) { +class FxSuggest(context: Context) { val storage by lazyMonitored { - FxSuggestStorage(context, crashReporter) + FxSuggestStorage(context) } val ingestionScheduler by lazyMonitored {