Closes #5678: Selected session may render in ExternalAppBrowserActivity
parent
b413a57159
commit
ee3871cd7c
|
@ -17,6 +17,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.NavDestination
|
||||
import androidx.navigation.NavDirections
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.NavigationUI
|
||||
|
@ -247,14 +248,15 @@ open class HomeActivity : AppCompatActivity() {
|
|||
if (navHost.navController.alreadyOnDestination(R.id.browserFragment)) return
|
||||
@IdRes val fragmentId = if (from.fragmentId != 0) from.fragmentId else null
|
||||
val directions = getNavDirections(from, customTabSessionId)
|
||||
|
||||
navHost.navController.nav(fragmentId, directions)
|
||||
if (directions != null) {
|
||||
navHost.navController.nav(fragmentId, directions)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun getNavDirections(
|
||||
from: BrowserDirection,
|
||||
customTabSessionId: String?
|
||||
) = when (from) {
|
||||
): NavDirections? = when (from) {
|
||||
BrowserDirection.FromGlobal ->
|
||||
NavGraphDirections.actionGlobalBrowser(customTabSessionId)
|
||||
BrowserDirection.FromHome ->
|
||||
|
|
|
@ -39,7 +39,12 @@ open class ExternalAppBrowserActivity : HomeActivity() {
|
|||
override fun getNavDirections(
|
||||
from: BrowserDirection,
|
||||
customTabSessionId: String?
|
||||
): NavDirections {
|
||||
): NavDirections? {
|
||||
if (customTabSessionId == null) {
|
||||
finish()
|
||||
return null
|
||||
}
|
||||
|
||||
val manifest = intent
|
||||
.getWebAppManifest()
|
||||
?.let { WebAppManifestParser().serialize(it).toString() }
|
||||
|
|
|
@ -5,10 +5,20 @@
|
|||
package org.mozilla.fenix.customtabs
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.navigation.NavDirections
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import mozilla.components.support.utils.toSafeIntent
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito.never
|
||||
import org.mockito.Mockito.spy
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
import org.mozilla.fenix.TestApplication
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
@ -33,4 +43,32 @@ class ExternalAppBrowserActivityTest {
|
|||
val otherIntent = Intent().toSafeIntent()
|
||||
assertEquals(Event.OpenedApp.Source.CUSTOM_TAB, activity.getIntentSource(otherIntent))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getNavDirections finishes activity if session ID is null`() {
|
||||
val activity = spy(object : ExternalAppBrowserActivity() {
|
||||
public override fun getNavDirections(
|
||||
from: BrowserDirection,
|
||||
customTabSessionId: String?
|
||||
): NavDirections? {
|
||||
return super.getNavDirections(from, customTabSessionId)
|
||||
}
|
||||
|
||||
override fun getIntent(): Intent {
|
||||
val intent: Intent = mockk()
|
||||
val bundle: Bundle = mockk()
|
||||
every { bundle.getString(any()) } returns ""
|
||||
every { intent.extras } returns bundle
|
||||
return intent
|
||||
}
|
||||
})
|
||||
|
||||
var directions = activity.getNavDirections(BrowserDirection.FromGlobal, "id")
|
||||
assertNotNull(directions)
|
||||
verify(activity, never()).finish()
|
||||
|
||||
directions = activity.getNavDirections(BrowserDirection.FromGlobal, null)
|
||||
assertNull(directions)
|
||||
verify(activity).finish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue