diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index d98b03cf57..c17efab613 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -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. 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 24386ab67f..c0ce930697 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Components.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Components.kt @@ -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, diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index 3054d600bb..725a78ba43 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -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(getPreferenceKey(R.string.pref_key_override_amo_collection)) val show = ( - Config.channel.isNightlyOrDebug && ( + FeatureFlags.customExtensionCollectionFeature && ( settings.amoCollectionOverrideConfigured() || settings.showSecretDebugMenuThisSession ) ) diff --git a/app/src/test/java/org/mozilla/fenix/settings/SettingsFragmentTest.kt b/app/src/test/java/org/mozilla/fenix/settings/SettingsFragmentTest.kt index 1d37183787..aefd14c313 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/SettingsFragmentTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/SettingsFragmentTest.kt @@ -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( 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( 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( + 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( @@ -143,4 +176,9 @@ class SettingsFragmentTest { assertEquals(summary, httpsOnlyPreference.summary) } + + @After + fun tearDown() { + unmockkObject(FeatureFlags) + } }