From 52c1ef3793aaab4fefaafc4e7446526dd21a46e2 Mon Sep 17 00:00:00 2001 From: Wenhui Yang Date: Tue, 20 Jun 2023 19:48:43 +0000 Subject: [PATCH] Add unit tests to AuthController Add unit tests for new BP "Not recognized" flow as discussed in ag/23717363. Fixes: 286993443 Test: atest AuthControllerTest Change-Id: Id5b35ab528f2c41b98aac8ab4cfa49a9108f4236 --- .../biometrics/AuthControllerTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java index b4a4a11a81a18..5cae23ce783a9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java @@ -491,6 +491,50 @@ public class AuthControllerTest extends SysuiTestCase { 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 modalityCaptor = ArgumentCaptor.forClass(Integer.class); + ArgumentCaptor 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 modalityCaptor = ArgumentCaptor.forClass(Integer.class); + ArgumentCaptor 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 public void testOnAuthenticationFailedInvoked_whenBiometricTimedOut() { showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */); @@ -1017,6 +1061,31 @@ public class AuthControllerTest extends SysuiTestCase { 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 int mBuildCount = 0; private PromptInfo mLastBiometricPromptInfo;