Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ internal class IntentConfirmationChallengeActivity : AppCompatActivity() {
hostUrl = HOST_URL,
errorHandler = { error ->
viewModel.handleWebViewError(error)
},
openUri = { uri ->
val browserIntent = Intent(Intent.ACTION_VIEW, uri)
startActivity(browserIntent)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ import androidx.annotation.RequiresApi

internal class IntentConfirmationWebViewClient(
private val hostUrl: String,
private val errorHandler: WebViewErrorHandler
private val errorHandler: WebViewErrorHandler,
private val openUri: (Uri) -> Unit
) : WebViewClient() {

override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
val host = request?.url ?: return super.shouldOverrideUrlLoading(view, request)
openUri(host)
return true
}

@RequiresApi(Build.VERSION_CODES.M)
override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
super.onReceivedError(view, request, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,40 @@ internal class IntentConfirmationWebViewClientTest {
assertThat(errors[0].webViewErrorType).isEqualTo("render_process_gone")
}

@Test
fun `shouldOverrideUrlLoading calls openUri with correct URI`() {
val capturedUris = mutableListOf<Uri>()
val openUri: (Uri) -> Unit = { uri -> capturedUris.add(uri) }
val client = IntentConfirmationWebViewClient(
hostUrl = HOST_URL,
errorHandler = { },
openUri = openUri
)
val testUrl = "https://example.com/terms"
val request = createRequest(testUrl)
val webView = WebView(ApplicationProvider.getApplicationContext())

val result = client.shouldOverrideUrlLoading(webView, request)

assertThat(result).isTrue()
assertThat(capturedUris).hasSize(1)
assertThat(capturedUris[0].toString()).isEqualTo(testUrl)
}

// Helper methods
private fun testWithSetup(
hostUrl: String = HOST_URL,
block: (IntentConfirmationWebViewClient, MutableList<WebViewError>, WebView) -> Unit
) {
val capturedErrors = mutableListOf<WebViewError>()
val errorHandler = WebViewErrorHandler { error -> capturedErrors.add(error) }
val client = IntentConfirmationWebViewClient(hostUrl, errorHandler = errorHandler)
val capturedUris = mutableListOf<Uri>()
val openUri: (Uri) -> Unit = { uri -> capturedUris.add(uri) }
val client = IntentConfirmationWebViewClient(
hostUrl = hostUrl,
errorHandler = errorHandler,
openUri = openUri
)
val webView = WebView(ApplicationProvider.getApplicationContext())

block(client, capturedErrors, webView)
Expand Down
Loading