mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
Bug 1874885 - Fix reset to default locale when a test crashes
This commit is contained in:
parent
224c92b3eb
commit
f9fdb86eb9
@ -249,6 +249,7 @@ object AppAndSystemHelper {
|
||||
* Runs on Debug variant as we don't want to adjust Release permission manifests
|
||||
* Runs the test in its testBlock.
|
||||
* Cleans up and sets the default locale after it's done.
|
||||
* As a safety measure, always add the resetSystemLocaleToEnUS() method in the tearDown method of your Class.
|
||||
*/
|
||||
fun runWithSystemLocaleChanged(locale: Locale, testRule: ActivityTestRule<HomeActivity>, testBlock: () -> Unit) {
|
||||
if (Config.channel.isDebug) {
|
||||
@ -274,6 +275,21 @@ object AppAndSystemHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the default language of the entire device back to EN-US.
|
||||
* In case of a test instrumentation crash, the finally statement in the
|
||||
* runWithSystemLocaleChanged(locale: Locale) method, will not be reached.
|
||||
* Add this method inside the tearDown method of your test class, where the above method is used.
|
||||
* Note: If set inside the ActivityTestRule's afterActivityFinished() method, this also won't work,
|
||||
* as the methods inside it are not always executed: https://github.com/android/android-test/issues/498
|
||||
*/
|
||||
fun resetSystemLocaleToEnUS() {
|
||||
if (Locale.getDefault() != Locale.US) {
|
||||
Log.i(TAG, "Resetting system locale to EN US")
|
||||
setSystemLocale(Locale.US)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the default language of the entire device, not just the app.
|
||||
*/
|
||||
|
@ -14,6 +14,7 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.resetSystemLocaleToEnUS
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithSystemLocaleChanged
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
@ -54,6 +55,7 @@ class ComposeNavigationToolbarTest {
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
resetSystemLocaleToEnUS()
|
||||
}
|
||||
|
||||
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/987326
|
||||
|
@ -14,6 +14,7 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithSystemLocaleChanged
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
@ -50,6 +51,7 @@ class NavigationToolbarTest {
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
AppAndSystemHelper.resetSystemLocaleToEnUS()
|
||||
}
|
||||
|
||||
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/987326
|
||||
|
@ -21,6 +21,7 @@ import org.junit.Test
|
||||
import org.mozilla.fenix.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.assertNativeAppOpens
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.denyPermission
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.grantSystemPermission
|
||||
@ -92,6 +93,7 @@ class SearchTest {
|
||||
@After
|
||||
fun tearDown() {
|
||||
searchMockServer.shutdown()
|
||||
AppAndSystemHelper.resetSystemLocaleToEnUS()
|
||||
}
|
||||
|
||||
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2154189
|
||||
|
@ -14,6 +14,7 @@ import org.mozilla.fenix.FenixApplication
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.registerAndCleanupIdlingResources
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithSystemLocaleChanged
|
||||
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
|
||||
@ -51,6 +52,7 @@ class SettingsGeneralTest {
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
AppAndSystemHelper.resetSystemLocaleToEnUS()
|
||||
}
|
||||
|
||||
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2092697
|
||||
|
@ -14,6 +14,7 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.resetSystemLocaleToEnUS
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithSystemLocaleChanged
|
||||
import org.mozilla.fenix.helpers.AppAndSystemHelper.setSystemLocale
|
||||
import org.mozilla.fenix.helpers.DataGenerationHelper.setTextToClipBoard
|
||||
@ -64,6 +65,7 @@ class SettingsSearchTest {
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
resetSystemLocaleToEnUS()
|
||||
}
|
||||
|
||||
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2203333
|
||||
|
Loading…
Reference in New Issue
Block a user