mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] Complete browser-state migration and remove browser-session dependency.
Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com>
This commit is contained in:
parent
4e7c93e6f6
commit
e25cfcdc48
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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 {
|
||||
|
@ -70,7 +70,6 @@ class Components(private val context: Context) {
|
||||
UseCases(
|
||||
context,
|
||||
core.engine,
|
||||
core.sessionManager,
|
||||
core.store,
|
||||
core.webAppShortcutManager,
|
||||
core.topSitesStorage,
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
@ -26,11 +26,10 @@ abstract class LibraryPageFragment<T> : 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -266,10 +266,9 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), 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()
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ class TestComponents(private val context: Context) : Components(context) {
|
||||
UseCases(
|
||||
context,
|
||||
core.engine,
|
||||
core.sessionManager,
|
||||
core.store,
|
||||
core.webAppShortcutManager,
|
||||
core.topSitesStorage,
|
||||
|
@ -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<Engine>(relaxed = true) {
|
||||
every { this@mockk getProperty "settings" } returns mockk<Settings>(relaxed = true)
|
||||
}
|
||||
override val sessionManager = SessionManager(engine)
|
||||
override val store = mockk<BrowserStore>()
|
||||
override val client = mockk<Client>()
|
||||
override val webAppShortcutManager = mockk<WebAppShortcutManager>()
|
||||
|
@ -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(
|
||||
|
@ -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<Session>): 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<Session> {
|
||||
sessionId?.let { every { id } returns it }
|
||||
every { private } returns isPrivate
|
||||
every { isCustomTabSession() } returns isCustom
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ private fun newFact(
|
||||
action: Action,
|
||||
item: String = "itemName"
|
||||
) = Fact(
|
||||
Component.BROWSER_SESSION,
|
||||
Component.BROWSER_STATE,
|
||||
action,
|
||||
item
|
||||
)
|
||||
|
@ -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<BrowserState, BrowserAction>
|
||||
|
||||
@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<Session>()
|
||||
|
||||
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<Session>()
|
||||
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) }
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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}"
|
||||
|
Loading…
Reference in New Issue
Block a user