From e25cfcdc4826c7f12641541abe6226764401541e Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Thu, 6 May 2021 13:47:46 +0200 Subject: [PATCH] [fenix] Complete browser-state migration and remove browser-session dependency. Co-authored-by: Christian Sadilek --- app/build.gradle | 1 - .../org/mozilla/fenix/FenixApplication.kt | 19 ++-- .../java/org/mozilla/fenix/HomeActivity.kt | 23 +++-- .../addons/InstalledAddonDetailsFragment.kt | 6 +- .../mozilla/fenix/components/Components.kt | 1 - .../java/org/mozilla/fenix/components/Core.kt | 59 ++++--------- .../fenix/components/IntentProcessors.kt | 6 +- .../org/mozilla/fenix/components/UseCases.kt | 8 +- .../customtabs/FennecWebAppIntentProcessor.kt | 26 +++--- .../org/mozilla/fenix/ext/SessionManager.kt | 22 ----- .../fenix/library/LibraryPageFragment.kt | 3 +- .../library/bookmarks/BookmarkController.kt | 5 +- .../fenix/library/history/HistoryFragment.kt | 7 +- .../quicksettings/QuickSettingsController.kt | 2 - .../fenix/tabstray/browser/UseCases.kt | 4 +- .../fenix/telemetry/TelemetryMiddleware.kt | 2 +- .../fenix/components/TestComponents.kt | 1 - .../org/mozilla/fenix/components/TestCore.kt | 2 - .../FennecWebAppIntentProcessorTest.kt | 4 +- .../mozilla/fenix/ext/SessionManagerTest.kt | 86 ------------------- .../bookmarks/BookmarkControllerTest.kt | 8 +- .../perf/ProfilerMarkerFactProcessorTest.kt | 2 +- .../search/SearchDialogControllerTest.kt | 43 ++++------ .../search/SearchDialogInteractorTest.kt | 7 +- .../tabhistory/TabHistoryControllerTest.kt | 7 +- .../TelemetryLifecycleObserverTest.kt | 4 +- .../telemetry/TelemetryMiddlewareTest.kt | 8 +- buildSrc/src/main/java/AndroidComponents.kt | 2 +- buildSrc/src/main/java/Dependencies.kt | 1 - 29 files changed, 108 insertions(+), 261 deletions(-) delete mode 100644 app/src/main/java/org/mozilla/fenix/ext/SessionManager.kt delete mode 100644 app/src/test/java/org/mozilla/fenix/ext/SessionManagerTest.kt diff --git a/app/build.gradle b/app/build.gradle index 327c4ce48d..7195044a75 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -420,7 +420,6 @@ dependencies { implementation Deps.mozilla_browser_icons implementation Deps.mozilla_browser_menu implementation Deps.mozilla_browser_menu2 - implementation Deps.mozilla_browser_session implementation Deps.mozilla_browser_session_storage implementation Deps.mozilla_browser_state implementation Deps.mozilla_browser_storage_sync diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 4cb11de431..f971d2ff04 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -467,19 +467,12 @@ open class FenixApplication : LocaleAwareApplication(), Provider { components.core.store.state.selectedTab?.content?.private ?: components.settings.openLinksInAPrivateTab - if (shouldCreatePrivateSession) { - components.useCases.tabsUseCases.addPrivateTab( - url = url, - selectTab = true, - engineSession = engineSession - ) - } else { - components.useCases.tabsUseCases.addTab( - url = url, - selectTab = true, - engineSession = engineSession - ) - } + components.useCases.tabsUseCases.addTab( + url = url, + selectTab = true, + engineSession = engineSession, + private = shouldCreatePrivateSession + ) }, onCloseTabOverride = { _, sessionId -> components.useCases.tabsUseCases.removeTab(sessionId) diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index f730ece393..56bd1479c5 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -834,18 +834,27 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { val startTime = components.core.engine.profiler?.getProfilerTime() val mode = browsingModeManager.mode - val loadUrlUseCase = if (newTab) { - when (mode) { - BrowsingMode.Private -> components.useCases.tabsUseCases.addPrivateTab - BrowsingMode.Normal -> components.useCases.tabsUseCases.addTab - } - } else components.useCases.sessionUseCases.loadUrl + val private = when (mode) { + BrowsingMode.Private -> true + BrowsingMode.Normal -> false + } // In situations where we want to perform a search but have no search engine (e.g. the user // has removed all of them, or we couldn't load any) we will pass searchTermOrURL to Gecko // and let it try to load whatever was entered. if ((!forceSearch && searchTermOrURL.isUrl()) || engine == null) { - loadUrlUseCase.invoke(searchTermOrURL.toNormalizedUrl(), flags) + if (newTab) { + components.useCases.tabsUseCases.addTab( + url = searchTermOrURL.toNormalizedUrl(), + flags = flags, + private = private + ) + } else { + components.useCases.sessionUseCases.loadUrl( + url = searchTermOrURL.toNormalizedUrl(), + flags = flags + ) + } if (requestDesktopMode) { handleRequestDesktopMode() diff --git a/app/src/main/java/org/mozilla/fenix/addons/InstalledAddonDetailsFragment.kt b/app/src/main/java/org/mozilla/fenix/addons/InstalledAddonDetailsFragment.kt index cb550e2b54..9147ad943c 100644 --- a/app/src/main/java/org/mozilla/fenix/addons/InstalledAddonDetailsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/addons/InstalledAddonDetailsFragment.kt @@ -205,11 +205,7 @@ class InstalledAddonDetailsFragment : Fragment() { val shouldCreatePrivateSession = (activity as HomeActivity).browsingModeManager.mode.isPrivate - if (shouldCreatePrivateSession) { - components.useCases.tabsUseCases.addPrivateTab(settingUrl) - } else { - components.useCases.tabsUseCases.addTab(settingUrl) - } + components.useCases.tabsUseCases.addTab(settingUrl, private = shouldCreatePrivateSession) InstalledAddonDetailsFragmentDirections.actionGlobalBrowser(null) } else { diff --git a/app/src/main/java/org/mozilla/fenix/components/Components.kt b/app/src/main/java/org/mozilla/fenix/components/Components.kt index 25e60d7c82..13bdf93223 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Components.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Components.kt @@ -70,7 +70,6 @@ class Components(private val context: Context) { UseCases( context, core.engine, - core.sessionManager, core.store, core.webAppShortcutManager, core.topSitesStorage, diff --git a/app/src/main/java/org/mozilla/fenix/components/Core.kt b/app/src/main/java/org/mozilla/fenix/components/Core.kt index c18624e347..169fb72153 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Core.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Core.kt @@ -14,9 +14,7 @@ import io.sentry.Sentry import mozilla.components.browser.engine.gecko.GeckoEngine import mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient import mozilla.components.browser.icons.BrowserIcons -import mozilla.components.browser.session.Session -import mozilla.components.browser.session.SessionManager -import mozilla.components.browser.session.engine.EngineMiddleware +import mozilla.components.browser.state.engine.EngineMiddleware import mozilla.components.browser.session.storage.SessionStorage import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.store.BrowserStore @@ -191,7 +189,7 @@ class Core( metrics ), ThumbnailsMiddleware(thumbnailStorage), - UndoMiddleware(::lookupSessionManager, context.getUndoDelay()), + UndoMiddleware(context.getUndoDelay()), RegionMiddleware(context, locationService), SearchMiddleware( context, @@ -203,18 +201,24 @@ class Core( ) BrowserStore( - middleware = middlewareList + EngineMiddleware.create(engine, ::findSessionById) - ) - } + middleware = middlewareList + EngineMiddleware.create(engine) + ).apply { + // Install the "icons" WebExtension to automatically load icons for every visited website. + icons.install(engine, this) - @Suppress("Deprecation") - private fun lookupSessionManager(): SessionManager { - return sessionManager - } + // Install the "ads" WebExtension to get the links in an partner page. + adsTelemetry.install(engine, this) - @Suppress("Deprecation") - private fun findSessionById(tabId: String): Session? { - return sessionManager.findSessionById(tabId) + // Install the "cookies" WebExtension and tracks user interaction with SERPs. + searchTelemetry.install(engine, this) + + WebNotificationFeature( + context, engine, icons, R.drawable.ic_status_logo, + permissionStorage.permissionsStorage, HomeActivity::class.java + ) + + MediaSessionFeature(context, MediaSessionService::class.java, this).start() + } } /** @@ -229,33 +233,6 @@ class Core( StatementRelationChecker(StatementApi(client)) } - /** - * The session manager component provides access to a centralized registry of - * all browser sessions (i.e. tabs). It is initialized here to persist and restore - * sessions from the [SessionStorage], and with a default session (about:blank) in - * case all sessions/tabs are closed. - */ - @Deprecated("Use browser store (for reading) and use cases (for writing) instead") - val sessionManager by lazyMonitored { - SessionManager(engine, store).also { - // Install the "icons" WebExtension to automatically load icons for every visited website. - icons.install(engine, store) - - // Install the "ads" WebExtension to get the links in an partner page. - adsTelemetry.install(engine, store) - - // Install the "cookies" WebExtension and tracks user interaction with SERPs. - searchTelemetry.install(engine, store) - - WebNotificationFeature( - context, engine, icons, R.drawable.ic_status_logo, - permissionStorage.permissionsStorage, HomeActivity::class.java - ) - - MediaSessionFeature(context, MediaSessionService::class.java, store).start() - } - } - /** * Icons component for loading, caching and processing website icons. */ diff --git a/app/src/main/java/org/mozilla/fenix/components/IntentProcessors.kt b/app/src/main/java/org/mozilla/fenix/components/IntentProcessors.kt index cf80fb2b00..9dfef29136 100644 --- a/app/src/main/java/org/mozilla/fenix/components/IntentProcessors.kt +++ b/app/src/main/java/org/mozilla/fenix/components/IntentProcessors.kt @@ -66,13 +66,13 @@ class IntentProcessors( val externalAppIntentProcessors by lazyMonitored { listOf( TrustedWebActivityIntentProcessor( - addNewTabUseCase = tabsUseCases.addTab, + addNewTabUseCase = customTabsUseCases.add, packageManager = context.packageManager, relationChecker = relationChecker, store = customTabsStore ), - WebAppIntentProcessor(store, tabsUseCases.addTab, sessionUseCases.loadUrl, manifestStorage), - FennecWebAppIntentProcessor(context, tabsUseCases.addTab, manifestStorage) + WebAppIntentProcessor(store, customTabsUseCases.addWebApp, sessionUseCases.loadUrl, manifestStorage), + FennecWebAppIntentProcessor(context, customTabsUseCases, manifestStorage) ) } diff --git a/app/src/main/java/org/mozilla/fenix/components/UseCases.kt b/app/src/main/java/org/mozilla/fenix/components/UseCases.kt index 849a3a9730..76441d6d36 100644 --- a/app/src/main/java/org/mozilla/fenix/components/UseCases.kt +++ b/app/src/main/java/org/mozilla/fenix/components/UseCases.kt @@ -5,7 +5,6 @@ package org.mozilla.fenix.components import android.content.Context -import mozilla.components.browser.session.SessionManager import mozilla.components.browser.state.store.BrowserStore import mozilla.components.concept.engine.Engine import mozilla.components.concept.storage.BookmarksStorage @@ -36,7 +35,6 @@ import org.mozilla.fenix.utils.Mockable class UseCases( private val context: Context, private val engine: Engine, - private val sessionManager: SessionManager, private val store: BrowserStore, private val shortcutManager: WebAppShortcutManager, private val topSitesStorage: TopSitesStorage, @@ -45,18 +43,18 @@ class UseCases( /** * Use cases that provide engine interactions for a given browser session. */ - val sessionUseCases by lazyMonitored { SessionUseCases(store, sessionManager) } + val sessionUseCases by lazyMonitored { SessionUseCases(store) } /** * Use cases that provide tab management. */ - val tabsUseCases: TabsUseCases by lazyMonitored { TabsUseCases(store, sessionManager) } + val tabsUseCases: TabsUseCases by lazyMonitored { TabsUseCases(store) } /** * Use cases for managing custom tabs. */ val customTabsUseCases: CustomTabsUseCases by lazyMonitored { - CustomTabsUseCases(sessionManager, sessionUseCases.loadUrl) + CustomTabsUseCases(store, sessionUseCases.loadUrl) } /** diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/FennecWebAppIntentProcessor.kt b/app/src/main/java/org/mozilla/fenix/customtabs/FennecWebAppIntentProcessor.kt index 68fbfe2498..b00b90c124 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/FennecWebAppIntentProcessor.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/FennecWebAppIntentProcessor.kt @@ -11,7 +11,6 @@ import androidx.annotation.VisibleForTesting import androidx.core.content.ContextCompat import mozilla.components.browser.state.state.CustomTabConfig import mozilla.components.browser.state.state.SessionState -import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.manifest.WebAppManifest import mozilla.components.concept.engine.manifest.WebAppManifestParser import mozilla.components.concept.engine.manifest.getOrNull @@ -20,7 +19,7 @@ import mozilla.components.feature.intent.processing.IntentProcessor import mozilla.components.feature.pwa.ManifestStorage import mozilla.components.feature.pwa.ext.putWebAppManifest import mozilla.components.feature.pwa.ext.toCustomTabConfig -import mozilla.components.feature.tabs.TabsUseCases +import mozilla.components.feature.tabs.CustomTabsUseCases import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.utils.SafeIntent import mozilla.components.support.utils.toSafeIntent @@ -36,7 +35,7 @@ import java.io.IOException */ class FennecWebAppIntentProcessor( private val context: Context, - private val addNewTabUseCase: TabsUseCases.AddNewTabUseCase, + private val useCases: CustomTabsUseCases, private val storage: ManifestStorage ) : IntentProcessor { val logger = Logger("FennecWebAppIntentProcessor") @@ -59,13 +58,20 @@ class FennecWebAppIntentProcessor( return if (!url.isNullOrEmpty() && matches(intent)) { val webAppManifest = runBlockingIncrement { loadManifest(safeIntent, url) } - val sessionId = addNewTabUseCase( - url = url, - source = SessionState.Source.HOME_SCREEN, - flags = EngineSession.LoadUrlFlags.external(), - webAppManifest = webAppManifest, - customTabConfig = webAppManifest?.toCustomTabConfig() ?: createFallbackCustomTabConfig() - ) + val sessionId = if (webAppManifest != null) { + useCases.addWebApp( + url = url, + source = SessionState.Source.HOME_SCREEN, + webAppManifest = webAppManifest, + customTabConfig = webAppManifest.toCustomTabConfig() + ) + } else { + useCases.add( + url = url, + source = SessionState.Source.HOME_SCREEN, + customTabConfig = createFallbackCustomTabConfig() + ) + } intent.putSessionId(sessionId) if (webAppManifest != null) { diff --git a/app/src/main/java/org/mozilla/fenix/ext/SessionManager.kt b/app/src/main/java/org/mozilla/fenix/ext/SessionManager.kt deleted file mode 100644 index ba25e340d1..0000000000 --- a/app/src/main/java/org/mozilla/fenix/ext/SessionManager.kt +++ /dev/null @@ -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.ext - -import mozilla.components.browser.session.SessionManager - -/** - * Returns only normal or only private sessions. - */ -fun SessionManager.sessionsOfType(private: Boolean) = - sessions.asSequence().filter { it.private == private } - -/** - * @return the number of currently active sessions that are neither custom nor private - */ -fun SessionManager.normalSessionSize(): Int { - return this.sessions.filter { session -> - (!session.isCustomTabSession() && !session.private) - }.size -} diff --git a/app/src/main/java/org/mozilla/fenix/library/LibraryPageFragment.kt b/app/src/main/java/org/mozilla/fenix/library/LibraryPageFragment.kt index 5b8c0660d6..ea0c59dd5a 100644 --- a/app/src/main/java/org/mozilla/fenix/library/LibraryPageFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/LibraryPageFragment.kt @@ -26,11 +26,10 @@ abstract class LibraryPageFragment : Fragment() { protected fun openItemsInNewTab(private: Boolean = false, toUrl: (T) -> String?) { context?.components?.useCases?.tabsUseCases?.let { tabsUseCases -> - val addTab = if (private) tabsUseCases.addPrivateTab else tabsUseCases.addTab selectedItems.asSequence() .mapNotNull(toUrl) .forEach { url -> - addTab.invoke(url) + tabsUseCases.addTab.invoke(url, private = private) } } diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkController.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkController.kt index 2f6950e227..ecc20e18ad 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkController.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkController.kt @@ -192,10 +192,7 @@ class DefaultBookmarkController( ) { invokePendingDeletion.invoke() activity.browsingModeManager.mode = BrowsingMode.fromBoolean(mode == BrowsingMode.Private) - tabsUseCases?.let { tabsUseCases -> - val addTab = if (mode == BrowsingMode.Private) tabsUseCases.addPrivateTab else tabsUseCases.addTab - addTab.invoke(url) - } + tabsUseCases?.addTab?.invoke(url, private = (mode == BrowsingMode.Private)) } private fun navigateToGivenDirection(directions: NavDirections) { diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt index 8eac22ccd3..a815e8f9e1 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt @@ -266,10 +266,9 @@ class HistoryFragment : LibraryPageFragment(), UserInteractionHandl val homeActivity = activity as HomeActivity homeActivity.browsingModeManager.mode = mode - homeActivity.components.useCases.tabsUseCases.let { tabsUseCases -> - val addTab = if (mode == BrowsingMode.Private) tabsUseCases.addPrivateTab else tabsUseCases.addTab - addTab.invoke(item.url) - } + homeActivity.components.useCases.tabsUseCases.addTab.invoke( + item.url, private = (mode == BrowsingMode.Private) + ) showTabTray() } diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsController.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsController.kt index c8dbe8ac46..1008d7cd38 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsController.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsController.kt @@ -10,7 +10,6 @@ import androidx.core.net.toUri import androidx.navigation.NavController import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch -import mozilla.components.browser.session.Session import mozilla.components.browser.state.selector.findTabOrCustomTab import mozilla.components.browser.state.store.BrowserStore import mozilla.components.feature.session.SessionUseCases.ReloadUrlUseCase @@ -66,7 +65,6 @@ interface QuickSettingsController { * in this Controller's Fragment. * @param ioScope [CoroutineScope] with an IO dispatcher used for structured concurrency. * @param navController NavController] used for navigation. - * @param session [Session]? current browser state. * @param sitePermissions [SitePermissions]? list of website permissions and their status. * @param settings [Settings] application settings. * @param permissionStorage [PermissionStorage] app state for website permissions exception. diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/browser/UseCases.kt b/app/src/main/java/org/mozilla/fenix/tabstray/browser/UseCases.kt index 7dbfaa4576..377453bb86 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/browser/UseCases.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/browser/UseCases.kt @@ -24,8 +24,8 @@ class RemoveTabUseCaseWrapper( private val metrics: MetricController, private val onRemove: (String) -> Unit ) : TabsUseCases.RemoveTabUseCase { - override fun invoke(sessionId: String) { + override fun invoke(tabId: String) { metrics.track(Event.ClosedExistingTab) - onRemove(sessionId) + onRemove(tabId) } } diff --git a/app/src/main/java/org/mozilla/fenix/telemetry/TelemetryMiddleware.kt b/app/src/main/java/org/mozilla/fenix/telemetry/TelemetryMiddleware.kt index 0441a9a325..05a5955296 100644 --- a/app/src/main/java/org/mozilla/fenix/telemetry/TelemetryMiddleware.kt +++ b/app/src/main/java/org/mozilla/fenix/telemetry/TelemetryMiddleware.kt @@ -101,7 +101,7 @@ class TelemetryMiddleware( metrics.track(Event.DownloadAdded) } is EngineAction.KillEngineSessionAction -> { - val tab = context.state.findTabOrCustomTab(action.sessionId) + val tab = context.state.findTabOrCustomTab(action.tabId) onEngineSessionKilled(context.state, tab) } } diff --git a/app/src/test/java/org/mozilla/fenix/components/TestComponents.kt b/app/src/test/java/org/mozilla/fenix/components/TestComponents.kt index 3aa8d41dcc..7d0c8e2d76 100644 --- a/app/src/test/java/org/mozilla/fenix/components/TestComponents.kt +++ b/app/src/test/java/org/mozilla/fenix/components/TestComponents.kt @@ -21,7 +21,6 @@ class TestComponents(private val context: Context) : Components(context) { UseCases( context, core.engine, - core.sessionManager, core.store, core.webAppShortcutManager, core.topSitesStorage, diff --git a/app/src/test/java/org/mozilla/fenix/components/TestCore.kt b/app/src/test/java/org/mozilla/fenix/components/TestCore.kt index d5161017e6..c7ac58e9a9 100644 --- a/app/src/test/java/org/mozilla/fenix/components/TestCore.kt +++ b/app/src/test/java/org/mozilla/fenix/components/TestCore.kt @@ -7,7 +7,6 @@ package org.mozilla.fenix.components import android.content.Context import io.mockk.every import io.mockk.mockk -import mozilla.components.browser.session.SessionManager import mozilla.components.browser.state.store.BrowserStore import mozilla.components.browser.storage.sync.PlacesBookmarksStorage import mozilla.components.browser.thumbnails.storage.ThumbnailStorage @@ -27,7 +26,6 @@ class TestCore(context: Context, crashReporter: CrashReporting) : Core( override val engine = mockk(relaxed = true) { every { this@mockk getProperty "settings" } returns mockk(relaxed = true) } - override val sessionManager = SessionManager(engine) override val store = mockk() override val client = mockk() override val webAppShortcutManager = mockk() diff --git a/app/src/test/java/org/mozilla/fenix/customtabs/FennecWebAppIntentProcessorTest.kt b/app/src/test/java/org/mozilla/fenix/customtabs/FennecWebAppIntentProcessorTest.kt index b39b012a87..bde3f02ceb 100644 --- a/app/src/test/java/org/mozilla/fenix/customtabs/FennecWebAppIntentProcessorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/customtabs/FennecWebAppIntentProcessorTest.kt @@ -6,7 +6,7 @@ package org.mozilla.fenix.customtabs import io.mockk.mockk import mozilla.components.feature.pwa.ManifestStorage -import mozilla.components.feature.tabs.TabsUseCases +import mozilla.components.feature.tabs.CustomTabsUseCases import mozilla.components.support.test.robolectric.testContext import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue @@ -59,7 +59,7 @@ class FennecWebAppIntentProcessorTest { } private fun createFennecWebAppIntentProcessor(): FennecWebAppIntentProcessor { - val useCase: TabsUseCases.AddNewTabUseCase = mockk(relaxed = true) + val useCase: CustomTabsUseCases = mockk(relaxed = true) val storage: ManifestStorage = mockk(relaxed = true) return FennecWebAppIntentProcessor( diff --git a/app/src/test/java/org/mozilla/fenix/ext/SessionManagerTest.kt b/app/src/test/java/org/mozilla/fenix/ext/SessionManagerTest.kt deleted file mode 100644 index d0c31bcc34..0000000000 --- a/app/src/test/java/org/mozilla/fenix/ext/SessionManagerTest.kt +++ /dev/null @@ -1,86 +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.ext - -import io.mockk.every -import io.mockk.mockk -import mozilla.components.browser.session.Session -import mozilla.components.browser.session.SessionManager -import org.junit.Assert.assertEquals -import org.junit.Test - -class SessionManagerTest { - - @Test - fun `returns all normal sessions`() { - val sessions = listOf( - Session("https://example.com", private = false), - Session("https://mozilla.org", private = true), - Session("https://github.com", private = false) - ) - val sessionManager = mockSessionManager(sessions) - - assertEquals( - listOf(sessions[0], sessions[2]), - sessionManager.sessionsOfType(private = false).toList() - ) - } - - @Test - fun `returns all private sessions`() { - val sessions = listOf( - Session("https://example.com", private = false), - Session("https://mozilla.org", private = true), - Session("https://github.com", private = false) - ) - val sessionManager = mockSessionManager(sessions) - - assertEquals( - listOf(sessions[1]), - sessionManager.sessionsOfType(private = true).toList() - ) - } - - @Test - fun `normalSessionSize only counts non-private non-custom sessions`() { - val normal1 = mockSession() - val normal2 = mockSession() - val normal3 = mockSession() - - val private1 = mockSession(isPrivate = true) - val private2 = mockSession(isPrivate = true) - - val custom1 = mockSession(isCustom = true) - val custom2 = mockSession(isCustom = true) - val custom3 = mockSession(isCustom = true) - - val privateCustom = mockSession(isPrivate = true, isCustom = true) - - val sessionManager = mockSessionManager( - listOf( - normal1, private1, private2, custom1, - normal2, normal3, custom2, custom3, privateCustom - ) - ) - - assertEquals(3, sessionManager.normalSessionSize()) - } - - private fun mockSessionManager(sessions: List): SessionManager { - val sessionManager: SessionManager = mockk() - every { sessionManager.sessions } returns sessions - return sessionManager - } - - private fun mockSession( - sessionId: String? = null, - isPrivate: Boolean = false, - isCustom: Boolean = false - ) = mockk { - sessionId?.let { every { id } returns it } - every { private } returns isPrivate - every { isCustomTabSession() } returns isCustom - } -} diff --git a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt index 9708a253b7..0c1f865b95 100644 --- a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt @@ -66,7 +66,6 @@ class BookmarkControllerTest { private val homeActivity: HomeActivity = mockk(relaxed = true) private val services: Services = mockk(relaxed = true) private val addNewTabUseCase: TabsUseCases.AddNewTabUseCase = mockk(relaxed = true) - private val addNewPrivateTabUseCase: TabsUseCases.AddNewPrivateTabUseCase = mockk(relaxed = true) private val item = BookmarkNode(BookmarkNodeType.ITEM, "456", "123", 0, "Mozilla", "http://mozilla.org", null) @@ -106,7 +105,6 @@ class BookmarkControllerTest { every { bookmarkStore.dispatch(any()) } returns mockk() every { sharedViewModel.selectedFolder = any() } just runs every { tabsUseCases.addTab } returns addNewTabUseCase - every { tabsUseCases.addPrivateTab } returns addNewPrivateTabUseCase controller = DefaultBookmarkController( activity = homeActivity, @@ -293,8 +291,7 @@ class BookmarkControllerTest { verifyOrder { invokePendingDeletion.invoke() homeActivity.browsingModeManager.mode = BrowsingMode.Normal - tabsUseCases.addTab - addNewTabUseCase.invoke(item.url!!) + addNewTabUseCase.invoke(item.url!!, private = false) showTabTray } } @@ -306,8 +303,7 @@ class BookmarkControllerTest { verifyOrder { invokePendingDeletion.invoke() homeActivity.browsingModeManager.mode = BrowsingMode.Private - tabsUseCases.addPrivateTab - addNewPrivateTabUseCase.invoke(item.url!!) + addNewTabUseCase.invoke(item.url!!, private = true) showTabTray } } diff --git a/app/src/test/java/org/mozilla/fenix/perf/ProfilerMarkerFactProcessorTest.kt b/app/src/test/java/org/mozilla/fenix/perf/ProfilerMarkerFactProcessorTest.kt index d0763e75ae..f54b8eef52 100644 --- a/app/src/test/java/org/mozilla/fenix/perf/ProfilerMarkerFactProcessorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/perf/ProfilerMarkerFactProcessorTest.kt @@ -83,7 +83,7 @@ private fun newFact( action: Action, item: String = "itemName" ) = Fact( - Component.BROWSER_SESSION, + Component.BROWSER_STATE, action, item ) diff --git a/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt b/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt index 5d14550ce9..dc8edd681e 100644 --- a/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt @@ -8,10 +8,8 @@ import androidx.appcompat.app.AlertDialog import androidx.navigation.NavController import androidx.navigation.NavDirections import io.mockk.MockKAnnotations -import io.mockk.Runs import io.mockk.every import io.mockk.impl.annotations.MockK -import io.mockk.just import io.mockk.mockk import io.mockk.mockkObject import io.mockk.spyk @@ -19,12 +17,15 @@ import io.mockk.unmockkObject import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runBlockingTest -import mozilla.components.browser.session.Session -import mozilla.components.browser.session.SessionManager +import mozilla.components.browser.state.action.BrowserAction +import mozilla.components.browser.state.action.TabListAction import mozilla.components.browser.state.search.SearchEngine +import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.store.BrowserStore import mozilla.components.feature.tabs.TabsUseCases +import mozilla.components.support.test.middleware.CaptureActionsMiddleware import org.junit.After +import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Rule import org.junit.Test @@ -50,13 +51,13 @@ class SearchDialogControllerTest { @MockK private lateinit var searchEngine: SearchEngine @MockK(relaxed = true) private lateinit var metrics: MetricController @MockK(relaxed = true) private lateinit var settings: Settings - @MockK private lateinit var sessionManager: SessionManager @MockK(relaxed = true) private lateinit var clearToolbarFocus: () -> Unit @MockK(relaxed = true) private lateinit var focusToolbar: () -> Unit @MockK(relaxed = true) private lateinit var clearToolbar: () -> Unit @MockK(relaxed = true) private lateinit var dismissDialog: () -> Unit private lateinit var controller: SearchDialogController + private lateinit var middleware: CaptureActionsMiddleware @get:Rule val disableNavGraphProviderAssertionRule = DisableNavGraphProviderAssertionRule() @@ -65,16 +66,18 @@ class SearchDialogControllerTest { fun setUp() { MockKAnnotations.init(this) mockkObject(MetricsUtils) - val browserStore = BrowserStore() + middleware = CaptureActionsMiddleware() + val browserStore = BrowserStore( + middleware = listOf(middleware) + ) every { store.state.tabId } returns "test-tab-id" every { store.state.searchEngineSource.searchEngine } returns searchEngine - every { sessionManager.select(any()) } just Runs every { navController.currentDestination } returns mockk { every { id } returns R.id.searchDialogFragment } every { MetricsUtils.createSearchEvent(searchEngine, browserStore, any()) } returns null - val tabsUseCases = TabsUseCases(browserStore, sessionManager) + val tabsUseCases = TabsUseCases(browserStore) controller = SearchDialogController( activity = activity, @@ -331,34 +334,22 @@ class SearchDialogControllerTest { @Test fun handleExistingSessionSelected() { - val session = mockk() - - every { sessionManager.findSessionById("selected") } returns session - controller.handleExistingSessionSelected("selected") - verify { sessionManager.select(session) } - verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) } - } + middleware.assertFirstAction(TabListAction.SelectTabAction::class) { action -> + assertEquals("selected", action.tabId) + } - @Test - fun handleExistingSessionSelected_tabId_nullSession() { - every { sessionManager.findSessionById("tab-id") } returns null - - controller.handleExistingSessionSelected("tab-id") - - verify(inverse = true) { sessionManager.select(any()) } verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) } } @Test fun handleExistingSessionSelected_tabId() { - val session = mockk() - every { sessionManager.findSessionById("tab-id") } returns session - controller.handleExistingSessionSelected("tab-id") - verify { sessionManager.select(any()) } + middleware.assertFirstAction(TabListAction.SelectTabAction::class) { action -> + assertEquals("tab-id", action.tabId) + } verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) } } diff --git a/app/src/test/java/org/mozilla/fenix/search/SearchDialogInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/search/SearchDialogInteractorTest.kt index 77014b1c2e..b3e8421115 100644 --- a/app/src/test/java/org/mozilla/fenix/search/SearchDialogInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/SearchDialogInteractorTest.kt @@ -8,7 +8,6 @@ import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runBlockingTest -import mozilla.components.browser.session.Session import mozilla.components.browser.state.search.SearchEngine import org.junit.Before import org.junit.Test @@ -98,12 +97,12 @@ class SearchDialogInteractorTest { @Test fun onExistingSessionSelected() { - val session = Session("http://mozilla.org", false) + val sessionId = "mozilla" - interactor.onExistingSessionSelected(session.id) + interactor.onExistingSessionSelected(sessionId) verify { - searchController.handleExistingSessionSelected(session.id) + searchController.handleExistingSessionSelected(sessionId) } } diff --git a/app/src/test/java/org/mozilla/fenix/tabhistory/TabHistoryControllerTest.kt b/app/src/test/java/org/mozilla/fenix/tabhistory/TabHistoryControllerTest.kt index dc79446f8a..391cabfddb 100644 --- a/app/src/test/java/org/mozilla/fenix/tabhistory/TabHistoryControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/tabhistory/TabHistoryControllerTest.kt @@ -6,7 +6,9 @@ package org.mozilla.fenix.tabhistory import androidx.navigation.NavController import io.mockk.mockk +import io.mockk.spyk import io.mockk.verify +import mozilla.components.browser.state.store.BrowserStore import mozilla.components.feature.session.SessionUseCases import org.junit.Before import org.junit.Test @@ -16,11 +18,13 @@ class TabHistoryControllerTest { private lateinit var navController: NavController private lateinit var goToHistoryIndexUseCase: SessionUseCases.GoToHistoryIndexUseCase private lateinit var currentItem: TabHistoryItem + private lateinit var store: BrowserStore @Before fun setUp() { + store = BrowserStore() navController = mockk(relaxed = true) - goToHistoryIndexUseCase = mockk(relaxed = true) + goToHistoryIndexUseCase = spyk(SessionUseCases(store).goToHistoryIndex) currentItem = TabHistoryItem( index = 0, title = "", @@ -28,7 +32,6 @@ class TabHistoryControllerTest { isSelected = true ) } - @Test fun handleGoToHistoryIndexNormalBrowsing() { val controller = DefaultTabHistoryController( diff --git a/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryLifecycleObserverTest.kt b/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryLifecycleObserverTest.kt index cf054b9af5..79414e26cb 100644 --- a/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryLifecycleObserverTest.kt +++ b/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryLifecycleObserverTest.kt @@ -6,8 +6,8 @@ package org.mozilla.fenix.telemetry import androidx.test.core.app.ApplicationProvider import io.mockk.mockk -import mozilla.components.browser.session.engine.EngineMiddleware import mozilla.components.browser.state.action.EngineAction +import mozilla.components.browser.state.engine.EngineMiddleware import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.createTab import mozilla.components.browser.state.store.BrowserStore @@ -85,7 +85,7 @@ class TelemetryLifecycleObserverTest { createTab("https://getpocket.com", id = "pocket", crashed = true) ) ), - middleware = EngineMiddleware.create(engine = mockk(), sessionLookup = { null }) + middleware = EngineMiddleware.create(engine = mockk()) ) val observer = TelemetryLifecycleObserver(store) diff --git a/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryMiddlewareTest.kt b/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryMiddlewareTest.kt index 672c6df431..e73d47280c 100644 --- a/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryMiddlewareTest.kt +++ b/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryMiddlewareTest.kt @@ -9,7 +9,7 @@ import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher -import mozilla.components.browser.session.engine.EngineMiddleware +import mozilla.components.browser.state.engine.EngineMiddleware import mozilla.components.browser.state.action.ContentAction import mozilla.components.browser.state.action.DownloadAction import mozilla.components.browser.state.action.EngineAction @@ -73,7 +73,7 @@ class TelemetryMiddlewareTest { metrics ) store = BrowserStore( - middleware = listOf(telemetryMiddleware) + EngineMiddleware.create(engine = mockk(), sessionLookup = { null }), + middleware = listOf(telemetryMiddleware) + EngineMiddleware.create(engine = mockk()), initialState = BrowserState() ) } @@ -340,7 +340,7 @@ class TelemetryMiddlewareTest { clock.elapsedTime = 100 store.dispatch(EngineAction.LinkEngineSessionAction( - sessionId = "foreground", + tabId = "foreground", engineSession = mock() )).joinBlocking() @@ -372,7 +372,7 @@ class TelemetryMiddlewareTest { clock.elapsedTime = 100 store.dispatch(EngineAction.LinkEngineSessionAction( - sessionId = "background_pocket", + tabId = "background_pocket", engineSession = mock() )).joinBlocking() diff --git a/buildSrc/src/main/java/AndroidComponents.kt b/buildSrc/src/main/java/AndroidComponents.kt index 51c8c213e3..e904c2aecf 100644 --- a/buildSrc/src/main/java/AndroidComponents.kt +++ b/buildSrc/src/main/java/AndroidComponents.kt @@ -3,5 +3,5 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ object AndroidComponents { - const val VERSION = "91.0.20210607143102" + const val VERSION = "91.0.20210609144806" } diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 10e683ab10..21ffe28d6c 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -78,7 +78,6 @@ object Deps { const val mozilla_browser_engine_gecko = "org.mozilla.components:browser-engine-gecko:${Versions.mozilla_android_components}" const val mozilla_browser_domains = "org.mozilla.components:browser-domains:${Versions.mozilla_android_components}" const val mozilla_browser_icons = "org.mozilla.components:browser-icons:${Versions.mozilla_android_components}" - const val mozilla_browser_session = "org.mozilla.components:browser-session:${Versions.mozilla_android_components}" const val mozilla_browser_session_storage = "org.mozilla.components:browser-session-storage:${Versions.mozilla_android_components}" const val mozilla_browser_state = "org.mozilla.components:browser-state:${Versions.mozilla_android_components}" const val mozilla_browser_tabstray = "org.mozilla.components:browser-tabstray:${Versions.mozilla_android_components}"