|
|
@ -9,11 +9,13 @@ import androidx.preference.Preference
|
|
|
|
import io.mockk.every
|
|
|
|
import io.mockk.every
|
|
|
|
import io.mockk.mockk
|
|
|
|
import io.mockk.mockk
|
|
|
|
import io.mockk.mockkObject
|
|
|
|
import io.mockk.mockkObject
|
|
|
|
|
|
|
|
import io.mockk.unmockkObject
|
|
|
|
import kotlinx.coroutines.test.advanceUntilIdle
|
|
|
|
import kotlinx.coroutines.test.advanceUntilIdle
|
|
|
|
import mozilla.components.concept.fetch.Client
|
|
|
|
import mozilla.components.concept.fetch.Client
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
|
|
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
|
|
|
import mozilla.components.support.test.rule.runTestOnMain
|
|
|
|
import mozilla.components.support.test.rule.runTestOnMain
|
|
|
|
|
|
|
|
import org.junit.After
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Assert.assertFalse
|
|
|
|
import org.junit.Assert.assertFalse
|
|
|
|
import org.junit.Assert.assertNotNull
|
|
|
|
import org.junit.Assert.assertNotNull
|
|
|
@ -22,9 +24,8 @@ import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.mozilla.fenix.Config
|
|
|
|
import org.mozilla.fenix.FeatureFlags
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.ReleaseChannel
|
|
|
|
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.ext.getPreferenceKey
|
|
|
|
import org.mozilla.fenix.ext.getPreferenceKey
|
|
|
|
import org.mozilla.fenix.ext.settings
|
|
|
|
import org.mozilla.fenix.ext.settings
|
|
|
@ -51,8 +52,8 @@ class SettingsFragmentTest {
|
|
|
|
every { testContext.components.settings } returns mockk(relaxed = true)
|
|
|
|
every { testContext.components.settings } returns mockk(relaxed = true)
|
|
|
|
every { testContext.components.analytics } returns mockk(relaxed = true)
|
|
|
|
every { testContext.components.analytics } returns mockk(relaxed = true)
|
|
|
|
every { testContext.components.backgroundServices } 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()
|
|
|
|
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
|
|
|
|
activity.supportFragmentManager.beginTransaction()
|
|
|
|
activity.supportFragmentManager.beginTransaction()
|
|
|
@ -61,7 +62,7 @@ class SettingsFragmentTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@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 settingsFragment = SettingsFragment()
|
|
|
|
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
|
|
|
|
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
|
|
|
|
|
|
|
|
|
|
|
@ -71,6 +72,8 @@ class SettingsFragmentTest {
|
|
|
|
|
|
|
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
every { FeatureFlags.customExtensionCollectionFeature } returns true
|
|
|
|
|
|
|
|
|
|
|
|
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
|
|
|
|
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
|
|
|
|
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection),
|
|
|
|
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection),
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -86,7 +89,7 @@ class SettingsFragmentTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@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 settingsFragment = SettingsFragment()
|
|
|
|
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
|
|
|
|
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
|
|
|
|
|
|
|
|
|
|
|
@ -96,6 +99,8 @@ class SettingsFragmentTest {
|
|
|
|
|
|
|
|
|
|
|
|
advanceUntilIdle()
|
|
|
|
advanceUntilIdle()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
every { FeatureFlags.customExtensionCollectionFeature } returns true
|
|
|
|
|
|
|
|
|
|
|
|
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
|
|
|
|
val preferenceAmoCollectionOverride = settingsFragment.findPreference<Preference>(
|
|
|
|
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection),
|
|
|
|
settingsFragment.getPreferenceKey(R.string.pref_key_override_amo_collection),
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -116,6 +121,34 @@ class SettingsFragmentTest {
|
|
|
|
assertTrue(preferenceAmoCollectionOverride.isVisible)
|
|
|
|
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
|
|
|
|
@Test
|
|
|
|
fun `GIVEN the HttpsOnly is enabled THEN set the appropriate preference summary`() {
|
|
|
|
fun `GIVEN the HttpsOnly is enabled THEN set the appropriate preference summary`() {
|
|
|
|
val httpsOnlyPreference = settingsFragment.findPreference<Preference>(
|
|
|
|
val httpsOnlyPreference = settingsFragment.findPreference<Preference>(
|
|
|
@ -143,4 +176,9 @@ class SettingsFragmentTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(summary, httpsOnlyPreference.summary)
|
|
|
|
assertEquals(summary, httpsOnlyPreference.summary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
|
|
|
fun tearDown() {
|
|
|
|
|
|
|
|
unmockkObject(FeatureFlags)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|