mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/24262 - Filter Amazon/eBay sponsored tiles when the respective search engine is set
This commit is contained in:
parent
326743a822
commit
e78350b2ca
@ -417,7 +417,14 @@ class HomeFragment : Fragment() {
|
||||
frecencyConfig = FrecencyThresholdOption.SKIP_ONE_TIME_PAGES,
|
||||
providerConfig = TopSitesProviderConfig(
|
||||
showProviderTopSites = settings.showContileFeature,
|
||||
maxThreshold = TOP_SITES_PROVIDER_MAX_THRESHOLD
|
||||
maxThreshold = TOP_SITES_PROVIDER_MAX_THRESHOLD,
|
||||
providerFilter = { topSite ->
|
||||
when (store.state.search.selectedOrDefaultSearchEngine?.name) {
|
||||
AMAZON_SEARCH_ENGINE_NAME -> topSite.title != AMAZON_SPONSORED_TITLE
|
||||
EBAY_SPONSORED_TITLE -> topSite.title != EBAY_SPONSORED_TITLE
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -487,6 +494,7 @@ class HomeFragment : Fragment() {
|
||||
HomeScreen.homeScreenViewCount.add()
|
||||
|
||||
observeSearchEngineChanges()
|
||||
observeSearchEngineNameChanges()
|
||||
createHomeMenu(requireContext(), WeakReference(binding.menuButton))
|
||||
createTabCounterMenu()
|
||||
|
||||
@ -570,6 +578,27 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to listen to search engine name changes and trigger a top sites update accordingly
|
||||
*/
|
||||
private fun observeSearchEngineNameChanges() {
|
||||
consumeFlow(store) { flow ->
|
||||
flow.map { state ->
|
||||
when (state.search.selectedOrDefaultSearchEngine?.name) {
|
||||
AMAZON_SEARCH_ENGINE_NAME -> AMAZON_SPONSORED_TITLE
|
||||
EBAY_SPONSORED_TITLE -> EBAY_SPONSORED_TITLE
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
.ifChanged()
|
||||
.collect {
|
||||
topSitesFeature.withFeature {
|
||||
it.storage.notifyObservers { onStorageUpdated() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createTabCounterMenu() {
|
||||
val browsingModeManager = (activity as HomeActivity).browsingModeManager
|
||||
val mode = browsingModeManager.mode
|
||||
@ -1084,6 +1113,11 @@ class HomeFragment : Fragment() {
|
||||
private const val CFR_WIDTH_DIVIDER = 1.7
|
||||
private const val CFR_Y_OFFSET = -20
|
||||
|
||||
// Sponsored top sites titles and search engine names used for filtering
|
||||
const val AMAZON_SPONSORED_TITLE = "Amazon"
|
||||
const val AMAZON_SEARCH_ENGINE_NAME = "Amazon.com"
|
||||
const val EBAY_SPONSORED_TITLE = "eBay"
|
||||
|
||||
// Elevation for undo toasts
|
||||
internal const val TOAST_ELEVATION = 80f
|
||||
}
|
||||
|
@ -7,28 +7,39 @@ package org.mozilla.fenix.home
|
||||
import android.content.Context
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.spyk
|
||||
import io.mockk.verify
|
||||
import mozilla.components.browser.menu.view.MenuButton
|
||||
import mozilla.components.browser.state.state.SearchState
|
||||
import mozilla.components.browser.state.state.selectedOrDefaultSearchEngine
|
||||
import mozilla.components.feature.top.sites.TopSite
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.FenixApplication
|
||||
import org.mozilla.fenix.components.Core
|
||||
import org.mozilla.fenix.ext.application
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.home.HomeFragment.Companion.AMAZON_SPONSORED_TITLE
|
||||
import org.mozilla.fenix.home.HomeFragment.Companion.EBAY_SPONSORED_TITLE
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
class HomeFragmentTest {
|
||||
|
||||
private lateinit var settings: Settings
|
||||
private lateinit var context: Context
|
||||
private lateinit var core: Core
|
||||
private lateinit var homeFragment: HomeFragment
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
settings = mockk(relaxed = true)
|
||||
context = mockk(relaxed = true)
|
||||
core = mockk(relaxed = true)
|
||||
|
||||
val fenixApplication: FenixApplication = mockk(relaxed = true)
|
||||
|
||||
@ -37,6 +48,7 @@ class HomeFragmentTest {
|
||||
every { context.application } returns fenixApplication
|
||||
every { homeFragment.context } answers { context }
|
||||
every { context.components.settings } answers { settings }
|
||||
every { context.components.core } answers { core }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -58,6 +70,31 @@ class HomeFragmentTest {
|
||||
assertEquals(topSitesMaxLimit, topSitesConfig.totalSites)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN the selected search engine is set to eBay WHEN getTopSitesConfig is called THEN providerFilter filters the eBay provided top sites`() {
|
||||
mockkStatic("mozilla.components.browser.state.state.SearchStateKt")
|
||||
every { core.store } returns mockk() {
|
||||
every { state } returns mockk() {
|
||||
every { search } returns mockk()
|
||||
}
|
||||
}
|
||||
every { any<SearchState>().selectedOrDefaultSearchEngine } returns mockk {
|
||||
every { name } returns EBAY_SPONSORED_TITLE
|
||||
}
|
||||
val eBayTopSite = TopSite.Provided(1L, EBAY_SPONSORED_TITLE, "eBay.com", "", "", "", 0L)
|
||||
val amazonTopSite = TopSite.Provided(2L, AMAZON_SPONSORED_TITLE, "Amazon.com", "", "", "", 0L)
|
||||
val firefoxTopSite = TopSite.Provided(3L, "Firefox", "mozilla.org", "", "", "", 0L)
|
||||
val providedTopSites = listOf(eBayTopSite, amazonTopSite, firefoxTopSite)
|
||||
|
||||
val topSitesConfig = homeFragment.getTopSitesConfig()
|
||||
|
||||
val filteredProvidedSites = providedTopSites.filter {
|
||||
topSitesConfig.providerConfig?.providerFilter?.invoke(it) ?: true
|
||||
}
|
||||
assertTrue(filteredProvidedSites.containsAll(listOf(amazonTopSite, firefoxTopSite)))
|
||||
assertFalse(filteredProvidedSites.contains(eBayTopSite))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN configuration changed menu is dismissed`() {
|
||||
val menuButton: MenuButton = mockk(relaxed = true)
|
||||
|
Loading…
Reference in New Issue
Block a user