Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6239bcb authored by Yining Liu's avatar Yining Liu
Browse files

Add unit tests for End-aligning short shelf on split shade when

minimalism enabled

Add unit tests for aligning the short shelf to the end for split shade
on lock screen when the notification minimalism is enabled.

Bug: 357643925
Flag: com.android.server.notification.notification_minimalism
Test: atest NotificationShelfTest
Change-Id: I5935fdb00409be15633bf583b19249586ee2ecd0
parent 4f11fba0
Loading
Loading
Loading
Loading
+184 −10
Original line number Diff line number Diff line
package com.android.systemui.statusbar.notification.stack

import android.platform.test.annotations.EnableFlags
import android.service.notification.StatusBarNotification
import android.testing.TestableLooper.RunWithLooper
import android.view.LayoutInflater
@@ -20,6 +21,7 @@ import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.ExpandableView
import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.StackScrollAlgorithmState
import com.android.systemui.util.mockito.mock
import junit.framework.Assert.assertEquals
@@ -30,6 +32,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.Mockito.spy
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations

@@ -59,7 +62,7 @@ open class NotificationShelfTest : SysuiTestCase() {
                .inflate(
                    /* resource = */ R.layout.status_bar_notification_shelf,
                    /* root = */ root,
                    /* attachToRoot = */ false
                    /* attachToRoot = */ false,
                ) as NotificationShelf

        whenever(ambientState.largeScreenShadeInterpolator).thenReturn(largeScreenShadeInterpolator)
@@ -127,6 +130,177 @@ open class NotificationShelfTest : SysuiTestCase() {
        assertFalse(isYBelowShelfInView)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testAlignment_splitShade_LTR() {
        // Given: LTR mode, split shade
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = false, splitShade = true, width = 100, actualWidth = 40)

        // Then: shelf should align to end
        assertTrue(shelfSpy.isAlignedToEnd)
        assertTrue(shelfSpy.isAlignedToRight)
        assertTrue(shelfSpy.mBackgroundNormal.alignToEnd)
        assertTrue(shelfSpy.mShelfIcons.alignToEnd)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testAlignment_nonSplitShade_LTR() {
        // Given: LTR mode, non split shade
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = false, splitShade = false, width = 100, actualWidth = 40)

        // Then: shelf should not align to end
        assertFalse(shelfSpy.isAlignedToEnd)
        assertFalse(shelfSpy.isAlignedToRight)
        assertFalse(shelfSpy.mBackgroundNormal.alignToEnd)
        assertFalse(shelfSpy.mShelfIcons.alignToEnd)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testAlignment_splitShade_RTL() {
        // Given: RTL mode, split shade
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = true, splitShade = true, width = 100, actualWidth = 40)

        // Then: shelf should align to end, but to left due to RTL
        assertTrue(shelfSpy.isAlignedToEnd)
        assertFalse(shelfSpy.isAlignedToRight)
        assertTrue(shelfSpy.mBackgroundNormal.alignToEnd)
        assertTrue(shelfSpy.mShelfIcons.alignToEnd)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testAlignment_nonSplitShade_RTL() {
        // Given: RTL mode, non split shade
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = true, splitShade = false, width = 100, actualWidth = 40)

        // Then: shelf should not align to end, but to right due to RTL
        assertFalse(shelfSpy.isAlignedToEnd)
        assertTrue(shelfSpy.isAlignedToRight)
        assertFalse(shelfSpy.mBackgroundNormal.alignToEnd)
        assertFalse(shelfSpy.mShelfIcons.alignToEnd)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testGetShelfLeftBound_splitShade_LTR() {
        // Given: LTR mode, split shade
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = false, splitShade = true, width = 100, actualWidth = 40)

        // When: get the left bound of the shelf
        val shelfLeftBound = shelfSpy.shelfLeftBound

        // Then: should be equal to shelf's width - actual width
        assertEquals(60f, shelfLeftBound)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testGetShelfRightBound_splitShade_LTR() {
        // Given: LTR mode, split shade, width 100, actual width 40
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = false, splitShade = true, width = 100, actualWidth = 40)

        // Then: the right bound of the shelf should be equal to shelf's width
        assertEquals(100f, shelfSpy.shelfRightBound)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testGetShelfLeftBound_nonSplitShade_LTR() {
        // Given: LTR mode, non split shade
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = false, splitShade = false, width = 100, actualWidth = 40)

        // When: get the left bound of the shelf
        val shelfLeftBound = shelfSpy.shelfLeftBound

        // Then: should be equal to 0f
        assertEquals(0f, shelfLeftBound)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testGetShelfRightBound_nonSplitShade_LTR() {
        // Given: LTR mode, non split shade, width 100, actual width 40
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = false, splitShade = false, width = 100, actualWidth = 40)

        // Then: the right bound of the shelf should be equal to shelf's actual width
        assertEquals(40f, shelfSpy.shelfRightBound)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testGetShelfLeftBound_splitShade_RTL() {
        // Given: RTL mode, split shade
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = true, splitShade = true, width = 100, actualWidth = 40)

        // When: get the left bound of the shelf
        val shelfLeftBound = shelfSpy.shelfLeftBound

        // Then: should be equal to 0f
        assertEquals(0f, shelfLeftBound)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testGetShelfRightBound_splitShade_RTL() {
        // Given: RTL mode, split shade, width 100, actual width 40
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = true, splitShade = true, width = 100, actualWidth = 40)

        // Then: the right bound of the shelf should be equal to shelf's actual width
        assertEquals(40f, shelfSpy.shelfRightBound)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testGetShelfLeftBound_nonSplitShade_RTL() {
        // Given: RTL mode, non split shade
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = true, splitShade = false, width = 100, actualWidth = 40)

        // When: get the left bound of the shelf
        val shelfLeftBound = shelfSpy.shelfLeftBound

        // Then: should be equal to shelf's width - actual width
        assertEquals(60f, shelfLeftBound)
    }

    @Test
    @EnableFlags(NotificationMinimalism.FLAG_NAME)
    fun testGetShelfRightBound_nonSplitShade_RTL() {
        // Given: LTR mode, non split shade, width 100, actual width 40
        val shelfSpy =
            prepareShelfSpy(shelf, rtl = true, splitShade = false, width = 100, actualWidth = 40)

        // Then: the right bound of the shelf should be equal to shelf's width
        assertEquals(100f, shelfSpy.shelfRightBound)
    }

    private fun prepareShelfSpy(
        shelf: NotificationShelf,
        rtl: Boolean,
        splitShade: Boolean,
        width: Int,
        actualWidth: Int,
    ): NotificationShelf {
        val shelfSpy = spy(shelf)
        whenever(shelfSpy.isLayoutRtl).thenReturn(rtl)
        whenever(ambientState.useSplitShade).thenReturn(splitShade)
        whenever(shelfSpy.width).thenReturn(width)
        shelfSpy.setActualWidth(actualWidth.toFloat())
        return shelfSpy
    }

    @Test
    fun getAmountInShelf_lastViewBelowShelf_completelyInShelf() {
        val shelfClipStart = 0f
@@ -152,7 +326,7 @@ open class NotificationShelfTest : SysuiTestCase() {
                /* scrollingFast= */ false,
                /* expandingAnimated= */ false,
                /* isLastChild= */ true,
                shelfClipStart
                shelfClipStart,
            )
        assertEquals(1f, amountInShelf)
    }
@@ -182,7 +356,7 @@ open class NotificationShelfTest : SysuiTestCase() {
                /* scrollingFast= */ false,
                /* expandingAnimated= */ false,
                /* isLastChild= */ true,
                shelfClipStart
                shelfClipStart,
            )
        assertEquals(1f, amountInShelf)
    }
@@ -212,7 +386,7 @@ open class NotificationShelfTest : SysuiTestCase() {
                /* scrollingFast= */ false,
                /* expandingAnimated= */ false,
                /* isLastChild= */ true,
                shelfClipStart
                shelfClipStart,
            )
        assertEquals(0.5f, amountInShelf)
    }
@@ -241,7 +415,7 @@ open class NotificationShelfTest : SysuiTestCase() {
                /* scrollingFast= */ false,
                /* expandingAnimated= */ false,
                /* isLastChild= */ true,
                shelfClipStart
                shelfClipStart,
            )
        assertEquals(0f, amountInShelf)
    }
@@ -250,7 +424,7 @@ open class NotificationShelfTest : SysuiTestCase() {
    fun updateState_expansionChanging_shelfTransparent() {
        updateState_expansionChanging_shelfAlphaUpdated(
            expansionFraction = 0.25f,
            expectedAlpha = 0.0f
            expectedAlpha = 0.0f,
        )
    }

@@ -260,7 +434,7 @@ open class NotificationShelfTest : SysuiTestCase() {

        updateState_expansionChanging_shelfAlphaUpdated(
            expansionFraction = 0.85f,
            expectedAlpha = 0.0f
            expectedAlpha = 0.0f,
        )
    }

@@ -281,7 +455,7 @@ open class NotificationShelfTest : SysuiTestCase() {

        updateState_expansionChanging_shelfAlphaUpdated(
            expansionFraction = expansionFraction,
            expectedAlpha = 0.123f
            expectedAlpha = 0.123f,
        )
    }

@@ -330,7 +504,7 @@ open class NotificationShelfTest : SysuiTestCase() {
                /* scrollingFast= */ false,
                /* expandingAnimated= */ false,
                /* isLastChild= */ true,
                shelfClipStart
                shelfClipStart,
            )
        assertEquals(1f, amountInShelf)
    }
@@ -628,7 +802,7 @@ open class NotificationShelfTest : SysuiTestCase() {

    private fun updateState_expansionChanging_shelfAlphaUpdated(
        expansionFraction: Float,
        expectedAlpha: Float
        expectedAlpha: Float,
    ) {
        val sbnMock: StatusBarNotification = mock()
        val mockEntry = mock<NotificationEntry>().apply { whenever(this.sbn).thenReturn(sbnMock) }
+17 −7
Original line number Diff line number Diff line
@@ -79,9 +79,11 @@ public class NotificationShelf extends ActivatableNotificationView {
    private static final SourceType BASE_VALUE = SourceType.from("BaseValue");
    private static final SourceType SHELF_SCROLL = SourceType.from("ShelfScroll");

    private NotificationShelfIconContainer mShelfIcons;
    @VisibleForTesting
    public NotificationShelfIconContainer mShelfIcons;
    // This field hides mBackgroundNormal from super class for short-shelf alignment
    private NotificationShelfBackgroundView mBackgroundNormal;
    @VisibleForTesting
    public NotificationShelfBackgroundView mBackgroundNormal;
    private boolean mHideBackground;
    private int mStatusBarHeight;
    private boolean mEnableNotificationClipping;
@@ -275,7 +277,11 @@ public class NotificationShelf extends ActivatableNotificationView {
        }
    }

    private void setActualWidth(float actualWidth) {
    /**
     * Set the actual width of the shelf, this will only differ from width for short shelves.
     */
    @VisibleForTesting
    public void setActualWidth(float actualWidth) {
        setBackgroundWidth((int) actualWidth);
        if (mShelfIcons != null) {
            mShelfIcons.setAlignToEnd(isAlignedToEnd());
@@ -369,7 +375,8 @@ public class NotificationShelf extends ActivatableNotificationView {
    /**
     * @return The left boundary of the shelf.
     */
    private float getShelfLeftBound() {
    @VisibleForTesting
    public float getShelfLeftBound() {
        if (isAlignedToRight()) {
            return getWidth() - getActualWidth();
        } else {
@@ -380,7 +387,8 @@ public class NotificationShelf extends ActivatableNotificationView {
    /**
     * @return The right boundary of the shelf.
     */
    private float getShelfRightBound() {
    @VisibleForTesting
    public float getShelfRightBound() {
        if (isAlignedToRight()) {
            return getWidth();
        } else {
@@ -388,7 +396,8 @@ public class NotificationShelf extends ActivatableNotificationView {
        }
    }

    private boolean isAlignedToRight() {
    @VisibleForTesting
    public boolean isAlignedToRight() {
        return isAlignedToEnd() ^ isLayoutRtl();
    }

@@ -397,7 +406,8 @@ public class NotificationShelf extends ActivatableNotificationView {
     * to the layout end (right for LTR; left for RTL).
     * @return whether to align with the minimalism split shade style
     */
    private boolean isAlignedToEnd() {
    @VisibleForTesting
    public boolean isAlignedToEnd() {
        if (!NotificationMinimalism.isEnabled()) {
            return false;
        }
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification.shelf

import android.content.Context
import android.util.AttributeSet
import androidx.annotation.VisibleForTesting
import com.android.systemui.statusbar.notification.row.NotificationBackgroundView
import com.android.systemui.statusbar.notification.shared.NotificationMinimalism

@@ -31,7 +32,8 @@ constructor(context: Context, attrs: AttributeSet? = null) :
    var alignToEnd = false

    /** @return whether the alignment of the notification shelf is right. */
    override fun isAlignedToRight(): Boolean {
    @VisibleForTesting
    public override fun isAlignedToRight(): Boolean {
        if (!NotificationMinimalism.isEnabled) {
            return super.isAlignedToRight()
        }