1
0
Fork 0

For #13221 - Update global ETP to include PBM

master
ekager 2020-08-04 10:42:29 -04:00 committed by Arturo Mejia
parent c9f8986d2b
commit a1a839f237
4 changed files with 18 additions and 6 deletions

View File

@ -24,7 +24,7 @@ class TrackingProtectionPolicyFactory(private val settings: Settings) {
@Suppress("ComplexMethod")
fun createTrackingProtectionPolicy(
normalMode: Boolean = settings.shouldUseTrackingProtection,
privateMode: Boolean = true
privateMode: Boolean = settings.shouldUseTrackingProtection
): TrackingProtectionPolicy {
val trackingProtectionPolicy =
when {

View File

@ -77,8 +77,7 @@ class OnboardingTrackingProtectionViewHolder(view: View) : RecyclerView.ViewHold
private fun updateTrackingProtectionSetting(enabled: Boolean) {
itemView.context.settings().shouldUseTrackingProtection = enabled
with(itemView.context.components) {
val policy = core.trackingProtectionPolicyFactory
.createTrackingProtectionPolicy(enabled)
val policy = core.trackingProtectionPolicyFactory.createTrackingProtectionPolicy()
useCases.settingsUseCases.updateTrackingProtection.invoke(policy)
useCases.sessionUseCases.reload.invoke()
}

View File

@ -64,8 +64,7 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
preference.context.settings().shouldUseTrackingProtection =
trackingProtectionOn
with(preference.context.components) {
val policy = core.trackingProtectionPolicyFactory
.createTrackingProtectionPolicy(trackingProtectionOn)
val policy = core.trackingProtectionPolicyFactory.createTrackingProtectionPolicy()
useCases.settingsUseCases.updateTrackingProtection(policy)
useCases.sessionUseCases.reload()
}

View File

@ -198,6 +198,18 @@ class TrackingProtectionPolicyFactoryTest {
// `normalMode = true, privateMode = true` can never be shown to the user
}
@Test
fun `factory should follow global ETP settings by default`() {
var useETPFactory = TrackingProtectionPolicyFactory(mockSettings(useTrackingProtection = true))
var policy = useETPFactory.createTrackingProtectionPolicy()
assertTrue(policy.useForPrivateSessions)
assertTrue(policy.useForRegularSessions)
useETPFactory = TrackingProtectionPolicyFactory(mockSettings(useTrackingProtection = false))
policy = useETPFactory.createTrackingProtectionPolicy()
assertEquals(policy, EngineSession.TrackingProtectionPolicy.none())
}
@Test
fun `custom tabs should respect their privacy rules`() {
val allSettings = listOf(
@ -315,10 +327,12 @@ class TrackingProtectionPolicyFactoryTest {
private fun mockSettings(
useStrict: Boolean = false,
useCustom: Boolean = false
useCustom: Boolean = false,
useTrackingProtection: Boolean = false
): Settings = mockk {
every { useStrictTrackingProtection } returns useStrict
every { useCustomTrackingProtection } returns useCustom
every { shouldUseTrackingProtection } returns useTrackingProtection
}
@Suppress("LongParameterList")