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.support; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.pm.PackageManager; 24 import android.content.pm.ResolveInfo; 25 26 import com.android.settings.R; 27 import com.android.settings.search.SearchIndexableRaw; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.robolectric.RobolectricTestRunner; 33 import org.robolectric.RuntimeEnvironment; 34 35 import java.util.List; 36 37 @RunWith(RobolectricTestRunner.class) 38 public class SupportDashboardActivityTest { 39 40 private Context mContext; 41 42 @Before setUp()43 public void setUp() { 44 mContext = RuntimeEnvironment.application; 45 } 46 47 @Test shouldIndexSearchActivityForSearch()48 public void shouldIndexSearchActivityForSearch() { 49 final List<SearchIndexableRaw> indexables = 50 SupportDashboardActivity.SEARCH_INDEX_DATA_PROVIDER 51 .getRawDataToIndex(mContext, true /* enabled */); 52 53 assertThat(indexables).hasSize(1); 54 55 final SearchIndexableRaw value = indexables.get(0); 56 57 assertThat(value.title).isEqualTo(mContext.getString(R.string.page_tab_title_support)); 58 assertThat(value.screenTitle).isEqualTo(mContext.getString(R.string.settings_label)); 59 assertThat(value.intentTargetPackage).isEqualTo(mContext.getPackageName()); 60 assertThat(value.intentTargetClass).isEqualTo(SupportDashboardActivity.class.getName()); 61 assertThat(value.intentAction).isEqualTo(Intent.ACTION_MAIN); 62 } 63 64 @Test shouldHandleIntentAction()65 public void shouldHandleIntentAction() { 66 PackageManager packageManager = mContext.getPackageManager(); 67 // Intent action used by setup wizard to start support settings 68 Intent intent = new Intent("com.android.settings.action.SUPPORT_SETTINGS"); 69 ResolveInfo resolveInfo = 70 packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); 71 assertThat(resolveInfo).isNotNull(); 72 assertThat(resolveInfo.activityInfo.name) 73 .isEqualTo(SupportDashboardActivity.class.getName()); 74 } 75 } 76