1 /* 2 * Copyright (C) 2017 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.backup; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.app.Instrumentation; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.pm.PackageManager; 25 import android.content.pm.ResolveInfo; 26 27 import androidx.test.InstrumentationRegistry; 28 import androidx.test.filters.SmallTest; 29 import androidx.test.runner.AndroidJUnit4; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 import java.util.List; 36 37 @RunWith(AndroidJUnit4.class) 38 @SmallTest 39 public class BackupIntentTest { 40 private static final String INTENT_PRIVACY_SETTINGS = "android.settings.PRIVACY_SETTINGS"; 41 private static final String BACKUP_SETTINGS_ACTIVITY = 42 "com.android.settings.Settings$PrivacyDashboardActivity"; 43 44 private Context mContext; 45 46 @Before setUp()47 public void setUp() throws Exception { 48 Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 49 mContext = instrumentation.getTargetContext(); 50 } 51 52 @Test testPrivacySettingsIntentResolvesToOnlyOneActivity()53 public void testPrivacySettingsIntentResolvesToOnlyOneActivity(){ 54 PackageManager pm = mContext.getPackageManager(); 55 Intent intent = new Intent(INTENT_PRIVACY_SETTINGS); 56 List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); 57 assertThat(activities).isNotNull(); 58 assertThat(activities.size()).isEqualTo(1); 59 assertThat(activities.get(0).activityInfo.getComponentName().getClassName()). 60 isEqualTo(BACKUP_SETTINGS_ACTIVITY); 61 } 62 } 63