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/25736: Add experiment for Total cookie protection.
This commit is contained in:
parent
e176468d38
commit
3c58b8e405
@ -15,6 +15,9 @@ engine-settings:
|
||||
tabs-prioritization-enabled:
|
||||
type: boolean
|
||||
description: "If true, enables tabs prioritization feature."
|
||||
total-cookie-protection-enabled:
|
||||
type: boolean
|
||||
description: "If true, enables the total cookie protection in all browsing modes."
|
||||
homescreen:
|
||||
description: The homescreen that the user goes to when they press home or new tab.
|
||||
hasExposure: true
|
||||
|
@ -42,16 +42,22 @@ class TrackingProtectionPolicyFactory(
|
||||
}
|
||||
|
||||
return when {
|
||||
normalMode && privateMode -> trackingProtectionPolicy.adaptPolicyToChannel()
|
||||
normalMode && !privateMode -> trackingProtectionPolicy.adaptPolicyToChannel().forRegularSessionsOnly()
|
||||
!normalMode && privateMode -> trackingProtectionPolicy.adaptPolicyToChannel().forPrivateSessionsOnly()
|
||||
normalMode && privateMode -> trackingProtectionPolicy.applyTCPIfNeeded(settings)
|
||||
normalMode && !privateMode -> trackingProtectionPolicy.applyTCPIfNeeded(settings).forRegularSessionsOnly()
|
||||
!normalMode && privateMode -> trackingProtectionPolicy.applyTCPIfNeeded(settings).forPrivateSessionsOnly()
|
||||
else -> TrackingProtectionPolicy.none()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createCustomTrackingProtectionPolicy(): TrackingProtectionPolicy {
|
||||
val cookiePolicy = if (settings.enabledTotalCookieProtection) {
|
||||
CookiePolicy.ACCEPT_FIRST_PARTY_AND_ISOLATE_OTHERS
|
||||
} else {
|
||||
getCustomCookiePolicy()
|
||||
}
|
||||
|
||||
return TrackingProtectionPolicy.select(
|
||||
cookiePolicy = getCustomCookiePolicy(),
|
||||
cookiePolicy = cookiePolicy,
|
||||
trackingCategories = getCustomTrackingCategories(),
|
||||
cookiePurging = getCustomCookiePurgingPolicy()
|
||||
).let {
|
||||
@ -106,10 +112,17 @@ class TrackingProtectionPolicyFactory(
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun TrackingProtectionPolicyForSessionTypes.adaptPolicyToChannel(): TrackingProtectionPolicyForSessionTypes {
|
||||
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 = cookiePolicy,
|
||||
cookiePolicy = updatedCookiePolicy,
|
||||
strictSocialTrackingProtection = strictSocialTrackingProtection,
|
||||
cookiePurging = cookiePurging
|
||||
)
|
||||
|
@ -605,6 +605,10 @@ class Settings(private val appContext: Context) : PreferencesHolder {
|
||||
true
|
||||
)
|
||||
|
||||
val enabledTotalCookieProtection: Boolean by lazy {
|
||||
FxNimbus.features.engineSettings.value().totalCookieProtectionEnabled
|
||||
}
|
||||
|
||||
val blockCookiesSelectionInCustomTrackingProtection by stringPreference(
|
||||
appContext.getPreferenceKey(R.string.pref_key_tracking_protection_custom_cookies_select),
|
||||
appContext.getString(R.string.social)
|
||||
|
@ -8,6 +8,7 @@ import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkObject
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.CookiePolicy
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
@ -137,21 +138,40 @@ class TrackingProtectionPolicyFactoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `adaptPolicyToChannel MUST only update properties that have changed per given channel`() {
|
||||
mockkObject(Config)
|
||||
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 (channel in ReleaseChannel.values()) {
|
||||
every { Config.channel } returns channel
|
||||
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.adaptPolicyToChannel()
|
||||
policy.assertPolicyEquals(adaptedPolicy, checkPrivacy = false)
|
||||
}
|
||||
val adaptedPolicy = policy.applyTCPIfNeeded(settings)
|
||||
assertEquals(
|
||||
policy.cookiePolicy,
|
||||
adaptedPolicy.cookiePolicy
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -578,6 +598,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
|
||||
|
@ -210,7 +210,10 @@ features:
|
||||
description: If true, enables tabs prioritization feature.
|
||||
type: Boolean
|
||||
default: true
|
||||
|
||||
total-cookie-protection-enabled:
|
||||
description: If true, enables the total cookie protection in all browsing modes.
|
||||
type: Boolean
|
||||
default: false
|
||||
types:
|
||||
objects:
|
||||
MessageData:
|
||||
|
Loading…
Reference in New Issue
Block a user