• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.ArgumentMatchers.anyBoolean;
22 import static org.mockito.ArgumentMatchers.eq;
23 import static org.mockito.Mockito.never;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
26 
27 import android.hardware.biometrics.BiometricSourceType;
28 import android.testing.TestableLooper;
29 
30 import androidx.test.ext.junit.runners.AndroidJUnit4;
31 import androidx.test.filters.SmallTest;
32 
33 import com.android.systemui.SysuiTestCase;
34 import com.android.systemui.statusbar.policy.ConfigurationController;
35 import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
36 
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.mockito.ArgumentCaptor;
41 import org.mockito.Mock;
42 import org.mockito.MockitoAnnotations;
43 
44 @SmallTest
45 @TestableLooper.RunWithLooper
46 @RunWith(AndroidJUnit4.class)
47 public class KeyguardMessageAreaControllerTest extends SysuiTestCase {
48     @Mock
49     private ConfigurationController mConfigurationController;
50     @Mock
51     private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
52     @Mock
53     private KeyguardMessageArea mKeyguardMessageArea;
54     private KeyguardMessageAreaController mMessageAreaController;
55 
56     @Before
setUp()57     public void setUp() throws Exception {
58         MockitoAnnotations.initMocks(this);
59         mMessageAreaController = new KeyguardMessageAreaController.Factory(
60                 mKeyguardUpdateMonitor, mConfigurationController).create(
61                 mKeyguardMessageArea);
62     }
63 
64     @Test
onAttachedToWindow_registersConfigurationCallback()65     public void onAttachedToWindow_registersConfigurationCallback() {
66         ArgumentCaptor<ConfigurationListener> configurationListenerArgumentCaptor =
67                 ArgumentCaptor.forClass(ConfigurationListener.class);
68 
69         mMessageAreaController.onViewAttached();
70         verify(mConfigurationController).addCallback(configurationListenerArgumentCaptor.capture());
71 
72         mMessageAreaController.onViewDetached();
73         verify(mConfigurationController).removeCallback(
74                 eq(configurationListenerArgumentCaptor.getValue()));
75     }
76 
77     @Test
onAttachedToWindow_registersKeyguardUpdateMontiorCallback()78     public void onAttachedToWindow_registersKeyguardUpdateMontiorCallback() {
79         ArgumentCaptor<KeyguardUpdateMonitorCallback> keyguardUpdateMonitorCallbackArgumentCaptor =
80                 ArgumentCaptor.forClass(KeyguardUpdateMonitorCallback.class);
81 
82         mMessageAreaController.onViewAttached();
83         verify(mKeyguardUpdateMonitor).registerCallback(
84                 keyguardUpdateMonitorCallbackArgumentCaptor.capture());
85 
86         mMessageAreaController.onViewDetached();
87         verify(mKeyguardUpdateMonitor).removeCallback(
88                 eq(keyguardUpdateMonitorCallbackArgumentCaptor.getValue()));
89     }
90 
91     @Test
testClearsTextField()92     public void testClearsTextField() {
93         mMessageAreaController.setMessage("");
94         verify(mKeyguardMessageArea).setMessage("", /* animate= */ true);
95     }
96 
97     @Test
testSetBouncerVisible()98     public void testSetBouncerVisible() {
99         mMessageAreaController.setIsVisible(true);
100         verify(mKeyguardMessageArea).setIsVisible(true);
101     }
102 
103     @Test
testGetMessage()104     public void testGetMessage() {
105         String msg = "abc";
106         when(mKeyguardMessageArea.getText()).thenReturn(msg);
107         assertThat(mMessageAreaController.getMessage()).isEqualTo(msg);
108     }
109 
110     @Test
testFingerprintMessageUpdate()111     public void testFingerprintMessageUpdate() {
112         String msg = "fpMessage";
113         mMessageAreaController.setMessage(
114                 msg, BiometricSourceType.FINGERPRINT
115         );
116         verify(mKeyguardMessageArea).setMessage(msg, /* animate= */ true);
117 
118         String msg2 = "fpMessage2";
119         mMessageAreaController.setMessage(
120                 msg2, BiometricSourceType.FINGERPRINT
121         );
122         verify(mKeyguardMessageArea).setMessage(msg2, /* animate= */ true);
123     }
124 
125     @Test
testFaceMessageDroppedWhileFingerprintMessageShowing()126     public void testFaceMessageDroppedWhileFingerprintMessageShowing() {
127         String fpMsg = "fpMessage";
128         mMessageAreaController.setMessage(
129                 fpMsg, BiometricSourceType.FINGERPRINT
130         );
131         verify(mKeyguardMessageArea).setMessage(eq(fpMsg), /* animate= */ anyBoolean());
132 
133         String faceMessage = "faceMessage";
134         mMessageAreaController.setMessage(
135                 faceMessage, BiometricSourceType.FACE
136         );
137         verify(mKeyguardMessageArea, never())
138                 .setMessage(eq(faceMessage), /* animate= */ anyBoolean());
139     }
140 
141     @Test
testGenericMessageShowsAfterFingerprintMessageShowing()142     public void testGenericMessageShowsAfterFingerprintMessageShowing() {
143         String fpMsg = "fpMessage";
144         mMessageAreaController.setMessage(
145                 fpMsg, BiometricSourceType.FINGERPRINT
146         );
147         verify(mKeyguardMessageArea).setMessage(eq(fpMsg), /* animate= */ anyBoolean());
148 
149         String genericMessage = "genericMessage";
150         mMessageAreaController.setMessage(
151                 genericMessage, null
152         );
153         verify(mKeyguardMessageArea)
154                 .setMessage(eq(genericMessage), /* animate= */ anyBoolean());
155     }
156 }
157