• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.settings.applications;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 import static org.mockito.Mockito.spy;
20 
21 import android.content.Context;
22 import android.provider.SearchIndexableResource;
23 
24 import com.android.settings.R;
25 import com.android.settings.testutils.SettingsRobolectricTestRunner;
26 
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.MockitoAnnotations;
31 import org.robolectric.RuntimeEnvironment;
32 import org.robolectric.annotation.Config;
33 
34 import java.util.List;
35 
36 @RunWith(SettingsRobolectricTestRunner.class)
37 public class SpecialAccessSettingsTest {
38 
39   private Context mContext;
40   private SpecialAccessSettings mFragment;
41 
42   @Before
setUp()43   public void setUp() {
44     MockitoAnnotations.initMocks(this);
45     mContext = spy(RuntimeEnvironment.application);
46     mFragment = new SpecialAccessSettings() {
47       @Override
48       public Context getContext() {
49         return mContext;
50       }
51     };
52   }
53 
54   @Test
testSearchIndexProvider_shouldIndexResource()55   public void testSearchIndexProvider_shouldIndexResource() {
56     final List<SearchIndexableResource> indexRes =
57             SpecialAccessSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext,
58                     true /* enabled */);
59     final List<String> niks =
60             SpecialAccessSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
61 
62     assertThat(indexRes).isNotNull();
63     assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.special_access);
64     assertThat(niks).isEmpty();
65   }
66 
67   @Test
68   @Config(qualifiers = "mcc999")
testSearchIndexProvider_ifElementsAreNotShown_shouldNotBeIndexed()69   public void testSearchIndexProvider_ifElementsAreNotShown_shouldNotBeIndexed() {
70     final List<String> niks =
71             SpecialAccessSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
72 
73     assertThat(niks).contains(HighPowerAppsController.KEY_HIGH_POWER_APPS);
74     assertThat(niks).contains(DeviceAdministratorsController.KEY_DEVICE_ADMIN);
75     assertThat(niks).contains(PremiumSmsController.KEY_PREMIUM_SMS);
76     assertThat(niks).contains(DataSaverController.KEY_DATA_SAVER);
77     assertThat(niks).contains(EnabledVrListenersController.KEY_ENABLED_VR_LISTENERS);
78   }
79 }