brizental pushed to branch tor-browser-152.0a1-16.0-2 at The Tor Project / Applications / Tor Browser
Commits:
-
8bf5e1ff
by Beatriz Rizental at 2026-06-24T21:04:06+02:00
2 changed files:
- mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/AppStartupTest.kt → mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/torbrowser/AppStartupTest.kt
- + mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/torbrowser/HomeActivityScenarioRule.kt
Changes:
| 1 | -package org.mozilla.fenix
|
|
| 1 | +package org.mozilla.fenix.torbrowser
|
|
| 2 | 2 | |
| 3 | -import androidx.test.ext.junit.rules.ActivityScenarioRule
|
|
| 4 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4
|
| 5 | 4 | import androidx.test.platform.app.InstrumentationRegistry
|
| 6 | 5 | import androidx.test.uiautomator.UiDevice
|
| ... | ... | @@ -10,12 +9,11 @@ import org.junit.runner.RunWith |
| 10 | 9 | import java.util.concurrent.CountDownLatch
|
| 11 | 10 | import java.util.concurrent.TimeUnit
|
| 12 | 11 | |
| 13 | - |
|
| 14 | 12 | @RunWith(AndroidJUnit4::class)
|
| 15 | 13 | class LaunchTest {
|
| 16 | 14 | |
| 17 | 15 | @get:Rule
|
| 18 | - var rule: ActivityScenarioRule<HomeActivity> = ActivityScenarioRule(HomeActivity::class.java)
|
|
| 16 | + var rule = HomeActivityScenarioRule()
|
|
| 19 | 17 | |
| 20 | 18 | @Test
|
| 21 | 19 | fun appLaunchesWithoutCrash() {
|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
| 4 | + |
|
| 5 | +package org.mozilla.fenix.torbrowser
|
|
| 6 | + |
|
| 7 | +import androidx.test.ext.junit.rules.ActivityScenarioRule
|
|
| 8 | +import org.junit.rules.TestRule
|
|
| 9 | +import org.junit.runner.Description
|
|
| 10 | +import org.junit.runners.model.Statement
|
|
| 11 | +import org.mozilla.fenix.HomeActivity
|
|
| 12 | +import org.mozilla.fenix.ext.components
|
|
| 13 | + |
|
| 14 | +class HomeActivityScenarioRule : TestRule {
|
|
| 15 | + private val delegate = ActivityScenarioRule<HomeActivity>(HomeActivity::class.java)
|
|
| 16 | + |
|
| 17 | + val scenario get() = delegate.scenario
|
|
| 18 | + |
|
| 19 | + // ActivityScenarioRule waits for the DESTROYED lifecycle state during teardown, which means
|
|
| 20 | + // HomeActivity.onDestroy runs synchronously before the rule returns. onDestroy calls shutDown() ->
|
|
| 21 | + // exitProcess(0) when isFinishing, which kills the instrumentation process. Setting this flag
|
|
| 22 | + // prevents that code path so tests can report their results normally.
|
|
| 23 | + override fun apply(base: Statement, description: Description): Statement {
|
|
| 24 | + return delegate.apply(object : Statement() {
|
|
| 25 | + override fun evaluate() {
|
|
| 26 | + delegate.scenario.onActivity { activity ->
|
|
| 27 | + activity.applicationContext.components.notificationsDelegate.shouldShutDownWithOnDestroyWhenIsFinishing = false
|
|
| 28 | + }
|
|
| 29 | + base.evaluate()
|
|
| 30 | + }
|
|
| 31 | + }, description)
|
|
| 32 | + }
|
|
| 33 | +} |