mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-11 13:11:01 +00:00
No issue: Do not prevent trackers duplication in the tracking
protection panel.
This commit is contained in:
parent
13637c59a2
commit
0275ca0693
@ -69,50 +69,69 @@ class TrackerBuckets {
|
||||
val loadedMap =
|
||||
EnumMap<TrackingProtectionCategory, List<String>>(TrackingProtectionCategory::class.java)
|
||||
for (item in list) {
|
||||
when {
|
||||
// Blocked categories
|
||||
item.cookiesHasBeenBlocked -> {
|
||||
|
||||
if (item.cookiesHasBeenBlocked) {
|
||||
blockedMap[CROSS_SITE_TRACKING_COOKIES] =
|
||||
blockedMap[CROSS_SITE_TRACKING_COOKIES].orEmpty() + item.url.tryGetHostFromUrl()
|
||||
}
|
||||
CRYPTOMINING in item.blockedCategories -> {
|
||||
blockedMap[CRYPTOMINERS] = blockedMap[CRYPTOMINERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
FINGERPRINTING in item.blockedCategories -> {
|
||||
blockedMap[FINGERPRINTERS] = blockedMap[FINGERPRINTERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
MOZILLA_SOCIAL in item.blockedCategories -> {
|
||||
blockedMap[SOCIAL_MEDIA_TRACKERS] =
|
||||
blockedMap[SOCIAL_MEDIA_TRACKERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
TrackingCategory.SCRIPTS_AND_SUB_RESOURCES in item.blockedCategories -> {
|
||||
blockedMap[TRACKING_CONTENT] = blockedMap[TRACKING_CONTENT].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
|
||||
// Blocked categories
|
||||
bucketBlockedCategories(item, blockedMap)
|
||||
|
||||
// Loaded categories
|
||||
CRYPTOMINING in item.loadedCategories -> {
|
||||
bucketLoadedCategories(item, loadedMap)
|
||||
}
|
||||
return BucketedTrackerLog(blockedMap, loadedMap)
|
||||
}
|
||||
|
||||
private fun bucketLoadedCategories(
|
||||
item: TrackerLog,
|
||||
loadedMap: EnumMap<TrackingProtectionCategory, List<String>>
|
||||
) {
|
||||
item.loadedCategories.forEach { category ->
|
||||
if (CRYPTOMINING == category) {
|
||||
loadedMap[CRYPTOMINERS] = loadedMap[CRYPTOMINERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
FINGERPRINTING in item.loadedCategories -> {
|
||||
if (FINGERPRINTING == category) {
|
||||
loadedMap[FINGERPRINTERS] = loadedMap[FINGERPRINTERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
MOZILLA_SOCIAL in item.loadedCategories -> {
|
||||
if (MOZILLA_SOCIAL == category) {
|
||||
loadedMap[SOCIAL_MEDIA_TRACKERS] =
|
||||
loadedMap[SOCIAL_MEDIA_TRACKERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
TrackingCategory.SCRIPTS_AND_SUB_RESOURCES in item.loadedCategories -> {
|
||||
if (TrackingCategory.SCRIPTS_AND_SUB_RESOURCES == category) {
|
||||
loadedMap[TRACKING_CONTENT] = loadedMap[TRACKING_CONTENT].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
}
|
||||
}
|
||||
return BucketedTrackerLog(blockedMap, loadedMap)
|
||||
|
||||
private fun bucketBlockedCategories(
|
||||
item: TrackerLog,
|
||||
blockedMap: EnumMap<TrackingProtectionCategory, List<String>>
|
||||
) {
|
||||
item.blockedCategories.forEach { category ->
|
||||
if (CRYPTOMINING == category) {
|
||||
blockedMap[CRYPTOMINERS] = blockedMap[CRYPTOMINERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
if (FINGERPRINTING == category) {
|
||||
blockedMap[FINGERPRINTERS] = blockedMap[FINGERPRINTERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
if (MOZILLA_SOCIAL == category) {
|
||||
blockedMap[SOCIAL_MEDIA_TRACKERS] =
|
||||
blockedMap[SOCIAL_MEDIA_TRACKERS].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
if (TrackingCategory.SCRIPTS_AND_SUB_RESOURCES == category) {
|
||||
blockedMap[TRACKING_CONTENT] = blockedMap[TRACKING_CONTENT].orEmpty() +
|
||||
item.url.tryGetHostFromUrl()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
package org.mozilla.fenix.trackingprotection
|
||||
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory.SCRIPTS_AND_SUB_RESOURCES
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory.CRYPTOMINING
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory.FINGERPRINTING
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory.MOZILLA_SOCIAL
|
||||
import mozilla.components.concept.engine.content.blocking.TrackerLog
|
||||
@ -13,6 +15,7 @@ import org.junit.Test
|
||||
import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CRYPTOMINERS
|
||||
import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.FINGERPRINTERS
|
||||
|
||||
private typealias FenixTrackingProtectionCategory = TrackingProtectionCategory
|
||||
class TrackerBucketsTest {
|
||||
|
||||
@Test
|
||||
@ -38,7 +41,7 @@ class TrackerBucketsTest {
|
||||
assertEquals(listOf("google.com"), buckets.buckets.blockedBucketMap[FINGERPRINTERS])
|
||||
assertEquals(
|
||||
listOf("facebook.com"),
|
||||
buckets.buckets.loadedBucketMap[TrackingProtectionCategory.SOCIAL_MEDIA_TRACKERS]
|
||||
buckets.buckets.loadedBucketMap[FenixTrackingProtectionCategory.SOCIAL_MEDIA_TRACKERS]
|
||||
)
|
||||
assertTrue(buckets.buckets.blockedBucketMap[CRYPTOMINERS].isNullOrEmpty())
|
||||
assertTrue(buckets.buckets.loadedBucketMap[CRYPTOMINERS].isNullOrEmpty())
|
||||
@ -60,7 +63,7 @@ class TrackerBucketsTest {
|
||||
|
||||
assertEquals(
|
||||
mapOf(
|
||||
TrackingProtectionCategory.SOCIAL_MEDIA_TRACKERS to listOf("facebook.com")
|
||||
FenixTrackingProtectionCategory.SOCIAL_MEDIA_TRACKERS to listOf("facebook.com")
|
||||
), buckets.buckets.loadedBucketMap
|
||||
)
|
||||
|
||||
@ -70,4 +73,40 @@ class TrackerBucketsTest {
|
||||
), buckets.buckets.blockedBucketMap
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `trackers in the same site but with different categories`() {
|
||||
val buckets = TrackerBuckets()
|
||||
val acCategories = listOf(
|
||||
CRYPTOMINING,
|
||||
MOZILLA_SOCIAL,
|
||||
FINGERPRINTING,
|
||||
SCRIPTS_AND_SUB_RESOURCES
|
||||
)
|
||||
|
||||
buckets.updateIfNeeded(
|
||||
listOf(
|
||||
TrackerLog(
|
||||
url = "http://facebook.com",
|
||||
cookiesHasBeenBlocked = true,
|
||||
blockedCategories = acCategories,
|
||||
loadedCategories = acCategories
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val expectedBlockedMap =
|
||||
mapOf(
|
||||
FenixTrackingProtectionCategory.SOCIAL_MEDIA_TRACKERS to listOf("facebook.com"),
|
||||
FenixTrackingProtectionCategory.TRACKING_CONTENT to listOf("facebook.com"),
|
||||
FenixTrackingProtectionCategory.FINGERPRINTERS to listOf("facebook.com"),
|
||||
FenixTrackingProtectionCategory.CRYPTOMINERS to listOf("facebook.com"),
|
||||
FenixTrackingProtectionCategory.CROSS_SITE_TRACKING_COOKIES to listOf("facebook.com")
|
||||
)
|
||||
val expectedLoadedMap =
|
||||
expectedBlockedMap - FenixTrackingProtectionCategory.CROSS_SITE_TRACKING_COOKIES
|
||||
|
||||
assertEquals(expectedBlockedMap, buckets.buckets.blockedBucketMap)
|
||||
assertEquals(expectedLoadedMap, buckets.buckets.loadedBucketMap)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user