Loading packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt +25 −33 Original line number Diff line number Diff line Loading @@ -81,7 +81,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onShown() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) lockDeviceAndOpenPasswordBouncer() assertThat(underTest.textFieldState.text.toString()).isEmpty() Loading @@ -104,7 +104,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onPasswordInputChanged() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) lockDeviceAndOpenPasswordBouncer() verify(onIntentionalUserInputMock, never()).invoke() Loading @@ -120,8 +120,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateKeyPressed_whenCorrect() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPasswordBouncer() underTest.textFieldState.setTextAndPlaceCursorAtEnd("password") Loading @@ -133,8 +132,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateKeyPressed_whenWrong() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPasswordBouncer() underTest.textFieldState.setTextAndPlaceCursorAtEnd("wrong") Loading @@ -147,9 +145,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateKeyPressed_whenEmpty() = kosmos.runTest { kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Password ) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Password) showBouncer() // No input entered. Loading @@ -162,8 +158,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateKeyPressed_correctAfterWrong() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPasswordBouncer() // Enter the wrong password: Loading @@ -183,7 +178,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onShown_againAfterSceneChange_resetsPassword() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) lockDeviceAndOpenPasswordBouncer() // The user types a password. Loading @@ -204,7 +199,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onImeDismissed() = kosmos.runTest { val events by collectValues(kosmos.bouncerInteractor.onImeHiddenByUser) val events by collectValues(bouncerInteractor.onImeHiddenByUser) assertThat(events).isEmpty() underTest.onImeDismissed() Loading Loading @@ -267,7 +262,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun isImeSwitcherButtonVisible() = kosmos.runTest { val selectedUserId by collectLastValue(kosmos.selectedUserInteractor.selectedUser) val selectedUserId by collectLastValue(selectedUserInteractor.selectedUser) selectUser(USER_INFOS.first()) enableInputMethodsForUser(checkNotNull(selectedUserId)) Loading @@ -283,7 +278,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { selectUser(USER_INFOS.last()) assertThat( kosmos.inputMethodInteractor.hasMultipleEnabledImesOrSubtypes( inputMethodInteractor.hasMultipleEnabledImesOrSubtypes( checkNotNull(selectedUserId) ) ) Loading @@ -300,21 +295,20 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { fun onImeSwitcherButtonClicked() = kosmos.runTest { val displayId = 7 assertThat(kosmos.fakeInputMethodRepository.inputMethodPickerShownDisplayId) assertThat(fakeInputMethodRepository.inputMethodPickerShownDisplayId) .isNotEqualTo(displayId) underTest.onImeSwitcherButtonClicked(displayId) runCurrent() assertThat(kosmos.fakeInputMethodRepository.inputMethodPickerShownDisplayId) assertThat(fakeInputMethodRepository.inputMethodPickerShownDisplayId) .isEqualTo(displayId) } @Test fun afterSuccessfulAuthentication_focusIsNotRequested() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) val textInputFocusRequested by collectLastValue(underTest.isTextFieldFocusRequested) lockDeviceAndOpenPasswordBouncer() Loading Loading @@ -347,16 +341,16 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.showBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.sceneInteractor.showOverlay(Overlays.Bouncer, "reason") val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) sceneInteractor.showOverlay(Overlays.Bouncer, "reason") runCurrent() assertThat(currentOverlays).contains(Overlays.Bouncer) } private fun Kosmos.hideBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.sceneInteractor.hideOverlay(Overlays.Bouncer, "reason") val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) sceneInteractor.hideOverlay(Overlays.Bouncer, "reason") underTest.onHidden() runCurrent() Loading @@ -364,22 +358,20 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.lockDeviceAndOpenPasswordBouncer() { kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Password ) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Password) showBouncer() } private suspend fun Kosmos.setLockout(isLockedOut: Boolean, failedAttemptCount: Int = 5) { if (isLockedOut) { repeat(failedAttemptCount) { kosmos.fakeAuthenticationRepository.reportAuthenticationAttempt(false) fakeAuthenticationRepository.reportAuthenticationAttempt(false) } kosmos.fakeAuthenticationRepository.reportLockoutStarted( fakeAuthenticationRepository.reportLockoutStarted( 30.seconds.inWholeMilliseconds.toInt() ) } else { kosmos.fakeAuthenticationRepository.reportAuthenticationAttempt(true) fakeAuthenticationRepository.reportAuthenticationAttempt(true) } isInputEnabled.value = !isLockedOut Loading @@ -387,7 +379,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.selectUser(userInfo: UserInfo) { kosmos.fakeUserRepository.selectedUser.value = fakeUserRepository.selectedUser.value = SelectedUserModel( userInfo = userInfo, selectionStatus = SelectionStatus.SELECTION_COMPLETE, Loading @@ -395,13 +387,13 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { advanceTimeBy(PasswordBouncerViewModel.DELAY_TO_FETCH_IMES) } private suspend fun enableInputMethodsForUser(userId: Int) { kosmos.fakeInputMethodRepository.setEnabledInputMethods( private suspend fun Kosmos.enableInputMethodsForUser(userId: Int) { fakeInputMethodRepository.setEnabledInputMethods( userId, createInputMethodWithSubtypes(auxiliarySubtypes = 0, nonAuxiliarySubtypes = 0), createInputMethodWithSubtypes(auxiliarySubtypes = 0, nonAuxiliarySubtypes = 1), ) assertThat(kosmos.inputMethodInteractor.hasMultipleEnabledImesOrSubtypes(userId)).isTrue() assertThat(inputMethodInteractor.hasMultipleEnabledImesOrSubtypes(userId)).isTrue() } private fun createInputMethodWithSubtypes( Loading packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/PatternBouncerViewModelTest.kt +19 −24 Original line number Diff line number Diff line Loading @@ -79,7 +79,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onShown() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading @@ -93,7 +93,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragStart() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading @@ -111,8 +111,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragEnd_whenCorrect() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading Loading @@ -145,7 +144,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragEnd_whenWrong() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading Loading @@ -298,8 +297,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragEnd_whenPatternTooShort() = kosmos.runTest { val dialogViewModel by collectLastValue(kosmos.bouncerOverlayContentViewModel.dialogViewModel) val dialogViewModel by collectLastValue(bouncerOverlayContentViewModel.dialogViewModel) lockDeviceAndOpenPatternBouncer() // Enter a pattern that's too short more than enough times that would normally trigger Loading @@ -307,8 +305,8 @@ class PatternBouncerViewModelTest : SysuiTestCase() { val attempts = FakeAuthenticationRepository.MAX_FAILED_AUTH_TRIES_BEFORE_LOCKOUT + 1 repeat(attempts) { attempt -> underTest.onDragStart() CORRECT_PATTERN.subList(0, kosmos.authenticationRepository.minPatternLength - 1) .forEach { coordinate -> CORRECT_PATTERN.subList(0, authenticationRepository.minPatternLength - 1).forEach { coordinate -> underTest.onDrag( xPx = 30f * coordinate.x + 15, yPx = 30f * coordinate.y + 15, Loading @@ -325,8 +323,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragEnd_correctAfterWrong() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading @@ -352,9 +349,9 @@ class PatternBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { underTest.performDotFeedback(null) assertThat(kosmos.fakeMSDLPlayer.latestTokenPlayed) assertThat(fakeMSDLPlayer.latestTokenPlayed) .isEqualTo(MSDLToken.DRAG_INDICATOR_DISCRETE) assertThat(kosmos.fakeMSDLPlayer.latestPropertiesPlayed).isNull() assertThat(fakeMSDLPlayer.latestPropertiesPlayed).isNull() } private fun dragOverCoordinates(vararg coordinatesDragged: Point) { Loading @@ -371,12 +368,10 @@ class PatternBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.lockDeviceAndOpenPatternBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pattern ) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pattern) kosmos.sceneInteractor.showOverlay(Overlays.Bouncer, "reason") sceneInteractor.showOverlay(Overlays.Bouncer, "reason") runCurrent() assertThat(currentOverlays).contains(Overlays.Bouncer) Loading packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt +37 −51 Original line number Diff line number Diff line Loading @@ -95,11 +95,11 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun simBouncerViewModel_simAreaIsVisible() = kosmos.runTest { val underTest = kosmos.pinBouncerViewModelFactory.create( pinBouncerViewModelFactory.create( isInputEnabled = MutableStateFlow(true), onIntentionalUserInput = {}, authenticationMethod = AuthenticationMethodModel.Sim, bouncerHapticPlayer = kosmos.bouncerHapticPlayer, bouncerHapticPlayer = bouncerHapticPlayer, ) assertThat(underTest.isSimAreaVisible).isTrue() Loading @@ -109,7 +109,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun onErrorDialogDismissed_clearsDialogMessage() = kosmos.runTest { val dialogMessage by collectLastValue(underTest.errorDialogMessage) kosmos.fakeSimBouncerRepository.setSimVerificationErrorMessage("abc") fakeSimBouncerRepository.setSimVerificationErrorMessage("abc") assertThat(dialogMessage).isEqualTo("abc") underTest.onErrorDialogDismissed() Loading @@ -121,13 +121,13 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun simBouncerViewModel_autoConfirmEnabled_hintedPinLengthIsNull() = kosmos.runTest { val underTest = kosmos.pinBouncerViewModelFactory.create( pinBouncerViewModelFactory.create( isInputEnabled = MutableStateFlow(true), onIntentionalUserInput = {}, authenticationMethod = AuthenticationMethodModel.Pin, bouncerHapticPlayer = kosmos.bouncerHapticPlayer, bouncerHapticPlayer = bouncerHapticPlayer, ) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) val hintedPinLength by collectLastValue(underTest.hintedPinLength) assertThat(hintedPinLength).isNull() Loading Loading @@ -181,7 +181,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { @Test fun onBackspaceButtonLongPressed() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) lockDeviceAndOpenPinBouncer() Loading @@ -200,8 +200,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateButtonClicked_whenCorrect() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPinBouncer() FakeAuthenticationRepository.DEFAULT_PIN.forEach(underTest::onPinButtonClicked) Loading @@ -214,7 +213,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateButtonClicked_whenWrong() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) lockDeviceAndOpenPinBouncer() Loading @@ -233,8 +232,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateButtonClicked_correctAfterWrong() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) lockDeviceAndOpenPinBouncer() Loading Loading @@ -262,12 +260,11 @@ class PinBouncerViewModelTest : SysuiTestCase() { // Collect the flow so that it is hot, in the real application this is done by using a // refreshingFlow that relies on the UI to make this flow hot. val autoConfirmEnabled by collectLastValue(kosmos.authenticationInteractor.isAutoConfirmEnabled) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) collectLastValue(authenticationInteractor.isAutoConfirmEnabled) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) assertThat(autoConfirmEnabled).isTrue() val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPinBouncer() FakeAuthenticationRepository.DEFAULT_PIN.forEach(underTest::onPinButtonClicked) Loading @@ -282,11 +279,11 @@ class PinBouncerViewModelTest : SysuiTestCase() { // Collect the flow so that it is hot, in the real application this is done by using a // refreshingFlow that relies on the UI to make this flow hot. val autoConfirmEnabled by collectLastValue(kosmos.authenticationInteractor.isAutoConfirmEnabled) collectLastValue(authenticationInteractor.isAutoConfirmEnabled) val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) assertThat(autoConfirmEnabled).isTrue() lockDeviceAndOpenPinBouncer() Loading Loading @@ -327,9 +324,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { val backspaceButtonAppearance by collectLastValue(underTest.backspaceButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(backspaceButtonAppearance).isEqualTo(ActionButtonAppearance.Shown) } Loading @@ -338,10 +333,8 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun backspaceButtonAppearance_withAutoConfirmButNoInput_isHidden() = kosmos.runTest { val backspaceButtonAppearance by collectLastValue(underTest.backspaceButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) assertThat(backspaceButtonAppearance).isEqualTo(ActionButtonAppearance.Hidden) } Loading @@ -350,10 +343,8 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun backspaceButtonAppearance_withAutoConfirmAndInput_isShownQuiet() = kosmos.runTest { val backspaceButtonAppearance by collectLastValue(underTest.backspaceButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) runCurrent() underTest.onPinButtonClicked(1) Loading @@ -366,9 +357,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { val confirmButtonAppearance by collectLastValue(underTest.confirmButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(confirmButtonAppearance).isEqualTo(ActionButtonAppearance.Shown) } Loading @@ -377,10 +366,8 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun confirmButtonAppearance_withAutoConfirm_isHidden() = kosmos.runTest { val confirmButtonAppearance by collectLastValue(underTest.confirmButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) assertThat(confirmButtonAppearance).isEqualTo(ActionButtonAppearance.Hidden) } Loading @@ -390,10 +377,10 @@ class PinBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { val isAnimationEnabled by collectLastValue(underTest.isDigitButtonAnimationEnabled) kosmos.fakeAuthenticationRepository.setPinEnhancedPrivacyEnabled(true) fakeAuthenticationRepository.setPinEnhancedPrivacyEnabled(true) assertThat(isAnimationEnabled).isFalse() kosmos.fakeAuthenticationRepository.setPinEnhancedPrivacyEnabled(false) fakeAuthenticationRepository.setPinEnhancedPrivacyEnabled(false) assertThat(isAnimationEnabled).isTrue() } Loading @@ -401,7 +388,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun onPinButtonClicked_whenInputSameLengthAsHintedPin_ignoresClick() = kosmos.runTest { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) val hintedPinLength by collectLastValue(underTest.hintedPinLength) assertThat(hintedPinLength).isEqualTo(FakeAuthenticationRepository.HINTING_PIN_LENGTH) lockDeviceAndOpenPinBouncer() Loading @@ -410,7 +397,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { underTest.onPinButtonClicked(repetition + 1) runCurrent() } kosmos.fakeAuthenticationRepository.pauseCredentialChecking() fakeAuthenticationRepository.pauseCredentialChecking() // If credential checking were not paused, this would check the credentials and succeed. underTest.onPinButtonClicked(FakeAuthenticationRepository.HINTING_PIN_LENGTH) runCurrent() Loading @@ -430,7 +417,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { } ) kosmos.fakeAuthenticationRepository.unpauseCredentialChecking() fakeAuthenticationRepository.unpauseCredentialChecking() runCurrent() assertThat(pin).isEmpty() } Loading @@ -439,7 +426,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun onPinButtonClicked_whenPinNotHinted_doesNotIgnoreClick() = kosmos.runTest { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(false) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(false) val hintedPinLength by collectLastValue(underTest.hintedPinLength) assertThat(hintedPinLength).isNull() lockDeviceAndOpenPinBouncer() Loading Loading @@ -496,9 +483,8 @@ class PinBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { underTest.onDigitButtonDown(null) assertThat(kosmos.fakeMSDLPlayer.latestTokenPlayed) .isEqualTo(MSDLToken.KEYPRESS_STANDARD) assertThat(kosmos.fakeMSDLPlayer.latestPropertiesPlayed).isNull() assertThat(fakeMSDLPlayer.latestTokenPlayed).isEqualTo(MSDLToken.KEYPRESS_STANDARD) assertThat(fakeMSDLPlayer.latestPropertiesPlayed).isNull() } @Test Loading @@ -520,16 +506,16 @@ class PinBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.showBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.sceneInteractor.showOverlay(Overlays.Bouncer, "reason") val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) sceneInteractor.showOverlay(Overlays.Bouncer, "reason") runCurrent() assertThat(currentOverlays).contains(Overlays.Bouncer) } private fun Kosmos.hideBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.sceneInteractor.hideOverlay(Overlays.Bouncer, "reason") val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) sceneInteractor.hideOverlay(Overlays.Bouncer, "reason") underTest.onHidden() runCurrent() Loading @@ -537,7 +523,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.lockDeviceAndOpenPinBouncer() { kosmos.fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) showBouncer() } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt +25 −33 Original line number Diff line number Diff line Loading @@ -81,7 +81,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onShown() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) lockDeviceAndOpenPasswordBouncer() assertThat(underTest.textFieldState.text.toString()).isEmpty() Loading @@ -104,7 +104,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onPasswordInputChanged() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) lockDeviceAndOpenPasswordBouncer() verify(onIntentionalUserInputMock, never()).invoke() Loading @@ -120,8 +120,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateKeyPressed_whenCorrect() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPasswordBouncer() underTest.textFieldState.setTextAndPlaceCursorAtEnd("password") Loading @@ -133,8 +132,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateKeyPressed_whenWrong() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPasswordBouncer() underTest.textFieldState.setTextAndPlaceCursorAtEnd("wrong") Loading @@ -147,9 +145,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateKeyPressed_whenEmpty() = kosmos.runTest { kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Password ) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Password) showBouncer() // No input entered. Loading @@ -162,8 +158,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateKeyPressed_correctAfterWrong() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPasswordBouncer() // Enter the wrong password: Loading @@ -183,7 +178,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onShown_againAfterSceneChange_resetsPassword() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) lockDeviceAndOpenPasswordBouncer() // The user types a password. Loading @@ -204,7 +199,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun onImeDismissed() = kosmos.runTest { val events by collectValues(kosmos.bouncerInteractor.onImeHiddenByUser) val events by collectValues(bouncerInteractor.onImeHiddenByUser) assertThat(events).isEmpty() underTest.onImeDismissed() Loading Loading @@ -267,7 +262,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { @Test fun isImeSwitcherButtonVisible() = kosmos.runTest { val selectedUserId by collectLastValue(kosmos.selectedUserInteractor.selectedUser) val selectedUserId by collectLastValue(selectedUserInteractor.selectedUser) selectUser(USER_INFOS.first()) enableInputMethodsForUser(checkNotNull(selectedUserId)) Loading @@ -283,7 +278,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { selectUser(USER_INFOS.last()) assertThat( kosmos.inputMethodInteractor.hasMultipleEnabledImesOrSubtypes( inputMethodInteractor.hasMultipleEnabledImesOrSubtypes( checkNotNull(selectedUserId) ) ) Loading @@ -300,21 +295,20 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { fun onImeSwitcherButtonClicked() = kosmos.runTest { val displayId = 7 assertThat(kosmos.fakeInputMethodRepository.inputMethodPickerShownDisplayId) assertThat(fakeInputMethodRepository.inputMethodPickerShownDisplayId) .isNotEqualTo(displayId) underTest.onImeSwitcherButtonClicked(displayId) runCurrent() assertThat(kosmos.fakeInputMethodRepository.inputMethodPickerShownDisplayId) assertThat(fakeInputMethodRepository.inputMethodPickerShownDisplayId) .isEqualTo(displayId) } @Test fun afterSuccessfulAuthentication_focusIsNotRequested() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) val textInputFocusRequested by collectLastValue(underTest.isTextFieldFocusRequested) lockDeviceAndOpenPasswordBouncer() Loading Loading @@ -347,16 +341,16 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.showBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.sceneInteractor.showOverlay(Overlays.Bouncer, "reason") val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) sceneInteractor.showOverlay(Overlays.Bouncer, "reason") runCurrent() assertThat(currentOverlays).contains(Overlays.Bouncer) } private fun Kosmos.hideBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.sceneInteractor.hideOverlay(Overlays.Bouncer, "reason") val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) sceneInteractor.hideOverlay(Overlays.Bouncer, "reason") underTest.onHidden() runCurrent() Loading @@ -364,22 +358,20 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.lockDeviceAndOpenPasswordBouncer() { kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Password ) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Password) showBouncer() } private suspend fun Kosmos.setLockout(isLockedOut: Boolean, failedAttemptCount: Int = 5) { if (isLockedOut) { repeat(failedAttemptCount) { kosmos.fakeAuthenticationRepository.reportAuthenticationAttempt(false) fakeAuthenticationRepository.reportAuthenticationAttempt(false) } kosmos.fakeAuthenticationRepository.reportLockoutStarted( fakeAuthenticationRepository.reportLockoutStarted( 30.seconds.inWholeMilliseconds.toInt() ) } else { kosmos.fakeAuthenticationRepository.reportAuthenticationAttempt(true) fakeAuthenticationRepository.reportAuthenticationAttempt(true) } isInputEnabled.value = !isLockedOut Loading @@ -387,7 +379,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.selectUser(userInfo: UserInfo) { kosmos.fakeUserRepository.selectedUser.value = fakeUserRepository.selectedUser.value = SelectedUserModel( userInfo = userInfo, selectionStatus = SelectionStatus.SELECTION_COMPLETE, Loading @@ -395,13 +387,13 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { advanceTimeBy(PasswordBouncerViewModel.DELAY_TO_FETCH_IMES) } private suspend fun enableInputMethodsForUser(userId: Int) { kosmos.fakeInputMethodRepository.setEnabledInputMethods( private suspend fun Kosmos.enableInputMethodsForUser(userId: Int) { fakeInputMethodRepository.setEnabledInputMethods( userId, createInputMethodWithSubtypes(auxiliarySubtypes = 0, nonAuxiliarySubtypes = 0), createInputMethodWithSubtypes(auxiliarySubtypes = 0, nonAuxiliarySubtypes = 1), ) assertThat(kosmos.inputMethodInteractor.hasMultipleEnabledImesOrSubtypes(userId)).isTrue() assertThat(inputMethodInteractor.hasMultipleEnabledImesOrSubtypes(userId)).isTrue() } private fun createInputMethodWithSubtypes( Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/PatternBouncerViewModelTest.kt +19 −24 Original line number Diff line number Diff line Loading @@ -79,7 +79,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onShown() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading @@ -93,7 +93,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragStart() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading @@ -111,8 +111,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragEnd_whenCorrect() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading Loading @@ -145,7 +144,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragEnd_whenWrong() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading Loading @@ -298,8 +297,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragEnd_whenPatternTooShort() = kosmos.runTest { val dialogViewModel by collectLastValue(kosmos.bouncerOverlayContentViewModel.dialogViewModel) val dialogViewModel by collectLastValue(bouncerOverlayContentViewModel.dialogViewModel) lockDeviceAndOpenPatternBouncer() // Enter a pattern that's too short more than enough times that would normally trigger Loading @@ -307,8 +305,8 @@ class PatternBouncerViewModelTest : SysuiTestCase() { val attempts = FakeAuthenticationRepository.MAX_FAILED_AUTH_TRIES_BEFORE_LOCKOUT + 1 repeat(attempts) { attempt -> underTest.onDragStart() CORRECT_PATTERN.subList(0, kosmos.authenticationRepository.minPatternLength - 1) .forEach { coordinate -> CORRECT_PATTERN.subList(0, authenticationRepository.minPatternLength - 1).forEach { coordinate -> underTest.onDrag( xPx = 30f * coordinate.x + 15, yPx = 30f * coordinate.y + 15, Loading @@ -325,8 +323,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { @Test fun onDragEnd_correctAfterWrong() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) val selectedDots by collectLastValue(underTest.selectedDots) val currentDot by collectLastValue(underTest.currentDot) lockDeviceAndOpenPatternBouncer() Loading @@ -352,9 +349,9 @@ class PatternBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { underTest.performDotFeedback(null) assertThat(kosmos.fakeMSDLPlayer.latestTokenPlayed) assertThat(fakeMSDLPlayer.latestTokenPlayed) .isEqualTo(MSDLToken.DRAG_INDICATOR_DISCRETE) assertThat(kosmos.fakeMSDLPlayer.latestPropertiesPlayed).isNull() assertThat(fakeMSDLPlayer.latestPropertiesPlayed).isNull() } private fun dragOverCoordinates(vararg coordinatesDragged: Point) { Loading @@ -371,12 +368,10 @@ class PatternBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.lockDeviceAndOpenPatternBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pattern ) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pattern) kosmos.sceneInteractor.showOverlay(Overlays.Bouncer, "reason") sceneInteractor.showOverlay(Overlays.Bouncer, "reason") runCurrent() assertThat(currentOverlays).contains(Overlays.Bouncer) Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt +37 −51 Original line number Diff line number Diff line Loading @@ -95,11 +95,11 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun simBouncerViewModel_simAreaIsVisible() = kosmos.runTest { val underTest = kosmos.pinBouncerViewModelFactory.create( pinBouncerViewModelFactory.create( isInputEnabled = MutableStateFlow(true), onIntentionalUserInput = {}, authenticationMethod = AuthenticationMethodModel.Sim, bouncerHapticPlayer = kosmos.bouncerHapticPlayer, bouncerHapticPlayer = bouncerHapticPlayer, ) assertThat(underTest.isSimAreaVisible).isTrue() Loading @@ -109,7 +109,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun onErrorDialogDismissed_clearsDialogMessage() = kosmos.runTest { val dialogMessage by collectLastValue(underTest.errorDialogMessage) kosmos.fakeSimBouncerRepository.setSimVerificationErrorMessage("abc") fakeSimBouncerRepository.setSimVerificationErrorMessage("abc") assertThat(dialogMessage).isEqualTo("abc") underTest.onErrorDialogDismissed() Loading @@ -121,13 +121,13 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun simBouncerViewModel_autoConfirmEnabled_hintedPinLengthIsNull() = kosmos.runTest { val underTest = kosmos.pinBouncerViewModelFactory.create( pinBouncerViewModelFactory.create( isInputEnabled = MutableStateFlow(true), onIntentionalUserInput = {}, authenticationMethod = AuthenticationMethodModel.Pin, bouncerHapticPlayer = kosmos.bouncerHapticPlayer, bouncerHapticPlayer = bouncerHapticPlayer, ) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) val hintedPinLength by collectLastValue(underTest.hintedPinLength) assertThat(hintedPinLength).isNull() Loading Loading @@ -181,7 +181,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { @Test fun onBackspaceButtonLongPressed() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) lockDeviceAndOpenPinBouncer() Loading @@ -200,8 +200,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateButtonClicked_whenCorrect() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPinBouncer() FakeAuthenticationRepository.DEFAULT_PIN.forEach(underTest::onPinButtonClicked) Loading @@ -214,7 +213,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateButtonClicked_whenWrong() = kosmos.runTest { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) lockDeviceAndOpenPinBouncer() Loading @@ -233,8 +232,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { @Test fun onAuthenticateButtonClicked_correctAfterWrong() = kosmos.runTest { val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) lockDeviceAndOpenPinBouncer() Loading Loading @@ -262,12 +260,11 @@ class PinBouncerViewModelTest : SysuiTestCase() { // Collect the flow so that it is hot, in the real application this is done by using a // refreshingFlow that relies on the UI to make this flow hot. val autoConfirmEnabled by collectLastValue(kosmos.authenticationInteractor.isAutoConfirmEnabled) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) collectLastValue(authenticationInteractor.isAutoConfirmEnabled) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) assertThat(autoConfirmEnabled).isTrue() val authResult by collectLastValue(kosmos.authenticationInteractor.onAuthenticationResult) val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult) lockDeviceAndOpenPinBouncer() FakeAuthenticationRepository.DEFAULT_PIN.forEach(underTest::onPinButtonClicked) Loading @@ -282,11 +279,11 @@ class PinBouncerViewModelTest : SysuiTestCase() { // Collect the flow so that it is hot, in the real application this is done by using a // refreshingFlow that relies on the UI to make this flow hot. val autoConfirmEnabled by collectLastValue(kosmos.authenticationInteractor.isAutoConfirmEnabled) collectLastValue(authenticationInteractor.isAutoConfirmEnabled) val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) assertThat(autoConfirmEnabled).isTrue() lockDeviceAndOpenPinBouncer() Loading Loading @@ -327,9 +324,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { val backspaceButtonAppearance by collectLastValue(underTest.backspaceButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(backspaceButtonAppearance).isEqualTo(ActionButtonAppearance.Shown) } Loading @@ -338,10 +333,8 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun backspaceButtonAppearance_withAutoConfirmButNoInput_isHidden() = kosmos.runTest { val backspaceButtonAppearance by collectLastValue(underTest.backspaceButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) assertThat(backspaceButtonAppearance).isEqualTo(ActionButtonAppearance.Hidden) } Loading @@ -350,10 +343,8 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun backspaceButtonAppearance_withAutoConfirmAndInput_isShownQuiet() = kosmos.runTest { val backspaceButtonAppearance by collectLastValue(underTest.backspaceButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) runCurrent() underTest.onPinButtonClicked(1) Loading @@ -366,9 +357,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { val confirmButtonAppearance by collectLastValue(underTest.confirmButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(confirmButtonAppearance).isEqualTo(ActionButtonAppearance.Shown) } Loading @@ -377,10 +366,8 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun confirmButtonAppearance_withAutoConfirm_isHidden() = kosmos.runTest { val confirmButtonAppearance by collectLastValue(underTest.confirmButtonAppearance) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) assertThat(confirmButtonAppearance).isEqualTo(ActionButtonAppearance.Hidden) } Loading @@ -390,10 +377,10 @@ class PinBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { val isAnimationEnabled by collectLastValue(underTest.isDigitButtonAnimationEnabled) kosmos.fakeAuthenticationRepository.setPinEnhancedPrivacyEnabled(true) fakeAuthenticationRepository.setPinEnhancedPrivacyEnabled(true) assertThat(isAnimationEnabled).isFalse() kosmos.fakeAuthenticationRepository.setPinEnhancedPrivacyEnabled(false) fakeAuthenticationRepository.setPinEnhancedPrivacyEnabled(false) assertThat(isAnimationEnabled).isTrue() } Loading @@ -401,7 +388,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun onPinButtonClicked_whenInputSameLengthAsHintedPin_ignoresClick() = kosmos.runTest { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true) val hintedPinLength by collectLastValue(underTest.hintedPinLength) assertThat(hintedPinLength).isEqualTo(FakeAuthenticationRepository.HINTING_PIN_LENGTH) lockDeviceAndOpenPinBouncer() Loading @@ -410,7 +397,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { underTest.onPinButtonClicked(repetition + 1) runCurrent() } kosmos.fakeAuthenticationRepository.pauseCredentialChecking() fakeAuthenticationRepository.pauseCredentialChecking() // If credential checking were not paused, this would check the credentials and succeed. underTest.onPinButtonClicked(FakeAuthenticationRepository.HINTING_PIN_LENGTH) runCurrent() Loading @@ -430,7 +417,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { } ) kosmos.fakeAuthenticationRepository.unpauseCredentialChecking() fakeAuthenticationRepository.unpauseCredentialChecking() runCurrent() assertThat(pin).isEmpty() } Loading @@ -439,7 +426,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { fun onPinButtonClicked_whenPinNotHinted_doesNotIgnoreClick() = kosmos.runTest { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(false) fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(false) val hintedPinLength by collectLastValue(underTest.hintedPinLength) assertThat(hintedPinLength).isNull() lockDeviceAndOpenPinBouncer() Loading Loading @@ -496,9 +483,8 @@ class PinBouncerViewModelTest : SysuiTestCase() { kosmos.runTest { underTest.onDigitButtonDown(null) assertThat(kosmos.fakeMSDLPlayer.latestTokenPlayed) .isEqualTo(MSDLToken.KEYPRESS_STANDARD) assertThat(kosmos.fakeMSDLPlayer.latestPropertiesPlayed).isNull() assertThat(fakeMSDLPlayer.latestTokenPlayed).isEqualTo(MSDLToken.KEYPRESS_STANDARD) assertThat(fakeMSDLPlayer.latestPropertiesPlayed).isNull() } @Test Loading @@ -520,16 +506,16 @@ class PinBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.showBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.sceneInteractor.showOverlay(Overlays.Bouncer, "reason") val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) sceneInteractor.showOverlay(Overlays.Bouncer, "reason") runCurrent() assertThat(currentOverlays).contains(Overlays.Bouncer) } private fun Kosmos.hideBouncer() { val currentOverlays by collectLastValue(kosmos.sceneInteractor.currentOverlays) kosmos.sceneInteractor.hideOverlay(Overlays.Bouncer, "reason") val currentOverlays by collectLastValue(sceneInteractor.currentOverlays) sceneInteractor.hideOverlay(Overlays.Bouncer, "reason") underTest.onHidden() runCurrent() Loading @@ -537,7 +523,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { } private fun Kosmos.lockDeviceAndOpenPinBouncer() { kosmos.fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) showBouncer() } Loading