This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #8122: Do not redirect to market app if app is already installed
- Loading branch information
1 parent
d48e98e
commit d2aa92b
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import android.content.Context | |
import android.content.Intent | ||
import android.content.IntentFilter | ||
import android.content.pm.ActivityInfo | ||
import android.content.pm.PackageInfo | ||
import android.content.pm.ResolveInfo | ||
import android.net.Uri | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
@@ -56,13 +57,19 @@ class AppLinksUseCasesTest { | |
private val layerActivity = "com.example2.app.intentActivity" | ||
private val mailUrl = "mailto:[email protected]" | ||
private val mailPackage = "com.mail.app" | ||
private val appIntentWithPackageAndFallback = | ||
"intent://com.example.app#Intent;package=com.example.com;S.browser_fallback_url=https://example.com;end" | ||
|
||
@Before | ||
fun setup() { | ||
AppLinksUseCases.redirectCache = null | ||
} | ||
|
||
private fun createContext(vararg urlToPackages: Triple<String, String, String>, default: Boolean = false): Context { | ||
private fun createContext( | ||
vararg urlToPackages: Triple<String, String, String>, | ||
default: Boolean = false, | ||
installedApps: List<String> = emptyList() | ||
): Context { | ||
|
||
val pm = testContext.packageManager | ||
val packageManager = shadowOf(pm) | ||
|
@@ -94,6 +101,13 @@ class AppLinksUseCasesTest { | |
`when`(context.packageName).thenReturn(testBrowserPackage) | ||
} | ||
|
||
installedApps.forEach { name -> | ||
val packageInfo = PackageInfo().apply { | ||
packageName = name | ||
} | ||
packageManager.addPackageNoDefaults(packageInfo) | ||
} | ||
|
||
return context | ||
} | ||
|
||
|
@@ -135,6 +149,27 @@ class AppLinksUseCasesTest { | |
assertTrue(redirect.isRedirect()) | ||
} | ||
|
||
@Test | ||
fun `A intent that targets a specific package but installed will not uses market intent`() { | ||
val context = createContext(installedApps = listOf("com.example.com")) | ||
val subject = AppLinksUseCases(context, { true }) | ||
|
||
val redirect = subject.interceptedAppLinkRedirect(appIntentWithPackageAndFallback) | ||
assertFalse(redirect.hasMarketplaceIntent()) | ||
assertTrue(redirect.hasFallback()) | ||
} | ||
|
||
@Test | ||
fun `A intent that targets a specific package but not installed will uses market intent`() { | ||
val context = createContext() | ||
val subject = AppLinksUseCases(context, { true }) | ||
|
||
val redirect = subject.interceptedAppLinkRedirect(appIntentWithPackageAndFallback) | ||
assertFalse(redirect.hasExternalApp()) | ||
assertTrue(redirect.hasMarketplaceIntent()) | ||
assertTrue(redirect.hasFallback()) | ||
} | ||
|
||
@Test | ||
fun `A file is not an app link`() { | ||
val context = createContext(Triple(filePath, appPackage, "")) | ||
|