blob: cd52e8792cfd80e0538a5cbb7b6a3c232896c957 [file] [log] [blame]
Robert Snoeberger57872e32018-11-06 15:22:01 -05001/*
2 * Copyright (C) 2018 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
17package com.android.systemui.statusbar.phone;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import android.support.test.filters.SmallTest;
22import android.testing.AndroidTestingRunner;
23import android.testing.TestableLooper;
24
25import com.android.systemui.SysuiTestCase;
26
27import org.junit.Before;
28import org.junit.Test;
29import org.junit.runner.RunWith;
30
31@SmallTest
32@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050033@TestableLooper.RunWithLooper
Robert Snoeberger57872e32018-11-06 15:22:01 -050034public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
35
36 private static final int SCREEN_HEIGHT = 2000;
37 private static final int EMPTY_MARGIN = 0;
38 private static final int EMPTY_HEIGHT = 0;
39 private static final boolean SECURE_LOCKED = false;
Robert Snoeberger57872e32018-11-06 15:22:01 -050040 private static final float ZERO_DRAG = 0.f;
41 private static final float OPAQUE = 1.f;
42 private static final float TRANSPARENT = 0.f;
43
44 private KeyguardClockPositionAlgorithm mClockPositionAlgorithm;
45 private KeyguardClockPositionAlgorithm.Result mClockPosition;
46 private int mNotificationStackHeight;
47 private float mPanelExpansion;
48 private int mKeyguardStatusHeight;
49 private float mDark;
50
51 @Before
52 public void setUp() {
53 mClockPositionAlgorithm = new KeyguardClockPositionAlgorithm();
54 mClockPosition = new KeyguardClockPositionAlgorithm.Result();
55 }
56
57 @Test
58 public void clockPositionMiddleOfScreenOnAOD() {
59 // GIVEN on AOD and both stack scroll and clock have 0 height
60 givenAOD();
61 mNotificationStackHeight = EMPTY_HEIGHT;
62 mKeyguardStatusHeight = EMPTY_HEIGHT;
63 // WHEN the clock position algorithm is run
64 positionClock();
65 // THEN the clock Y position is the middle of the screen (SCREEN_HEIGHT / 2).
66 assertThat(mClockPosition.clockY).isEqualTo(1000);
67 // AND the clock is opaque and positioned on the left.
68 assertThat(mClockPosition.clockX).isEqualTo(0);
69 assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
70 }
71
72 @Test
73 public void clockPositionAdjustsForKeyguardStatusOnAOD() {
74 // GIVEN on AOD with a clock of height 100
75 givenAOD();
76 mNotificationStackHeight = EMPTY_HEIGHT;
77 mKeyguardStatusHeight = 100;
78 // WHEN the clock position algorithm is run
79 positionClock();
80 // THEN the clock Y position adjusts for the clock height (SCREEN_HEIGHT / 2 - 100).
81 assertThat(mClockPosition.clockY).isEqualTo(900);
82 // AND the clock is opaque and positioned on the left.
83 assertThat(mClockPosition.clockX).isEqualTo(0);
84 assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
85 }
86
87 @Test
88 public void clockPositionLargeClockOnAOD() {
89 // GIVEN on AOD with a full screen clock
90 givenAOD();
91 mNotificationStackHeight = EMPTY_HEIGHT;
92 mKeyguardStatusHeight = SCREEN_HEIGHT;
93 // WHEN the clock position algorithm is run
94 positionClock();
Robert Snoeberger10b63532018-11-07 16:14:11 -050095 // THEN the clock Y position doesn't overflow the screen.
96 assertThat(mClockPosition.clockY).isEqualTo(0);
Robert Snoeberger57872e32018-11-06 15:22:01 -050097 // AND the clock is opaque and positioned on the left.
98 assertThat(mClockPosition.clockX).isEqualTo(0);
99 assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
100 }
101
102 @Test
103 public void clockPositionMiddleOfScreenOnLockScreen() {
104 // GIVEN on lock screen with stack scroll and clock of 0 height
105 givenLockScreen();
106 mNotificationStackHeight = EMPTY_HEIGHT;
107 mKeyguardStatusHeight = EMPTY_HEIGHT;
108 // WHEN the clock position algorithm is run
109 positionClock();
110 // THEN the clock Y position is the middle of the screen (SCREEN_HEIGHT / 2).
111 assertThat(mClockPosition.clockY).isEqualTo(1000);
112 // AND the clock is opaque and positioned on the left.
113 assertThat(mClockPosition.clockX).isEqualTo(0);
114 assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
115 }
116
117 @Test
118 public void clockPositionWithStackScrollExpandOnLockScreen() {
119 // GIVEN on lock screen with stack scroll of height 500
120 givenLockScreen();
121 mNotificationStackHeight = 500;
122 mKeyguardStatusHeight = EMPTY_HEIGHT;
123 // WHEN the clock position algorithm is run
124 positionClock();
125 // THEN the clock Y position adjusts for stack scroll height ( (SCREEN_HEIGHT - 500 ) / 2).
126 assertThat(mClockPosition.clockY).isEqualTo(750);
127 // AND the clock is opaque and positioned on the left.
128 assertThat(mClockPosition.clockX).isEqualTo(0);
129 assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
130 }
131
132 @Test
133 public void clockPositionWithPartialDragOnLockScreen() {
134 // GIVEN dragging up on lock screen
135 givenLockScreen();
136 mNotificationStackHeight = EMPTY_HEIGHT;
137 mKeyguardStatusHeight = EMPTY_HEIGHT;
138 mPanelExpansion = 0.5f;
139 // WHEN the clock position algorithm is run
140 positionClock();
141 // THEN the clock Y position adjusts with drag gesture.
142 assertThat(mClockPosition.clockY).isLessThan(1000);
143 // AND the clock is positioned on the left and not fully opaque.
144 assertThat(mClockPosition.clockX).isEqualTo(0);
145 assertThat(mClockPosition.clockAlpha).isLessThan(OPAQUE);
146 }
147
148 @Test
149 public void clockPositionWithFullDragOnLockScreen() {
150 // GIVEN the lock screen is dragged up
151 givenLockScreen();
152 mNotificationStackHeight = EMPTY_HEIGHT;
153 mKeyguardStatusHeight = EMPTY_HEIGHT;
154 mPanelExpansion = 0.f;
155 // WHEN the clock position algorithm is run
156 positionClock();
157 // THEN the clock is transparent.
158 assertThat(mClockPosition.clockAlpha).isEqualTo(TRANSPARENT);
159 }
160
161 @Test
162 public void largeClockOnLockScreenIsTransparent() {
163 // GIVEN on lock screen with a full screen clock
164 givenLockScreen();
165 mNotificationStackHeight = EMPTY_HEIGHT;
166 mKeyguardStatusHeight = SCREEN_HEIGHT;
167 // WHEN the clock position algorithm is run
168 positionClock();
169 // THEN the clock is transparent
170 assertThat(mClockPosition.clockAlpha).isEqualTo(TRANSPARENT);
171 }
172
Robert Snoeberger6067dfb2018-11-27 15:50:13 -0500173 @Test
174 public void notifPositionMiddleOfScreenOnAOD() {
175 // GIVEN on AOD and both stack scroll and clock have 0 height
176 givenAOD();
177 mNotificationStackHeight = EMPTY_HEIGHT;
178 mKeyguardStatusHeight = EMPTY_HEIGHT;
179 // WHEN the position algorithm is run
180 positionClock();
181 // THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
182 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
183 }
184
185 @Test
186 public void notifPositionIndependentOfKeyguardStatusHeightOnAOD() {
187 // GIVEN on AOD and clock has a nonzero height
188 givenAOD();
189 mNotificationStackHeight = EMPTY_HEIGHT;
190 mKeyguardStatusHeight = 100;
191 // WHEN the position algorithm is run
192 positionClock();
193 // THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
194 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
195 }
196
197 @Test
198 public void notifPositionWithLargeClockOnAOD() {
199 // GIVEN on AOD and clock has a nonzero height
200 givenAOD();
201 mNotificationStackHeight = EMPTY_HEIGHT;
202 mKeyguardStatusHeight = SCREEN_HEIGHT;
203 // WHEN the position algorithm is run
204 positionClock();
205 // THEN the notif padding is, unfortunately, the entire screen.
206 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(SCREEN_HEIGHT);
207 }
208
209 @Test
Robert Snoeberger6067dfb2018-11-27 15:50:13 -0500210 public void notifPositionMiddleOfScreenOnLockScreen() {
211 // GIVEN on lock screen and both stack scroll and clock have 0 height
212 givenLockScreen();
213 mNotificationStackHeight = EMPTY_HEIGHT;
214 mKeyguardStatusHeight = EMPTY_HEIGHT;
215 // WHEN the position algorithm is run
216 positionClock();
217 // THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
218 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
219 }
220
221 @Test
222 public void notifPositionAdjustsForStackHeightOnLockScreen() {
223 // GIVEN on lock screen and stack scroller has a nonzero height
224 givenLockScreen();
225 mNotificationStackHeight = 500;
226 mKeyguardStatusHeight = EMPTY_HEIGHT;
227 // WHEN the position algorithm is run
228 positionClock();
229 // THEN the notif padding adjusts for the expanded notif stack.
230 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(750);
231 }
232
233 @Test
234 public void notifPositionAdjustsForClockHeightOnLockScreen() {
235 // GIVEN on lock screen and stack scroller has a nonzero height
236 givenLockScreen();
237 mNotificationStackHeight = EMPTY_HEIGHT;
238 mKeyguardStatusHeight = 200;
239 // WHEN the position algorithm is run
240 positionClock();
241 // THEN the notif padding adjusts for both clock and notif stack.
242 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
243 }
244
245 @Test
246 public void notifPositionAdjustsForStackHeightAndClockHeightOnLockScreen() {
247 // GIVEN on lock screen and stack scroller has a nonzero height
248 givenLockScreen();
249 mNotificationStackHeight = 500;
250 mKeyguardStatusHeight = 200;
251 // WHEN the position algorithm is run
252 positionClock();
253 // THEN the notif padding adjusts for both clock and notif stack.
254 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(810);
255 }
256
257 @Test
258 public void notifPositionWithLargeClockOnLockScreen() {
259 // GIVEN on lock screen and clock has a nonzero height
260 givenLockScreen();
261 mNotificationStackHeight = EMPTY_HEIGHT;
262 mKeyguardStatusHeight = SCREEN_HEIGHT;
263 // WHEN the position algorithm is run
264 positionClock();
265 // THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
266 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
267 }
268
269 @Test
270 public void notifPositionWithFullDragOnLockScreen() {
271 // GIVEN the lock screen is dragged up
272 givenLockScreen();
273 mNotificationStackHeight = EMPTY_HEIGHT;
274 mKeyguardStatusHeight = EMPTY_HEIGHT;
275 mPanelExpansion = 0.f;
276 // WHEN the clock position algorithm is run
277 positionClock();
278 // THEN the notif padding is zero.
279 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
280 }
281
282 @Test
283 public void notifPositionWithLargeClockFullDragOnLockScreen() {
284 // GIVEN the lock screen is dragged up and a full screen clock
285 givenLockScreen();
286 mNotificationStackHeight = EMPTY_HEIGHT;
287 mKeyguardStatusHeight = SCREEN_HEIGHT;
288 mPanelExpansion = 0.f;
289 // WHEN the clock position algorithm is run
290 positionClock();
291 // THEN the notif padding is zero.
292 assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
293 }
294
Robert Snoeberger57872e32018-11-06 15:22:01 -0500295 private void givenAOD() {
296 mPanelExpansion = 1.f;
297 mDark = 1.f;
298 }
299
300 private void givenLockScreen() {
301 mPanelExpansion = 1.f;
302 mDark = 0.f;
303 }
304
305 private void positionClock() {
306 mClockPositionAlgorithm.setup(EMPTY_MARGIN, SCREEN_HEIGHT, mNotificationStackHeight,
307 mPanelExpansion, SCREEN_HEIGHT, mKeyguardStatusHeight, mDark, SECURE_LOCKED,
Lucas Dupin00be88f2019-01-03 17:50:52 -0800308 ZERO_DRAG);
Robert Snoeberger57872e32018-11-06 15:22:01 -0500309 mClockPositionAlgorithm.run(mClockPosition);
310 }
311}