1 /* 2 * Copyright (C) 2018 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.eq; 20 import static org.mockito.Mockito.mock; 21 import static org.mockito.Mockito.verify; 22 import static org.mockito.Mockito.verifyZeroInteractions; 23 24 import android.testing.AndroidTestingRunner; 25 import android.testing.TestableLooper.RunWithLooper; 26 import android.view.KeyEvent; 27 import android.view.LayoutInflater; 28 29 import androidx.test.filters.SmallTest; 30 31 import com.android.systemui.R; 32 import com.android.systemui.SysuiTestCase; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.mockito.InjectMocks; 38 import org.mockito.Mock; 39 import org.mockito.MockitoAnnotations; 40 41 @SmallTest 42 @RunWith(AndroidTestingRunner.class) 43 @RunWithLooper 44 public class KeyguardPinBasedInputViewTest extends SysuiTestCase { 45 46 @Mock 47 private PasswordTextView mPasswordEntry; 48 @Mock 49 private SecurityMessageDisplay mSecurityMessageDisplay; 50 @InjectMocks 51 private KeyguardPinBasedInputView mKeyguardPinView; 52 53 @Before setup()54 public void setup() { 55 LayoutInflater inflater = LayoutInflater.from(getContext()); 56 mDependency.injectMockDependency(KeyguardUpdateMonitor.class); 57 mKeyguardPinView = 58 (KeyguardPinBasedInputView) inflater.inflate(R.layout.keyguard_pin_view, null); 59 MockitoAnnotations.initMocks(this); 60 } 61 62 @Test onResume_requestsFocus()63 public void onResume_requestsFocus() { 64 mKeyguardPinView.onResume(KeyguardSecurityView.SCREEN_ON); 65 verify(mPasswordEntry).requestFocus(); 66 } 67 68 @Test onKeyDown_clearsSecurityMessage()69 public void onKeyDown_clearsSecurityMessage() { 70 mKeyguardPinView.onKeyDown(KeyEvent.KEYCODE_0, mock(KeyEvent.class)); 71 verify(mSecurityMessageDisplay).setMessage(eq("")); 72 } 73 74 @Test onKeyDown_noSecurityMessageInteraction()75 public void onKeyDown_noSecurityMessageInteraction() { 76 mKeyguardPinView.onKeyDown(KeyEvent.KEYCODE_UNKNOWN, mock(KeyEvent.class)); 77 verifyZeroInteractions(mSecurityMessageDisplay); 78 } 79 } 80