From 916e4b7c0e399510928747e71cc96c1d1e18f85f Mon Sep 17 00:00:00 2001 From: Arturo Mejia Date: Wed, 28 Aug 2019 15:09:42 -0400 Subject: [PATCH] Closes #4213: Use the social strict tracking protection list when the TrackingProtectionPolicy.strict() is set. --- .../browser/engine/gecko/GeckoEngine.kt | 5 ++++ .../browser/engine/gecko/GeckoEngineTest.kt | 27 +++++++++++++++++++ .../browser/engine/gecko/GeckoEngine.kt | 5 ++++ .../browser/engine/gecko/GeckoEngineTest.kt | 27 +++++++++++++++++++ docs/changelog.md | 3 +++ 5 files changed, 67 insertions(+) diff --git a/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt b/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt index 39bebf18956..4ec23943e53 100644 --- a/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt +++ b/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt @@ -168,6 +168,11 @@ class GeckoEngine( override var trackingProtectionPolicy: TrackingProtectionPolicy? = null set(value) { value?.let { policy -> + val activateStrictSocialTracking = + policy.trackingCategories.contains(TrackingProtectionPolicy.TrackingCategory.STRICT) + runtime.settings.contentBlocking.setStrictSocialTrackingProtection( + activateStrictSocialTracking + ) runtime.settings.contentBlocking.setAntiTracking(policy.trackingCategories.sumBy { it.id }) runtime.settings.contentBlocking.cookieBehavior = policy.cookiePolicy.id defaultSettings?.trackingProtectionPolicy = value diff --git a/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt b/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt index add1cdf3482..268b36f9ddc 100644 --- a/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt +++ b/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt @@ -20,6 +20,7 @@ import mozilla.components.support.test.argumentCaptor import mozilla.components.support.test.eq import mozilla.components.support.test.mock import mozilla.components.support.test.whenever +import mozilla.components.support.test.robolectric.testContext import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull @@ -160,6 +161,32 @@ class GeckoEngineTest { } catch (e: UnsupportedSettingException) { } } + @Test + fun `WHEN a strict tracking protection policy is set THEN the strict social list must be activated`() { + val mockRuntime = mock() + 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).setStrictSocialTrackingProtection(true) + } + + @Test + fun `WHEN a non strict tracking protection policy is set THEN the strict social list must be disabled`() { + val mockRuntime = mock() + whenever(mockRuntime.settings).thenReturn(mock()) + whenever(mockRuntime.settings.contentBlocking).thenReturn(mock()) + + val engine = GeckoEngine(testContext, runtime = mockRuntime) + + engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.recommended() + + verify(mockRuntime.settings.contentBlocking).setStrictSocialTrackingProtection(false) + } + @Test fun defaultSettings() { val runtime = mock() diff --git a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt index 39bebf18956..4ec23943e53 100644 --- a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt +++ b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt @@ -168,6 +168,11 @@ class GeckoEngine( override var trackingProtectionPolicy: TrackingProtectionPolicy? = null set(value) { value?.let { policy -> + val activateStrictSocialTracking = + policy.trackingCategories.contains(TrackingProtectionPolicy.TrackingCategory.STRICT) + runtime.settings.contentBlocking.setStrictSocialTrackingProtection( + activateStrictSocialTracking + ) runtime.settings.contentBlocking.setAntiTracking(policy.trackingCategories.sumBy { it.id }) runtime.settings.contentBlocking.cookieBehavior = policy.cookiePolicy.id defaultSettings?.trackingProtectionPolicy = value diff --git a/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt b/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt index add1cdf3482..eb6ec150340 100644 --- a/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt +++ b/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt @@ -19,6 +19,7 @@ import mozilla.components.support.test.any import mozilla.components.support.test.argumentCaptor import mozilla.components.support.test.eq import mozilla.components.support.test.mock +import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.whenever import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse @@ -160,6 +161,32 @@ class GeckoEngineTest { } catch (e: UnsupportedSettingException) { } } + @Test + fun `WHEN a strict tracking protection policy is set THEN the strict social list must be activated`() { + val mockRuntime = mock() + 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).setStrictSocialTrackingProtection(true) + } + + @Test + fun `WHEN a non strict tracking protection policy is set THEN the strict social list must be disabled`() { + val mockRuntime = mock() + whenever(mockRuntime.settings).thenReturn(mock()) + whenever(mockRuntime.settings.contentBlocking).thenReturn(mock()) + + val engine = GeckoEngine(testContext, runtime = mockRuntime) + + engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.recommended() + + verify(mockRuntime.settings.contentBlocking).setStrictSocialTrackingProtection(false) + } + @Test fun defaultSettings() { val runtime = mock() diff --git a/docs/changelog.md b/docs/changelog.md index a988445f3c6..76235ed96f5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -23,6 +23,9 @@ permalink: /changelog/ ) ``` +* **browser-engine-gecko-nightly** and **browser-engine-gecko-beta** + * The `TrackingProtectionPolicy.strict()` now blocks trackers from the social-tracking-protection-digest256 list, for more details take a look at the [issue #4213](https://github.com/mozilla-mobile/android-components/issues/4213) + # 11.0.0 * [Commits](https://github.com/mozilla-mobile/android-components/compare/v10.0.0...v11.0.0)