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 21 import static org.mockito.ArgumentMatchers.any; 22 import static org.mockito.Mockito.never; 23 import static org.mockito.Mockito.spy; 24 import static org.mockito.Mockito.verify; 25 import static org.mockito.Mockito.when; 26 27 import android.content.Context; 28 import android.os.Bundle; 29 30 import com.android.settings.aware.AwareFeatureProvider; 31 import com.android.settings.testutils.FakeFeatureFactory; 32 import com.android.settings.testutils.XmlTestUtils; 33 import com.android.settings.testutils.shadow.SettingsShadowResources; 34 import com.android.settings.testutils.shadow.ShadowUserManager; 35 36 import org.junit.After; 37 import org.junit.Before; 38 import org.junit.Test; 39 import org.junit.runner.RunWith; 40 import org.robolectric.RobolectricTestRunner; 41 import org.robolectric.RuntimeEnvironment; 42 import org.robolectric.annotation.Config; 43 44 import java.util.List; 45 46 @RunWith(RobolectricTestRunner.class) 47 @Config(shadows = {SettingsShadowResources.class, ShadowUserManager.class}) 48 public class SystemDashboardFragmentTest { 49 50 private Context mContext; 51 private SystemDashboardFragment mFragment; 52 53 @Before setup()54 public void setup() { 55 SettingsShadowResources.overrideResource( 56 com.android.internal.R.bool.config_supportSystemNavigationKeys, true); 57 ShadowUserManager.getShadow().setIsAdminUser(true); 58 mContext = RuntimeEnvironment.application; 59 mFragment = spy(new SystemDashboardFragment()); 60 when(mFragment.getContext()).thenReturn(mContext); 61 } 62 63 @After tearDown()64 public void tearDown() { 65 SettingsShadowResources.reset(); 66 } 67 68 @Test testNonIndexableKeys_existInXmlLayout()69 public void testNonIndexableKeys_existInXmlLayout() { 70 final List<String> niks = SystemDashboardFragment.SEARCH_INDEX_DATA_PROVIDER 71 .getNonIndexableKeys(mContext); 72 final int xmlId = (new SystemDashboardFragment()).getPreferenceScreenResId(); 73 74 final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId); 75 76 assertThat(keys).containsAtLeastElementsIn(niks); 77 } 78 79 @Test showRestrictionDialog_hasValidExtra_shouldShowDialog()80 public void showRestrictionDialog_hasValidExtra_shouldShowDialog() { 81 final AwareFeatureProvider mProvider = 82 FakeFeatureFactory.setupForTest().mAwareFeatureProvider; 83 final Bundle bundle = new Bundle(); 84 bundle.putBoolean(SystemDashboardFragment.EXTRA_SHOW_AWARE_DISABLED, true); 85 when(mFragment.getArguments()).thenReturn(bundle); 86 87 mFragment.showRestrictionDialog(); 88 89 verify(mProvider).showRestrictionDialog(any()); 90 } 91 92 @Test showRestrictionDialog_hasInvalidExtra_shouldNotShowDialog()93 public void showRestrictionDialog_hasInvalidExtra_shouldNotShowDialog() { 94 final AwareFeatureProvider mProvider = 95 FakeFeatureFactory.setupForTest().mAwareFeatureProvider; 96 97 mFragment.showRestrictionDialog(); 98 99 verify(mProvider, never()).showRestrictionDialog(any()); 100 } 101 } 102