1 /* 2 * Copyright (C) 2023 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.platform.test.flag.junit.FlagsParameterization 20 import androidx.test.filters.SmallTest 21 import com.android.systemui.SysuiTestCase 22 import com.android.systemui.flags.andSceneContainer 23 import com.android.systemui.kosmos.applicationCoroutineScope 24 import com.android.systemui.kosmos.testScope 25 import com.android.systemui.shade.domain.interactor.shadeInteractor 26 import com.android.systemui.shade.shadeTestUtil 27 import com.android.systemui.testKosmos 28 import kotlinx.coroutines.test.runCurrent 29 import kotlinx.coroutines.test.runTest 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.verify 35 import org.mockito.MockitoAnnotations 36 import org.mockito.kotlin.verifyZeroInteractions 37 import platform.test.runner.parameterized.ParameterizedAndroidJunit4 38 import platform.test.runner.parameterized.Parameters 39 40 @SmallTest 41 @RunWith(ParameterizedAndroidJunit4::class) 42 class AuthDialogPanelInteractionDetectorTest(flags: FlagsParameterization?) : SysuiTestCase() { 43 44 companion object { 45 @JvmStatic 46 @Parameters(name = "{0}") getParamsnull47 fun getParams(): List<FlagsParameterization> { 48 return FlagsParameterization.allCombinationsOf().andSceneContainer() 49 } 50 } 51 52 init { 53 mSetFlagsRule.setFlagsParameterization(flags!!) 54 } 55 56 private val kosmos = testKosmos() 57 private val testScope = kosmos.testScope 58 <lambda>null59 private val shadeTestUtil by lazy { kosmos.shadeTestUtil } 60 61 @Mock private lateinit var action: Runnable 62 63 lateinit var detector: AuthDialogPanelInteractionDetector 64 65 @Before setUpnull66 fun setUp() { 67 MockitoAnnotations.initMocks(this) 68 detector = 69 AuthDialogPanelInteractionDetector( 70 kosmos.applicationCoroutineScope, 71 { kosmos.shadeInteractor }, 72 ) 73 } 74 75 @Test enableDetector_expand_shouldRunActionnull76 fun enableDetector_expand_shouldRunAction() = 77 testScope.runTest { 78 // GIVEN shade is closed and detector is enabled 79 shadeTestUtil.setShadeExpansion(0f) 80 detector.enable(action) 81 runCurrent() 82 83 // WHEN shade expands 84 shadeTestUtil.setTracking(true) 85 shadeTestUtil.setShadeExpansion(.5f) 86 runCurrent() 87 88 // THEN action was run 89 verify(action).run() 90 } 91 92 @Test enableDetector_isUserInteractingTrue_shouldNotPostRunnablenull93 fun enableDetector_isUserInteractingTrue_shouldNotPostRunnable() = 94 testScope.runTest { 95 // GIVEN isInteracting starts true 96 shadeTestUtil.setTracking(true) 97 runCurrent() 98 detector.enable(action) 99 100 // THEN action was not run 101 verifyZeroInteractions(action) 102 } 103 104 @Test enableDetector_shadeExpandImmediate_shouldNotPostRunnablenull105 fun enableDetector_shadeExpandImmediate_shouldNotPostRunnable() = 106 testScope.runTest { 107 // GIVEN shade is closed and detector is enabled 108 shadeTestUtil.setShadeExpansion(0f) 109 detector.enable(action) 110 runCurrent() 111 112 // WHEN shade expands fully instantly 113 shadeTestUtil.setShadeExpansion(1f) 114 runCurrent() 115 116 // THEN action not run 117 verifyZeroInteractions(action) 118 detector.disable() 119 } 120 121 @Test disableDetector_shouldNotPostRunnablenull122 fun disableDetector_shouldNotPostRunnable() = 123 testScope.runTest { 124 // GIVEN shade is closed and detector is enabled 125 shadeTestUtil.setShadeExpansion(0f) 126 detector.enable(action) 127 runCurrent() 128 129 // WHEN detector is disabled and shade opens 130 detector.disable() 131 runCurrent() 132 shadeTestUtil.setTracking(true) 133 shadeTestUtil.setShadeExpansion(.5f) 134 runCurrent() 135 136 // THEN action not run 137 verifyZeroInteractions(action) 138 } 139 140 @Test enableDetector_beginCollapse_shouldNotPostRunnablenull141 fun enableDetector_beginCollapse_shouldNotPostRunnable() = 142 testScope.runTest { 143 // GIVEN shade is open and detector is enabled 144 shadeTestUtil.setShadeExpansion(1f) 145 detector.enable(action) 146 runCurrent() 147 148 // WHEN shade begins to collapse 149 shadeTestUtil.programmaticCollapseShade() 150 runCurrent() 151 152 // THEN action not run 153 verifyZeroInteractions(action) 154 detector.disable() 155 } 156 } 157