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