Use correct category key for SecurityAdvancedSettings
based on the type of active Security Settings Test: atest SettingsUnitTests:SecurityAdvancedSettingsTest Bug: 206001340 Change-Id: I7bdac4b26653eedb45e3e2f056e6804a6c16cb18
This commit is contained in:
@@ -18,13 +18,18 @@ package com.android.settings.security;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
@@ -35,6 +40,9 @@ import org.junit.runner.RunWith;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SecurityAdvancedSettingsTest {
|
||||
private static final String SCREEN_XML_RESOURCE_NAME = "security_advanced_settings";
|
||||
private static final String ALTERNATIVE_CATEGORY_KEY = "alternative_category_key";
|
||||
private static final String LEGACY_CATEGORY_KEY =
|
||||
"com.android.settings.category.ia.legacy_advanced_security";
|
||||
|
||||
private Context mContext;
|
||||
private SecurityAdvancedSettings mSecurityAdvancedSettings;
|
||||
@@ -58,12 +66,51 @@ public class SecurityAdvancedSettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenCalled_returnsSecurity() {
|
||||
public void getCategoryKey_whenSafetyCenterIsEnabled_returnsSecurity() {
|
||||
setSafetyCenterEnabled(true);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
.isEqualTo(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenAlternativeFragmentPresented_returnsAlternative() {
|
||||
setSafetyCenterEnabled(false);
|
||||
setupAlternativeFragment(true, ALTERNATIVE_CATEGORY_KEY);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
.isEqualTo(ALTERNATIVE_CATEGORY_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenNoAlternativeFragmentPresented_returnsLegacy() {
|
||||
setSafetyCenterEnabled(false);
|
||||
setupAlternativeFragment(false, null);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
.isEqualTo(LEGACY_CATEGORY_KEY);
|
||||
}
|
||||
|
||||
private int getXmlResId(String resName) {
|
||||
return ResourcesUtils.getResourcesId(mContext, "xml", resName);
|
||||
}
|
||||
|
||||
private void setSafetyCenterEnabled(boolean isEnabled) {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(isEnabled),
|
||||
/* makeDefault = */ false);
|
||||
}
|
||||
|
||||
private void setupAlternativeFragment(boolean hasAlternativeFragment,
|
||||
String alternativeCategoryKey) {
|
||||
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(fakeFeatureFactory.securitySettingsFeatureProvider
|
||||
.hasAlternativeSecuritySettingsFragment())
|
||||
.thenReturn(hasAlternativeFragment);
|
||||
when(fakeFeatureFactory.securitySettingsFeatureProvider
|
||||
.getAlternativeAdvancedSettingsCategoryKey())
|
||||
.thenReturn(alternativeCategoryKey);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user