Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1ac88f78 authored by Grace Cheng's avatar Grace Cheng Committed by Android (Google) Code Review
Browse files

Merge "Add missing CUJs to PromptViewModelTest" into main

parents a3351585 e23b3ac4
Loading
Loading
Loading
Loading
+215 −141
Original line number Original line Diff line number Diff line
@@ -449,8 +449,71 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
    }
    }


    @Test
    @Test
    fun shows_authenticated_no_errors_no_confirmation_required() = runGenericTest {
    fun shows_error_to_unlock_or_success() {
        // Face-only auth does not use error -> unlock or error -> success assets
        if (testCase.isFingerprintOnly || testCase.isCoex) {
            runGenericTest {
                // Distinct asset for error -> success only applicable for fingerprint-only /
                // explicit co-ex auth
                val iconAsset by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val iconContentDescriptionId by
                    collectLastValue(kosmos.promptViewModel.iconViewModel.contentDescriptionId)
                val shouldAnimateIconView by
                    collectLastValue(kosmos.promptViewModel.iconViewModel.shouldAnimateIconView)

                var forceExplicitFlow =
                    testCase.isCoex && testCase.confirmationRequested ||
                        testCase.authenticatedByFingerprint
                if (forceExplicitFlow) {
                    kosmos.promptViewModel.ensureFingerprintHasStarted(isDelayed = true)
                }
                verifyIconSize(forceExplicitFlow)

                kosmos.promptViewModel.ensureFingerprintHasStarted(isDelayed = true)
                kosmos.promptViewModel.iconViewModel.setPreviousIconWasError(true)

                kosmos.promptViewModel.showAuthenticated(
                    modality = testCase.authenticatedModality,
                    dismissAfterDelay = DELAY
                )

                // TODO(b/350121748): SFPS test cases to be added after SFPS assets update
                if (testCase.sensorType != FingerprintSensorProperties.TYPE_POWER_BUTTON) {
                    // Non-SFPS (UDFPS / rear-FPS) test cases
                    // Covers (1) fingerprint-only (2) co-ex, authenticated by fingerprint
                    if (testCase.authenticatedByFingerprint) {
                        assertThat(iconAsset)
                            .isEqualTo(R.raw.fingerprint_dialogue_error_to_success_lottie)
                        assertThat(iconContentDescriptionId)
                            .isEqualTo(R.string.fingerprint_dialog_touch_sensor)
                        assertThat(shouldAnimateIconView).isEqualTo(true)
                    } else { //  co-ex, authenticated by face
                        assertThat(iconAsset)
                            .isEqualTo(R.raw.fingerprint_dialogue_error_to_unlock_lottie)
                        assertThat(iconContentDescriptionId)
                            .isEqualTo(R.string.fingerprint_dialog_authenticated_confirmation)
                        assertThat(shouldAnimateIconView).isEqualTo(true)

                        // Confirm authentication
                        kosmos.promptViewModel.confirmAuthenticated()

                        assertThat(iconAsset)
                            .isEqualTo(
                                R.raw.fingerprint_dialogue_unlocked_to_checkmark_success_lottie
                            )
                        assertThat(iconContentDescriptionId)
                            .isEqualTo(R.string.fingerprint_dialog_touch_sensor)
                        assertThat(shouldAnimateIconView).isEqualTo(true)
                    }
                }
            }
        }
    }

    @Test
    fun shows_authenticated_no_errors_no_confirmation_required() {
        if (!testCase.confirmationRequested) {
        if (!testCase.confirmationRequested) {
            runGenericTest {
                val iconAsset by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val iconAsset by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val iconOverlayAsset by
                val iconOverlayAsset by
                    collectLastValue(kosmos.promptViewModel.iconViewModel.iconOverlayAsset)
                    collectLastValue(kosmos.promptViewModel.iconViewModel.iconOverlayAsset)
@@ -472,7 +535,9 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
                    if (testCase.sensorType == FingerprintSensorProperties.TYPE_POWER_BUTTON) {
                    if (testCase.sensorType == FingerprintSensorProperties.TYPE_POWER_BUTTON) {
                        assertThat(iconAsset).isEqualTo(getSfpsBaseIconAsset())
                        assertThat(iconAsset).isEqualTo(getSfpsBaseIconAsset())
                        assertThat(iconOverlayAsset)
                        assertThat(iconOverlayAsset)
                        .isEqualTo(R.raw.biometricprompt_symbol_fingerprint_to_success_landscape)
                            .isEqualTo(
                                R.raw.biometricprompt_symbol_fingerprint_to_success_landscape
                            )
                        assertThat(iconContentDescriptionId)
                        assertThat(iconContentDescriptionId)
                            .isEqualTo(R.string.security_settings_sfps_enroll_find_sensor_message)
                            .isEqualTo(R.string.security_settings_sfps_enroll_find_sensor_message)
                        assertThat(shouldAnimateIconView).isEqualTo(true)
                        assertThat(shouldAnimateIconView).isEqualTo(true)
@@ -498,14 +563,12 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
                }
                }
            }
            }
        }
        }
    }


    @Test
    @Test
    fun shows_pending_confirmation() = runGenericTest {
    fun shows_pending_confirmation() {
        if (
        if (testCase.authenticatedByFace && testCase.confirmationRequested) {
            (testCase.isFaceOnly || testCase.isCoex) &&
            runGenericTest {
                testCase.authenticatedByFace &&
                testCase.confirmationRequested
        ) {
                val iconAsset by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val iconAsset by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val iconOverlayAsset by
                val iconOverlayAsset by
                    collectLastValue(kosmos.promptViewModel.iconViewModel.iconOverlayAsset)
                    collectLastValue(kosmos.promptViewModel.iconViewModel.iconOverlayAsset)
@@ -545,14 +608,12 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
                }
                }
            }
            }
        }
        }
    }


    @Test
    @Test
    fun shows_authenticated_explicitly_confirmed_iconUpdate() = runGenericTest {
    fun shows_authenticated_explicitly_confirmed() {
        if (
        if (testCase.authenticatedByFace && testCase.confirmationRequested) {
            (testCase.isFaceOnly || testCase.isCoex) &&
            runGenericTest {
                testCase.authenticatedByFace &&
                testCase.confirmationRequested
        ) {
                val iconAsset by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val iconAsset by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val iconOverlayAsset by
                val iconOverlayAsset by
                    collectLastValue(kosmos.promptViewModel.iconViewModel.iconOverlayAsset)
                    collectLastValue(kosmos.promptViewModel.iconViewModel.iconOverlayAsset)
@@ -586,7 +647,9 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
                    // TODO: Update when SFPS co-ex is implemented
                    // TODO: Update when SFPS co-ex is implemented
                    if (testCase.sensorType != FingerprintSensorProperties.TYPE_POWER_BUTTON) {
                    if (testCase.sensorType != FingerprintSensorProperties.TYPE_POWER_BUTTON) {
                        assertThat(iconAsset)
                        assertThat(iconAsset)
                        .isEqualTo(R.raw.fingerprint_dialogue_unlocked_to_checkmark_success_lottie)
                            .isEqualTo(
                                R.raw.fingerprint_dialogue_unlocked_to_checkmark_success_lottie
                            )
                        assertThat(iconOverlayAsset).isEqualTo(-1)
                        assertThat(iconOverlayAsset).isEqualTo(-1)
                        assertThat(iconContentDescriptionId)
                        assertThat(iconContentDescriptionId)
                            .isEqualTo(R.string.fingerprint_dialog_touch_sensor)
                            .isEqualTo(R.string.fingerprint_dialog_touch_sensor)
@@ -596,6 +659,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
                }
                }
            }
            }
        }
        }
    }


    @Test
    @Test
    fun shows_authenticated_with_no_errors() = runGenericTest {
    fun shows_authenticated_with_no_errors() = runGenericTest {
@@ -700,26 +764,33 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
    }
    }


    @Test
    @Test
    fun sfpsIconUpdates_onFoldConfigurationChanged() = runGenericTest {
    fun sfpsIconUpdates_onFoldConfigurationChanged() {
        if (
        if (
            testCase.sensorType == FingerprintSensorProperties.TYPE_POWER_BUTTON &&
            testCase.sensorType == FingerprintSensorProperties.TYPE_POWER_BUTTON &&
                !testCase.isInRearDisplayMode
                !testCase.isInRearDisplayMode
        ) {
        ) {
            runGenericTest {
                val currentIcon by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val currentIcon by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)


            kosmos.promptViewModel.iconViewModel.onConfigurationChanged(getFoldedConfiguration())
                kosmos.promptViewModel.iconViewModel.onConfigurationChanged(
                    getFoldedConfiguration()
                )
                val foldedIcon = currentIcon
                val foldedIcon = currentIcon


            kosmos.promptViewModel.iconViewModel.onConfigurationChanged(getUnfoldedConfiguration())
                kosmos.promptViewModel.iconViewModel.onConfigurationChanged(
                    getUnfoldedConfiguration()
                )
                val unfoldedIcon = currentIcon
                val unfoldedIcon = currentIcon


                assertThat(foldedIcon).isNotEqualTo(unfoldedIcon)
                assertThat(foldedIcon).isNotEqualTo(unfoldedIcon)
            }
            }
        }
        }
    }


    @Test
    @Test
    fun sfpsIconUpdates_onRotation() = runGenericTest {
    fun sfpsIconUpdates_onRotation() {
        if (testCase.sensorType == FingerprintSensorProperties.TYPE_POWER_BUTTON) {
        if (testCase.sensorType == FingerprintSensorProperties.TYPE_POWER_BUTTON) {
            runGenericTest {
                val currentIcon by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val currentIcon by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)


                kosmos.displayStateRepository.setCurrentRotation(DisplayRotation.ROTATION_0)
                kosmos.displayStateRepository.setCurrentRotation(DisplayRotation.ROTATION_0)
@@ -739,10 +810,12 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
                assertThat(iconRotation0).isNotEqualTo(iconRotation270)
                assertThat(iconRotation0).isNotEqualTo(iconRotation270)
            }
            }
        }
        }
    }


    @Test
    @Test
    fun sfpsIconUpdates_onRearDisplayMode() = runGenericTest {
    fun sfpsIconUpdates_onRearDisplayMode() {
        if (testCase.sensorType == FingerprintSensorProperties.TYPE_POWER_BUTTON) {
        if (testCase.sensorType == FingerprintSensorProperties.TYPE_POWER_BUTTON) {
            runGenericTest {
                val currentIcon by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)
                val currentIcon by collectLastValue(kosmos.promptViewModel.iconViewModel.iconAsset)


                kosmos.displayStateRepository.setIsInRearDisplayMode(false)
                kosmos.displayStateRepository.setIsInRearDisplayMode(false)
@@ -754,6 +827,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
                assertThat(iconNotRearDisplayMode).isNotEqualTo(iconRearDisplayMode)
                assertThat(iconNotRearDisplayMode).isNotEqualTo(iconRearDisplayMode)
            }
            }
        }
        }
    }


    private suspend fun TestScope.showAuthenticated(
    private suspend fun TestScope.showAuthenticated(
        authenticatedModality: BiometricModality,
        authenticatedModality: BiometricModality,