Add tests for some security setting controllers
Bug: 32953042 Test: robotests Change-Id: Ieab4e6434bbb80313f6d1b25ff1cdea5713038f0
This commit is contained in:
@@ -1222,7 +1222,7 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
|
|
||||||
public static FingerprintManager getFingerprintManagerOrNull(Context context) {
|
public static FingerprintManager getFingerprintManagerOrNull(Context context) {
|
||||||
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
|
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
|
||||||
return context.getSystemService(FingerprintManager.class);
|
return (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.security;
|
package com.android.settings.fingerprint;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.security;
|
package com.android.settings.fingerprint;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -28,8 +28,6 @@ import com.android.internal.widget.LockPatternUtils;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.fingerprint.FingerprintEnrollIntroduction;
|
|
||||||
import com.android.settings.fingerprint.FingerprintSettings;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
@@ -16,8 +16,11 @@ import com.android.settings.dashboard.DashboardFragment;
|
|||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
|
import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
|
||||||
import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
|
import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
|
||||||
|
import com.android.settings.fingerprint.FingerprintProfileStatusPreferenceController;
|
||||||
|
import com.android.settings.fingerprint.FingerprintStatusPreferenceController;
|
||||||
import com.android.settings.location.LocationPreferenceController;
|
import com.android.settings.location.LocationPreferenceController;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.security.screenlock.LockScreenPreferenceController;
|
||||||
import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
|
import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
|
||||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||||
import com.android.settings.widget.PreferenceCategoryController;
|
import com.android.settings.widget.PreferenceCategoryController;
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.security;
|
package com.android.settings.security.screenlock;
|
||||||
|
|
||||||
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||||
|
|
@@ -58,7 +58,8 @@ public class FingerprintEnrollSuggestionActivityTest {
|
|||||||
.thenReturn(mDevicePolicyManager);
|
.thenReturn(mDevicePolicyManager);
|
||||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(), anyInt()))
|
when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(), anyInt()))
|
||||||
.thenReturn(0);
|
.thenReturn(0);
|
||||||
when(mContext.getSystemService(FingerprintManager.class)).thenReturn(mFingerprintManager);
|
when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
|
||||||
|
.thenReturn(mFingerprintManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* 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.fingerprint;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
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.ShadowApplication;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class FingerprintProfileStatusPreferenceControllerTest {
|
||||||
|
|
||||||
|
private static final int FAKE_PROFILE_USER_ID = 1234;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private PackageManager mPackageManager;
|
||||||
|
@Mock
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
@Mock
|
||||||
|
private FingerprintManager mFingerprintManager;
|
||||||
|
@Mock
|
||||||
|
private UserManager mUm;
|
||||||
|
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
private FingerprintProfileStatusPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
|
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.FINGERPRINT_SERVICE,
|
||||||
|
mFingerprintManager);
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
|
||||||
|
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||||
|
.thenReturn(mLockPatternUtils);
|
||||||
|
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
|
||||||
|
mController = new FingerprintProfileStatusPreferenceController(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUserId_shouldReturnProfileId() {
|
||||||
|
assertThat(mController.getUserId()).isEqualTo(FAKE_PROFILE_USER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isUserSupported_separateChallengeAllowed_true() {
|
||||||
|
when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(true);
|
||||||
|
assertThat(mController.isUserSupported()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isUserSupported_separateChallengeNotAllowed_false() {
|
||||||
|
when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.isUserSupported()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_userNotSupported_DISABLED() {
|
||||||
|
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||||
|
when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* 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.fingerprint;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.DISABLED_UNSUPPORTED;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.hardware.fingerprint.Fingerprint;
|
||||||
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
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.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class FingerprintStatusPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
@Mock
|
||||||
|
private FingerprintManager mFingerprintManager;
|
||||||
|
@Mock
|
||||||
|
private UserManager mUm;
|
||||||
|
@Mock
|
||||||
|
private PackageManager mPackageManager;
|
||||||
|
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
private FingerprintStatusPreferenceController mController;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
|
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.FINGERPRINT_SERVICE,
|
||||||
|
mFingerprintManager);
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||||
|
.thenReturn(mLockPatternUtils);
|
||||||
|
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
|
||||||
|
mController = new FingerprintStatusPreferenceController(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_noFingerprintManger_DISABLED() {
|
||||||
|
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_hasFingerprintManger_AVAILABLE() {
|
||||||
|
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_notSupported_shouldDoNothing() {
|
||||||
|
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.isVisible()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_noFingerprint_shouldShowDefaultSummary() {
|
||||||
|
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo(
|
||||||
|
mContext.getString(R.string.security_settings_fingerprint_preference_summary_none));
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
|
assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_hasFingerprint_shouldShowSummary() {
|
||||||
|
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||||
|
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||||
|
.thenReturn(Arrays.asList(mock(Fingerprint.class)));
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources().getQuantityString(
|
||||||
|
R.plurals.security_settings_fingerprint_preference_summary, 1, 1));
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
|
assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
|
||||||
|
}
|
||||||
|
}
|
@@ -59,8 +59,7 @@ public class SwipeToNotificationPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mController = new SwipeToNotificationPreferenceController(mContext, null, KEY_SWIPE_DOWN);
|
mController = new SwipeToNotificationPreferenceController(mContext, null, KEY_SWIPE_DOWN);
|
||||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
// Explicit casting to object due to MockitoCast bug
|
when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
|
||||||
when((Object) mContext.getSystemService(FingerprintManager.class))
|
|
||||||
.thenReturn(mFingerprintManager);
|
.thenReturn(mFingerprintManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
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.ShadowApplication;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class LockUnificationPreferenceControllerTest {
|
||||||
|
|
||||||
|
private static final int FAKE_PROFILE_USER_ID = 1234;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
@Mock
|
||||||
|
private UserManager mUm;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
@Mock
|
||||||
|
private SecuritySettingsV2 mHost;
|
||||||
|
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
private LockUnificationPreferenceController mController;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
|
||||||
|
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
|
||||||
|
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||||
|
.thenReturn(mLockPatternUtils);
|
||||||
|
|
||||||
|
mController = new LockUnificationPreferenceController(mContext, mHost);
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||||
|
.thenReturn(mPreference);
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_noProfile_false() {
|
||||||
|
ReflectionHelpers.setField(mController, "mProfileChallengeUserId", UserHandle.USER_NULL);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_separateChallengeNotAllowed_false() {
|
||||||
|
when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_separateChallengeAllowed_true() {
|
||||||
|
when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
}
|
@@ -23,13 +23,10 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.reset;
|
import static org.mockito.Mockito.reset;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.hardware.fingerprint.FingerprintManager;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.os.UserManager.EnforcingUser;
|
import android.os.UserManager.EnforcingUser;
|
||||||
@@ -86,54 +83,6 @@ public class SecuritySettingsTest {
|
|||||||
mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
|
mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSummaryProvider_notListening() {
|
|
||||||
mSummaryProvider.setListening(false);
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(mSummaryLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
|
|
||||||
final FingerprintManager fpm = mock(FingerprintManager.class);
|
|
||||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
|
||||||
.thenReturn(true);
|
|
||||||
|
|
||||||
// Cast to Object to workaround a robolectric casting bug
|
|
||||||
when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
|
|
||||||
when(fpm.isHardwareDetected()).thenReturn(true);
|
|
||||||
|
|
||||||
mSummaryProvider.setListening(true);
|
|
||||||
|
|
||||||
verify(mContext).getString(R.string.security_dashboard_summary);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
|
|
||||||
final FingerprintManager fpm = mock(FingerprintManager.class);
|
|
||||||
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() {
|
|
||||||
final FingerprintManager fpm = mock(FingerprintManager.class);
|
|
||||||
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
|
||||||
.thenReturn(true);
|
|
||||||
|
|
||||||
// Cast to Object to workaround a robolectric casting bug
|
|
||||||
when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
|
|
||||||
when(fpm.isHardwareDetected()).thenReturn(false);
|
|
||||||
|
|
||||||
mSummaryProvider.setListening(true);
|
|
||||||
|
|
||||||
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitTrustAgentPreference_secure_shouldSetSummaryToNumberOfTrustAgent() {
|
public void testInitTrustAgentPreference_secure_shouldSetSummaryToNumberOfTrustAgent() {
|
||||||
final Preference preference = mock(Preference.class);
|
final Preference preference = mock(Preference.class);
|
||||||
|
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* 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 android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
|
||||||
|
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
|
||||||
|
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
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.ShadowApplication;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class VisiblePatternProfilePreferenceControllerTest {
|
||||||
|
|
||||||
|
private static final int FAKE_PROFILE_USER_ID = 1234;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private PackageManager mPackageManager;
|
||||||
|
@Mock
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
@Mock
|
||||||
|
private FingerprintManager mFingerprintManager;
|
||||||
|
@Mock
|
||||||
|
private UserManager mUm;
|
||||||
|
|
||||||
|
private Lifecycle mLifecycle;
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
private VisiblePatternProfilePreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
|
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.FINGERPRINT_SERVICE,
|
||||||
|
mFingerprintManager);
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
|
||||||
|
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||||
|
.thenReturn(mLockPatternUtils);
|
||||||
|
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
|
||||||
|
|
||||||
|
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||||
|
mController = new VisiblePatternProfilePreferenceController(mContext, mLifecycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_notSecure_DISABLED() {
|
||||||
|
when(mLockPatternUtils.isSecure(FAKE_PROFILE_USER_ID)).thenReturn(false);
|
||||||
|
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(FAKE_PROFILE_USER_ID))
|
||||||
|
.thenReturn(PASSWORD_QUALITY_UNSPECIFIED);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_secureWithPassword_DISABLED() {
|
||||||
|
when(mLockPatternUtils.isSecure(FAKE_PROFILE_USER_ID)).thenReturn(true);
|
||||||
|
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(FAKE_PROFILE_USER_ID))
|
||||||
|
.thenReturn(PASSWORD_QUALITY_ALPHABETIC);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_secureWithPattern_AVAILABLE() {
|
||||||
|
when(mLockPatternUtils.isSecure(FAKE_PROFILE_USER_ID)).thenReturn(true);
|
||||||
|
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(FAKE_PROFILE_USER_ID))
|
||||||
|
.thenReturn(PASSWORD_QUALITY_SOMETHING);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* 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.screenlock;
|
||||||
|
|
||||||
|
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
|
||||||
|
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||||
|
import static android.arch.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
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.ShadowApplication;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class LockScreenPreferenceControllerTest {
|
||||||
|
|
||||||
|
private static final int FAKE_PROFILE_USER_ID = 1234;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
@Mock
|
||||||
|
private UserManager mUm;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private Lifecycle mLifecycle;
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
private LockScreenPreferenceController mController;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
|
||||||
|
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||||
|
.thenReturn(mLockPatternUtils);
|
||||||
|
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||||
|
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||||
|
mController = new LockScreenPreferenceController(mContext, mLifecycle);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_notSecure_lockscreenDisabled_DISABLED() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
||||||
|
when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_notSecure_lockscreenEnabled_AVAILABLE() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
||||||
|
when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_secure_hasLockScreen_AVAILABLE() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||||
|
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
|
||||||
|
.thenReturn(PASSWORD_QUALITY_ALPHABETIC);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_secure_noLockScreen_DISABLED() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||||
|
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
|
||||||
|
.thenReturn(PASSWORD_QUALITY_UNSPECIFIED);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onResume_available_shouldShow() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||||
|
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
|
||||||
|
.thenReturn(PASSWORD_QUALITY_ALPHABETIC);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||||
|
|
||||||
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onResume_unavailable_shouldHide() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||||
|
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
|
||||||
|
.thenReturn(PASSWORD_QUALITY_UNSPECIFIED);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||||
|
|
||||||
|
assertThat(mPreference.isVisible()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user