Commit a72ab2e9 authored by Arturo Mejia's avatar Arturo Mejia
Browse files

Closes #5109: Fix breaking change on GeckoView nightly 72.0.20191120094758

parent b5c787f3
......@@ -6,7 +6,7 @@ internal object GeckoVersions {
/**
* GeckoView Nightly Version.
*/
const val nightly_version = "72.0.20191118093852"
const val nightly_version = "72.0.20191119043902"
/**
* GeckoView Beta Version.
......
......@@ -48,7 +48,7 @@ import java.util.WeakHashMap
/**
* Gecko-based implementation of Engine interface.
*/
@Suppress("TooManyFunctions")
@Suppress("TooManyFunctions", "LargeClass")
class GeckoEngine(
context: Context,
private val defaultSettings: Settings? = null,
......@@ -414,6 +414,48 @@ class GeckoEngine(
this.forceUserScalableContent = it.forceUserScalableContent
}
}
internal fun ContentBlockingController.LogEntry.BlockingData.getLoadedCategory(): TrackingCategory {
return when (category) {
Event.LOADED_FINGERPRINTING_CONTENT -> TrackingCategory.FINGERPRINTING
Event.LOADED_CRYPTOMINING_CONTENT -> TrackingCategory.CRYPTOMINING
Event.LOADED_SOCIALTRACKING_CONTENT -> TrackingCategory.MOZILLA_SOCIAL
Event.LOADED_LEVEL_1_TRACKING_CONTENT -> TrackingCategory.SCRIPTS_AND_SUB_RESOURCES
Event.LOADED_LEVEL_2_TRACKING_CONTENT -> {
// We are making sure that we are only showing trackers that our settings are
// taking into consideration.
val isContentListActive =
settings.trackingProtectionPolicy?.contains(TrackingCategory.CONTENT)
?: false
val isStrictLevelActive =
runtime.settings
.contentBlocking
.getEnhancedTrackingProtectionLevel() == ContentBlocking.EtpLevel.STRICT
if (isStrictLevelActive && isContentListActive) {
TrackingCategory.SCRIPTS_AND_SUB_RESOURCES
} else {
TrackingCategory.NONE
}
}
else -> TrackingCategory.NONE
}
}
internal fun ContentBlockingController.LogEntry.toTrackerLog(): TrackerLog {
val cookiesHasBeenBlocked = this.blockingData.any { it.hasBlockedCookies() }
return TrackerLog(
url = origin,
loadedCategories = blockingData.map { it.getLoadedCategory() }
.filterNot { it == TrackingCategory.NONE }
.distinct(),
blockedCategories = blockingData.map { it.getBlockedCategory() }
.filterNot { it == TrackingCategory.NONE }
.distinct(),
cookiesHasBeenBlocked = cookiesHasBeenBlocked
)
}
}
internal fun ContentBlockingController.LogEntry.BlockingData.hasBlockedCookies(): Boolean {
......@@ -433,23 +475,3 @@ internal fun ContentBlockingController.LogEntry.BlockingData.getBlockedCategory(
else -> TrackingCategory.NONE
}
}
internal fun ContentBlockingController.LogEntry.BlockingData.getLoadedCategory(): TrackingCategory {
return when (category) {
Event.LOADED_FINGERPRINTING_CONTENT -> TrackingCategory.FINGERPRINTING
Event.LOADED_CRYPTOMINING_CONTENT -> TrackingCategory.CRYPTOMINING
Event.LOADED_SOCIALTRACKING_CONTENT -> TrackingCategory.MOZILLA_SOCIAL
Event.LOADED_TRACKING_CONTENT -> TrackingCategory.SCRIPTS_AND_SUB_RESOURCES
else -> TrackingCategory.NONE
}
}
internal fun ContentBlockingController.LogEntry.toTrackerLog(): TrackerLog {
val cookiesHasBeenBlocked = this.blockingData.any { it.hasBlockedCookies() }
return TrackerLog(
url = origin,
loadedCategories = blockingData.map { it.getLoadedCategory() }.filterNot { it == TrackingCategory.NONE },
blockedCategories = blockingData.map { it.getBlockedCategory() }.filterNot { it == TrackingCategory.NONE },
cookiesHasBeenBlocked = cookiesHasBeenBlocked
)
}
......@@ -691,11 +691,18 @@ class GeckoEngineTest {
var onSuccessCalled = false
var onErrorCalled = false
val mockSession = mock<GeckoEngineSession>()
val mockGeckoSetting = mock<GeckoRuntimeSettings>()
val mockGeckoContentBlockingSetting = mock<ContentBlocking.Settings>()
var trackersLog: List<TrackerLog>? = null
val mockContentBlockingController = mock<ContentBlockingController>()
var logEntriesResult = GeckoResult<List<ContentBlockingController.LogEntry>>()
whenever(runtime.settings).thenReturn(mockGeckoSetting)
whenever(mockGeckoSetting.contentBlocking).thenReturn(mockGeckoContentBlockingSetting)
whenever(mockGeckoContentBlockingSetting.getEnhancedTrackingProtectionLevel()).thenReturn(
ContentBlocking.EtpLevel.STRICT
)
whenever(runtime.contentBlockingController).thenReturn(mockContentBlockingController)
whenever(mockContentBlockingController.getLog(any())).thenReturn(logEntriesResult)
......@@ -742,6 +749,50 @@ class GeckoEngineTest {
assertTrue(onErrorCalled)
}
@Test
fun `fetch trackers logged of the level 2 list`() {
val runtime = mock<GeckoRuntime>()
val engine = GeckoEngine(context, runtime = runtime)
val mockSession = mock<GeckoEngineSession>()
val mockGeckoSetting = mock<GeckoRuntimeSettings>()
val mockGeckoContentBlockingSetting = mock<ContentBlocking.Settings>()
var trackersLog: List<TrackerLog>? = null
val mockContentBlockingController = mock<ContentBlockingController>()
var logEntriesResult = GeckoResult<List<ContentBlockingController.LogEntry>>()
whenever(runtime.settings).thenReturn(mockGeckoSetting)
whenever(mockGeckoSetting.contentBlocking).thenReturn(mockGeckoContentBlockingSetting)
whenever(mockGeckoContentBlockingSetting.getEnhancedTrackingProtectionLevel()).thenReturn(
ContentBlocking.EtpLevel.STRICT
)
whenever(runtime.contentBlockingController).thenReturn(mockContentBlockingController)
whenever(mockContentBlockingController.getLog(any())).thenReturn(logEntriesResult)
engine.settings.trackingProtectionPolicy = TrackingProtectionPolicy.select(
arrayOf(
TrackingCategory.STRICT,
TrackingCategory.CONTENT
)
)
logEntriesResult = GeckoResult()
whenever(runtime.contentBlockingController).thenReturn(mockContentBlockingController)
whenever(mockContentBlockingController.getLog(any())).thenReturn(logEntriesResult)
engine.getTrackersLog(
mockSession,
onSuccess = {
trackersLog = it
},
onError = { }
)
logEntriesResult.complete(createDummyLogEntryList())
val trackerLog = trackersLog!![1]
assertTrue(trackerLog.loadedCategories.contains(TrackingCategory.SCRIPTS_AND_SUB_RESOURCES))
}
@Test
fun `registerWebNotificationDelegate sets delegate`() {
val runtime = mock<GeckoRuntime>()
......@@ -779,14 +830,16 @@ class GeckoEngineTest {
val blockedCyptominingContent = createBlockingData(Event.BLOCKED_CRYPTOMINING_CONTENT)
val blockedSocialContent = createBlockingData(Event.BLOCKED_SOCIALTRACKING_CONTENT)
val loadedTrackingContent = createBlockingData(Event.LOADED_TRACKING_CONTENT)
val loadedTrackingLevel1Content = createBlockingData(Event.LOADED_LEVEL_1_TRACKING_CONTENT)
val loadedTrackingLevel2Content = createBlockingData(Event.LOADED_LEVEL_2_TRACKING_CONTENT)
val loadedFingerprintingContent = createBlockingData(Event.LOADED_FINGERPRINTING_CONTENT)
val loadedCyptominingContent = createBlockingData(Event.LOADED_CRYPTOMINING_CONTENT)
val loadedSocialContent = createBlockingData(Event.LOADED_SOCIALTRACKING_CONTENT)
val contentBlockingList = listOf(
blockedTrackingContent,
loadedTrackingContent,
loadedTrackingLevel1Content,
loadedTrackingLevel2Content,
blockedFingerprintingContent,
loadedFingerprintingContent,
blockedCyptominingContent,
......@@ -796,9 +849,14 @@ class GeckoEngineTest {
loadedSocialContent
)
val addLogSecondEntry = object : ContentBlockingController.LogEntry() {}
ReflectionUtils.setField(addLogSecondEntry, "origin", "www.tracker2.com")
val contentBlockingSecondEntryList = listOf(loadedTrackingLevel2Content)
ReflectionUtils.setField(addLogEntry, "blockingData", contentBlockingList)
ReflectionUtils.setField(addLogSecondEntry, "blockingData", contentBlockingSecondEntryList)
return listOf(addLogEntry)
return listOf(addLogEntry, addLogSecondEntry)
}
private fun createBlockingData(category: Int): ContentBlockingController.LogEntry.BlockingData {
......
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