Commit 27260e31 authored by MozLando's avatar MozLando
Browse files

Merge #4877



4877: Close issue #4876: Fix tracking protection not working properly on gecko-beta and gecko-stable r=csadilek a=Amejia481



Co-authored-by: default avatarArturo Mejia <arturomejiamarmol@gmail.com>
parents 9995709d f9aeb2e4
......@@ -26,6 +26,7 @@ import mozilla.components.concept.engine.utils.EngineVersion
import mozilla.components.concept.engine.webextension.WebExtension
import mozilla.components.concept.engine.webextension.WebExtensionDelegate
import org.json.JSONObject
import org.mozilla.geckoview.ContentBlocking
import org.mozilla.geckoview.ContentBlockingController
import org.mozilla.geckoview.ContentBlockingController.Event
import org.mozilla.geckoview.GeckoResult
......@@ -238,6 +239,13 @@ class GeckoEngine(
policy.strictSocialTrackingProtection ?: policy.trackingCategories.contains(
TrackingCategory.STRICT
)
val etpLevel =
when {
policy.trackingCategories.contains(TrackingCategory.NONE) ->
ContentBlocking.EtpLevel.NONE
else -> ContentBlocking.EtpLevel.DEFAULT
}
runtime.settings.contentBlocking.setEnhancedTrackingProtectionLevel(etpLevel)
runtime.settings.contentBlocking.setStrictSocialTrackingProtection(
activateStrictSocialTracking
)
......
......@@ -38,6 +38,7 @@ import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyFloat
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mozilla.geckoview.ContentBlocking
import org.mozilla.geckoview.ContentBlockingController
......@@ -208,6 +209,35 @@ class GeckoEngineTest {
assertEquals(0, geckoRunTime.settings.contentBlocking.antiTrackingCategories)
}
@Test
fun `setEnhancedTrackingProtectionLevel MUST always be set to DEFAULT unless the tracking protection policy is none`() {
val mockRuntime = mock<GeckoRuntime>()
whenever(mockRuntime.settings).thenReturn(mock())
whenever(mockRuntime.settings.contentBlocking).thenReturn(mock())
val engine = GeckoEngine(testContext, runtime = mockRuntime)
engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.strict()
verify(mockRuntime.settings.contentBlocking).setEnhancedTrackingProtectionLevel(
ContentBlocking.EtpLevel.DEFAULT
)
engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.none()
verify(mockRuntime.settings.contentBlocking).setEnhancedTrackingProtectionLevel(
ContentBlocking.EtpLevel.NONE
)
engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.select(
arrayOf(TrackingCategory.SCRIPTS_AND_SUB_RESOURCES)
)
verify(mockRuntime.settings.contentBlocking, times(2)).setEnhancedTrackingProtectionLevel(
ContentBlocking.EtpLevel.DEFAULT
)
}
@Test
fun `WHEN a strict tracking protection policy is set THEN the strict social list must be activated`() {
val mockRuntime = mock<GeckoRuntime>()
......
......@@ -26,6 +26,7 @@ import mozilla.components.concept.engine.utils.EngineVersion
import mozilla.components.concept.engine.webextension.WebExtension
import mozilla.components.concept.engine.webextension.WebExtensionDelegate
import org.json.JSONObject
import org.mozilla.geckoview.ContentBlocking
import org.mozilla.geckoview.ContentBlockingController
import org.mozilla.geckoview.ContentBlockingController.Event
import org.mozilla.geckoview.GeckoResult
......@@ -238,6 +239,13 @@ class GeckoEngine(
policy.strictSocialTrackingProtection ?: policy.trackingCategories.contains(
TrackingCategory.STRICT
)
val etpLevel =
when {
policy.trackingCategories.contains(TrackingCategory.NONE) ->
ContentBlocking.EtpLevel.NONE
else -> ContentBlocking.EtpLevel.DEFAULT
}
runtime.settings.contentBlocking.setEnhancedTrackingProtectionLevel(etpLevel)
runtime.settings.contentBlocking.setStrictSocialTrackingProtection(
activateStrictSocialTracking
)
......
......@@ -36,6 +36,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyFloat
import org.mockito.Mockito
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mozilla.geckoview.ContentBlocking
......@@ -201,6 +202,35 @@ class GeckoEngineTest {
assertEquals(0, geckoRunTime.settings.contentBlocking.antiTrackingCategories)
}
@Test
fun `setEnhancedTrackingProtectionLevel MUST always be set to DEFAULT unless the tracking protection policy is none`() {
val mockRuntime = mock<GeckoRuntime>()
whenever(mockRuntime.settings).thenReturn(mock())
whenever(mockRuntime.settings.contentBlocking).thenReturn(mock())
val engine = GeckoEngine(testContext, runtime = mockRuntime)
engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.strict()
verify(mockRuntime.settings.contentBlocking).setEnhancedTrackingProtectionLevel(
ContentBlocking.EtpLevel.DEFAULT
)
engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.none()
verify(mockRuntime.settings.contentBlocking).setEnhancedTrackingProtectionLevel(
ContentBlocking.EtpLevel.NONE
)
engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.select(
arrayOf(TrackingProtectionPolicy.TrackingCategory.SCRIPTS_AND_SUB_RESOURCES)
)
verify(mockRuntime.settings.contentBlocking, Mockito.times(2)).setEnhancedTrackingProtectionLevel(
ContentBlocking.EtpLevel.DEFAULT
)
}
@Test
fun `WHEN a strict tracking protection policy is set THEN the strict social list must be activated`() {
val mockRuntime = mock<GeckoRuntime>()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment