Skip to content

Commit

Permalink
Make maliciousSiteProtection webView agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisBarreiro committed Dec 10, 2024
1 parent 7f8a206 commit 8d0f3b0
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ import com.duckduckgo.app.trackerdetection.TrackerDetector
import com.duckduckgo.app.trackerdetection.model.TrackerStatus
import com.duckduckgo.app.trackerdetection.model.TrackerType
import com.duckduckgo.app.trackerdetection.model.TrackingEvent
import com.duckduckgo.browser.api.MaliciousSiteBlockerWebViewIntegration
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.duckplayer.api.DuckPlayer
import com.duckduckgo.feature.toggles.api.FeatureToggle
import com.duckduckgo.httpsupgrade.api.HttpsUpgrader
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection
import com.duckduckgo.privacy.config.api.Gpc
import com.duckduckgo.privacy.config.impl.features.gpc.RealGpc.Companion.GPC_HEADER
import com.duckduckgo.request.filterer.api.RequestFilterer
Expand Down Expand Up @@ -98,7 +98,7 @@ class WebViewRequestInterceptorTest {
fakeToggle,
fakeUserAllowListRepository,
)
private val mockMaliciousSiteProtection: MaliciousSiteProtection = mock()
private val mockMaliciousSiteProtection: MaliciousSiteBlockerWebViewIntegration = mock()

private var webView: WebView = mock()

Expand Down Expand Up @@ -130,7 +130,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)
assertCancelledResponse(response)
Expand All @@ -143,7 +143,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -157,7 +157,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -172,7 +172,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -187,7 +187,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)
verify(mockHttpsUpgrader).upgrade(any())
Expand All @@ -203,7 +203,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -217,7 +217,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)
verify(mockDuckPlayer).intercept(any(), any(), any())
Expand All @@ -231,7 +231,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -245,7 +245,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -259,7 +259,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)
assertRequestCanContinueToLoad(response)
Expand All @@ -272,7 +272,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "duckduckgo.com/a/b/c?q=123".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -286,7 +286,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "donttrack.us/a/b/c?q=123".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -300,7 +300,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "spreadprivacy.com/a/b/c?q=123".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -314,7 +314,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "duckduckhack.com/a/b/c?q=123".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -328,7 +328,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "privatebrowsingmyths.com/a/b/c?q=123".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -342,7 +342,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "duck.co/a/b/c?q=123".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -359,7 +359,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockListener,
)

Expand All @@ -377,7 +377,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockListener,
)

Expand All @@ -395,7 +395,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -418,7 +418,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -442,7 +442,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -457,7 +457,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -474,7 +474,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -492,7 +492,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -510,7 +510,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -528,7 +528,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -546,7 +546,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -563,7 +563,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -580,7 +580,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -597,7 +597,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand All @@ -614,7 +614,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = null,
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = mockWebViewClientListener,
)

Expand Down Expand Up @@ -674,7 +674,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand Down Expand Up @@ -713,7 +713,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -735,7 +735,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand All @@ -755,7 +755,7 @@ class WebViewRequestInterceptorTest {
request = mockRequest,
documentUri = "foo.com".toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import com.duckduckgo.app.browser.*
import com.duckduckgo.app.browser.certificates.rootstore.TrustedCertificateStore
import com.duckduckgo.app.browser.cookies.ThirdPartyCookieManager
import com.duckduckgo.app.browser.httpauth.WebViewHttpAuthStore
import com.duckduckgo.browser.api.MaliciousSiteBlockerWebViewIntegration
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.cookies.api.CookieManagerProvider
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Before
Expand All @@ -51,7 +51,7 @@ class UrlExtractingWebViewClientTest {
private val thirdPartyCookieManager: ThirdPartyCookieManager = mock()
private val urlExtractor: DOMUrlExtractor = mock()
private val mockWebView: WebView = mock()
private val mockMaliciousSiteProtection: MaliciousSiteProtection = mock()
private val mockMaliciousSiteProtection: MaliciousSiteBlockerWebViewIntegration = mock()

@UiThreadTest
@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ import com.duckduckgo.app.trackerdetection.db.TdsCnameEntityDao
import com.duckduckgo.app.trackerdetection.db.TdsDomainEntityDao
import com.duckduckgo.app.trackerdetection.db.TdsEntityDao
import com.duckduckgo.app.trackerdetection.db.WebTrackersBlockedDao
import com.duckduckgo.browser.api.MaliciousSiteBlockerWebViewIntegration
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.common.test.FileUtilities
import com.duckduckgo.duckplayer.api.DuckPlayer
import com.duckduckgo.feature.toggles.api.FeatureToggle
import com.duckduckgo.httpsupgrade.api.HttpsUpgrader
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection
import com.duckduckgo.privacy.config.api.ContentBlocking
import com.duckduckgo.privacy.config.api.Gpc
import com.duckduckgo.privacy.config.api.TrackerAllowlist
Expand Down Expand Up @@ -120,7 +120,7 @@ class DomainsReferenceTest(private val testCase: TestCase) {
)
private val mockGpc: Gpc = mock()
private val mockAdClickManager: AdClickManager = mock()
private val mockMaliciousSiteProtection: MaliciousSiteProtection = mock()
private val mockMaliciousSiteProtection: MaliciousSiteBlockerWebViewIntegration = mock()

companion object {
private val moshi = Moshi.Builder().add(ActionJsonAdapter()).build()
Expand Down Expand Up @@ -200,7 +200,7 @@ class DomainsReferenceTest(private val testCase: TestCase) {
request = mockRequest,
documentUri = testCase.siteURL.toUri(),
webView = webView,
maliciousSiteProtection = mockMaliciousSiteProtection,
maliciousSiteProtectionWebViewIntegration = mockMaliciousSiteProtection,
webViewClientListener = null,
)

Expand Down
Loading

0 comments on commit 8d0f3b0

Please sign in to comment.