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.keyguard 18 19 import android.testing.AndroidTestingRunner 20 import android.view.View 21 import androidx.test.filters.SmallTest 22 import com.android.systemui.SysuiTestCase 23 import com.android.systemui.keyguard.ui.view.KeyguardRootView 24 import com.android.systemui.kosmos.Kosmos 25 import com.android.systemui.plugins.statusbar.StatusBarStateController 26 import com.android.systemui.res.R 27 import com.android.systemui.shade.NotificationShadeWindowView 28 import com.android.systemui.statusbar.StatusBarState.KEYGUARD 29 import com.android.systemui.statusbar.StatusBarState.SHADE 30 import com.android.systemui.unfold.FakeUnfoldTransitionProvider 31 import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener 32 import com.android.systemui.unfold.fakeUnfoldTransitionProgressProvider 33 import com.google.common.truth.Truth.assertThat 34 import org.junit.Before 35 import org.junit.Test 36 import org.junit.runner.RunWith 37 import org.mockito.Mock 38 import org.mockito.MockitoAnnotations 39 import org.mockito.kotlin.whenever 40 41 /** 42 * Translates items away/towards the hinge when the device is opened/closed. This is controlled by 43 * the set of ids, which also dictact which direction to move and when, via a filter fn. 44 */ 45 @SmallTest 46 @RunWith(AndroidTestingRunner::class) 47 class KeyguardUnfoldTransitionTest : SysuiTestCase() { 48 49 private val kosmos = Kosmos() 50 51 private val progressProvider: FakeUnfoldTransitionProvider = 52 kosmos.fakeUnfoldTransitionProgressProvider 53 54 @Mock 55 private lateinit var keyguardRootView: KeyguardRootView 56 57 @Mock 58 private lateinit var notificationShadeWindowView: NotificationShadeWindowView 59 60 @Mock private lateinit var statusBarStateController: StatusBarStateController 61 62 private lateinit var underTest: KeyguardUnfoldTransition 63 private lateinit var progressListener: TransitionProgressListener 64 private var xTranslationMax = 0f 65 66 @Before setupnull67 fun setup() { 68 MockitoAnnotations.initMocks(this) 69 70 xTranslationMax = 71 context.resources.getDimensionPixelSize(R.dimen.keyguard_unfold_translation_x).toFloat() 72 73 underTest = KeyguardUnfoldTransition( 74 context, keyguardRootView, notificationShadeWindowView, 75 statusBarStateController, progressProvider 76 ) 77 78 underTest.setup() 79 underTest.statusViewCentered = false 80 81 progressListener = progressProvider 82 } 83 84 @Test onTransition_centeredViewDoesNotMovenull85 fun onTransition_centeredViewDoesNotMove() { 86 whenever(statusBarStateController.getState()).thenReturn(KEYGUARD) 87 underTest.statusViewCentered = true 88 89 val view = View(context) 90 whenever(keyguardRootView.findViewById<View>(R.id.lockscreen_clock_view_large)).thenReturn( 91 view 92 ) 93 94 progressListener.onTransitionStarted() 95 assertThat(view.translationX).isZero() 96 97 progressListener.onTransitionProgress(0f) 98 assertThat(view.translationX).isZero() 99 100 progressListener.onTransitionProgress(0.5f) 101 assertThat(view.translationX).isZero() 102 103 progressListener.onTransitionFinished() 104 assertThat(view.translationX).isZero() 105 } 106 107 @Test whenInShadeState_viewDoesNotMovenull108 fun whenInShadeState_viewDoesNotMove() { 109 whenever(statusBarStateController.getState()).thenReturn(SHADE) 110 111 val view = View(context) 112 whenever(keyguardRootView.findViewById<View>(R.id.lockscreen_clock_view_large)).thenReturn( 113 view 114 ) 115 116 progressListener.onTransitionStarted() 117 assertThat(view.translationX).isZero() 118 119 progressListener.onTransitionProgress(0f) 120 assertThat(view.translationX).isZero() 121 122 progressListener.onTransitionProgress(0.5f) 123 assertThat(view.translationX).isZero() 124 125 progressListener.onTransitionFinished() 126 assertThat(view.translationX).isZero() 127 } 128 129 @Test whenInKeyguardState_viewDoesMovenull130 fun whenInKeyguardState_viewDoesMove() { 131 whenever(statusBarStateController.getState()).thenReturn(KEYGUARD) 132 133 val view = View(context) 134 whenever( 135 notificationShadeWindowView 136 .findViewById<View>(R.id.lockscreen_clock_view_large) 137 ).thenReturn(view) 138 139 progressListener.onTransitionStarted() 140 assertThat(view.translationX).isZero() 141 142 progressListener.onTransitionProgress(0f) 143 assertThat(view.translationX).isEqualTo(xTranslationMax) 144 145 progressListener.onTransitionProgress(0.5f) 146 assertThat(view.translationX).isEqualTo(0.5f * xTranslationMax) 147 148 progressListener.onTransitionFinished() 149 assertThat(view.translationX).isZero() 150 } 151 } 152