• 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.any;
22 import static org.mockito.ArgumentMatchers.anyLong;
23 import static org.mockito.ArgumentMatchers.eq;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
26 
27 import android.test.suitebuilder.annotation.SmallTest;
28 import android.testing.AndroidTestingRunner;
29 import android.testing.TestableLooper;
30 import android.text.Editable;
31 import android.text.TextWatcher;
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(AndroidTestingRunner.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
textChanged_AnnounceForAccessibility()98     public void textChanged_AnnounceForAccessibility() {
99         ArgumentCaptor<TextWatcher> textWatcherArgumentCaptor = ArgumentCaptor.forClass(
100                 TextWatcher.class);
101         mMessageAreaController.onViewAttached();
102         verify(mKeyguardMessageArea).addTextChangedListener(textWatcherArgumentCaptor.capture());
103 
104         textWatcherArgumentCaptor.getValue().afterTextChanged(
105                 Editable.Factory.getInstance().newEditable("abc"));
106         verify(mKeyguardMessageArea).removeCallbacks(any(Runnable.class));
107         verify(mKeyguardMessageArea).postDelayed(any(Runnable.class), anyLong());
108     }
109 
110     @Test
testSetBouncerVisible()111     public void testSetBouncerVisible() {
112         mMessageAreaController.setIsVisible(true);
113         verify(mKeyguardMessageArea).setIsVisible(true);
114     }
115 
116     @Test
testGetMessage()117     public void testGetMessage() {
118         String msg = "abc";
119         when(mKeyguardMessageArea.getText()).thenReturn(msg);
120         assertThat(mMessageAreaController.getMessage()).isEqualTo(msg);
121     }
122 }
123