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