Home | History | Annotate | Download | only in system
      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.system;
     18 
     19 import static com.google.common.truth.Truth.assertThat;
     20 import static org.mockito.Mockito.doReturn;
     21 import static org.mockito.Mockito.mock;
     22 import static org.mockito.Mockito.spy;
     23 import static org.mockito.Mockito.when;
     24 
     25 import android.content.Context;
     26 import android.os.UserManager;
     27 
     28 import com.android.settings.TestConfig;
     29 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     30 import com.android.settings.testutils.XmlTestUtils;
     31 import com.android.settings.testutils.shadow.SettingsShadowResources;
     32 import com.android.settings.testutils.shadow.ShadowUserManager;
     33 
     34 import org.junit.After;
     35 import org.junit.Before;
     36 import org.junit.Test;
     37 import org.junit.runner.RunWith;
     38 import org.robolectric.RuntimeEnvironment;
     39 import org.robolectric.annotation.Config;
     40 
     41 import java.util.List;
     42 
     43 @RunWith(SettingsRobolectricTestRunner.class)
     44 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
     45         shadows = {
     46                 ShadowUserManager.class,
     47                 SettingsShadowResources.class,
     48         })
     49 public class SystemDashboardFragmentTest {
     50 
     51     @Before
     52     public void setup() {
     53         SettingsShadowResources.overrideResource(
     54                 com.android.internal.R.bool.config_supportSystemNavigationKeys, true);
     55     }
     56 
     57     @After
     58     public void tearDown() {
     59         SettingsShadowResources.reset();
     60     }
     61 
     62     @Test
     63     public void testNonIndexableKeys_existInXmlLayout() {
     64         final Context context = spy(RuntimeEnvironment.application);
     65         UserManager manager = mock(UserManager.class);
     66         when(manager.isAdminUser()).thenReturn(false);
     67         doReturn(manager).when(context).getSystemService(Context.USER_SERVICE);
     68         final List<String> niks = SystemDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
     69                 .getNonIndexableKeys(context);
     70         final int xmlId = (new SystemDashboardFragment()).getPreferenceScreenResId();
     71 
     72         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
     73 
     74         assertThat(keys).containsAllIn(niks);
     75     }
     76 }
     77