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 android.testing.AndroidTestingRunner
20 import android.testing.TestableLooper
21 import androidx.test.filters.SmallTest
22 import com.android.internal.util.LatencyTracker
23 import com.android.internal.widget.LockPatternUtils
24 import com.android.internal.widget.LockPatternView
25 import com.android.systemui.R
26 import com.android.systemui.SysuiTestCase
27 import com.android.systemui.classifier.FalsingCollector
28 import com.android.systemui.classifier.FalsingCollectorFake
29 import com.android.systemui.statusbar.policy.DevicePostureController
30 import org.junit.Before
31 import org.junit.Test
32 import org.junit.runner.RunWith
33 import org.mockito.Mock
34 import org.mockito.Mockito.`when`
35 import org.mockito.Mockito.verify
36 import org.mockito.MockitoAnnotations
37 
38 @SmallTest
39 @RunWith(AndroidTestingRunner::class)
40 @TestableLooper.RunWithLooper
41 class KeyguardPatternViewControllerTest : SysuiTestCase() {
42     @Mock
43     private lateinit var mKeyguardPatternView: KeyguardPatternView
44     @Mock
45     private lateinit var mKeyguardUpdateMonitor: KeyguardUpdateMonitor
46     @Mock
47     private lateinit var mSecurityMode: KeyguardSecurityModel.SecurityMode
48     @Mock
49     private lateinit var mLockPatternUtils: LockPatternUtils
50     @Mock
51     private lateinit var mKeyguardSecurityCallback: KeyguardSecurityCallback
52     @Mock
53     private lateinit var mLatencyTracker: LatencyTracker
54     private var mFalsingCollector: FalsingCollector = FalsingCollectorFake()
55     @Mock
56     private lateinit var mEmergencyButtonController: EmergencyButtonController
57     @Mock
58     private lateinit
59     var mKeyguardMessageAreaControllerFactory: KeyguardMessageAreaController.Factory
60     @Mock
61     private lateinit var mKeyguardMessageArea: KeyguardMessageArea
62     @Mock
63     private lateinit var mKeyguardMessageAreaController: KeyguardMessageAreaController
64     @Mock
65     private lateinit var mLockPatternView: LockPatternView
66     @Mock
67     private lateinit var mPostureController: DevicePostureController
68 
69     private lateinit var mKeyguardPatternViewController: KeyguardPatternViewController
70 
71     @Before
72     fun setup() {
73         MockitoAnnotations.initMocks(this)
74         `when`(mKeyguardPatternView.isAttachedToWindow).thenReturn(true)
75         `when`(mKeyguardPatternView.findViewById<KeyguardMessageArea>(R.id.keyguard_message_area))
76                 .thenReturn(mKeyguardMessageArea)
77         `when`(mKeyguardPatternView.findViewById<LockPatternView>(R.id.lockPatternView))
78                 .thenReturn(mLockPatternView)
79         `when`(mKeyguardMessageAreaControllerFactory.create(mKeyguardMessageArea))
80                 .thenReturn(mKeyguardMessageAreaController)
81         mKeyguardPatternViewController = KeyguardPatternViewController(mKeyguardPatternView,
82         mKeyguardUpdateMonitor, mSecurityMode, mLockPatternUtils, mKeyguardSecurityCallback,
83                 mLatencyTracker, mFalsingCollector, mEmergencyButtonController,
84                 mKeyguardMessageAreaControllerFactory, mPostureController)
85     }
86 
87     @Test
88     fun onPause_clearsTextField() {
89         mKeyguardPatternViewController.init()
90         mKeyguardPatternViewController.onPause()
91         verify(mKeyguardMessageAreaController).setMessage("")
92     }
93 }
94