1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.activityembedding 18 19 import android.content.Context 20 import android.content.Intent 21 import android.net.Uri 22 import android.provider.Settings 23 import androidx.test.core.app.ApplicationProvider 24 import androidx.test.ext.junit.runners.AndroidJUnit4 25 import com.android.settings.activityembedding.EmbeddedDeepLinkUtils.getTrampolineIntent 26 import com.google.common.truth.Truth.assertThat 27 import org.junit.Test 28 import org.junit.runner.RunWith 29 30 @RunWith(AndroidJUnit4::class) 31 class EmbeddedDeepLinkUtilsTest { 32 33 private val context: Context = ApplicationProvider.getApplicationContext() 34 35 @Test getTrampolineIntent_intentSelector_shouldNotChangeIntentActionnull36 fun getTrampolineIntent_intentSelector_shouldNotChangeIntentAction() { 37 val targetIntent = Intent().setClassName( 38 "android", 39 "com.android.internal.app.PlatLogoActivity" 40 ) 41 val intent = Intent(Settings.ACTION_DISPLAY_SETTINGS).apply { 42 setComponent(resolveActivity(context.packageManager)) 43 setSelector( 44 Intent().setData( 45 Uri.fromParts( 46 targetIntent.toUri(Intent.URI_INTENT_SCHEME), 47 /* ssp= */ "", 48 /* fragment= */ null, 49 ) 50 ) 51 ) 52 } 53 54 val resultIntent = getTrampolineIntent(intent, "menu_key") 55 56 val intentUriString = 57 resultIntent.getStringExtra(Settings.EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI) 58 val parsedIntent = Intent.parseUri(intentUriString, Intent.URI_INTENT_SCHEME) 59 assertThat(parsedIntent.action).isEqualTo(intent.action) 60 } 61 } 62