1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.keyguard 18 19 import android.testing.AndroidTestingRunner 20 import android.testing.TestableLooper 21 import android.view.View 22 import androidx.test.filters.SmallTest 23 import com.android.internal.util.LatencyTracker 24 import com.android.internal.widget.LockPatternUtils 25 import com.android.keyguard.KeyguardSecurityModel.SecurityMode 26 import com.android.systemui.R 27 import com.android.systemui.SysuiTestCase 28 import com.android.systemui.classifier.FalsingCollector 29 import com.android.systemui.classifier.FalsingCollectorFake 30 import com.android.systemui.statusbar.policy.DevicePostureController 31 import org.junit.Before 32 import org.junit.Test 33 import org.junit.runner.RunWith 34 import org.mockito.ArgumentMatchers.anyBoolean 35 import org.mockito.ArgumentMatchers.anyString 36 import org.mockito.Mock 37 import org.mockito.Mockito 38 import org.mockito.Mockito.any 39 import org.mockito.Mockito.verify 40 import org.mockito.Mockito.`when` 41 import org.mockito.MockitoAnnotations 42 43 @SmallTest 44 @RunWith(AndroidTestingRunner::class) 45 @TestableLooper.RunWithLooper 46 class KeyguardPinViewControllerTest : SysuiTestCase() { 47 @Mock private lateinit var keyguardPinView: KeyguardPINView 48 49 @Mock private lateinit var keyguardMessageArea: BouncerKeyguardMessageArea 50 51 @Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor 52 53 @Mock private lateinit var securityMode: SecurityMode 54 55 @Mock private lateinit var lockPatternUtils: LockPatternUtils 56 57 @Mock private lateinit var mKeyguardSecurityCallback: KeyguardSecurityCallback 58 59 @Mock 60 private lateinit var keyguardMessageAreaControllerFactory: KeyguardMessageAreaController.Factory 61 62 @Mock 63 private lateinit var keyguardMessageAreaController: 64 KeyguardMessageAreaController<BouncerKeyguardMessageArea> 65 66 @Mock private lateinit var mLatencyTracker: LatencyTracker 67 68 @Mock private lateinit var liftToActivateListener: LiftToActivateListener 69 70 @Mock private val mEmergencyButtonController: EmergencyButtonController? = null 71 private val falsingCollector: FalsingCollector = FalsingCollectorFake() 72 @Mock lateinit var postureController: DevicePostureController 73 74 lateinit var pinViewController: KeyguardPinViewController 75 76 @Before setupnull77 fun setup() { 78 MockitoAnnotations.initMocks(this) 79 Mockito.`when`(keyguardPinView.requireViewById<View>(R.id.bouncer_message_area)) 80 .thenReturn(keyguardMessageArea) 81 Mockito.`when`( 82 keyguardMessageAreaControllerFactory.create(any(KeyguardMessageArea::class.java)) 83 ) 84 .thenReturn(keyguardMessageAreaController) 85 `when`(keyguardPinView.resources).thenReturn(context.resources) 86 pinViewController = 87 KeyguardPinViewController( 88 keyguardPinView, 89 keyguardUpdateMonitor, 90 securityMode, 91 lockPatternUtils, 92 mKeyguardSecurityCallback, 93 keyguardMessageAreaControllerFactory, 94 mLatencyTracker, 95 liftToActivateListener, 96 mEmergencyButtonController, 97 falsingCollector, 98 postureController 99 ) 100 } 101 102 @Test startAppearAnimationnull103 fun startAppearAnimation() { 104 pinViewController.startAppearAnimation() 105 verify(keyguardMessageAreaController) 106 .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false) 107 } 108 109 @Test startAppearAnimation_withExistingMessagenull110 fun startAppearAnimation_withExistingMessage() { 111 Mockito.`when`(keyguardMessageAreaController.message).thenReturn("Unlock to continue.") 112 pinViewController.startAppearAnimation() 113 verify(keyguardMessageAreaController, Mockito.never()).setMessage(anyString(), anyBoolean()) 114 } 115 } 116