Skip to content

Commit

Permalink
Closes mozilla-mobile#4320: Add api to indicate if strict social trac…
Browse files Browse the repository at this point in the history
…king protection

should be activated.
  • Loading branch information
Amejia481 committed Sep 5, 2019
1 parent 5e27953 commit 1941cfb
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ class GeckoEngine(
set(value) {
value?.let { policy ->
val activateStrictSocialTracking =
policy.trackingCategories.contains(TrackingProtectionPolicy.TrackingCategory.STRICT)
if (policy.strictSocialTrackingProtection != null) {
policy.strictSocialTrackingProtection ?: false
} else {
policy.trackingCategories.contains(TrackingProtectionPolicy.TrackingCategory.STRICT)
}

runtime.settings.contentBlocking.setStrictSocialTrackingProtection(
activateStrictSocialTracking
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,36 @@ class GeckoEngineTest {
verify(mockRuntime.settings.contentBlocking).setStrictSocialTrackingProtection(false)
}

@Test
fun `WHEN strict social tracking protection is set to true THEN the strict social list must be activated`() {
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.select(
strictSocialTrackingProtection = true
)

verify(mockRuntime.settings.contentBlocking).setStrictSocialTrackingProtection(true)
}

@Test
fun `WHEN strict social tracking protection is set to false THEN the strict social list must be disabled`() {
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.select(
strictSocialTrackingProtection = false
)

verify(mockRuntime.settings.contentBlocking).setStrictSocialTrackingProtection(false)
}

@Test
fun defaultSettings() {
val runtime = mock<GeckoRuntime>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ class GeckoEngine(
set(value) {
value?.let { policy ->
val activateStrictSocialTracking =
policy.trackingCategories.contains(TrackingProtectionPolicy.TrackingCategory.STRICT)
if (policy.strictSocialTrackingProtection != null) {
policy.strictSocialTrackingProtection ?: false
} else {
policy.trackingCategories.contains(TrackingProtectionPolicy.TrackingCategory.STRICT)
}

runtime.settings.contentBlocking.setStrictSocialTrackingProtection(
activateStrictSocialTracking
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,36 @@ class GeckoEngineTest {
verify(mockRuntime.settings.contentBlocking).setStrictSocialTrackingProtection(false)
}

@Test
fun `WHEN strict social tracking protection is set to true THEN the strict social list must be activated`() {
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.select(
strictSocialTrackingProtection = true
)

verify(mockRuntime.settings.contentBlocking).setStrictSocialTrackingProtection(true)
}

@Test
fun `WHEN strict social tracking protection is set to false THEN the strict social list must be disabled`() {
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.select(
strictSocialTrackingProtection = false
)

verify(mockRuntime.settings.contentBlocking).setStrictSocialTrackingProtection(false)
}

@Test
fun defaultSettings() {
val runtime = mock<GeckoRuntime>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ abstract class EngineSession(
val trackingCategories: Array<TrackingCategory> = arrayOf(TrackingCategory.RECOMMENDED),
val useForPrivateSessions: Boolean = true,
val useForRegularSessions: Boolean = true,
val cookiePolicy: CookiePolicy = ACCEPT_NON_TRACKERS
val cookiePolicy: CookiePolicy = ACCEPT_NON_TRACKERS,
val strictSocialTrackingProtection: Boolean? = null
) {

/**
Expand Down Expand Up @@ -248,10 +249,12 @@ abstract class EngineSession(

fun select(
trackingCategories: Array<TrackingCategory> = arrayOf(TrackingCategory.RECOMMENDED),
cookiePolicy: CookiePolicy = ACCEPT_NON_TRACKERS
cookiePolicy: CookiePolicy = ACCEPT_NON_TRACKERS,
strictSocialTrackingProtection: Boolean? = null
) = TrackingProtectionPolicyForSessionTypes(
trackingCategories,
cookiePolicy
cookiePolicy,
strictSocialTrackingProtection
)
}

Expand All @@ -276,10 +279,12 @@ abstract class EngineSession(
*/
class TrackingProtectionPolicyForSessionTypes internal constructor(
trackingCategory: Array<TrackingCategory> = arrayOf(TrackingCategory.RECOMMENDED),
cookiePolicy: CookiePolicy = ACCEPT_NON_TRACKERS
cookiePolicy: CookiePolicy = ACCEPT_NON_TRACKERS,
strictSocialTrackingProtection: Boolean? = null
) : TrackingProtectionPolicy(
trackingCategories = trackingCategory,
cookiePolicy = cookiePolicy
cookiePolicy = cookiePolicy,
strictSocialTrackingProtection = strictSocialTrackingProtection
) {
/**
* Marks this policy to be used for private sessions only.
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ 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** and **browser-engine-gecko-beta**
* The `TrackingProtectionPolicy.select` function now allows you to indicate if `strictSocialTrackingProtection` should be activated or not. When it is active blocks trackers from the social-tracking-protection-digest256 list, for more details take a look at the [issue #4320](/~https://github.com/mozilla-mobile/android-components/issues/4320)
```kotlin
val policy = TrackingProtectionPolicy.select(
strictSocialTrackingProtection = true
)
```

* **browser-engine-gecko**, **browser-engine-gecko-beta**, **browser-engine-gecko-nightly**
* **Merge day!**
* `browser-engine-gecko-release`: GeckoView 69.0
Expand Down

0 comments on commit 1941cfb

Please sign in to comment.