• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.systemui.biometrics
18 
19 import android.graphics.Rect
20 import android.testing.TestableLooper
21 import android.view.MotionEvent
22 import androidx.test.ext.junit.runners.AndroidJUnit4
23 import androidx.test.filters.SmallTest
24 import com.android.systemui.RoboPilotTest
25 import com.android.systemui.SysuiTestCase
26 import com.android.systemui.biometrics.UdfpsController.UdfpsOverlayController
27 import com.android.systemui.statusbar.commandline.CommandRegistry
28 import com.android.systemui.util.mockito.any
29 import junit.framework.Assert.assertEquals
30 import org.junit.Before
31 import org.junit.Rule
32 import org.junit.Test
33 import org.junit.runner.RunWith
34 import org.mockito.ArgumentCaptor
35 import org.mockito.Captor
36 import org.mockito.Mock
37 import org.mockito.Mockito.times
38 import org.mockito.Mockito.verify
39 import org.mockito.Mockito.`when` as whenEver
40 import org.mockito.junit.MockitoJUnit
41 
42 @SmallTest
43 @RoboPilotTest
44 @RunWith(AndroidJUnit4::class)
45 @TestableLooper.RunWithLooper
46 class UdfpsShellTest : SysuiTestCase() {
47 
48     @JvmField @Rule var rule = MockitoJUnit.rule()
49 
50     // Unit under test
51     private lateinit var udfpsShell: UdfpsShell
52 
53     @Mock lateinit var commandRegistry: CommandRegistry
54     @Mock lateinit var udfpsOverlayController: UdfpsOverlayController
55 
56     @Captor private lateinit var motionEvent: ArgumentCaptor<MotionEvent>
57 
58     private val sensorBounds = Rect()
59 
60     @Before
setupnull61     fun setup() {
62         whenEver(udfpsOverlayController.sensorBounds).thenReturn(sensorBounds)
63 
64         udfpsShell = UdfpsShell(commandRegistry)
65         udfpsShell.udfpsOverlayController = udfpsOverlayController
66     }
67 
68     @Test
testSimFingerDownnull69     fun testSimFingerDown() {
70         udfpsShell.simFingerDown()
71 
72         verify(udfpsOverlayController, times(2)).debugOnTouch(motionEvent.capture())
73 
74         assertEquals(motionEvent.allValues[0].action, MotionEvent.ACTION_DOWN) // ACTION_MOVE
75         assertEquals(motionEvent.allValues[1].action, MotionEvent.ACTION_MOVE) // ACTION_MOVE
76     }
77 
78     @Test
testSimFingerUpnull79     fun testSimFingerUp() {
80         udfpsShell.simFingerUp()
81 
82         verify(udfpsOverlayController).debugOnTouch(motionEvent.capture())
83 
84         assertEquals(motionEvent.value.action, MotionEvent.ACTION_UP)
85     }
86 
87     @Test
testOnUiReadynull88     fun testOnUiReady() {
89         udfpsShell.onUiReady()
90 
91         verify(udfpsOverlayController).debugOnUiReady(any())
92     }
93 }
94