tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 738243227c4feb1a27bb9e059757615eb2f59c3e
parent 89c4b1d36f8fde5ff7f9a47be9d360327f77eac9
Author: mcarare <48995920+mcarare@users.noreply.github.com>
Date:   Tue,  7 Oct 2025 15:35:59 +0000

Bug 1992015 - Remove MainCoroutineRule from crash reporting test code. r=android-reviewers,giorga

This patch migrates tests in `SettingsCrashReportCacheTest` from `runTestOnMain` to the standard `runTest` and removes MainCoroutineRule.
It also removes the redundant `withContext(Dispatchers.IO)` wrapper from `setReportOption` since SharedPreferences editor handles the threading.

Differential Revision: https://phabricator.services.mozilla.com/D267786

Diffstat:
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/crashes/SettingsCrashReportCache.kt | 4+---
Mmobile/android/fenix/app/src/test/java/org/mozilla/fenix/crashes/SettingsCrashReportCacheTest.kt | 17++++++-----------
2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/crashes/SettingsCrashReportCache.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/crashes/SettingsCrashReportCache.kt @@ -4,8 +4,6 @@ package org.mozilla.fenix.crashes -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext import mozilla.components.lib.crash.store.CrashReportCache import mozilla.components.lib.crash.store.CrashReportOption import mozilla.components.lib.crash.store.TimeInMillis @@ -53,7 +51,7 @@ class SettingsCrashReportCache(private val settings: Settings) : CrashReportCach CrashReportOption.Never } - override suspend fun setReportOption(option: CrashReportOption) = withContext(Dispatchers.IO) { + override suspend fun setReportOption(option: CrashReportOption) { settings.crashReportChoice = option.toString() } } diff --git a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/crashes/SettingsCrashReportCacheTest.kt b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/crashes/SettingsCrashReportCacheTest.kt @@ -4,12 +4,10 @@ package org.mozilla.fenix.crashes +import kotlinx.coroutines.test.runTest import mozilla.components.lib.crash.store.TimeInMillis -import mozilla.components.support.test.rule.MainCoroutineRule -import mozilla.components.support.test.rule.runTestOnMain import org.junit.Assert.assertEquals import org.junit.Before -import org.junit.Rule import org.junit.Test import org.mockito.Mockito.mock import org.mockito.Mockito.verify @@ -17,9 +15,6 @@ import org.mockito.Mockito.`when` import org.mozilla.fenix.utils.Settings class SettingsCrashReportCacheTest { - - @get:Rule val coroutineRule = MainCoroutineRule() - private lateinit var settings: Settings @Before @@ -28,7 +23,7 @@ class SettingsCrashReportCacheTest { } @Test - fun `GIVEN cache has 0 stored for crashReportCutoffDate WHEN accessed THEN returns null`() = runTestOnMain { + fun `GIVEN cache has 0 stored for crashReportCutoffDate WHEN accessed THEN returns null`() = runTest { `when`(settings.crashReportCutoffDate).thenReturn(0) val cache = SettingsCrashReportCache(settings) @@ -38,7 +33,7 @@ class SettingsCrashReportCacheTest { } @Test - fun `WHEN setting CutoffDate with null value THEN 0 is stored`() = runTestOnMain { + fun `WHEN setting CutoffDate with null value THEN 0 is stored`() = runTest { val cache = SettingsCrashReportCache(settings) cache.setCutoffDate(null) @@ -46,7 +41,7 @@ class SettingsCrashReportCacheTest { } @Test - fun `GIVEN cache has 0 stored for DeferredUntil WHEN accessed THEN returns null`() = runTestOnMain { + fun `GIVEN cache has 0 stored for DeferredUntil WHEN accessed THEN returns null`() = runTest { `when`(settings.crashReportDeferredUntil).thenReturn(0) val cache = SettingsCrashReportCache(settings) @@ -56,7 +51,7 @@ class SettingsCrashReportCacheTest { } @Test - fun `WHEN setting DeferredUntil with null value THEN 0 is stored`() = runTestOnMain { + fun `WHEN setting DeferredUntil with null value THEN 0 is stored`() = runTest { val cache = SettingsCrashReportCache(settings) cache.setDeferredUntil(null) @@ -64,7 +59,7 @@ class SettingsCrashReportCacheTest { } @Test - fun `WHEN retrieving CrashPullDeferUntil with never show again set THEN returns a future timestamp`() = runTestOnMain { + fun `WHEN retrieving CrashPullDeferUntil with never show again set THEN returns a future timestamp`() = runTest { `when`(settings.crashPullNeverShowAgain).thenReturn(true) `when`(settings.crashPullDontShowBefore).thenReturn(0)