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