mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/19886 - Improve quick setting dialogs navigation
This commit is contained in:
parent
c9575d0d62
commit
39dc0701a8
@ -9,10 +9,8 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.NavController
|
||||
import mozilla.components.browser.state.state.SessionState
|
||||
import mozilla.components.concept.engine.permission.SitePermissions
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.browser.BrowserFragmentDirections
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.nav
|
||||
import org.mozilla.fenix.ext.runIfFragmentIsAttached
|
||||
|
||||
/**
|
||||
@ -36,7 +34,7 @@ interface ConnectionDetailsController {
|
||||
class DefaultConnectionDetailsController(
|
||||
private val context: Context,
|
||||
private val fragment: Fragment,
|
||||
private val navController: NavController,
|
||||
private val navController: () -> NavController,
|
||||
internal var sitePermissions: SitePermissions?,
|
||||
private val gravity: Int,
|
||||
private val getCurrentTab: () -> SessionState?,
|
||||
@ -46,7 +44,7 @@ class DefaultConnectionDetailsController(
|
||||
getCurrentTab()?.let { tab ->
|
||||
context.components.useCases.trackingProtectionUseCases.containsException(tab.id) { contains ->
|
||||
fragment.runIfFragmentIsAttached {
|
||||
dismiss()
|
||||
navController().popBackStack()
|
||||
val isTrackingProtectionEnabled = tab.trackingProtection.enabled && !contains
|
||||
val directions =
|
||||
BrowserFragmentDirections.actionGlobalQuickSettingsSheetDialogFragment(
|
||||
@ -60,7 +58,7 @@ class DefaultConnectionDetailsController(
|
||||
permissionHighlights = tab.content.permissionHighlights,
|
||||
isTrackingProtectionEnabled = isTrackingProtectionEnabled
|
||||
)
|
||||
navController.nav(R.id.quickSettingsSheetDialogFragment, directions)
|
||||
navController().navigate(directions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class ConnectionPanelDialogFragment : FenixDialogFragment() {
|
||||
val controller = DefaultConnectionDetailsController(
|
||||
context = requireContext(),
|
||||
fragment = this,
|
||||
navController = findNavController(),
|
||||
navController = { findNavController() },
|
||||
sitePermissions = args.sitePermissions,
|
||||
gravity = args.gravity,
|
||||
getCurrentTab = ::getCurrentTab,
|
||||
|
@ -16,12 +16,11 @@ import mozilla.components.feature.session.SessionUseCases.ReloadUrlUseCase
|
||||
import mozilla.components.feature.tabs.TabsUseCases.AddNewTabUseCase
|
||||
import mozilla.components.support.base.feature.OnNeedToRequestPermissions
|
||||
import mozilla.components.support.ktx.kotlin.getOrigin
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.NavGraphDirections
|
||||
import org.mozilla.fenix.components.PermissionStorage
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.metrics
|
||||
import org.mozilla.fenix.ext.nav
|
||||
import org.mozilla.fenix.settings.PhoneFeature
|
||||
import org.mozilla.fenix.settings.quicksettings.ext.shouldBeEnabled
|
||||
import org.mozilla.fenix.settings.toggle
|
||||
@ -101,7 +100,7 @@ class DefaultQuickSettingsController(
|
||||
private val quickSettingsStore: QuickSettingsFragmentStore,
|
||||
private val browserStore: BrowserStore,
|
||||
private val ioScope: CoroutineScope,
|
||||
private val navController: NavController,
|
||||
private val navController: () -> NavController,
|
||||
@VisibleForTesting
|
||||
internal val sessionId: String,
|
||||
@VisibleForTesting
|
||||
@ -198,21 +197,21 @@ class DefaultQuickSettingsController(
|
||||
}
|
||||
|
||||
override fun handleBlockedItemsClicked() {
|
||||
dismiss.invoke()
|
||||
navController().popBackStack()
|
||||
|
||||
val state = quickSettingsStore.state.trackingProtectionState
|
||||
val directions = QuickSettingsSheetDialogFragmentDirections
|
||||
val directions = NavGraphDirections
|
||||
.actionGlobalTrackingProtectionPanelDialogFragment(
|
||||
sessionId = sessionId,
|
||||
url = state.url,
|
||||
trackingProtectionEnabled = state.isTrackingProtectionEnabled,
|
||||
gravity = context.components.settings.toolbarPosition.androidGravity
|
||||
)
|
||||
navController.nav(R.id.quickSettingsSheetDialogFragment, directions)
|
||||
navController().navigate(directions)
|
||||
}
|
||||
|
||||
override fun handleConnectionDetailsClicked() {
|
||||
dismiss.invoke()
|
||||
navController().popBackStack()
|
||||
|
||||
val state = quickSettingsStore.state.webInfoState
|
||||
val directions = ConnectionPanelDialogFragmentDirections
|
||||
@ -225,7 +224,7 @@ class DefaultQuickSettingsController(
|
||||
gravity = context.components.settings.toolbarPosition.androidGravity,
|
||||
sitePermissions = sitePermissions
|
||||
)
|
||||
navController.nav(R.id.quickSettingsSheetDialogFragment, directions)
|
||||
navController().navigate(directions)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,6 +269,6 @@ class DefaultQuickSettingsController(
|
||||
private fun navigateToManagePhoneFeature(phoneFeature: PhoneFeature) {
|
||||
val directions = QuickSettingsSheetDialogFragmentDirections
|
||||
.actionGlobalSitePermissionsManagePhoneFeature(phoneFeature)
|
||||
navController.navigate(directions)
|
||||
navController().navigate(directions)
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class QuickSettingsSheetDialogFragment : FenixDialogFragment() {
|
||||
quickSettingsStore = quickSettingsStore,
|
||||
browserStore = components.core.store,
|
||||
ioScope = viewLifecycleOwner.lifecycleScope + Dispatchers.IO,
|
||||
navController = findNavController(),
|
||||
navController = { findNavController() },
|
||||
sessionId = args.sessionId,
|
||||
sitePermissions = args.sitePermissions,
|
||||
settings = components.settings,
|
||||
|
@ -208,9 +208,6 @@
|
||||
<action
|
||||
android:id="@+id/action_browserFragment_to_quickSettingsSheetDialogFragment"
|
||||
app:destination="@id/quickSettingsSheetDialogFragment" />
|
||||
<action
|
||||
android:id="@+id/action_browserFragment_to_trackingProtectionPanelDialogFragment"
|
||||
app:destination="@id/trackingProtectionPanelDialogFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
|
@ -7,6 +7,7 @@ package org.mozilla.fenix.settings.quicksettings
|
||||
import android.content.Context
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavDirections
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
@ -23,10 +24,8 @@ import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.browser.BrowserFragmentDirections
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.nav
|
||||
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
@ -62,7 +61,7 @@ class DefaultConnectionDetailsControllerTest {
|
||||
controller = DefaultConnectionDetailsController(
|
||||
fragment = fragment,
|
||||
context = context,
|
||||
navController = navController,
|
||||
navController = { navController },
|
||||
sitePermissions = sitePermissions,
|
||||
gravity = gravity,
|
||||
getCurrentTab = { tab },
|
||||
@ -82,25 +81,13 @@ class DefaultConnectionDetailsControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN handleBackPressed is called THEN should call dismiss and navigate`() {
|
||||
fun `WHEN handleBackPressed is called THEN should call popBackStack and navigate`() {
|
||||
controller.handleBackPressed()
|
||||
|
||||
verify {
|
||||
dismiss.invoke()
|
||||
navController.popBackStack()
|
||||
|
||||
navController.nav(
|
||||
R.id.quickSettingsSheetDialogFragment,
|
||||
BrowserFragmentDirections.actionGlobalQuickSettingsSheetDialogFragment(
|
||||
sessionId = tab.id,
|
||||
url = tab.content.url,
|
||||
title = tab.content.title,
|
||||
isSecured = tab.content.securityInfo.secure,
|
||||
sitePermissions = sitePermissions,
|
||||
certificateName = tab.content.securityInfo.issuer,
|
||||
permissionHighlights = tab.content.permissionHighlights,
|
||||
isTrackingProtectionEnabled = true
|
||||
)
|
||||
)
|
||||
navController.navigateBlockingForAsyncNavGraph(any<NavDirections>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,14 +37,13 @@ import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.PermissionStorage
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.components.metrics.MetricController
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.directionsEq
|
||||
import org.mozilla.fenix.ext.metrics
|
||||
import org.mozilla.fenix.ext.nav
|
||||
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.settings.PhoneFeature
|
||||
import org.mozilla.fenix.settings.quicksettings.ext.shouldBeEnabled
|
||||
@ -101,7 +100,7 @@ class DefaultQuickSettingsControllerTest {
|
||||
browserStore = browserStore,
|
||||
sessionId = tab.id,
|
||||
ioScope = coroutinesScope,
|
||||
navController = navController,
|
||||
navController = { navController },
|
||||
sitePermissions = sitePermissions,
|
||||
settings = appSettings,
|
||||
permissionStorage = permissionStorage,
|
||||
@ -177,7 +176,7 @@ class DefaultQuickSettingsControllerTest {
|
||||
quickSettingsStore = store,
|
||||
browserStore = BrowserStore(),
|
||||
ioScope = coroutinesScope,
|
||||
navController = navController,
|
||||
navController = { navController },
|
||||
sessionId = "123",
|
||||
sitePermissions = null,
|
||||
settings = appSettings,
|
||||
@ -357,7 +356,7 @@ class DefaultQuickSettingsControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `handleBlockedItemsClicked should call dismiss and navigate to the tracking protection panel dialog`() {
|
||||
fun `handleBlockedItemsClicked should call popBackStack and navigate to the tracking protection panel dialog`() {
|
||||
every { context.components.core.store } returns browserStore
|
||||
every { context.components.settings } returns appSettings
|
||||
every { context.components.settings.toolbarPosition.androidGravity } returns mockk(relaxed = true)
|
||||
@ -375,22 +374,14 @@ class DefaultQuickSettingsControllerTest {
|
||||
controller.handleBlockedItemsClicked()
|
||||
|
||||
verify {
|
||||
dismiss.invoke()
|
||||
navController.popBackStack()
|
||||
|
||||
navController.nav(
|
||||
R.id.quickSettingsSheetDialogFragment,
|
||||
QuickSettingsSheetDialogFragmentDirections.actionGlobalTrackingProtectionPanelDialogFragment(
|
||||
sessionId = tab.id,
|
||||
url = state.url,
|
||||
trackingProtectionEnabled = state.isTrackingProtectionEnabled,
|
||||
gravity = context.components.settings.toolbarPosition.androidGravity
|
||||
)
|
||||
)
|
||||
navController.navigateBlockingForAsyncNavGraph(any<NavDirections>())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN handleConnectionDetailsClicked THEN call dismiss and navigate to the connection details dialog`() {
|
||||
fun `WHEN handleConnectionDetailsClicked THEN call popBackStack and navigate to the connection details dialog`() {
|
||||
every { context.components.core.store } returns browserStore
|
||||
every { context.components.settings } returns appSettings
|
||||
every { context.components.settings.toolbarPosition.androidGravity } returns mockk(relaxed = true)
|
||||
@ -407,19 +398,9 @@ class DefaultQuickSettingsControllerTest {
|
||||
controller.handleConnectionDetailsClicked()
|
||||
|
||||
verify {
|
||||
dismiss.invoke()
|
||||
navController.popBackStack()
|
||||
|
||||
navController.nav(
|
||||
R.id.quickSettingsSheetDialogFragment,
|
||||
QuickSettingsSheetDialogFragmentDirections.actionGlobalConnectionDetailsDialogFragment(
|
||||
sessionId = tab.id,
|
||||
url = state.websiteUrl,
|
||||
title = state.websiteTitle,
|
||||
isSecured = true,
|
||||
sitePermissions = sitePermissions,
|
||||
gravity = context.components.settings.toolbarPosition.androidGravity
|
||||
)
|
||||
)
|
||||
navController.navigateBlockingForAsyncNavGraph(any<NavDirections>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ class WebsiteInfoViewTest {
|
||||
|
||||
@Test
|
||||
fun `WHEN updating on not detailed mode THEN only connection details listener should be binded`() {
|
||||
val view = WebsiteInfoView(FrameLayout(testContext), icons, interactor, isDetailsMode = false)
|
||||
val view = spyk(WebsiteInfoView(FrameLayout(testContext), icons, interactor, isDetailsMode = false))
|
||||
|
||||
view.update(WebsiteInfoState(
|
||||
websiteUrl = "https://mozilla.org",
|
||||
|
Loading…
Reference in New Issue
Block a user