Close #26948: Enable custom extension collections in Beta.

Similar to how Nightly functions, custom extension collections are enabled to be used in Firefox Beta as well.
This commit is contained in:
kycn 2022-10-06 14:28:55 +02:00 committed by mergify[bot]
parent 90fb56a251
commit f9efa5e8bb
4 changed files with 57 additions and 9 deletions

View File

@ -12,6 +12,14 @@ import mozilla.components.support.locale.LocaleManager.getSystemDefault
* A single source for setting feature flags that are mostly based on build type.
*/
object FeatureFlags {
/**
* Enables custom extension collection feature,
* This feature does not only depend on this flag. It requires the AMO collection override to
* be enabled which is behind the Secret Settings.
* */
val customExtensionCollectionFeature = Config.channel.isNightlyOrDebug || Config.channel.isBeta
/**
* Pull-to-refresh allows you to pull the web content down far enough to have the page to
* reload.

View File

@ -22,6 +22,7 @@ import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import mozilla.components.support.base.worker.Frequency
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.autofill.AutofillConfirmActivity
@ -105,8 +106,8 @@ class Components(private val context: Context) {
}
val addonCollectionProvider by lazyMonitored {
// Check if we have a customized (overridden) AMO collection (only supported in Nightly)
if (Config.channel.isNightlyOrDebug && context.settings().amoCollectionOverrideConfigured()) {
// Check if we have a customized (overridden) AMO collection (supported in Nightly & Beta)
if (FeatureFlags.customExtensionCollectionFeature && context.settings().amoCollectionOverrideConfigured()) {
AddonCollectionProvider(
context,
core.client,

View File

@ -38,6 +38,7 @@ import mozilla.components.service.glean.private.NoExtras
import mozilla.components.support.ktx.android.view.showKeyboard
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.TrackingProtection
@ -522,7 +523,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
findPreference<Preference>(getPreferenceKey(R.string.pref_key_override_amo_collection))
val show = (
Config.channel.isNightlyOrDebug && (
FeatureFlags.customExtensionCollectionFeature && (
settings.amoCollectionOverrideConfigured() || settings.showSecretDebugMenuThisSession
)
)

View File

@ -9,11 +9,13 @@ import androidx.preference.Preference
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.unmockkObject
import kotlinx.coroutines.test.advanceUntilIdle
import mozilla.components.concept.fetch.Client
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.rule.MainCoroutineRule
import mozilla.components.support.test.rule.runTestOnMain
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
@ -22,9 +24,8 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R
import org.mozilla.fenix.ReleaseChannel
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.settings
@ -51,8 +52,8 @@ class SettingsFragmentTest {
every { testContext.components.settings } returns mockk(relaxed = true)
every { testContext.components.analytics } returns mockk(relaxed = true)
every { testContext.components.backgroundServices } returns mockk(relaxed = true)
mockkObject(Config)
every { Config.channel } returns ReleaseChannel.Nightly
mockkObject(FeatureFlags)
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
activity.supportFragmentManager.beginTransaction()
@ -61,7 +62,7 @@ class SettingsFragmentTest {
}
@Test
fun `Add-on collection override pref is visible if debug menu active`() = runTestOnMain {
fun `Add-on collection override pref is visible if debug menu active and feature is enabled`() = runTestOnMain {
val settingsFragment = SettingsFragment()
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
@ -71,6 +72,8 @@ class SettingsFragmentTest {
advanceUntilIdle()
every { FeatureFlags.customExtensionCollectionFeature } returns true
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection),
)
@ -86,7 +89,7 @@ class SettingsFragmentTest {
}
@Test
fun `Add-on collection override pref is visible if already configured`() = runTestOnMain {
fun `Add-on collection override pref is visible if already configured and feature is enabled`() = runTestOnMain {
val settingsFragment = SettingsFragment()
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
@ -96,6 +99,8 @@ class SettingsFragmentTest {
advanceUntilIdle()
every { FeatureFlags.customExtensionCollectionFeature } returns true
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection),
)
@ -116,6 +121,34 @@ class SettingsFragmentTest {
assertTrue(preferenceAmoCollectionOverride.isVisible)
}
@Test
fun `Add-on collection override pref is not visible if feature is disabled`() = runTestOnMain {
val settingsFragment = SettingsFragment()
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
activity.supportFragmentManager.beginTransaction()
.add(settingsFragment, "test")
.commitNow()
advanceUntilIdle()
every { FeatureFlags.customExtensionCollectionFeature } returns false
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection),
)
val settings: Settings = mockk(relaxed = true)
settingsFragment.setupAmoCollectionOverridePreference(settings)
assertNotNull(preferenceAmoCollectionOverride)
assertFalse(preferenceAmoCollectionOverride!!.isVisible)
every { settings.showSecretDebugMenuThisSession } returns true
every { settings.amoCollectionOverrideConfigured() } returns true
settingsFragment.setupAmoCollectionOverridePreference(settings)
assertFalse(preferenceAmoCollectionOverride.isVisible)
}
@Test
fun `GIVEN the HttpsOnly is enabled THEN set the appropriate preference summary`() {
val httpsOnlyPreference = settingsFragment.findPreference<Preference>(
@ -143,4 +176,9 @@ class SettingsFragmentTest {
assertEquals(summary, httpsOnlyPreference.summary)
}
@After
fun tearDown() {
unmockkObject(FeatureFlags)
}
}