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