Bug 1861455 - Unify PBM types by replacing Mode with BrowsingMode

fenix/121.0
Matthew Tighe 8 months ago committed by mergify[bot]
parent 4d5560550d
commit d4d68f4b23

@ -13,8 +13,8 @@ import mozilla.components.service.nimbus.messaging.MessageSurfaceId
import mozilla.components.service.pocket.PocketStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import org.mozilla.fenix.browser.StandardSnackbarError
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesCategory
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesSelectedCategory
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
@ -42,7 +42,7 @@ sealed class AppAction : Action {
data class Change(
val topSites: List<TopSite>,
val mode: Mode,
val mode: BrowsingMode,
val collections: List<TabCollection>,
val showCollectionPlaceholder: Boolean,
val recentTabs: List<RecentTab>,
@ -56,7 +56,7 @@ sealed class AppAction : Action {
AppAction()
data class CollectionsChange(val collections: List<TabCollection>) : AppAction()
data class ModeChange(val mode: Mode) : AppAction()
data class ModeChange(val mode: BrowsingMode) : AppAction()
data class TopSitesChange(val topSites: List<TopSite>) : AppAction()
data class RecentTabsChange(val recentTabs: List<RecentTab>) : AppAction()
data class RemoveRecentTab(val recentTab: RecentTab) : AppAction()

@ -13,9 +13,9 @@ import mozilla.components.service.pocket.PocketStory
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import org.mozilla.fenix.browser.StandardSnackbarError
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.appstate.shopping.ShoppingState
import org.mozilla.fenix.home.HomeFragment
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesCategory
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesSelectedCategory
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
@ -37,7 +37,7 @@ import org.mozilla.fenix.wallpapers.WallpaperState
* @property collections The list of [TabCollection] to display in the [HomeFragment].
* @property expandedCollections A set containing the ids of the [TabCollection] that are expanded
* in the [HomeFragment].
* @property mode The state of the [HomeFragment] UI.
* @property mode Whether the app is in private browsing mode.
* @property topSites The list of [TopSite] in the [HomeFragment].
* @property showCollectionPlaceholder If true, shows a placeholder when there are no collections.
* @property recentTabs The list of recent [RecentTab] in the [HomeFragment].
@ -63,7 +63,7 @@ data class AppState(
val nonFatalCrashes: List<NativeCodeCrash> = emptyList(),
val collections: List<TabCollection> = emptyList(),
val expandedCollections: Set<Long> = emptySet(),
val mode: Mode = Mode.Normal,
val mode: BrowsingMode = BrowsingMode.Normal,
val topSites: List<TopSite> = emptyList(),
val showCollectionPlaceholder: Boolean = false,
val recentTabs: List<RecentTab> = emptyList(),

@ -249,7 +249,7 @@ class HomeFragment : Fragment() {
val currentWallpaperName = requireContext().settings().currentWallpaperName
applyWallpaper(wallpaperName = currentWallpaperName, orientationChange = false)
components.appStore.dispatch(AppAction.ModeChange(Mode.fromBrowsingMode(browsingModeManager.mode)))
components.appStore.dispatch(AppAction.ModeChange(browsingModeManager.mode))
lifecycleScope.launch(IO) {
if (requireContext().settings().showPocketRecommendationsFeature) {

@ -1,22 +0,0 @@
/* 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.home
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
/**
* Describes various states of the home fragment UI.
*/
sealed class Mode {
object Normal : Mode()
object Private : Mode()
companion object {
fun fromBrowsingMode(browsingMode: BrowsingMode) = when (browsingMode) {
BrowsingMode.Normal -> Normal
BrowsingMode.Private -> Private
}
}
}

@ -13,7 +13,6 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.privatebrowsing.interactor.PrivateBrowsingInteractor
import org.mozilla.fenix.settings.SupportUtils
@ -55,7 +54,7 @@ class DefaultPrivateBrowsingController(
}
appStore.dispatch(
AppAction.ModeChange(Mode.fromBrowsingMode(newMode)),
AppAction.ModeChange(newMode),
)
if (navController.currentDestination?.id == R.id.searchDialogFragment) {

@ -13,13 +13,13 @@ import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.service.nimbus.messaging.Message
import mozilla.components.service.pocket.PocketStory
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.appstate.AppState
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.shouldShowRecentSyncedTabs
import org.mozilla.fenix.ext.shouldShowRecentTabs
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem
import org.mozilla.fenix.messaging.FenixMessageSurfaceId
@ -131,7 +131,7 @@ private fun showCollections(
private fun privateModeAdapterItems() = listOf(AdapterItem.PrivateBrowsingDescription)
private fun AppState.toAdapterList(settings: Settings): List<AdapterItem> = when (mode) {
is Mode.Normal -> normalModeAdapterItems(
BrowsingMode.Normal -> normalModeAdapterItems(
settings,
topSites,
collections,
@ -145,7 +145,7 @@ private fun AppState.toAdapterList(settings: Settings): List<AdapterItem> = when
pocketStories,
firstFrameDrawn,
)
is Mode.Private -> privateModeAdapterItems()
BrowsingMode.Private -> privateModeAdapterItems()
}
private fun collectionTabItems(collection: TabCollection) =

@ -55,7 +55,6 @@ import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.runIfFragmentIsAttached
import org.mozilla.fenix.ext.setTextColor
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.library.LibraryPageFragment
import org.mozilla.fenix.library.history.state.HistoryNavigationMiddleware
import org.mozilla.fenix.library.history.state.HistoryStorageMiddleware
@ -117,7 +116,7 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler,
onBackPressed = requireActivity().onBackPressedDispatcher::onBackPressed,
),
HistoryTelemetryMiddleware(
isInPrivateMode = requireComponents.appStore.state.mode == Mode.Private,
isInPrivateMode = requireComponents.appStore.state.mode == BrowsingMode.Private,
),
HistorySyncMiddleware(
accountManager = requireContext().components.backgroundServices.accountManager,

@ -34,7 +34,6 @@ import org.mozilla.fenix.components.appstate.AppState
import org.mozilla.fenix.components.appstate.filterOut
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getFilteredStories
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesCategory
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesSelectedCategory
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
@ -79,7 +78,7 @@ class AppStoreTest {
appState = AppState(
collections = emptyList(),
expandedCollections = emptySet(),
mode = Mode.fromBrowsingMode(browsingModeManager.mode),
mode = browsingModeManager.mode,
topSites = emptyList(),
showCollectionPlaceholder = true,
recentTabs = emptyList(),
@ -92,15 +91,15 @@ class AppStoreTest {
@Test
fun `Test toggling the mode in AppStore`() = runTest {
// Verify that the default mode and tab states of the HomeFragment are correct.
assertEquals(Mode.Normal, appStore.state.mode)
assertEquals(BrowsingMode.Normal, appStore.state.mode)
// Change the AppStore to Private mode.
appStore.dispatch(AppAction.ModeChange(Mode.Private)).join()
assertEquals(Mode.Private, appStore.state.mode)
appStore.dispatch(AppAction.ModeChange(BrowsingMode.Private)).join()
assertEquals(BrowsingMode.Private, appStore.state.mode)
// Change the AppStore back to Normal mode.
appStore.dispatch(AppAction.ModeChange(Mode.Normal)).join()
assertEquals(Mode.Normal, appStore.state.mode)
appStore.dispatch(AppAction.ModeChange(BrowsingMode.Normal)).join()
assertEquals(BrowsingMode.Normal, appStore.state.mode)
}
@Test
@ -264,7 +263,7 @@ class AppStoreTest {
assertEquals(0, appStore.state.recentTabs.size)
assertEquals(0, appStore.state.recentBookmarks.size)
assertEquals(0, appStore.state.recentHistory.size)
assertEquals(Mode.Normal, appStore.state.mode)
assertEquals(BrowsingMode.Normal, appStore.state.mode)
assertEquals(
RecentSyncedTabState.Success(recentSyncedTabsList),
appStore.state.recentSyncedTabState,
@ -292,7 +291,7 @@ class AppStoreTest {
appStore.dispatch(
AppAction.Change(
collections = collections,
mode = Mode.Private,
mode = BrowsingMode.Private,
topSites = topSites,
showCollectionPlaceholder = true,
recentTabs = recentTabs,
@ -307,7 +306,7 @@ class AppStoreTest {
assertEquals(recentTabs, appStore.state.recentTabs)
assertEquals(recentBookmarks, appStore.state.recentBookmarks)
assertEquals(listOf(group1, group2, group3, highlight), appStore.state.recentHistory)
assertEquals(Mode.Private, appStore.state.mode)
assertEquals(BrowsingMode.Private, appStore.state.mode)
assertEquals(
recentSyncedTabState,
appStore.state.recentSyncedTabState,

@ -12,7 +12,6 @@ import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.browser.state.action.SearchAction
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.search.RegionState
@ -54,6 +53,7 @@ import org.mozilla.fenix.GleanMetrics.RecentTabs
import org.mozilla.fenix.GleanMetrics.TopSites
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.Analytics
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.TabCollectionStorage
@ -75,7 +75,6 @@ import java.io.File
import mozilla.components.feature.tab.collections.Tab as ComponentTab
@RunWith(FenixRobolectricTestRunner::class) // For gleanTestRule
@OptIn(ExperimentalCoroutinesApi::class)
class DefaultSessionControlControllerTest {
@get:Rule
@ -139,7 +138,7 @@ class DefaultSessionControlControllerTest {
every { appStore.state } returns AppState(
collections = emptyList(),
expandedCollections = emptySet(),
mode = Mode.Normal,
mode = BrowsingMode.Normal,
topSites = emptyList(),
showCollectionPlaceholder = true,
recentTabs = emptyList(),

@ -1,37 +0,0 @@
/* 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.home
import io.mockk.every
import io.mockk.mockk
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
class ModeTest {
private lateinit var browsingModeManager: BrowsingModeManager
@Before
fun setup() {
browsingModeManager = mockk(relaxed = true)
}
@Test
fun `WHEN browsing mode is normal THEN return normal mode`() {
every { browsingModeManager.mode } returns BrowsingMode.Normal
assertEquals(Mode.Normal, Mode.fromBrowsingMode(browsingModeManager.mode))
}
@Test
fun `WHEN browsing mode is private THEN return private mode`() {
every { browsingModeManager.mode } returns BrowsingMode.Private
assertEquals(Mode.Private, Mode.fromBrowsingMode(browsingModeManager.mode))
}
}

@ -26,7 +26,6 @@ import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.appstate.AppState
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.privatebrowsing.controller.DefaultPrivateBrowsingController
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.utils.Settings
@ -87,7 +86,7 @@ class DefaultPrivateBrowsingControllerTest {
verify {
settings.incrementNumTimesPrivateModeOpened()
AppAction.ModeChange(Mode.fromBrowsingMode(newMode))
AppAction.ModeChange(newMode)
}
}
@ -114,7 +113,7 @@ class DefaultPrivateBrowsingControllerTest {
verify {
settings.incrementNumTimesPrivateModeOpened()
AppAction.ModeChange(Mode.fromBrowsingMode(newMode))
AppAction.ModeChange(newMode)
navController.navigate(
BrowserFragmentDirections.actionGlobalSearchDialog(
sessionId = null,
@ -147,7 +146,7 @@ class DefaultPrivateBrowsingControllerTest {
}
verify {
appStore.dispatch(
AppAction.ModeChange(Mode.fromBrowsingMode(newMode)),
AppAction.ModeChange(newMode),
)
navController.navigate(
BrowserFragmentDirections.actionGlobalSearchDialog(

Loading…
Cancel
Save