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.suggestions; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.annotation.StringRes; 22 import android.content.ComponentName; 23 import android.content.Context; 24 import android.content.pm.ActivityInfo; 25 import android.content.pm.PackageManager; 26 import android.content.pm.PackageManager.NameNotFoundException; 27 import android.content.res.Resources; 28 29 import com.android.settings.R; 30 import com.android.settings.Settings; 31 import com.android.settings.fingerprint.FingerprintEnrollSuggestionActivity; 32 import com.android.settings.fingerprint.FingerprintSuggestionActivity; 33 import com.android.settings.notification.ZenOnboardingActivity; 34 import com.android.settings.notification.ZenSuggestionActivity; 35 import com.android.settings.support.NewDeviceIntroSuggestionActivity; 36 import com.android.settings.testutils.SettingsRobolectricTestRunner; 37 import com.android.settings.wallpaper.WallpaperSuggestionActivity; 38 import com.android.settings.wifi.calling.WifiCallingSuggestionActivity; 39 40 import org.junit.Test; 41 import org.junit.runner.RunWith; 42 import org.robolectric.RuntimeEnvironment; 43 44 @RunWith(SettingsRobolectricTestRunner.class) 45 public class SettingsSuggestionsTest { 46 47 @Test 48 public void wallpaperSuggestion_isValid() { 49 assertSuggestionEquals( 50 WallpaperSuggestionActivity.class.getName(), 51 R.string.wallpaper_suggestion_title, 52 R.string.wallpaper_suggestion_summary); 53 } 54 55 @Test 56 public void fingerprintSuggestion_isValid() { 57 assertSuggestionEquals( 58 FingerprintSuggestionActivity.class.getName(), 59 R.string.suggestion_additional_fingerprints, 60 R.string.suggestion_additional_fingerprints_summary); 61 } 62 63 @Test 64 public void fingerprintEnrollSuggestion_isValid() { 65 assertSuggestionEquals( 66 FingerprintEnrollSuggestionActivity.class.getName(), 67 R.string.suggested_fingerprint_lock_settings_title, 68 R.string.suggested_fingerprint_lock_settings_summary); 69 } 70 71 @Test 72 public void wifiCallingSuggestion_isValid() { 73 assertSuggestionEquals( 74 WifiCallingSuggestionActivity.class.getName(), 75 R.string.wifi_calling_suggestion_title, 76 R.string.wifi_calling_suggestion_summary); 77 } 78 79 @Test 80 public void nightDisplaySuggestion_isValid() { 81 assertSuggestionEquals( 82 Settings.NightDisplaySuggestionActivity.class.getName(), 83 R.string.night_display_suggestion_title, 84 R.string.night_display_suggestion_summary); 85 } 86 87 @Test 88 public void zenSuggestion_isValid() { 89 assertSuggestionEquals( 90 ZenSuggestionActivity.class.getName(), 91 R.string.zen_suggestion_title, 92 R.string.zen_suggestion_summary); 93 } 94 95 @Test 96 public void newDeviceIntroSuggestion_isValid() { 97 assertSuggestionEquals( 98 NewDeviceIntroSuggestionActivity.class.getName(), 99 R.string.new_device_suggestion_title, 100 R.string.new_device_suggestion_summary); 101 } 102 103 private void assertSuggestionEquals(String activityName, @StringRes int titleRes, 104 @StringRes int summaryRes) { 105 106 final Context context = RuntimeEnvironment.application; 107 final PackageManager pm = context.getPackageManager(); 108 final ComponentName componentName = new ComponentName(context, activityName); 109 final ActivityInfo info; 110 try { 111 info = pm.getActivityInfo(componentName, PackageManager.GET_META_DATA); 112 } catch (NameNotFoundException e) { 113 throw new RuntimeException(e); 114 } 115 116 final String pName = context.getPackageName(); 117 final Resources resources = context.getResources(); 118 119 final String title = (String) info.metaData.get("com.android.settings.title"); 120 final String actualTitle = 121 context.getString(resources.getIdentifier(title.substring(8), "string", pName)); 122 final String expectedTitle = context.getString(titleRes); 123 assertThat(actualTitle).isEqualTo(expectedTitle); 124 125 final String summary = (String) info.metaData.get("com.android.settings.summary"); 126 final String actualSummary = 127 context.getString(resources.getIdentifier(summary.substring(8), "string", pName)); 128 final String expectedSummary = context.getString(summaryRes); 129 assertThat(actualSummary).isEqualTo(expectedSummary); 130 } 131 } 132