From ca7784d94b7599e7376165349e6626a87426e640 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 +++++++++++++++++++ docs/changelog.md | 3 +++ 3 files changed, 35 insertions(+) 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 ed23552512d..4fd02569685 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -12,6 +12,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Config.kt) +* **browser-engine-gecko-nightly** + * 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)