Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 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 | |
Lucas Dupin | 29e796d | 2018-05-10 15:31:20 -0700 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.eq; |
| 20 | import static org.mockito.Mockito.mock; |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 21 | import static org.mockito.Mockito.verify; |
Lucas Dupin | 29e796d | 2018-05-10 15:31:20 -0700 | [diff] [blame] | 22 | import static org.mockito.Mockito.verifyZeroInteractions; |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 23 | |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 24 | import android.testing.AndroidTestingRunner; |
| 25 | import android.testing.TestableLooper.RunWithLooper; |
Lucas Dupin | 29e796d | 2018-05-10 15:31:20 -0700 | [diff] [blame] | 26 | import android.view.KeyEvent; |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 27 | import android.view.LayoutInflater; |
| 28 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 29 | import androidx.test.filters.SmallTest; |
| 30 | |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 31 | import com.android.systemui.SysuiTestCase; |
| 32 | |
| 33 | import org.junit.Before; |
| 34 | import org.junit.Test; |
| 35 | import org.junit.runner.RunWith; |
Lucas Dupin | 29e796d | 2018-05-10 15:31:20 -0700 | [diff] [blame] | 36 | import org.mockito.InjectMocks; |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 37 | import org.mockito.Mock; |
| 38 | import org.mockito.MockitoAnnotations; |
| 39 | |
| 40 | @SmallTest |
| 41 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 42 | @RunWithLooper |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 43 | public class KeyguardPinBasedInputViewTest extends SysuiTestCase { |
| 44 | |
| 45 | @Mock |
Lucas Dupin | 29e796d | 2018-05-10 15:31:20 -0700 | [diff] [blame] | 46 | private PasswordTextView mPasswordEntry; |
| 47 | @Mock |
| 48 | private SecurityMessageDisplay mSecurityMessageDisplay; |
| 49 | @InjectMocks |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 50 | private KeyguardPinBasedInputView mKeyguardPinView; |
| 51 | |
| 52 | @Before |
| 53 | public void setup() { |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 54 | LayoutInflater inflater = LayoutInflater.from(getContext()); |
| 55 | mKeyguardPinView = |
| 56 | (KeyguardPinBasedInputView) inflater.inflate(R.layout.keyguard_pin_view, null); |
Lucas Dupin | 29e796d | 2018-05-10 15:31:20 -0700 | [diff] [blame] | 57 | MockitoAnnotations.initMocks(this); |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void onResume_requestsFocus() { |
| 62 | mKeyguardPinView.onResume(KeyguardSecurityView.SCREEN_ON); |
Lucas Dupin | 29e796d | 2018-05-10 15:31:20 -0700 | [diff] [blame] | 63 | verify(mPasswordEntry).requestFocus(); |
| 64 | } |
| 65 | |
| 66 | @Test |
| 67 | public void onKeyDown_clearsSecurityMessage() { |
| 68 | mKeyguardPinView.onKeyDown(KeyEvent.KEYCODE_0, mock(KeyEvent.class)); |
| 69 | verify(mSecurityMessageDisplay).setMessage(eq("")); |
| 70 | } |
| 71 | |
| 72 | @Test |
| 73 | public void onKeyDown_noSecurityMessageInteraction() { |
| 74 | mKeyguardPinView.onKeyDown(KeyEvent.KEYCODE_UNKNOWN, mock(KeyEvent.class)); |
| 75 | verifyZeroInteractions(mSecurityMessageDisplay); |
Lucas Dupin | 7065900 | 2018-04-30 15:56:52 -0700 | [diff] [blame] | 76 | } |
| 77 | } |