Merge "Add test for stack scroller padding."
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithm.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithm.java
index d8280ba..a81b7e5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithm.java
@@ -22,6 +22,7 @@
 import android.content.res.Resources;
 import android.util.MathUtils;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.keyguard.KeyguardStatusView;
 import com.android.systemui.Interpolators;
 import com.android.systemui.R;
@@ -229,6 +230,11 @@
                 - mBurnInPreventionOffsetX;
     }
 
+    @VisibleForTesting
+    void setPulsingPadding(int padding) {
+        mPulsingPadding = padding;
+    }
+
     public static class Result {
 
         /**
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java
index f8ad298..31014b8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java
@@ -37,7 +37,6 @@
     private static final int EMPTY_MARGIN = 0;
     private static final int EMPTY_HEIGHT = 0;
     private static final boolean SECURE_LOCKED = false;
-    private static final boolean PULSING_NO = false;
     private static final float ZERO_DRAG = 0.f;
     private static final float OPAQUE = 1.f;
     private static final float TRANSPARENT = 0.f;
@@ -48,6 +47,7 @@
     private float mPanelExpansion;
     private int mKeyguardStatusHeight;
     private float mDark;
+    private boolean mPulsing;
 
     @Before
     public void setUp() {
@@ -171,6 +171,156 @@
         assertThat(mClockPosition.clockAlpha).isEqualTo(TRANSPARENT);
     }
 
+    @Test
+    public void notifPositionMiddleOfScreenOnAOD() {
+        // GIVEN on AOD and both stack scroll and clock have 0 height
+        givenAOD();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = EMPTY_HEIGHT;
+        // WHEN the position algorithm is run
+        positionClock();
+        // THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
+    }
+
+    @Test
+    public void notifPositionIndependentOfKeyguardStatusHeightOnAOD() {
+        // GIVEN on AOD and clock has a nonzero height
+        givenAOD();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = 100;
+        // WHEN the position algorithm is run
+        positionClock();
+        // THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
+    }
+
+    @Test
+    public void notifPositionWithLargeClockOnAOD() {
+        // GIVEN on AOD and clock has a nonzero height
+        givenAOD();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = SCREEN_HEIGHT;
+        // WHEN the position algorithm is run
+        positionClock();
+        // THEN the notif padding is, unfortunately, the entire screen.
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(SCREEN_HEIGHT);
+    }
+
+    @Test
+    public void notifPositionWhilePulsingOnAOD() {
+        // GIVEN on AOD and pulsing
+        givenAOD();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = EMPTY_HEIGHT;
+        mPulsing = true;
+        mClockPositionAlgorithm.setPulsingPadding(200);
+        // WHEN the clock position algorithm is run
+        positionClock();
+        // THEN the notif padding doesn't adjust for pulsing.
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
+    }
+
+    @Test
+    public void notifPositionMiddleOfScreenOnLockScreen() {
+        // GIVEN on lock screen and both stack scroll and clock have 0 height
+        givenLockScreen();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = EMPTY_HEIGHT;
+        // WHEN the position algorithm is run
+        positionClock();
+        // THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
+    }
+
+    @Test
+    public void notifPositionAdjustsForStackHeightOnLockScreen() {
+        // GIVEN on lock screen and stack scroller has a nonzero height
+        givenLockScreen();
+        mNotificationStackHeight = 500;
+        mKeyguardStatusHeight = EMPTY_HEIGHT;
+        // WHEN the position algorithm is run
+        positionClock();
+        // THEN the notif padding adjusts for the expanded notif stack.
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(750);
+    }
+
+    @Test
+    public void notifPositionAdjustsForClockHeightOnLockScreen() {
+        // GIVEN on lock screen and stack scroller has a nonzero height
+        givenLockScreen();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = 200;
+        // WHEN the position algorithm is run
+        positionClock();
+        // THEN the notif padding adjusts for both clock and notif stack.
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
+    }
+
+    @Test
+    public void notifPositionAdjustsForStackHeightAndClockHeightOnLockScreen() {
+        // GIVEN on lock screen and stack scroller has a nonzero height
+        givenLockScreen();
+        mNotificationStackHeight = 500;
+        mKeyguardStatusHeight = 200;
+        // WHEN the position algorithm is run
+        positionClock();
+        // THEN the notif padding adjusts for both clock and notif stack.
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(810);
+    }
+
+    @Test
+    public void notifPositionWithLargeClockOnLockScreen() {
+        // GIVEN on lock screen and clock has a nonzero height
+        givenLockScreen();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = SCREEN_HEIGHT;
+        // WHEN the position algorithm is run
+        positionClock();
+        // THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
+    }
+
+    @Test
+    public void notifPositionWithFullDragOnLockScreen() {
+        // GIVEN the lock screen is dragged up
+        givenLockScreen();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = EMPTY_HEIGHT;
+        mPanelExpansion = 0.f;
+        // WHEN the clock position algorithm is run
+        positionClock();
+        // THEN the notif padding is zero.
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
+    }
+
+    @Test
+    public void notifPositionWithLargeClockFullDragOnLockScreen() {
+        // GIVEN the lock screen is dragged up and a full screen clock
+        givenLockScreen();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = SCREEN_HEIGHT;
+        mPanelExpansion = 0.f;
+        // WHEN the clock position algorithm is run
+        positionClock();
+        // THEN the notif padding is zero.
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
+    }
+
+    @Test
+    public void notifPositionWhilePulsingOnLockScreen() {
+        // GIVEN on lock screen and pulsing
+        givenLockScreen();
+        mNotificationStackHeight = EMPTY_HEIGHT;
+        mKeyguardStatusHeight = EMPTY_HEIGHT;
+        mPulsing = true;
+        mClockPositionAlgorithm.setPulsingPadding(200);
+        // WHEN the clock position algorithm is run
+        positionClock();
+        // THEN the notif padding adjusts for pulsing.
+        assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1200);
+    }
+
     private void givenAOD() {
         mPanelExpansion = 1.f;
         mDark = 1.f;
@@ -184,7 +334,7 @@
     private void positionClock() {
         mClockPositionAlgorithm.setup(EMPTY_MARGIN, SCREEN_HEIGHT, mNotificationStackHeight,
                 mPanelExpansion, SCREEN_HEIGHT, mKeyguardStatusHeight, mDark, SECURE_LOCKED,
-                PULSING_NO, ZERO_DRAG);
+                mPulsing, ZERO_DRAG);
         mClockPositionAlgorithm.run(mClockPosition);
     }
 }