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

Commit ee4cf685 authored by Matías Hernández's avatar Matías Hernández Committed by Automerger Merge Worker
Browse files

Fixes to HeadsUpManagerPhoneTest & friends am: d0cd9756

parents 4d6eb9b0 d0cd9756
Loading
Loading
Loading
Loading
+30 −28
Original line number Original line Diff line number Diff line
@@ -73,9 +73,7 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {
    // Number of notifications to use in tests requiring multiple notifications
    // Number of notifications to use in tests requiring multiple notifications
    private static final int TEST_NUM_NOTIFICATIONS = 4;
    private static final int TEST_NUM_NOTIFICATIONS = 4;
    protected static final int TEST_TIMEOUT_TIME = 15000;
    protected static final int TEST_TIMEOUT_TIME = 15000;
    protected final Runnable TEST_TIMEOUT_RUNNABLE = () -> mTimedOut = true;
    protected final Runnable mTestTimeoutRunnable = () -> mTimedOut = true;

    private AlertingNotificationManager mAlertingNotificationManager;


    protected NotificationEntry mEntry;
    protected NotificationEntry mEntry;
    protected Handler mTestHandler;
    protected Handler mTestHandler;
@@ -84,7 +82,7 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {


    @Mock protected ExpandableNotificationRow mRow;
    @Mock protected ExpandableNotificationRow mRow;


    private final class TestableAlertingNotificationManager extends AlertingNotificationManager {
    private static class TestableAlertingNotificationManager extends AlertingNotificationManager {
        private AlertEntry mLastCreatedEntry;
        private AlertEntry mLastCreatedEntry;


        private TestableAlertingNotificationManager(Handler handler) {
        private TestableAlertingNotificationManager(Handler handler) {
@@ -112,8 +110,8 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {
        }
        }
    }
    }


    protected AlertingNotificationManager createAlertingNotificationManager(Handler handler) {
    protected AlertingNotificationManager createAlertingNotificationManager() {
        return new TestableAlertingNotificationManager(handler);
        return new TestableAlertingNotificationManager(mTestHandler);
    }
    }


    protected StatusBarNotification createNewSbn(int id, Notification n) {
    protected StatusBarNotification createNewSbn(int id, Notification n) {
@@ -169,8 +167,6 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {
                .setSbn(mSbn)
                .setSbn(mSbn)
                .build();
                .build();
        mEntry.setRow(mRow);
        mEntry.setRow(mRow);

        mAlertingNotificationManager = createAlertingNotificationManager(mTestHandler);
    }
    }


    @After
    @After
@@ -180,68 +176,74 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {


    @Test
    @Test
    public void testShowNotification_addsEntry() {
    public void testShowNotification_addsEntry() {
        mAlertingNotificationManager.showNotification(mEntry);
        AlertingNotificationManager alm = createAlertingNotificationManager();


        assertTrue(mAlertingNotificationManager.isAlerting(mEntry.getKey()));
        alm.showNotification(mEntry);
        assertTrue(mAlertingNotificationManager.hasNotifications());

        assertEquals(mEntry, mAlertingNotificationManager.getEntry(mEntry.getKey()));
        assertTrue(alm.isAlerting(mEntry.getKey()));
        assertTrue(alm.hasNotifications());
        assertEquals(mEntry, alm.getEntry(mEntry.getKey()));
    }
    }


    @Test
    @Test
    public void testShowNotification_autoDismisses() {
    public void testShowNotification_autoDismisses() {
        mAlertingNotificationManager.showNotification(mEntry);
        AlertingNotificationManager alm = createAlertingNotificationManager();
        mTestHandler.postDelayed(TEST_TIMEOUT_RUNNABLE, TEST_TIMEOUT_TIME);

        alm.showNotification(mEntry);
        mTestHandler.postDelayed(mTestTimeoutRunnable, TEST_TIMEOUT_TIME);


        // Wait for remove runnable and then process it immediately
        // Wait for remove runnable and then process it immediately
        TestableLooper.get(this).processMessages(1);
        TestableLooper.get(this).processMessages(1);


        assertFalse("Test timed out", mTimedOut);
        assertFalse("Test timed out", mTimedOut);
        assertFalse(mAlertingNotificationManager.isAlerting(mEntry.getKey()));
        assertFalse(alm.isAlerting(mEntry.getKey()));
    }
    }


    @Test
    @Test
    public void testRemoveNotification_removeDeferred() {
    public void testRemoveNotification_removeDeferred() {
        mAlertingNotificationManager.showNotification(mEntry);
        AlertingNotificationManager alm = createAlertingNotificationManager();
        alm.showNotification(mEntry);


        // Try to remove but defer, since the notification has not been shown long enough.
        // Try to remove but defer, since the notification has not been shown long enough.
        mAlertingNotificationManager.removeNotification(
        alm.removeNotification(mEntry.getKey(), false /* releaseImmediately */);
                mEntry.getKey(), false /* releaseImmediately */);


        assertTrue(mAlertingNotificationManager.isAlerting(mEntry.getKey()));
        assertTrue(alm.isAlerting(mEntry.getKey()));
    }
    }


    @Test
    @Test
    public void testRemoveNotification_forceRemove() {
    public void testRemoveNotification_forceRemove() {
        mAlertingNotificationManager.showNotification(mEntry);
        AlertingNotificationManager alm = createAlertingNotificationManager();
        alm.showNotification(mEntry);


        // Remove forcibly with releaseImmediately = true.
        // Remove forcibly with releaseImmediately = true.
        mAlertingNotificationManager.removeNotification(
        alm.removeNotification(mEntry.getKey(), true /* releaseImmediately */);
                mEntry.getKey(), true /* releaseImmediately */);


        assertFalse(mAlertingNotificationManager.isAlerting(mEntry.getKey()));
        assertFalse(alm.isAlerting(mEntry.getKey()));
    }
    }


    @Test
    @Test
    public void testReleaseAllImmediately() {
    public void testReleaseAllImmediately() {
        AlertingNotificationManager alm = createAlertingNotificationManager();
        for (int i = 0; i < TEST_NUM_NOTIFICATIONS; i++) {
        for (int i = 0; i < TEST_NUM_NOTIFICATIONS; i++) {
            StatusBarNotification sbn = createNewNotification(i);
            StatusBarNotification sbn = createNewNotification(i);
            NotificationEntry entry = new NotificationEntryBuilder()
            NotificationEntry entry = new NotificationEntryBuilder()
                    .setSbn(sbn)
                    .setSbn(sbn)
                    .build();
                    .build();
            entry.setRow(mRow);
            entry.setRow(mRow);
            mAlertingNotificationManager.showNotification(entry);
            alm.showNotification(entry);
        }
        }


        mAlertingNotificationManager.releaseAllImmediately();
        alm.releaseAllImmediately();


        assertEquals(0, mAlertingNotificationManager.getAllEntries().count());
        assertEquals(0, alm.getAllEntries().count());
    }
    }


    @Test
    @Test
    public void testCanRemoveImmediately_notShownLongEnough() {
    public void testCanRemoveImmediately_notShownLongEnough() {
        mAlertingNotificationManager.showNotification(mEntry);
        AlertingNotificationManager alm = createAlertingNotificationManager();
        alm.showNotification(mEntry);


        // The entry has just been added so we should not remove immediately.
        // The entry has just been added so we should not remove immediately.
        assertFalse(mAlertingNotificationManager.canRemoveImmediately(mEntry.getKey()));
        assertFalse(alm.canRemoveImmediately(mEntry.getKey()));
    }
    }
}
}
+9 −4
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import android.testing.TestableLooper;
import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;


import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.R;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shade.ShadeExpansionStateManager;
import com.android.systemui.shade.ShadeExpansionStateManager;
import com.android.systemui.statusbar.AlertingNotificationManager;
import com.android.systemui.statusbar.AlertingNotificationManager;
@@ -107,11 +108,13 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
        }
        }
    }
    }


    @Override
    protected AlertingNotificationManager createAlertingNotificationManager() {
    protected AlertingNotificationManager createAlertingNotificationManager() {
        return mHeadsUpManager;
        return mHeadsUpManager;
    }
    }


    @Before
    @Before
    @Override
    public void setUp() {
    public void setUp() {
        AccessibilityManagerWrapper accessibilityMgr =
        AccessibilityManagerWrapper accessibilityMgr =
                mDependency.injectMockDependency(AccessibilityManagerWrapper.class);
                mDependency.injectMockDependency(AccessibilityManagerWrapper.class);
@@ -119,8 +122,10 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
                .thenReturn(TEST_AUTO_DISMISS_TIME);
                .thenReturn(TEST_AUTO_DISMISS_TIME);
        when(mVSProvider.isReorderingAllowed()).thenReturn(true);
        when(mVSProvider.isReorderingAllowed()).thenReturn(true);
        mDependency.injectMockDependency(NotificationShadeWindowController.class);
        mDependency.injectMockDependency(NotificationShadeWindowController.class);
        super.setUp();
        mContext.getOrCreateTestableResources().addOverride(
                R.integer.ambient_notification_extension_time, 500);


        super.setUp();
        mHeadsUpManager = new TestableHeadsUpManagerPhone(
        mHeadsUpManager = new TestableHeadsUpManagerPhone(
                mContext,
                mContext,
                mHeadsUpManagerLogger,
                mHeadsUpManagerLogger,
@@ -137,8 +142,9 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
    }
    }


    @After
    @After
    @Override
    public void tearDown() {
    public void tearDown() {
        mTestHandler.removeCallbacksAndMessages(null);
        super.tearDown();
    }
    }


    @Test
    @Test
@@ -184,7 +190,6 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
        assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.getKey()));
        assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.getKey()));
    }
    }



    @Test
    @Test
    public void testExtendHeadsUp() {
    public void testExtendHeadsUp() {
        mHeadsUpManager.showNotification(mEntry);
        mHeadsUpManager.showNotification(mEntry);
@@ -192,7 +197,7 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
                () -> mLivesPastNormalTime = mHeadsUpManager.isAlerting(mEntry.getKey());
                () -> mLivesPastNormalTime = mHeadsUpManager.isAlerting(mEntry.getKey());
        mTestHandler.postDelayed(pastNormalTimeRunnable,
        mTestHandler.postDelayed(pastNormalTimeRunnable,
                TEST_AUTO_DISMISS_TIME + mHeadsUpManager.mExtensionTime / 2);
                TEST_AUTO_DISMISS_TIME + mHeadsUpManager.mExtensionTime / 2);
        mTestHandler.postDelayed(TEST_TIMEOUT_RUNNABLE, TEST_TIMEOUT_TIME);
        mTestHandler.postDelayed(mTestTimeoutRunnable, TEST_TIMEOUT_TIME);


        mHeadsUpManager.extendHeadsUp();
        mHeadsUpManager.extendHeadsUp();


+5 −2
Original line number Original line Diff line number Diff line
@@ -89,11 +89,13 @@ public class HeadsUpManagerTest extends AlertingNotificationManagerTest {
        }
        }
    }
    }


    @Override
    protected AlertingNotificationManager createAlertingNotificationManager() {
    protected AlertingNotificationManager createAlertingNotificationManager() {
        return mHeadsUpManager;
        return mHeadsUpManager;
    }
    }


    @Before
    @Before
    @Override
    public void setUp() {
    public void setUp() {
        initMocks(this);
        initMocks(this);
        when(mEntry.getSbn()).thenReturn(mSbn);
        when(mEntry.getSbn()).thenReturn(mSbn);
@@ -105,8 +107,9 @@ public class HeadsUpManagerTest extends AlertingNotificationManagerTest {
    }
    }


    @After
    @After
    @Override
    public void tearDown() {
    public void tearDown() {
        mTestHandler.removeCallbacksAndMessages(null);
        super.tearDown();
    }
    }


    @Test
    @Test
@@ -173,7 +176,7 @@ public class HeadsUpManagerTest extends AlertingNotificationManagerTest {
                () -> mLivesPastNormalTime = mHeadsUpManager.isAlerting(mEntry.getKey());
                () -> mLivesPastNormalTime = mHeadsUpManager.isAlerting(mEntry.getKey());
        mTestHandler.postDelayed(pastNormalTimeRunnable,
        mTestHandler.postDelayed(pastNormalTimeRunnable,
                        (TEST_A11Y_AUTO_DISMISS_TIME + TEST_AUTO_DISMISS_TIME) / 2);
                        (TEST_A11Y_AUTO_DISMISS_TIME + TEST_AUTO_DISMISS_TIME) / 2);
        mTestHandler.postDelayed(TEST_TIMEOUT_RUNNABLE, TEST_A11Y_TIMEOUT_TIME);
        mTestHandler.postDelayed(mTestTimeoutRunnable, TEST_A11Y_TIMEOUT_TIME);


        TestableLooper.get(this).processMessages(2);
        TestableLooper.get(this).processMessages(2);