Loading packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt +48 −38 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import com.android.systemui.testKosmos import com.android.systemui.user.domain.interactor.SelectedUserInteractor import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import org.junit.After import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -110,6 +111,11 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Captor lateinit var postureCallbackCaptor: ArgumentCaptor<DevicePostureController.Callback> private val kosmos = testKosmos() private var underTest: KeyguardPinViewController? = null set(value) { field?.onPause() field = value } @Before fun setup() { Loading @@ -136,10 +142,14 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { .requireViewById(R.id.keyguard_pin_view) as KeyguardPINView } private fun constructPinViewController( mKeyguardPinView: KeyguardPINView ): KeyguardPinViewController { return KeyguardPinViewController( @After fun tearDown() { underTest?.onPause() } private fun constructPinViewController(mKeyguardPinView: KeyguardPINView) { underTest = KeyguardPinViewController( mKeyguardPinView, keyguardUpdateMonitor, securityMode, Loading @@ -162,22 +172,22 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun onViewAttached_deviceHalfFolded_propagatedToPatternView() { val pinViewController = constructPinViewController(objectKeyguardPINView) constructPinViewController(objectKeyguardPINView) overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) whenever(postureController.devicePosture).thenReturn(DEVICE_POSTURE_HALF_OPENED) pinViewController.onViewAttached() underTest?.onViewAttached() assertThat(getPinTopGuideline()).isEqualTo(getHalfOpenedBouncerHeightRatio()) } @Test fun onDevicePostureChanged_deviceOpened_propagatedToPatternView() { val pinViewController = constructPinViewController(objectKeyguardPINView) constructPinViewController(objectKeyguardPINView) overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) whenever(postureController.devicePosture).thenReturn(DEVICE_POSTURE_HALF_OPENED) pinViewController.onViewAttached() underTest?.onViewAttached() // Verify view begins in posture state DEVICE_POSTURE_HALF_OPENED assertThat(getPinTopGuideline()).isEqualTo(getHalfOpenedBouncerHeightRatio()) Loading Loading @@ -211,9 +221,9 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun testOnViewAttached() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) pinViewController.onViewAttached() underTest?.onViewAttached() verify(keyguardMessageAreaController) .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false) Loading @@ -221,23 +231,23 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun testOnViewAttached_withExistingMessage() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) Mockito.`when`(keyguardMessageAreaController.message).thenReturn("Unlock to continue.") pinViewController.onViewAttached() underTest?.onViewAttached() verify(keyguardMessageAreaController, Mockito.never()).setMessage(anyString(), anyBoolean()) } @Test fun testOnViewAttached_withAutoPinConfirmationFailedPasswordAttemptsLessThan5() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) `when`(lockPatternUtils.getPinLength(anyInt())).thenReturn(6) `when`(lockPatternUtils.isAutoPinConfirmEnabled(anyInt())).thenReturn(true) `when`(lockPatternUtils.getCurrentFailedPasswordAttempts(anyInt())).thenReturn(3) `when`(passwordTextView.text).thenReturn("") pinViewController.onViewAttached() underTest?.onViewAttached() verify(deleteButton).visibility = View.INVISIBLE verify(enterButton).visibility = View.INVISIBLE Loading @@ -247,13 +257,13 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun testOnViewAttached_withAutoPinConfirmationFailedPasswordAttemptsMoreThan5() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) `when`(lockPatternUtils.getPinLength(anyInt())).thenReturn(6) `when`(lockPatternUtils.isAutoPinConfirmEnabled(anyInt())).thenReturn(true) `when`(lockPatternUtils.getCurrentFailedPasswordAttempts(anyInt())).thenReturn(6) `when`(passwordTextView.text).thenReturn("") pinViewController.onViewAttached() underTest?.onViewAttached() verify(deleteButton).visibility = View.VISIBLE verify(enterButton).visibility = View.VISIBLE Loading @@ -263,16 +273,16 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun handleLockout_readsNumberOfErrorAttempts() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) pinViewController.handleAttemptLockout(0) underTest?.handleAttemptLockout(0) verify(lockPatternUtils).getCurrentFailedPasswordAttempts(anyInt()) } @Test fun onUserInput_autoConfirmation_attemptsUnlock() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) whenever(lockPatternUtils.getPinLength(anyInt())).thenReturn(6) whenever(lockPatternUtils.isAutoPinConfirmEnabled(anyInt())).thenReturn(true) whenever(passwordTextView.text).thenReturn("000000") Loading @@ -280,7 +290,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { whenever(mockKeyguardPinView.enteredCredential) .thenReturn(LockscreenCredential.createPin("000000")) pinViewController.onUserInput() underTest?.onUserInput() verify(uiEventLogger).log(PinBouncerUiEvent.ATTEMPT_UNLOCK_WITH_AUTO_CONFIRM_FEATURE) verify(keyguardUpdateMonitor).setCredentialAttempted() Loading Loading
packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt +48 −38 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import com.android.systemui.testKosmos import com.android.systemui.user.domain.interactor.SelectedUserInteractor import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import org.junit.After import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -110,6 +111,11 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Captor lateinit var postureCallbackCaptor: ArgumentCaptor<DevicePostureController.Callback> private val kosmos = testKosmos() private var underTest: KeyguardPinViewController? = null set(value) { field?.onPause() field = value } @Before fun setup() { Loading @@ -136,10 +142,14 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { .requireViewById(R.id.keyguard_pin_view) as KeyguardPINView } private fun constructPinViewController( mKeyguardPinView: KeyguardPINView ): KeyguardPinViewController { return KeyguardPinViewController( @After fun tearDown() { underTest?.onPause() } private fun constructPinViewController(mKeyguardPinView: KeyguardPINView) { underTest = KeyguardPinViewController( mKeyguardPinView, keyguardUpdateMonitor, securityMode, Loading @@ -162,22 +172,22 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun onViewAttached_deviceHalfFolded_propagatedToPatternView() { val pinViewController = constructPinViewController(objectKeyguardPINView) constructPinViewController(objectKeyguardPINView) overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) whenever(postureController.devicePosture).thenReturn(DEVICE_POSTURE_HALF_OPENED) pinViewController.onViewAttached() underTest?.onViewAttached() assertThat(getPinTopGuideline()).isEqualTo(getHalfOpenedBouncerHeightRatio()) } @Test fun onDevicePostureChanged_deviceOpened_propagatedToPatternView() { val pinViewController = constructPinViewController(objectKeyguardPINView) constructPinViewController(objectKeyguardPINView) overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) whenever(postureController.devicePosture).thenReturn(DEVICE_POSTURE_HALF_OPENED) pinViewController.onViewAttached() underTest?.onViewAttached() // Verify view begins in posture state DEVICE_POSTURE_HALF_OPENED assertThat(getPinTopGuideline()).isEqualTo(getHalfOpenedBouncerHeightRatio()) Loading Loading @@ -211,9 +221,9 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun testOnViewAttached() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) pinViewController.onViewAttached() underTest?.onViewAttached() verify(keyguardMessageAreaController) .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false) Loading @@ -221,23 +231,23 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun testOnViewAttached_withExistingMessage() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) Mockito.`when`(keyguardMessageAreaController.message).thenReturn("Unlock to continue.") pinViewController.onViewAttached() underTest?.onViewAttached() verify(keyguardMessageAreaController, Mockito.never()).setMessage(anyString(), anyBoolean()) } @Test fun testOnViewAttached_withAutoPinConfirmationFailedPasswordAttemptsLessThan5() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) `when`(lockPatternUtils.getPinLength(anyInt())).thenReturn(6) `when`(lockPatternUtils.isAutoPinConfirmEnabled(anyInt())).thenReturn(true) `when`(lockPatternUtils.getCurrentFailedPasswordAttempts(anyInt())).thenReturn(3) `when`(passwordTextView.text).thenReturn("") pinViewController.onViewAttached() underTest?.onViewAttached() verify(deleteButton).visibility = View.INVISIBLE verify(enterButton).visibility = View.INVISIBLE Loading @@ -247,13 +257,13 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun testOnViewAttached_withAutoPinConfirmationFailedPasswordAttemptsMoreThan5() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) `when`(lockPatternUtils.getPinLength(anyInt())).thenReturn(6) `when`(lockPatternUtils.isAutoPinConfirmEnabled(anyInt())).thenReturn(true) `when`(lockPatternUtils.getCurrentFailedPasswordAttempts(anyInt())).thenReturn(6) `when`(passwordTextView.text).thenReturn("") pinViewController.onViewAttached() underTest?.onViewAttached() verify(deleteButton).visibility = View.VISIBLE verify(enterButton).visibility = View.VISIBLE Loading @@ -263,16 +273,16 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { @Test fun handleLockout_readsNumberOfErrorAttempts() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) pinViewController.handleAttemptLockout(0) underTest?.handleAttemptLockout(0) verify(lockPatternUtils).getCurrentFailedPasswordAttempts(anyInt()) } @Test fun onUserInput_autoConfirmation_attemptsUnlock() { val pinViewController = constructPinViewController(mockKeyguardPinView) constructPinViewController(mockKeyguardPinView) whenever(lockPatternUtils.getPinLength(anyInt())).thenReturn(6) whenever(lockPatternUtils.isAutoPinConfirmEnabled(anyInt())).thenReturn(true) whenever(passwordTextView.text).thenReturn("000000") Loading @@ -280,7 +290,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { whenever(mockKeyguardPinView.enteredCredential) .thenReturn(LockscreenCredential.createPin("000000")) pinViewController.onUserInput() underTest?.onUserInput() verify(uiEventLogger).log(PinBouncerUiEvent.ATTEMPT_UNLOCK_WITH_AUTO_CONFIRM_FEATURE) verify(keyguardUpdateMonitor).setCredentialAttempted() Loading