Skip to content

Commit

Permalink
Merge branch 'hotfix/5.218.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
joshliebe committed Nov 1, 2024
2 parents f8d452e + fb16f52 commit 5f11d81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.adclick.api.AdClickManager
import com.duckduckgo.anrs.api.CrashLogger
import com.duckduckgo.anrs.api.CrashLogger.Crash
import com.duckduckgo.app.browser.SpecialUrlDetector.UrlType.Web
import com.duckduckgo.app.browser.WebViewErrorResponse.BAD_URL
import com.duckduckgo.app.browser.WebViewErrorResponse.CONNECTION
import com.duckduckgo.app.browser.WebViewErrorResponse.SSL_PROTOCOL_ERROR
Expand Down Expand Up @@ -427,6 +428,25 @@ class BrowserWebViewClientTest {
verify(mockWebView).loadUrl("www.youtube.com/watch?v=1234&origin=serp_auto")
}

@Test
fun whenShouldOverrideWithWebThenDoNotAddQueryParam() = runTest {
val urlType = Web("www.youtube.com/watch?v=1234")
whenever(specialUrlDetector.determineType(initiatingUrl = any(), uri = any())).thenReturn(urlType)
whenever(webResourceRequest.isForMainFrame).thenReturn(true)
whenever(webResourceRequest.isRedirect).thenReturn(false)
whenever(webResourceRequest.url).thenReturn("www.youtube.com/watch?v=1234".toUri())
whenever(mockDuckDuckGoUrlDetector.isDuckDuckGoUrl(any())).thenReturn(true)
val mockClientProvider: ClientBrandHintProvider = mock()
whenever(mockClientProvider.shouldChangeBranding(any())).thenReturn(false)
testee.clientProvider = mockClientProvider
doNothing().whenever(listener).willOverrideUrl(any())
val mockWebView = getImmediatelyInvokedMockWebView()
whenever(mockWebView.url).thenReturn("www.duckduckgo.com")
openInNewTabFlow.emit(Off)

assertFalse(testee.shouldOverrideUrlLoading(mockWebView, webResourceRequest))
}

@UiThreadTest
@Test
fun whenAppLinkDetectedAndIsHandledThenReturnTrue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ class BrowserWebViewClient @Inject constructor(
}
return true
} else {
shouldOverrideWebRequest(url, webView, isForMainFrame, openInNewTab = shouldOpenDuckPlayerInNewTab)
shouldOverrideWebRequest(
url,
webView,
isForMainFrame,
openInNewTab = shouldOpenDuckPlayerInNewTab,
willOpenDuckPlayer = true,
)
}
}
is SpecialUrlDetector.UrlType.NonHttpAppLink -> {
Expand Down Expand Up @@ -310,6 +316,7 @@ class BrowserWebViewClient @Inject constructor(
webView: WebView,
isForMainFrame: Boolean,
openInNewTab: Boolean = false,
willOpenDuckPlayer: Boolean = false,
): Boolean {
if (requestRewriter.shouldRewriteRequest(url)) {
webViewClientListener?.let { listener ->
Expand All @@ -330,9 +337,8 @@ class BrowserWebViewClient @Inject constructor(
loadUrl(listener, webView, url.toString())
}
return true
} else if (webView.url?.let { duckDuckGoUrlDetector.isDuckDuckGoUrl(it) } == true) {
} else if (willOpenDuckPlayer && webView.url?.let { duckDuckGoUrlDetector.isDuckDuckGoUrl(it) } == true) {
val newUrl = url.buildUpon().appendQueryParameter(ORIGIN_QUERY_PARAM, ORIGIN_QUERY_PARAM_SERP_AUTO).build()

if (openInNewTab) {
listener.openLinkInNewTab(newUrl)
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/version/version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=5.218.0
VERSION=5.218.1

0 comments on commit 5f11d81

Please sign in to comment.