Merge "Add unit tests to AuthController" into udc-d1-dev am: 6efc35cee7
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23986715 Change-Id: Iacfe6b88c9aad0cdc2f819bf0c6564f5c14f4735 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -491,6 +491,50 @@ public class AuthControllerTest extends SysuiTestCase {
|
|||||||
mContext.getString(R.string.biometric_not_recognized));
|
mContext.getString(R.string.biometric_not_recognized));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnAuthenticationFailedInvoked_whenFaceAuthRejected() throws RemoteException {
|
||||||
|
final int modality = BiometricAuthenticator.TYPE_FACE;
|
||||||
|
final int userId = 0;
|
||||||
|
|
||||||
|
enrollFingerprintAndFace(userId);
|
||||||
|
|
||||||
|
showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */);
|
||||||
|
|
||||||
|
mAuthController.onBiometricError(modality,
|
||||||
|
BiometricConstants.BIOMETRIC_PAUSED_REJECTED,
|
||||||
|
0 /* vendorCode */);
|
||||||
|
|
||||||
|
ArgumentCaptor<Integer> modalityCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||||
|
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
|
verify(mDialog1).onAuthenticationFailed(modalityCaptor.capture(), messageCaptor.capture());
|
||||||
|
|
||||||
|
assertEquals(modalityCaptor.getValue().intValue(), modality);
|
||||||
|
assertEquals(messageCaptor.getValue(),
|
||||||
|
mContext.getString(R.string.biometric_face_not_recognized));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnAuthenticationFailedInvoked_whenFingerprintAuthRejected() {
|
||||||
|
final int modality = BiometricAuthenticator.TYPE_FINGERPRINT;
|
||||||
|
final int userId = 0;
|
||||||
|
|
||||||
|
enrollFingerprintAndFace(userId);
|
||||||
|
|
||||||
|
showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */);
|
||||||
|
|
||||||
|
mAuthController.onBiometricError(modality,
|
||||||
|
BiometricConstants.BIOMETRIC_PAUSED_REJECTED,
|
||||||
|
0 /* vendorCode */);
|
||||||
|
|
||||||
|
ArgumentCaptor<Integer> modalityCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||||
|
ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
|
verify(mDialog1).onAuthenticationFailed(modalityCaptor.capture(), messageCaptor.capture());
|
||||||
|
|
||||||
|
assertEquals(modalityCaptor.getValue().intValue(), modality);
|
||||||
|
assertEquals(messageCaptor.getValue(),
|
||||||
|
mContext.getString(R.string.fingerprint_error_not_match));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnAuthenticationFailedInvoked_whenBiometricTimedOut() {
|
public void testOnAuthenticationFailedInvoked_whenBiometricTimedOut() {
|
||||||
showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */);
|
showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */);
|
||||||
@@ -998,6 +1042,31 @@ public class AuthControllerTest extends SysuiTestCase {
|
|||||||
return HAT;
|
return HAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enrollFingerprintAndFace(final int userId) {
|
||||||
|
|
||||||
|
// Enroll fingerprint
|
||||||
|
verify(mFingerprintManager).registerBiometricStateListener(
|
||||||
|
mBiometricStateCaptor.capture());
|
||||||
|
assertFalse(mAuthController.isFingerprintEnrolled(userId));
|
||||||
|
|
||||||
|
mBiometricStateCaptor.getValue().onEnrollmentsChanged(userId,
|
||||||
|
1 /* sensorId */, true /* hasEnrollments */);
|
||||||
|
waitForIdleSync();
|
||||||
|
|
||||||
|
assertTrue(mAuthController.isFingerprintEnrolled(userId));
|
||||||
|
|
||||||
|
// Enroll face
|
||||||
|
verify(mFaceManager).registerBiometricStateListener(
|
||||||
|
mBiometricStateCaptor.capture());
|
||||||
|
assertFalse(mAuthController.isFaceAuthEnrolled(userId));
|
||||||
|
|
||||||
|
mBiometricStateCaptor.getValue().onEnrollmentsChanged(userId,
|
||||||
|
2 /* sensorId */, true /* hasEnrollments */);
|
||||||
|
waitForIdleSync();
|
||||||
|
|
||||||
|
assertTrue(mAuthController.isFaceAuthEnrolled(userId));
|
||||||
|
}
|
||||||
|
|
||||||
private final class TestableAuthController extends AuthController {
|
private final class TestableAuthController extends AuthController {
|
||||||
private int mBuildCount = 0;
|
private int mBuildCount = 0;
|
||||||
private PromptInfo mLastBiometricPromptInfo;
|
private PromptInfo mLastBiometricPromptInfo;
|
||||||
|
|||||||
Reference in New Issue
Block a user