1 /*
2  * Copyright (C) 2020 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 static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
22 
23 import android.testing.AndroidTestingRunner;
24 import android.testing.TestableLooper.RunWithLooper;
25 import android.view.View;
26 
27 import androidx.test.filters.SmallTest;
28 
29 import com.android.internal.util.LatencyTracker;
30 import com.android.internal.widget.LockPatternUtils;
31 import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
32 import com.android.systemui.R;
33 import com.android.systemui.SysuiTestCase;
34 import com.android.systemui.classifier.FalsingCollector;
35 import com.android.systemui.classifier.FalsingCollectorFake;
36 import com.android.systemui.classifier.SingleTapClassifier;
37 
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.mockito.Mock;
42 import org.mockito.MockitoAnnotations;
43 
44 @SmallTest
45 @RunWith(AndroidTestingRunner.class)
46 @RunWithLooper
47 public class KeyguardPinBasedInputViewControllerTest extends SysuiTestCase {
48 
49     @Mock
50     private KeyguardPinBasedInputView mPinBasedInputView;
51     @Mock
52     private PasswordTextView mPasswordEntry;
53     @Mock
54     private KeyguardMessageArea mKeyguardMessageArea;
55     @Mock
56     private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
57     @Mock
58     private SecurityMode mSecurityMode;
59     @Mock
60     private LockPatternUtils mLockPatternUtils;
61     @Mock
62     private KeyguardSecurityCallback mKeyguardSecurityCallback;
63     @Mock
64     private KeyguardMessageAreaController.Factory mKeyguardMessageAreaControllerFactory;
65     @Mock
66     private KeyguardMessageAreaController mKeyguardMessageAreaController;
67     @Mock
68     private LatencyTracker mLatencyTracker;
69     @Mock
70     private LiftToActivateListener mLiftToactivateListener;
71     @Mock
72     private EmergencyButtonController mEmergencyButtonController;
73     private FalsingCollector mFalsingCollector = new FalsingCollectorFake();
74     @Mock
75     private SingleTapClassifier mSingleTapClassifier;
76     @Mock
77     private View mDeleteButton;
78     @Mock
79     private View mOkButton;
80     private NumPadKey[] mButtons = new NumPadKey[]{};
81 
82     private KeyguardPinBasedInputViewController mKeyguardPinViewController;
83 
84     @Before
setup()85     public void setup() {
86         MockitoAnnotations.initMocks(this);
87         when(mKeyguardMessageAreaControllerFactory.create(any(KeyguardMessageArea.class)))
88                 .thenReturn(mKeyguardMessageAreaController);
89         when(mPinBasedInputView.getPasswordTextViewId()).thenReturn(1);
90         when(mPinBasedInputView.findViewById(1)).thenReturn(mPasswordEntry);
91         when(mPinBasedInputView.isAttachedToWindow()).thenReturn(true);
92         when(mPinBasedInputView.getButtons()).thenReturn(mButtons);
93         when(mPinBasedInputView.findViewById(R.id.keyguard_message_area))
94                 .thenReturn(mKeyguardMessageArea);
95         when(mPinBasedInputView.findViewById(R.id.delete_button))
96                 .thenReturn(mDeleteButton);
97         when(mPinBasedInputView.findViewById(R.id.key_enter))
98                 .thenReturn(mOkButton);
99         mKeyguardPinViewController = new KeyguardPinBasedInputViewController(mPinBasedInputView,
100                 mKeyguardUpdateMonitor, mSecurityMode, mLockPatternUtils, mKeyguardSecurityCallback,
101                 mKeyguardMessageAreaControllerFactory, mLatencyTracker, mLiftToactivateListener,
102                 mEmergencyButtonController, mFalsingCollector) {
103             @Override
104             public void onResume(int reason) {
105                 super.onResume(reason);
106             }
107         };
108         mKeyguardPinViewController.init();
109     }
110 
111     @Test
onResume_requestsFocus()112     public void onResume_requestsFocus() {
113         mKeyguardPinViewController.onResume(KeyguardSecurityView.SCREEN_ON);
114         verify(mPasswordEntry).requestFocus();
115     }
116 }
117 
118