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.intentresolver 18 19 import android.content.ComponentName 20 import android.provider.Settings 21 import android.testing.TestableContext 22 import androidx.test.ext.junit.runners.AndroidJUnit4 23 import androidx.test.platform.app.InstrumentationRegistry 24 import com.google.common.truth.Truth.assertThat 25 import org.junit.Test 26 import org.junit.runner.RunWith 27 28 @RunWith(AndroidJUnit4::class) 29 class ChooserIntegratedDeviceComponentsTest { 30 private val secureSettings = mock<SecureSettings>() 31 private val testableContext = 32 TestableContext(InstrumentationRegistry.getInstrumentation().getContext()) 33 34 @Test testEditorAndNearbynull35 fun testEditorAndNearby() { 36 val resources = testableContext.getOrCreateTestableResources() 37 38 resources.addOverride(R.string.config_systemImageEditor, "") 39 resources.addOverride(R.string.config_defaultNearbySharingComponent, "") 40 41 var components = ChooserIntegratedDeviceComponents.get(testableContext, secureSettings) 42 43 assertThat(components.editSharingComponent).isNull() 44 assertThat(components.nearbySharingComponent).isNull() 45 46 val editor = ComponentName.unflattenFromString("com.android/com.android.Editor") 47 val nearby = ComponentName.unflattenFromString("com.android/com.android.nearby") 48 49 resources.addOverride(R.string.config_systemImageEditor, editor?.flattenToString()) 50 resources.addOverride( 51 R.string.config_defaultNearbySharingComponent, nearby?.flattenToString()) 52 53 components = ChooserIntegratedDeviceComponents.get(testableContext, secureSettings) 54 55 assertThat(components.editSharingComponent).isEqualTo(editor) 56 assertThat(components.nearbySharingComponent).isEqualTo(nearby) 57 58 val anotherNearby = 59 ComponentName.unflattenFromString("com.android/com.android.another_nearby") 60 whenever( 61 secureSettings.getString( 62 any(), 63 eq(Settings.Secure.NEARBY_SHARING_COMPONENT) 64 ) 65 ).thenReturn(anotherNearby?.flattenToString()) 66 67 components = ChooserIntegratedDeviceComponents.get(testableContext, secureSettings) 68 69 assertThat(components.nearbySharingComponent).isEqualTo(anotherNearby) 70 } 71 } 72