tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a4fdae530429edd5c44cdd36e99499c5b39e384b
parent cb452f7495f90c546f657a127a906621807d52be
Author: Roger Yang <royang@mozilla.com>
Date:   Mon,  3 Nov 2025 20:38:40 +0000

Bug 1996861 - Add unit tests for wallet custom schemes. r=android-reviewers,nalexander

Differential Revision: https://phabricator.services.mozilla.com/D270384

Diffstat:
Mmobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt | 3++-
Mmobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksFeatureTest.kt | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt b/mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt @@ -270,7 +270,8 @@ class AppLinksFeature( return fragmentManager?.findFragmentByTag(FRAGMENT_TAG) as? RedirectDialogFragment } - private fun isWalletLink(url: String, appIntent: Intent?): Boolean { + @VisibleForTesting + internal fun isWalletLink(url: String, appIntent: Intent?): Boolean { val urlScheme = url.toUri().scheme?.lowercase() val intentScheme = appIntent?.data?.scheme?.lowercase() return (urlScheme != null && WALLET_SCHEMES.contains(urlScheme)) || diff --git a/mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksFeatureTest.kt b/mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksFeatureTest.kt @@ -7,6 +7,7 @@ package mozilla.components.feature.app.links import android.content.ComponentName import android.content.Context import android.content.Intent +import androidx.core.net.toUri import androidx.fragment.app.FragmentManager import androidx.test.ext.junit.runners.AndroidJUnit4 import mozilla.components.browser.state.action.ContentAction @@ -415,4 +416,91 @@ class AppLinksFeatureTest { feature.cancelRedirect(tab, intentUrl, aboutUrl, intent) verify(mockLoadUrlUseCase, times(3)).invoke(anyString(), anyString(), any(), any(), any()) } + + @Test + fun `WHEN url scheme is a wallet scheme THEN wallet prompt is shown even if shouldPrompt is false`() { + feature = spy( + AppLinksFeature( + context = mockContext, + store = store, + fragmentManager = mockFragmentManager, + useCases = mockUseCases, + dialog = mockDialog, + loadUrlUseCase = mockLoadUrlUseCase, + shouldPrompt = { false }, + ), + ).also { + it.start() + } + + val walletUrl = "openid4vp://credential-offer" + val tab = createTab("https://example.com", private = false) + + val appIntent: Intent = mock() + + feature.handleAppIntent(tab, walletUrl, appIntent, null, null) + + verify(mockDialog).showNow(eq(mockFragmentManager), anyString()) + verify(mockOpenRedirect, never()).invoke(any(), anyBoolean(), any()) + } + + @Test + fun `WHEN intent data scheme is a wallet scheme THEN wallet prompt is shown even if shouldPrompt is false`() { + feature = spy( + AppLinksFeature( + context = mockContext, + store = store, + fragmentManager = mockFragmentManager, + useCases = mockUseCases, + dialog = mockDialog, + loadUrlUseCase = mockLoadUrlUseCase, + shouldPrompt = { false }, + ), + ).also { + it.start() + } + + val nonWalletUrl = "https://example.com" + val tab = createTab(nonWalletUrl, private = false) + + val appIntent = Intent(Intent.ACTION_VIEW).apply { + data = "mdoc-openid4vp://present".toUri() + } + + feature.handleAppIntent(tab, nonWalletUrl, appIntent, null, null) + + verify(mockDialog).showNow(eq(mockFragmentManager), anyString()) + verify(mockOpenRedirect, never()).invoke(any(), anyBoolean(), any()) + } + + @Test + fun `isWalletLink returns true only for wallet schemes`() { + val feature = AppLinksFeature( + context = mockContext, + store = store, + fragmentManager = mockFragmentManager, + useCases = mockUseCases, + loadUrlUseCase = mockLoadUrlUseCase, + ) + + val walletUrl = "openid4vp://credential-offer" + var appIntent = Intent(Intent.ACTION_VIEW) + assertTrue(feature.isWalletLink(walletUrl, appIntent)) + + val nonWalletUrl = "https://example.com" + appIntent = Intent(Intent.ACTION_VIEW).apply { + data = "mdoc-openid4vp://something".toUri() + } + assertTrue(feature.isWalletLink(nonWalletUrl, appIntent)) + + appIntent = Intent(Intent.ACTION_VIEW).apply { + data = "https://mozilla.org".toUri() + } + assertFalse(feature.isWalletLink("https://example.com", appIntent)) + + appIntent = Intent(Intent.ACTION_VIEW).apply { + data = "eudi-wallet://open".toUri() + } + assertTrue(feature.isWalletLink("openid-credential-offer://init", appIntent)) + } }