Commit 8bf5e1ff authored by brizental's avatar brizental Committed by brizental
Browse files

fixup! TB 43243: [android] Implement Android launch test

tor-browser-bundle-testsuite#40109: Get AndroidTest test working again.

Also create a base TestRule for future TorBrowser tests.
parent 13adb765
Loading
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
package org.mozilla.fenix
package org.mozilla.fenix.torbrowser

import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
@@ -10,12 +9,11 @@ import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit


@RunWith(AndroidJUnit4::class)
class LaunchTest {

    @get:Rule
    var rule: ActivityScenarioRule<HomeActivity> = ActivityScenarioRule(HomeActivity::class.java)
    var rule = HomeActivityScenarioRule()

    @Test
    fun appLaunchesWithoutCrash() {
+33 −0
Original line number Diff line number Diff line
/* 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 org.mozilla.fenix.torbrowser

import androidx.test.ext.junit.rules.ActivityScenarioRule
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.ext.components

class HomeActivityScenarioRule : TestRule {
    private val delegate = ActivityScenarioRule<HomeActivity>(HomeActivity::class.java)

    val scenario get() = delegate.scenario

    // ActivityScenarioRule waits for the DESTROYED lifecycle state during teardown, which means
    // HomeActivity.onDestroy runs synchronously before the rule returns. onDestroy calls shutDown() ->
    // exitProcess(0) when isFinishing, which kills the instrumentation process. Setting this flag
    // prevents that code path so tests can report their results normally.
    override fun apply(base: Statement, description: Description): Statement {
        return delegate.apply(object : Statement() {
            override fun evaluate() {
                delegate.scenario.onActivity { activity ->
                    activity.applicationContext.components.notificationsDelegate.shouldShutDownWithOnDestroyWhenIsFinishing = false
                }
                base.evaluate()
            }
        }, description)
    }
}