MainActivityDeepLinkTest.kt

1.3 KB · raw

1package com.peachpasswords23import android.content.Intent4import android.net.Uri5import androidx.test.ext.junit.runners.AndroidJUnit46import androidx.test.platform.app.InstrumentationRegistry7import org.junit.Assert.assertEquals8import org.junit.Assert.assertFalse9import org.junit.Test10import org.junit.runner.RunWith1112@RunWith(AndroidJUnit4::class)13class MainActivityDeepLinkTest {14    @Test15    fun merged_manifest_keeps_main_activity_launcher_only_and_rejects_peach_uri() {16        val context = InstrumentationRegistry.getInstrumentation().targetContext17        val packageManager = context.packageManager1819        val launcher = Intent(Intent.ACTION_MAIN)20            .addCategory(Intent.CATEGORY_LAUNCHER)21            .setPackage(context.packageName)22        val launcherMatches = packageManager.queryIntentActivities(launcher, 0)23        assertEquals(1, launcherMatches.count { it.activityInfo.name == MainActivity::class.java.name })2425        val peachUri = Intent(Intent.ACTION_VIEW, Uri.parse("peach://anything"))26            .addCategory(Intent.CATEGORY_BROWSABLE)27        assertFalse(28            "peach://anything must not resolve to Peach",29            packageManager.queryIntentActivities(peachUri, 0).any {30                it.activityInfo.packageName == context.packageName31            },32        )33    }34}