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 0b7f33d
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import com.duckduckgo.autoconsent.api.Autoconsent
import com.duckduckgo.autofill.api.BrowserAutofill
import com.duckduckgo.autofill.api.InternalTestUserChecker
import com.duckduckgo.browser.api.JsInjectorPlugin
import com.duckduckgo.browser.api.MaliciousSiteBlockerWebViewIntegration
import com.duckduckgo.browser.api.WebViewVersionProvider
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.common.utils.CurrentTimeProvider
Expand All @@ -79,7 +80,6 @@ import com.duckduckgo.duckplayer.api.DuckPlayer.OpenDuckPlayerInNewTab.Off
import com.duckduckgo.duckplayer.api.DuckPlayer.OpenDuckPlayerInNewTab.On
import com.duckduckgo.duckplayer.api.DuckPlayer.OpenDuckPlayerInNewTab.Unavailable
import com.duckduckgo.history.api.NavigationHistory
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection
import com.duckduckgo.privacy.config.api.AmpLinks
import com.duckduckgo.subscriptions.api.Subscriptions
import com.duckduckgo.user.agent.api.ClientBrandHintProvider
Expand Down Expand Up @@ -153,7 +153,7 @@ class BrowserWebViewClientTest {
private val mockUriLoadedManager: UriLoadedManager = mock()
private val mockAndroidBrowserConfigFeature: AndroidBrowserConfigFeature = mock()
private val mockAndroidFeaturesHeaderPlugin = AndroidFeaturesHeaderPlugin(mockDuckDuckGoUrlDetector, mockAndroidBrowserConfigFeature, 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 @@ -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
Loading

0 comments on commit 0b7f33d

Please sign in to comment.