1 package com.android.systemui.statusbar.phone 2 3 import android.graphics.Point 4 import android.view.Display 5 import android.view.Surface 6 import android.view.View 7 import android.view.WindowManager 8 import androidx.test.filters.SmallTest 9 import com.android.systemui.SysuiTestCase 10 import com.android.systemui.unfold.TestUnfoldTransitionProvider 11 import com.android.systemui.unfold.util.CurrentActivityTypeProvider 12 import com.android.systemui.unfold.util.ScopedUnfoldTransitionProgressProvider 13 import com.android.systemui.util.mockito.whenever 14 import com.google.common.truth.Truth.assertThat 15 import org.junit.Before 16 import org.junit.Test 17 import org.mockito.ArgumentMatchers.any 18 import org.mockito.Mock 19 import org.mockito.MockitoAnnotations 20 21 @SmallTest 22 class StatusBarMoveFromCenterAnimationControllerTest : SysuiTestCase() { 23 24 @Mock 25 private lateinit var windowManager: WindowManager 26 27 @Mock 28 private lateinit var display: Display 29 30 @Mock 31 private lateinit var currentActivityTypeProvider: CurrentActivityTypeProvider 32 33 private val view: View = View(context) 34 private val progressProvider = TestUnfoldTransitionProvider() 35 private val scopedProvider = ScopedUnfoldTransitionProgressProvider(progressProvider) 36 37 private lateinit var controller: StatusBarMoveFromCenterAnimationController 38 39 @Before setUpnull40 fun setUp() { 41 MockitoAnnotations.initMocks(this) 42 43 whenever(windowManager.defaultDisplay).thenReturn(display) 44 whenever(display.rotation).thenReturn(Surface.ROTATION_0) 45 whenever(display.getSize(any())).thenAnswer { 46 val point = it.arguments[0] as Point 47 point.x = 100 48 point.y = 100 49 Unit 50 } 51 52 scopedProvider.setReadyToHandleTransition(true) 53 54 controller = 55 StatusBarMoveFromCenterAnimationController( 56 scopedProvider, 57 currentActivityTypeProvider, 58 windowManager 59 ) 60 } 61 62 @Test onTransitionProgressAndFinished_resetsTranslationsnull63 fun onTransitionProgressAndFinished_resetsTranslations() { 64 controller.onViewsReady(arrayOf(view)) 65 66 progressProvider.onTransitionProgress(0.5f) 67 progressProvider.onTransitionFinished() 68 69 assertThat(view.translationX).isZero() 70 } 71 72 @Test onStatusBarWidthChangedWithNoTransitionBefore_noTranslationnull73 fun onStatusBarWidthChangedWithNoTransitionBefore_noTranslation() { 74 controller.onViewsReady(arrayOf(view)) 75 76 controller.onStatusBarWidthChanged() 77 78 assertThat(view.translationX).isZero() 79 } 80 81 @Test onTransitionProgress_updatesTranslationsnull82 fun onTransitionProgress_updatesTranslations() { 83 controller.onViewsReady(arrayOf(view)) 84 85 progressProvider.onTransitionProgress(0.5f) 86 87 assertThat(view.translationX).isNonZero() 88 } 89 90 @Test onTransitionProgress_whenDetached_doesNotUpdateTranslationsnull91 fun onTransitionProgress_whenDetached_doesNotUpdateTranslations() { 92 controller.onViewsReady(arrayOf(view)) 93 controller.onViewDetached() 94 95 progressProvider.onTransitionProgress(0.5f) 96 97 assertThat(view.translationX).isZero() 98 } 99 100 @Test detachedAfterProgress_resetsTranslationsnull101 fun detachedAfterProgress_resetsTranslations() { 102 controller.onViewsReady(arrayOf(view)) 103 progressProvider.onTransitionProgress(0.5f) 104 105 controller.onViewDetached() 106 107 assertThat(view.translationX).isZero() 108 } 109 110 @Test alpha_onLauncher_alphaDoesNotChangenull111 fun alpha_onLauncher_alphaDoesNotChange() { 112 whenever(currentActivityTypeProvider.isHomeActivity).thenReturn(true) 113 controller.onViewsReady(arrayOf(view)) 114 progressProvider.onTransitionStarted() 115 progressProvider.onTransitionProgress(0.0f) 116 assertThat(view.alpha).isEqualTo(1.0f) 117 118 progressProvider.onTransitionProgress(1.0f) 119 120 assertThat(view.alpha).isEqualTo(1.0f) 121 } 122 123 @Test alpha_NotOnLauncher_alphaChangesnull124 fun alpha_NotOnLauncher_alphaChanges() { 125 whenever(currentActivityTypeProvider.isHomeActivity).thenReturn(false) 126 controller.onViewsReady(arrayOf(view)) 127 progressProvider.onTransitionStarted() 128 assertThat(view.alpha).isEqualTo(1.0f) 129 130 progressProvider.onTransitionProgress(0.5f) 131 132 assertThat(view.alpha).isNotEqualTo(1.0f) 133 } 134 135 @Test transitionFinished_viewReAttached_noChangesToTranslationnull136 fun transitionFinished_viewReAttached_noChangesToTranslation() { 137 controller.onViewsReady(arrayOf(view)) 138 progressProvider.onTransitionProgress(0.5f) 139 progressProvider.onTransitionFinished() 140 controller.onViewDetached() 141 142 controller.onViewsReady(arrayOf(view)) 143 controller.onStatusBarWidthChanged() 144 145 assertThat(view.translationX).isZero() 146 } 147 } 148