blob: 58870e4acbd036ba8efa8672cd1a0d121fba516a [file] [log] [blame]
Lucas Dupin70659002018-04-30 15:56:52 -07001/*
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
17package com.android.keyguard;
18
Lucas Dupin29e796d2018-05-10 15:31:20 -070019import static org.mockito.ArgumentMatchers.eq;
20import static org.mockito.Mockito.mock;
Lucas Dupin70659002018-04-30 15:56:52 -070021import static org.mockito.Mockito.verify;
Lucas Dupin29e796d2018-05-10 15:31:20 -070022import static org.mockito.Mockito.verifyZeroInteractions;
Lucas Dupin70659002018-04-30 15:56:52 -070023
24import android.support.test.filters.SmallTest;
25import android.testing.AndroidTestingRunner;
26import android.testing.TestableLooper.RunWithLooper;
Lucas Dupin29e796d2018-05-10 15:31:20 -070027import android.view.KeyEvent;
Lucas Dupin70659002018-04-30 15:56:52 -070028import android.view.LayoutInflater;
29
30import com.android.systemui.SysuiTestCase;
31
32import org.junit.Before;
33import org.junit.Test;
34import org.junit.runner.RunWith;
Lucas Dupin29e796d2018-05-10 15:31:20 -070035import org.mockito.InjectMocks;
Lucas Dupin70659002018-04-30 15:56:52 -070036import org.mockito.Mock;
37import org.mockito.MockitoAnnotations;
38
39@SmallTest
40@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050041@RunWithLooper
Lucas Dupin70659002018-04-30 15:56:52 -070042public class KeyguardPinBasedInputViewTest extends SysuiTestCase {
43
44 @Mock
Lucas Dupin29e796d2018-05-10 15:31:20 -070045 private PasswordTextView mPasswordEntry;
46 @Mock
47 private SecurityMessageDisplay mSecurityMessageDisplay;
48 @InjectMocks
Lucas Dupin70659002018-04-30 15:56:52 -070049 private KeyguardPinBasedInputView mKeyguardPinView;
50
51 @Before
52 public void setup() {
Lucas Dupin70659002018-04-30 15:56:52 -070053 LayoutInflater inflater = LayoutInflater.from(getContext());
54 mKeyguardPinView =
55 (KeyguardPinBasedInputView) inflater.inflate(R.layout.keyguard_pin_view, null);
Lucas Dupin29e796d2018-05-10 15:31:20 -070056 MockitoAnnotations.initMocks(this);
Lucas Dupin70659002018-04-30 15:56:52 -070057 }
58
59 @Test
60 public void onResume_requestsFocus() {
61 mKeyguardPinView.onResume(KeyguardSecurityView.SCREEN_ON);
Lucas Dupin29e796d2018-05-10 15:31:20 -070062 verify(mPasswordEntry).requestFocus();
63 }
64
65 @Test
66 public void onKeyDown_clearsSecurityMessage() {
67 mKeyguardPinView.onKeyDown(KeyEvent.KEYCODE_0, mock(KeyEvent.class));
68 verify(mSecurityMessageDisplay).setMessage(eq(""));
69 }
70
71 @Test
72 public void onKeyDown_noSecurityMessageInteraction() {
73 mKeyguardPinView.onKeyDown(KeyEvent.KEYCODE_UNKNOWN, mock(KeyEvent.class));
74 verifyZeroInteractions(mSecurityMessageDisplay);
Lucas Dupin70659002018-04-30 15:56:52 -070075 }
76}