• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.inputmethod.InputMethodManager
22 import android.widget.EditText
23 import androidx.test.filters.SmallTest
24 import com.android.internal.util.LatencyTracker
25 import com.android.internal.widget.LockPatternUtils
26 import com.android.systemui.R
27 import com.android.systemui.SysuiTestCase
28 import com.android.systemui.classifier.FalsingCollector
29 import com.android.systemui.util.concurrency.DelayableExecutor
30 import org.junit.Before
31 import org.junit.Test
32 import org.junit.runner.RunWith
33 import org.mockito.ArgumentMatchers.anyBoolean
34 import org.mockito.ArgumentMatchers.anyString
35 import org.mockito.Mock
36 import org.mockito.Mockito
37 import org.mockito.Mockito.never
38 import org.mockito.Mockito.verify
39 import org.mockito.Mockito.`when`
40 import org.mockito.MockitoAnnotations
41 
42 @SmallTest
43 @RunWith(AndroidTestingRunner::class)
44 @TestableLooper.RunWithLooper
45 class KeyguardPasswordViewControllerTest : SysuiTestCase() {
46   @Mock private lateinit var keyguardPasswordView: KeyguardPasswordView
47   @Mock private lateinit var passwordEntry: EditText
48   @Mock lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
49   @Mock lateinit var securityMode: KeyguardSecurityModel.SecurityMode
50   @Mock lateinit var lockPatternUtils: LockPatternUtils
51   @Mock lateinit var keyguardSecurityCallback: KeyguardSecurityCallback
52   @Mock lateinit var messageAreaControllerFactory: KeyguardMessageAreaController.Factory
53   @Mock lateinit var latencyTracker: LatencyTracker
54   @Mock lateinit var inputMethodManager: InputMethodManager
55   @Mock lateinit var emergencyButtonController: EmergencyButtonController
56   @Mock lateinit var mainExecutor: DelayableExecutor
57   @Mock lateinit var falsingCollector: FalsingCollector
58   @Mock lateinit var keyguardViewController: KeyguardViewController
59   @Mock private lateinit var mKeyguardMessageArea: BouncerKeyguardMessageArea
60   @Mock
61   private lateinit var mKeyguardMessageAreaController:
62       KeyguardMessageAreaController<BouncerKeyguardMessageArea>
63 
64   private lateinit var keyguardPasswordViewController: KeyguardPasswordViewController
65 
66   @Before
setupnull67   fun setup() {
68     MockitoAnnotations.initMocks(this)
69     Mockito.`when`(
70             keyguardPasswordView.requireViewById<BouncerKeyguardMessageArea>(
71                 R.id.bouncer_message_area))
72         .thenReturn(mKeyguardMessageArea)
73     Mockito.`when`(messageAreaControllerFactory.create(mKeyguardMessageArea))
74         .thenReturn(mKeyguardMessageAreaController)
75     Mockito.`when`(keyguardPasswordView.passwordTextViewId).thenReturn(R.id.passwordEntry)
76     Mockito.`when`(keyguardPasswordView.findViewById<EditText>(R.id.passwordEntry))
77         .thenReturn(passwordEntry)
78     `when`(keyguardPasswordView.resources).thenReturn(context.resources)
79     keyguardPasswordViewController =
80         KeyguardPasswordViewController(
81             keyguardPasswordView,
82             keyguardUpdateMonitor,
83             securityMode,
84             lockPatternUtils,
85             keyguardSecurityCallback,
86             messageAreaControllerFactory,
87             latencyTracker,
88             inputMethodManager,
89             emergencyButtonController,
90             mainExecutor,
91             mContext.resources,
92             falsingCollector,
93             keyguardViewController)
94   }
95 
96   @Test
testFocusWhenBouncerIsShownnull97   fun testFocusWhenBouncerIsShown() {
98     Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(true)
99     Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true)
100     keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED)
101     keyguardPasswordView.post {
102       verify(keyguardPasswordView).requestFocus()
103       verify(keyguardPasswordView).showKeyboard()
104     }
105   }
106 
107   @Test
testDoNotFocusWhenBouncerIsHiddennull108   fun testDoNotFocusWhenBouncerIsHidden() {
109     Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(false)
110     Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true)
111     keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED)
112     verify(keyguardPasswordView, never()).requestFocus()
113   }
114 
115   @Test
testHideKeyboardWhenOnPausenull116   fun testHideKeyboardWhenOnPause() {
117     keyguardPasswordViewController.onPause()
118     keyguardPasswordView.post {
119       verify(keyguardPasswordView).clearFocus()
120       verify(keyguardPasswordView).hideKeyboard()
121     }
122   }
123 
124   @Test
startAppearAnimationnull125   fun startAppearAnimation() {
126     keyguardPasswordViewController.startAppearAnimation()
127     verify(mKeyguardMessageAreaController)
128         .setMessage(context.resources.getString(R.string.keyguard_enter_your_password), false)
129   }
130 
131   @Test
startAppearAnimation_withExistingMessagenull132   fun startAppearAnimation_withExistingMessage() {
133     `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.")
134     keyguardPasswordViewController.startAppearAnimation()
135     verify(mKeyguardMessageAreaController, never()).setMessage(anyString(), anyBoolean())
136   }
137 }
138