Remove security settings v1 code
Change-Id: I958ed1588009b91f64cd8ecb98208e72a891903e Fixes: 32953042 Test: robotests
This commit is contained in:
@@ -19,7 +19,6 @@ import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.search.SearchFeatureProviderImpl;
|
||||
import com.android.settings.search.XmlParserUtils;
|
||||
import com.android.settings.security.SecuritySettings;
|
||||
import com.android.settings.security.SecuritySettingsV2;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -32,7 +31,6 @@ import org.robolectric.annotation.Config;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -47,25 +45,13 @@ public class XmlControllerAttributeTest {
|
||||
// List of classes that are too hard to mock in order to retrieve xml information.
|
||||
private final List<Class> illegalClasses = new ArrayList<>(
|
||||
Arrays.asList(
|
||||
SecuritySettings.class,
|
||||
SecuritySettingsV2.class
|
||||
SecuritySettings.class
|
||||
));
|
||||
|
||||
// List of XML that could be retrieved from the illegalClasses list.
|
||||
private final List<Integer> whitelistXml = new ArrayList<>(
|
||||
Arrays.asList(
|
||||
R.xml.security_settings_misc,
|
||||
R.xml.security_settings_lockscreen_profile,
|
||||
R.xml.security_settings_lockscreen,
|
||||
R.xml.security_settings_chooser,
|
||||
R.xml.security_settings_pattern_profile,
|
||||
R.xml.security_settings_pin_profile,
|
||||
R.xml.security_settings_password_profile,
|
||||
R.xml.security_settings_pattern,
|
||||
R.xml.security_settings_pin,
|
||||
R.xml.security_settings_password,
|
||||
R.xml.security_settings,
|
||||
R.xml.security_settings_status
|
||||
R.xml.security_dashboard_settings
|
||||
));
|
||||
|
||||
private static final String NO_VALID_CONSTRUCTOR_ERROR =
|
||||
|
@@ -55,7 +55,7 @@ public class LockUnificationPreferenceControllerTest {
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private SecuritySettingsV2 mHost;
|
||||
private SecuritySettings mHost;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private Context mContext;
|
||||
|
@@ -16,192 +16,51 @@
|
||||
|
||||
package com.android.settings.security;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowTileUtils;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowLooper;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SecurityFeatureProviderImplTest {
|
||||
|
||||
private static final String MOCK_KEY = "key";
|
||||
private static final String MOCK_SUMMARY = "summary";
|
||||
private static final String URI_GET_SUMMARY = "content://package/text/summary";
|
||||
private static final String URI_GET_ICON = "content://package/icon/my_icon";
|
||||
|
||||
@Mock
|
||||
private Drawable mMockDrawable;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
|
||||
private SecurityFeatureProviderImpl mImpl;
|
||||
|
||||
@Before
|
||||
public void setUp() throws PackageManager.NameNotFoundException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mImpl = new SecurityFeatureProviderImpl();
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.getResourcesForApplication(anyString())).thenReturn(mResources);
|
||||
when(mResources.getDrawable(anyInt(), any())).thenReturn(mMockDrawable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateTilesData_shouldNotProcessEmptyScreenOrTiles() {
|
||||
mImpl.updatePreferencesToRunOnWorkerThread(mContext, null, null);
|
||||
ShadowLooper.runUiThreadTasks();
|
||||
mImpl.updatePreferencesToRunOnWorkerThread(
|
||||
mContext, new PreferenceScreen(mContext, null), null);
|
||||
ShadowLooper.runUiThreadTasks();
|
||||
verifyNoMoreInteractions(mPackageManager);
|
||||
public void getTrustAgentManager_shouldReturnCache() {
|
||||
final TrustAgentManager m1 = mImpl.getTrustAgentManager();
|
||||
final TrustAgentManager m2 = mImpl.getTrustAgentManager();
|
||||
|
||||
assertThat(m1).isSameAs(m2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateTilesData_shouldNotProcessNonMatchingPreference() {
|
||||
DashboardCategory dashboardCategory = new DashboardCategory();
|
||||
dashboardCategory.addTile(new Tile());
|
||||
mImpl.updatePreferencesToRunOnWorkerThread(
|
||||
mContext, getPreferenceScreen(), dashboardCategory);
|
||||
ShadowLooper.runUiThreadTasks();
|
||||
verifyNoMoreInteractions(mPackageManager);
|
||||
public void getLockPatternUtils_shouldReturnCache() {
|
||||
final LockPatternUtils l1 = mImpl.getLockPatternUtils(mContext);
|
||||
final LockPatternUtils l2 = mImpl.getLockPatternUtils(mContext);
|
||||
|
||||
assertThat(l1).isSameAs(l2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateTilesData_shouldNotProcessMatchingPreferenceWithNoData() {
|
||||
mImpl.updatePreferencesToRunOnWorkerThread(
|
||||
mContext, getPreferenceScreen(), getDashboardCategory());
|
||||
ShadowLooper.runUiThreadTasks();
|
||||
verifyNoMoreInteractions(mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowTileUtils.class,
|
||||
})
|
||||
public void updateTilesData_shouldUpdateMatchingPreference() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(TileUtils.META_DATA_PREFERENCE_ICON_URI, URI_GET_ICON);
|
||||
bundle.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, URI_GET_SUMMARY);
|
||||
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
DashboardCategory dashboardCategory = getDashboardCategory();
|
||||
dashboardCategory.getTile(0).intent = new Intent().setPackage("package");
|
||||
dashboardCategory.getTile(0).metaData = bundle;
|
||||
|
||||
mImpl.updatePreferencesToRunOnWorkerThread(mContext, screen, dashboardCategory);
|
||||
ShadowLooper.runUiThreadTasks();
|
||||
verify(screen.findPreference(MOCK_KEY)).setIcon(mMockDrawable);
|
||||
verify(screen.findPreference(MOCK_KEY)).setSummary(MOCK_SUMMARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowTileUtils.class,
|
||||
})
|
||||
public void updateTilesData_shouldNotUpdateAlreadyUpdatedPreference() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(TileUtils.META_DATA_PREFERENCE_ICON_URI, URI_GET_ICON);
|
||||
bundle.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, URI_GET_SUMMARY);
|
||||
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
when(screen.findPreference(MOCK_KEY).getSummary()).thenReturn(MOCK_SUMMARY);
|
||||
when(screen.findPreference(MOCK_KEY).getIcon()).thenReturn(mMockDrawable);
|
||||
|
||||
DashboardCategory dashboardCategory = getDashboardCategory();
|
||||
dashboardCategory.getTile(0).intent = new Intent().setPackage("package");
|
||||
dashboardCategory.getTile(0).metaData = bundle;
|
||||
|
||||
mImpl.updatePreferencesToRunOnWorkerThread(mContext, screen, dashboardCategory);
|
||||
ShadowLooper.runUiThreadTasks();
|
||||
verify(screen.findPreference(MOCK_KEY), never()).setSummary(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initPreferences_shouldLoadDefaults() {
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
DashboardCategory dashboardCategory = getDashboardCategory();
|
||||
dashboardCategory.getTile(0).metaData = new Bundle();
|
||||
|
||||
mImpl.initPreferences(mContext, screen, dashboardCategory);
|
||||
verify(screen.findPreference(MOCK_KEY)).setIcon(SecurityFeatureProviderImpl.DEFAULT_ICON);
|
||||
verify(screen.findPreference(MOCK_KEY))
|
||||
.setSummary(mContext.getString(R.string.summary_placeholder));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowTileUtils.class,
|
||||
})
|
||||
public void initPreferences_shouldLoadCached() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(TileUtils.META_DATA_PREFERENCE_ICON_URI, URI_GET_ICON);
|
||||
bundle.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, URI_GET_SUMMARY);
|
||||
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
DashboardCategory dashboardCategory = getDashboardCategory();
|
||||
dashboardCategory.getTile(0).metaData = bundle;
|
||||
|
||||
SecurityFeatureProviderImpl.sIconCache.put(
|
||||
URI_GET_ICON,
|
||||
ShadowTileUtils.getIconFromUri(null, null, null, null));
|
||||
SecurityFeatureProviderImpl.sSummaryCache.put(
|
||||
URI_GET_SUMMARY,
|
||||
MOCK_SUMMARY);
|
||||
|
||||
mImpl.initPreferences(mContext, screen, dashboardCategory);
|
||||
verify(screen.findPreference(MOCK_KEY)).setIcon(mMockDrawable);
|
||||
verify(screen.findPreference(MOCK_KEY)).setSummary(MOCK_SUMMARY);
|
||||
}
|
||||
|
||||
private PreferenceScreen getPreferenceScreen() {
|
||||
final PreferenceScreen screen = mock(PreferenceScreen.class);
|
||||
final Preference pref = mock(Preference.class);
|
||||
when(screen.findPreference(MOCK_KEY)).thenReturn(pref);
|
||||
when(pref.getKey()).thenReturn(MOCK_KEY);
|
||||
return screen;
|
||||
}
|
||||
|
||||
private static DashboardCategory getDashboardCategory() {
|
||||
DashboardCategory dashboardCategory = new DashboardCategory();
|
||||
Tile tile = new Tile();
|
||||
tile.key = MOCK_KEY;
|
||||
dashboardCategory.addTile(tile);
|
||||
return dashboardCategory;
|
||||
}
|
||||
}
|
||||
|
@@ -16,34 +16,18 @@
|
||||
|
||||
package com.android.settings.security;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.os.UserManager.EnforcingUser;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -51,123 +35,65 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
ShadowLockPatternUtils.class,
|
||||
ShadowUserManager.class,
|
||||
})
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SecuritySettingsTest {
|
||||
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
private SecuritySettings.SummaryProvider mSummaryProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest();
|
||||
when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
|
||||
.thenReturn(mFingerprintManager);
|
||||
|
||||
mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitTrustAgentPreference_secure_shouldSetSummaryToNumberOfTrustAgent() {
|
||||
final Preference preference = mock(Preference.class);
|
||||
final PreferenceScreen screen = mock(PreferenceScreen.class);
|
||||
when(screen.findPreference(SecuritySettings.KEY_MANAGE_TRUST_AGENTS))
|
||||
.thenReturn(preference);
|
||||
final LockPatternUtils utils = mock(LockPatternUtils.class);
|
||||
when(utils.isSecure(anyInt())).thenReturn(true);
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
final Activity activity = mock(Activity.class);
|
||||
when(activity.getResources()).thenReturn(context.getResources());
|
||||
final SecuritySettings securitySettings = spy(new SecuritySettings());
|
||||
when(securitySettings.getActivity()).thenReturn(activity);
|
||||
public void testSummaryProvider_notListening() {
|
||||
mSummaryProvider.setListening(false);
|
||||
|
||||
ReflectionHelpers.setField(securitySettings, "mLockPatternUtils", utils);
|
||||
|
||||
securitySettings.initTrustAgentPreference(screen, 0);
|
||||
verify(preference).setSummary(R.string.manage_trust_agents_summary);
|
||||
|
||||
securitySettings.initTrustAgentPreference(screen, 2);
|
||||
verify(preference).setSummary(context.getResources().getQuantityString(
|
||||
R.plurals.manage_trust_agents_summary_on, 2, 2));
|
||||
verifyNoMoreInteractions(mSummaryLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIndexableKeys_existInXmlLayout() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
UserManager manager = mock(UserManager.class);
|
||||
when(manager.isAdminUser()).thenReturn(false);
|
||||
doReturn(manager).when(context).getSystemService(Context.USER_SERVICE);
|
||||
final List<String> niks = SecuritySettings.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(context);
|
||||
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context,
|
||||
R.xml.security_settings_misc);
|
||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context,
|
||||
R.xml.location_settings));
|
||||
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context,
|
||||
R.xml.encryption_and_credential));
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
assertThat(keys).containsAllIn(niks);
|
||||
verify(mContext).getString(R.string.security_dashboard_summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnifyLockRestriction() {
|
||||
// Set up instance under test.
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
final SecuritySettings securitySettings = spy(new SecuritySettings());
|
||||
when(securitySettings.getContext()).thenReturn(context);
|
||||
public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(false);
|
||||
|
||||
final int userId = 123;
|
||||
ReflectionHelpers.setField(securitySettings, "mProfileChallengeUserId", userId);
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
final LockPatternUtils utils = mock(LockPatternUtils.class);
|
||||
when(utils.isSeparateProfileChallengeEnabled(userId)).thenReturn(true);
|
||||
ReflectionHelpers.setField(securitySettings, "mLockPatternUtils", utils);
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
|
||||
final RestrictedSwitchPreference unifyProfile = mock(RestrictedSwitchPreference.class);
|
||||
ReflectionHelpers.setField(securitySettings, "mUnifyProfile", unifyProfile);
|
||||
@Test
|
||||
public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoFingerprint() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
// Pretend that no admins enforce the restriction.
|
||||
ShadowUserManager.getShadow().setUserRestrictionSources(
|
||||
UserManager.DISALLOW_UNIFIED_PASSWORD,
|
||||
UserHandle.of(userId),
|
||||
Collections.emptyList());
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
securitySettings.updateUnificationPreference();
|
||||
|
||||
verify(unifyProfile).setDisabledByAdmin(null);
|
||||
|
||||
reset(unifyProfile);
|
||||
|
||||
// Pretend that the restriction is enforced by several admins. Having just one would
|
||||
// require more mocking of implementation details.
|
||||
final EnforcingUser enforcer1 = new EnforcingUser(
|
||||
userId, UserManager.RESTRICTION_SOURCE_PROFILE_OWNER);
|
||||
final EnforcingUser enforcer2 = new EnforcingUser(
|
||||
UserHandle.USER_SYSTEM, UserManager.RESTRICTION_SOURCE_DEVICE_OWNER);
|
||||
ShadowUserManager.getShadow().setUserRestrictionSources(
|
||||
UserManager.DISALLOW_UNIFIED_PASSWORD,
|
||||
UserHandle.of(userId),
|
||||
Arrays.asList(enforcer1, enforcer2));
|
||||
|
||||
securitySettings.updateUnificationPreference();
|
||||
|
||||
verify(unifyProfile).setDisabledByAdmin(EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN);
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
}
|
||||
|
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.security;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SecuritySettingsV2Test {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
private SecuritySettings.SummaryProvider mSummaryProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
|
||||
.thenReturn(mFingerprintManager);
|
||||
|
||||
mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_notListening() {
|
||||
mSummaryProvider.setListening(false);
|
||||
|
||||
verifyNoMoreInteractions(mSummaryLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoFingerprint() {
|
||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
||||
.thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
||||
}
|
||||
}
|
@@ -40,7 +40,7 @@ import android.support.v7.preference.PreferenceScreen;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.security.SecuritySettingsV2;
|
||||
import com.android.settings.security.SecuritySettings;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -69,7 +69,7 @@ public class TrustAgentListPreferenceControllerTest {
|
||||
@Mock
|
||||
private PreferenceCategory mCategory;
|
||||
@Mock
|
||||
private SecuritySettingsV2 mFragment;
|
||||
private SecuritySettings mFragment;
|
||||
|
||||
private Lifecycle mLifecycle;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
|
Reference in New Issue
Block a user