Bug 1870231 - Remove no-ops from ExternalAppBrowserActivity

fenix/123.0
t-p-white 5 months ago committed by mergify[bot]
parent ca7896ad4b
commit ccefb2dd2d

@ -33,6 +33,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.app.NotificationManagerCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI
@ -318,7 +319,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
// Unless the activity is recreated, navigate to home first (without rendering it)
// to add it to the back stack.
if (savedInstanceState == null) {
navigateToHome()
navigateToHome(navHost.navController)
}
if (!shouldStartOnHome() && shouldNavigateToBrowserOnColdStart(savedInstanceState)) {
@ -676,7 +677,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
startupPathProvider.onIntentReceived(intent)
}
open fun handleNewIntent(intent: Intent) {
@VisibleForTesting
internal fun handleNewIntent(intent: Intent) {
if (this is ExternalAppBrowserActivity) {
return
}
// Diagnostic breadcrumb for "Display already aquired" crash:
// https://github.com/mozilla-mobile/android-components/issues/7960
breadcrumb(
@ -1091,7 +1097,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
settings().openNextTabInDesktopMode = false
}
open fun navigateToBrowserOnColdStart() {
@VisibleForTesting
internal fun navigateToBrowserOnColdStart() {
if (this is ExternalAppBrowserActivity) {
return
}
// Normal tabs + cold start -> Should go back to browser if we had any tabs open when we left last
// except for PBM + Cold Start there won't be any tabs since they're evicted so we never will navigate
if (settings().shouldReturnToBrowser && !components.appStore.state.mode.isPrivate) {
@ -1100,8 +1111,13 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
}
open fun navigateToHome() {
navHost.navController.navigate(NavGraphDirections.actionStartupHome())
@VisibleForTesting
internal fun navigateToHome(navController: NavController) {
if (this is ExternalAppBrowserActivity) {
return
}
navController.navigate(NavGraphDirections.actionStartupHome())
}
override fun attachBaseContext(base: Context) {

@ -5,7 +5,6 @@
package org.mozilla.fenix.customtabs
import android.app.assist.AssistContent
import android.content.Intent
import android.net.Uri
import android.os.Build
import androidx.annotation.RequiresApi
@ -38,18 +37,6 @@ open class ExternalAppBrowserActivity : HomeActivity() {
}
}
override fun navigateToBrowserOnColdStart() {
// No-op for external app
}
override fun navigateToHome() {
// No-op for external app
}
override fun handleNewIntent(intent: Intent) {
// No-op for external app
}
override fun onDestroy() {
super.onDestroy()

@ -6,6 +6,7 @@ package org.mozilla.fenix.customtabs
import android.content.Intent
import android.os.Bundle
import androidx.navigation.NavController
import io.mockk.Called
import io.mockk.every
import io.mockk.mockk
@ -65,6 +66,15 @@ class ExternalAppBrowserActivityTest {
verify(exactly = 0) { activity.openToBrowser(BrowserDirection.FromGlobal, null) }
}
@Test
fun `navigateToHome does nothing for external app browser activity`() {
val activity = spyk(ExternalAppBrowserActivity())
val navHostController: NavController = mockk()
activity.navigateToHome(navHostController)
verify { navHostController wasNot Called }
}
@Test
fun `handleNewIntent does nothing for external app browser activity`() {
val activity = spyk(ExternalAppBrowserActivity())

@ -0,0 +1,55 @@
/* 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.settings.account
import android.content.Intent
import androidx.navigation.NavController
import io.mockk.Called
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
@RunWith(FenixRobolectricTestRunner::class)
class AuthCustomTabActivityTest {
@Test
fun `navigateToBrowserOnColdStart does nothing for AuthCustomTabActivity`() {
val activity = spyk(AuthCustomTabActivity())
val settings: Settings = mockk()
every { settings.shouldReturnToBrowser } returns true
every { activity.components.settings.shouldReturnToBrowser } returns true
every { activity.openToBrowser(any(), any()) } returns Unit
activity.navigateToBrowserOnColdStart()
verify(exactly = 0) { activity.openToBrowser(BrowserDirection.FromGlobal) }
}
@Test
fun `navigateToHome does nothing for AuthCustomTabActivity`() {
val activity = spyk(AuthCustomTabActivity())
val navHostController: NavController = mockk()
activity.navigateToHome(navHostController)
verify { navHostController wasNot Called }
}
@Test
fun `handleNewIntent does nothing for AuthCustomTabActivity`() {
val activity = spyk(AuthCustomTabActivity())
val intent: Intent = mockk(relaxed = true)
activity.handleNewIntent(intent)
verify { intent wasNot Called }
}
}
Loading…
Cancel
Save