For #26910: Enable TCP for all modes
Unify the TCP feature with the TCP setting allowing both to be controlled through the same Nimbus experiment. Allow changing the default cookie policy to TCP based on the Nimbus experiment.
This commit is contained in:
parent
d469624d25
commit
93615438fc
|
@ -5,8 +5,10 @@
|
|||
package org.mozilla.fenix.components
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.CookiePolicy
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicyForSessionTypes
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
|
@ -40,9 +42,9 @@ class TrackingProtectionPolicyFactory(
|
|||
}
|
||||
|
||||
return when {
|
||||
normalMode && privateMode -> trackingProtectionPolicy
|
||||
normalMode && !privateMode -> trackingProtectionPolicy.forRegularSessionsOnly()
|
||||
!normalMode && privateMode -> trackingProtectionPolicy.forPrivateSessionsOnly()
|
||||
normalMode && privateMode -> trackingProtectionPolicy.applyTCPIfNeeded(settings)
|
||||
normalMode && !privateMode -> trackingProtectionPolicy.applyTCPIfNeeded(settings).forRegularSessionsOnly()
|
||||
!normalMode && privateMode -> trackingProtectionPolicy.applyTCPIfNeeded(settings).forPrivateSessionsOnly()
|
||||
else -> TrackingProtectionPolicy.none()
|
||||
}
|
||||
}
|
||||
|
@ -103,3 +105,20 @@ class TrackingProtectionPolicyFactory(
|
|||
return settings.blockRedirectTrackersInCustomTrackingProtection
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun TrackingProtectionPolicyForSessionTypes.applyTCPIfNeeded(settings: Settings):
|
||||
TrackingProtectionPolicyForSessionTypes {
|
||||
val updatedCookiePolicy = if (settings.enabledTotalCookieProtection) {
|
||||
CookiePolicy.ACCEPT_FIRST_PARTY_AND_ISOLATE_OTHERS
|
||||
} else {
|
||||
cookiePolicy
|
||||
}
|
||||
|
||||
return TrackingProtectionPolicy.select(
|
||||
trackingCategories = trackingCategories,
|
||||
cookiePolicy = updatedCookiePolicy,
|
||||
strictSocialTrackingProtection = strictSocialTrackingProtection,
|
||||
cookiePurging = cookiePurging,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class CustomEtpCookiesOptionsDropDownListPreference @JvmOverloads constructor(
|
|||
)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
if (context.settings().enabledTotalCookieProtectionSetting) {
|
||||
if (context.settings().enabledTotalCookieProtection) {
|
||||
// If the new "Total cookie protection" should be shown it must be first item.
|
||||
entries = arrayOf(getString(R.string.preference_enhanced_tracking_protection_custom_cookies_5)) +
|
||||
entries as Array<String>
|
||||
|
|
|
@ -30,7 +30,7 @@ class TrackingProtectionBlockingFragment :
|
|||
binding = FragmentTrackingProtectionBlockingBinding.bind(view)
|
||||
|
||||
// Text for the updated "Total cookie protection" option should be updated as part of a staged rollout
|
||||
if (requireContext().settings().enabledTotalCookieProtectionSetting) {
|
||||
if (requireContext().settings().enabledTotalCookieProtection) {
|
||||
binding.categoryCookies.apply {
|
||||
trackingProtectionCategoryTitle.text = getText(R.string.etp_cookies_title_2)
|
||||
trackingProtectionCategoryItemDescription.text = getText(R.string.etp_cookies_description_2)
|
||||
|
|
|
@ -129,7 +129,7 @@ class TrackingProtectionPanelView(
|
|||
binding.notBlockingHeader.isGone = bucketedTrackers.loadedIsEmpty()
|
||||
binding.blockingHeader.isGone = bucketedTrackers.blockedIsEmpty()
|
||||
|
||||
if (containerView.context.settings().enabledTotalCookieProtectionSetting) {
|
||||
if (containerView.context.settings().enabledTotalCookieProtection) {
|
||||
binding.crossSiteTracking.text = containerView.context.getString(R.string.etp_cookies_title_2)
|
||||
binding.crossSiteTrackingLoaded.text = containerView.context.getString(R.string.etp_cookies_title_2)
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ class TrackingProtectionPanelView(
|
|||
binding.detailsMode.visibility = View.VISIBLE
|
||||
|
||||
if (category == CROSS_SITE_TRACKING_COOKIES &&
|
||||
containerView.context.settings().enabledTotalCookieProtectionSetting
|
||||
containerView.context.settings().enabledTotalCookieProtection
|
||||
) {
|
||||
binding.categoryTitle.setText(R.string.etp_cookies_title_2)
|
||||
binding.categoryDescription.setText(R.string.etp_cookies_description_2)
|
||||
|
|
|
@ -586,7 +586,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
|
|||
true,
|
||||
)
|
||||
|
||||
val enabledTotalCookieProtectionSetting: Boolean
|
||||
val enabledTotalCookieProtection: Boolean
|
||||
get() = mr2022Sections[Mr2022Section.TCP_FEATURE] == true
|
||||
|
||||
/**
|
||||
|
@ -599,7 +599,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
|
|||
|
||||
val blockCookiesSelectionInCustomTrackingProtection by stringPreference(
|
||||
key = appContext.getPreferenceKey(R.string.pref_key_tracking_protection_custom_cookies_select),
|
||||
default = if (enabledTotalCookieProtectionSetting) {
|
||||
default = if (enabledTotalCookieProtection) {
|
||||
appContext.getString(R.string.total_protection)
|
||||
} else {
|
||||
appContext.getString(R.string.social)
|
||||
|
|
|
@ -137,6 +137,46 @@ class TrackingProtectionPolicyFactoryTest {
|
|||
expected.assertPolicyEquals(always, checkPrivacy = false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN TCP is enabled by nimbus WHEN applyTCPIfNeeded THEN cookie policy should be TCP`() {
|
||||
val settings: Settings = mockk(relaxed = true)
|
||||
every { settings.enabledTotalCookieProtection } returns true
|
||||
|
||||
val policies = arrayOf(
|
||||
TrackingProtectionPolicy.strict(),
|
||||
TrackingProtectionPolicy.recommended(),
|
||||
TrackingProtectionPolicy.select(),
|
||||
)
|
||||
|
||||
for (policy in policies) {
|
||||
val adaptedPolicy = policy.applyTCPIfNeeded(settings)
|
||||
assertEquals(
|
||||
CookiePolicy.ACCEPT_FIRST_PARTY_AND_ISOLATE_OTHERS,
|
||||
adaptedPolicy.cookiePolicy,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun `GIVEN TCP is NOT enabled by nimbus WHEN applyTCPIfNeeded THEN reuse cookie policy`() {
|
||||
val settings: Settings = mockk(relaxed = true)
|
||||
|
||||
every { settings.enabledTotalCookieProtection } returns false
|
||||
|
||||
val policies = arrayOf(
|
||||
TrackingProtectionPolicy.strict(),
|
||||
TrackingProtectionPolicy.recommended(),
|
||||
TrackingProtectionPolicy.select(),
|
||||
)
|
||||
|
||||
for (policy in policies) {
|
||||
val adaptedPolicy = policy.applyTCPIfNeeded(settings)
|
||||
assertEquals(
|
||||
policy.cookiePolicy,
|
||||
adaptedPolicy.cookiePolicy,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN custom policy WHEN cookie policy social THEN tracking policy should have cookie policy allow non-trackers`() {
|
||||
val expected = TrackingProtectionPolicy.select(
|
||||
|
@ -586,6 +626,7 @@ class TrackingProtectionPolicyFactoryTest {
|
|||
useCustom: Boolean = false,
|
||||
useTrackingProtection: Boolean = false,
|
||||
): Settings = mockk {
|
||||
every { enabledTotalCookieProtection } returns false
|
||||
every { useStrictTrackingProtection } returns useStrict
|
||||
every { useCustomTrackingProtection } returns useCustom
|
||||
every { shouldUseTrackingProtection } returns useTrackingProtection
|
||||
|
|
|
@ -29,7 +29,7 @@ class CustomEtpCookiesOptionsDropDownListPreferenceTest {
|
|||
|
||||
mockkStatic("org.mozilla.fenix.ext.ContextKt") {
|
||||
every { any<Context>().settings() } returns mockk {
|
||||
every { enabledTotalCookieProtectionSetting } returns true
|
||||
every { enabledTotalCookieProtection } returns true
|
||||
}
|
||||
|
||||
val preference = CustomEtpCookiesOptionsDropDownListPreference(testContext)
|
||||
|
@ -44,7 +44,7 @@ class CustomEtpCookiesOptionsDropDownListPreferenceTest {
|
|||
fun `GIVEN total cookie protection is disabled WHEN using this preference THEN don't show the total cookie protection option`() {
|
||||
mockkStatic("org.mozilla.fenix.ext.ContextKt") {
|
||||
every { any<Context>().settings() } returns mockk {
|
||||
every { enabledTotalCookieProtectionSetting } returns false
|
||||
every { enabledTotalCookieProtection } returns false
|
||||
}
|
||||
|
||||
val preference = CustomEtpCookiesOptionsDropDownListPreference(testContext)
|
||||
|
|
|
@ -28,7 +28,7 @@ class TrackingProtectionBlockingFragmentTest {
|
|||
|
||||
mockkStatic("org.mozilla.fenix.ext.ContextKt") {
|
||||
every { any<Context>().settings() } returns mockk(relaxed = true) {
|
||||
every { enabledTotalCookieProtectionSetting } returns true
|
||||
every { enabledTotalCookieProtection } returns true
|
||||
}
|
||||
|
||||
val fragment = createFragment()
|
||||
|
@ -46,7 +46,7 @@ class TrackingProtectionBlockingFragmentTest {
|
|||
|
||||
mockkStatic("org.mozilla.fenix.ext.ContextKt") {
|
||||
every { any<Context>().settings() } returns mockk(relaxed = true) {
|
||||
every { enabledTotalCookieProtectionSetting } returns false
|
||||
every { enabledTotalCookieProtection } returns false
|
||||
}
|
||||
|
||||
val fragment = createFragment()
|
||||
|
|
|
@ -74,7 +74,7 @@ class TrackingProtectionPanelViewTest {
|
|||
fun testNormalModeUiCookiesWithTotalCookieProtectionEnabled() {
|
||||
mockkStatic("org.mozilla.fenix.ext.ContextKt") {
|
||||
every { any<Context>().settings() } returns mockk {
|
||||
every { enabledTotalCookieProtectionSetting } returns true
|
||||
every { enabledTotalCookieProtection } returns true
|
||||
}
|
||||
val expectedTitle = testContext.getString(R.string.etp_cookies_title_2)
|
||||
|
||||
|
@ -89,7 +89,7 @@ class TrackingProtectionPanelViewTest {
|
|||
fun testNormalModeUiCookiesWithTotalCookieProtectionDisabled() {
|
||||
mockkStatic("org.mozilla.fenix.ext.ContextKt") {
|
||||
every { any<Context>().settings() } returns mockk {
|
||||
every { enabledTotalCookieProtectionSetting } returns false
|
||||
every { enabledTotalCookieProtection } returns false
|
||||
}
|
||||
val expectedTitle = testContext.getString(R.string.etp_cookies_title)
|
||||
|
||||
|
@ -130,7 +130,7 @@ class TrackingProtectionPanelViewTest {
|
|||
fun testPrivateModeUiCookiesWithTotalCookieProtectionEnabled() {
|
||||
mockkStatic("org.mozilla.fenix.ext.ContextKt") {
|
||||
every { any<Context>().settings() } returns mockk {
|
||||
every { enabledTotalCookieProtectionSetting } returns true
|
||||
every { enabledTotalCookieProtection } returns true
|
||||
}
|
||||
val expectedTitle = testContext.getString(R.string.etp_cookies_title_2)
|
||||
val expectedDescription = testContext.getString(R.string.etp_cookies_description_2)
|
||||
|
@ -153,7 +153,7 @@ class TrackingProtectionPanelViewTest {
|
|||
fun testPrivateModeUiCookiesWithTotalCookieProtectionDisabled() {
|
||||
mockkStatic("org.mozilla.fenix.ext.ContextKt") {
|
||||
every { any<Context>().settings() } returns mockk {
|
||||
every { enabledTotalCookieProtectionSetting } returns false
|
||||
every { enabledTotalCookieProtection } returns false
|
||||
}
|
||||
val expectedTitle = testContext.getString(R.string.etp_cookies_title)
|
||||
val expectedDescription = testContext.getString(R.string.etp_cookies_description)
|
||||
|
|
Loading…
Reference in New Issue