commit 60ad45fd7139d48aa1565910899f3fed997f2bb7 parent 2bf971952649f68eb066e07fc283f96d1c881a51 Author: mcarare <48995920+mcarare@users.noreply.github.com> Date: Wed, 3 Dec 2025 14:50:21 +0000 Bug 2002488 - Replace usage of MainScope in tests r=android-reviewers,giorga In `FileUploadsDirCleanerTest` and `ContextMenuCandidateTest`, usage of `MainScope` is replaced with `TestScope`. In `ChangeAppLauncherIconTest` and `RecentlyClosedTabsStorageOnDeviceTest`, the fake crash reporting implementations now return a completed `Job` directly instead of launching an empty coroutine via `MainScope`. Differential Revision: https://phabricator.services.mozilla.com/D274929 Diffstat:
4 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/mobile/android/android-components/components/feature/contextmenu/src/test/java/mozilla/components/feature/contextmenu/ContextMenuCandidateTest.kt b/mobile/android/android-components/components/feature/contextmenu/src/test/java/mozilla/components/feature/contextmenu/ContextMenuCandidateTest.kt @@ -11,7 +11,7 @@ import android.view.View import androidx.compose.ui.text.style.TextOverflow import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.test.ext.junit.runners.AndroidJUnit4 -import kotlinx.coroutines.MainScope +import kotlinx.coroutines.test.TestScope import mozilla.components.browser.state.action.BrowserAction import mozilla.components.browser.state.action.EngineAction import mozilla.components.browser.state.engine.EngineMiddleware @@ -216,7 +216,7 @@ class ContextMenuCandidateTest { val store = BrowserStore( middleware = EngineMiddleware.create( engine = mock(), - scope = MainScope(), + scope = TestScope(), ), initialState = BrowserState( tabs = listOf( @@ -447,7 +447,7 @@ class ContextMenuCandidateTest { val store = BrowserStore( middleware = EngineMiddleware.create( engine = mock(), - scope = MainScope(), + scope = TestScope(), ), initialState = BrowserState( tabs = listOf( @@ -515,7 +515,7 @@ class ContextMenuCandidateTest { val store = BrowserStore( middleware = EngineMiddleware.create( engine = mock(), - scope = MainScope(), + scope = TestScope(), ), initialState = BrowserState( tabs = listOf( diff --git a/mobile/android/android-components/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/file/FileUploadsDirCleanerTest.kt b/mobile/android/android-components/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/file/FileUploadsDirCleanerTest.kt @@ -6,7 +6,7 @@ package mozilla.components.feature.prompts.file import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.MainScope +import kotlinx.coroutines.test.TestScope import mozilla.components.concept.engine.prompt.PromptRequest.File.Companion.DEFAULT_UPLOADS_DIR_NAME import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.rule.MainCoroutineRule @@ -30,7 +30,7 @@ class FileUploadsDirCleanerTest { @Before fun setup() { fileCleaner = FileUploadsDirCleaner( - scope = MainScope(), + scope = TestScope(), ) { testContext.cacheDir } diff --git a/mobile/android/android-components/components/feature/recentlyclosed/src/androidTest/java/mozilla/components/feature/recentlyclosed/RecentlyClosedTabsStorageOnDeviceTest.kt b/mobile/android/android-components/components/feature/recentlyclosed/src/androidTest/java/mozilla/components/feature/recentlyclosed/RecentlyClosedTabsStorageOnDeviceTest.kt @@ -6,9 +6,7 @@ package mozilla.components.feature.recentlyclosed import androidx.test.core.app.ApplicationProvider import kotlinx.coroutines.Job -import kotlinx.coroutines.MainScope import kotlinx.coroutines.flow.first -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import mozilla.components.browser.state.state.recover.RecoverableTab import mozilla.components.browser.state.state.recover.TabState @@ -75,7 +73,7 @@ class RecentlyClosedTabsStorageOnDeviceTest { private class FakeCrashReporting : CrashReporting { override fun submitCaughtException(throwable: Throwable): Job { - return MainScope().launch {} + return Job().apply { complete() } } override fun recordCrashBreadcrumb(breadcrumb: Breadcrumb) {} diff --git a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/utils/ChangeAppLauncherIconTest.kt b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/utils/ChangeAppLauncherIconTest.kt @@ -10,8 +10,6 @@ import android.content.Intent import android.content.pm.PackageManager import androidx.core.content.pm.ShortcutInfoCompat import kotlinx.coroutines.Job -import kotlinx.coroutines.MainScope -import kotlinx.coroutines.launch import mozilla.components.concept.base.crash.Breadcrumb import mozilla.components.concept.base.crash.CrashReporting import mozilla.components.support.test.any @@ -620,7 +618,7 @@ private class TestCrashReporter() : CrashReporting { override fun submitCaughtException(throwable: Throwable): Job { submitCaughtExceptionInvoked = true errors.add(throwable) - return MainScope().launch {} + return Job().apply { complete() } } override fun recordCrashBreadcrumb(breadcrumb: Breadcrumb) {}