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

Commit 563a7b08 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Edit NEM tests to prevent flakiness"

parents 8820327b 433923a1
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -19,8 +19,11 @@ import static org.mockito.Mockito.mock;
import android.content.Context;
import android.content.Context;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Log;


public class TestableDependency extends Dependency {
public class TestableDependency extends Dependency {
    private static final String TAG = "TestableDependency";

    private final ArrayMap<Object, Object> mObjs = new ArrayMap<>();
    private final ArrayMap<Object, Object> mObjs = new ArrayMap<>();
    private final ArraySet<Object> mInstantiatedObjects = new ArraySet<>();
    private final ArraySet<Object> mInstantiatedObjects = new ArraySet<>();


@@ -44,7 +47,7 @@ public class TestableDependency extends Dependency {


    public <T> void injectTestDependency(Class<T> key, T obj) {
    public <T> void injectTestDependency(Class<T> key, T obj) {
        if (mInstantiatedObjects.contains(key)) {
        if (mInstantiatedObjects.contains(key)) {
            throw new IllegalStateException(key + " was already initialized");
            Log.d(TAG, key + " was already initialized but overriding with testDependency.");
        }
        }
        mObjs.put(key, obj);
        mObjs.put(key, obj);
    }
    }
+12 −17
Original line number Original line Diff line number Diff line
@@ -45,7 +45,6 @@ import android.app.PendingIntent;
import android.content.Intent;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.graphics.drawable.Icon;
import android.os.Handler;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.NotificationListenerService.RankingMap;
@@ -88,7 +87,6 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.NotifRemoteViewCache;
import com.android.systemui.statusbar.notification.row.NotifRemoteViewCache;
import com.android.systemui.statusbar.notification.row.NotificationContentInflater;
import com.android.systemui.statusbar.notification.row.NotificationContentInflater;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder;
import com.android.systemui.statusbar.notification.row.RowInflaterTask;
import com.android.systemui.statusbar.notification.row.RowInflaterTask;
import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent;
import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
@@ -99,6 +97,7 @@ import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.util.Assert;
import com.android.systemui.util.Assert;
import com.android.systemui.util.leak.LeakDetector;
import com.android.systemui.util.leak.LeakDetector;


import org.junit.After;
import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
@@ -190,15 +189,14 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
    @Before
    @Before
    public void setUp() {
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);
        if (!mDependency.hasInstantiatedDependency(SmartReplyController.class)) {
        mDependency.injectMockDependency(SmartReplyController.class);
        mDependency.injectMockDependency(SmartReplyController.class);
        }
        mDependency.injectMockDependency(NotificationMediaManager.class);
        mDependency.injectMockDependency(NotificationMediaManager.class);


        mCountDownLatch = new CountDownLatch(1);
        mCountDownLatch = new CountDownLatch(1);


        Assert.sMainLooper = TestableLooper.get(this).getLooper();
        mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
        mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
                Handler.createAsync(Looper.myLooper()));
                Handler.createAsync(TestableLooper.get(this).getLooper()));
        when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
        when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
        when(mListContainer.getViewParentForNotification(any())).thenReturn(
        when(mListContainer.getViewParentForNotification(any())).thenReturn(
                new FrameLayout(mContext));
                new FrameLayout(mContext));
@@ -208,9 +206,10 @@ public class NotificationEntryManagerTest extends SysuiTestCase {


        mEntry.expandedIcon = mock(StatusBarIconView.class);
        mEntry.expandedIcon = mock(StatusBarIconView.class);


        NotificationRowContentBinder contentBinder = new NotificationContentInflater(
        NotificationContentInflater contentBinder = new NotificationContentInflater(
                mock(NotifRemoteViewCache.class),
                mock(NotifRemoteViewCache.class),
                mRemoteInputManager);
                mRemoteInputManager);
        contentBinder.setInflateSynchronously(true);


        when(mNotificationRowComponentBuilder.activatableNotificationView(any()))
        when(mNotificationRowComponentBuilder.activatableNotificationView(any()))
                .thenReturn(mNotificationRowComponentBuilder);
                .thenReturn(mNotificationRowComponentBuilder);
@@ -263,6 +262,12 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
                mEntry.getKey(), Ranking.USER_SENTIMENT_NEUTRAL);
                mEntry.getKey(), Ranking.USER_SENTIMENT_NEUTRAL);
    }
    }


    @After
    public void tearDown() {
        // CLEAN UP inflation tasks so they don't callback in a future test
        mEntry.abortTask();
    }

    @Test
    @Test
    public void testAddNotification() throws Exception {
    public void testAddNotification() throws Exception {
        TestableLooper.get(this).processAllMessages();
        TestableLooper.get(this).processAllMessages();
@@ -348,9 +353,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {


    @Test
    @Test
    public void testRemoveNotification() {
    public void testRemoveNotification() {
        // Row inflation happens off thread, so pretend that this test looper is main
        Assert.sMainLooper = TestableLooper.get(this).getLooper();

        mEntry.setRow(mRow);
        mEntry.setRow(mRow);
        mEntryManager.addActiveNotificationForTest(mEntry);
        mEntryManager.addActiveNotificationForTest(mEntry);


@@ -468,9 +470,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {


    @Test
    @Test
    public void testLifetimeExtenders_whenRetentionEndsNotificationIsRemoved() {
    public void testLifetimeExtenders_whenRetentionEndsNotificationIsRemoved() {
        // Row inflation happens off thread, so pretend that this test looper is main
        Assert.sMainLooper = TestableLooper.get(this).getLooper();

        // GIVEN an entry manager with a notification whose life has been extended
        // GIVEN an entry manager with a notification whose life has been extended
        mEntryManager.addActiveNotificationForTest(mEntry);
        mEntryManager.addActiveNotificationForTest(mEntry);
        final FakeNotificationLifetimeExtender extender = new FakeNotificationLifetimeExtender();
        final FakeNotificationLifetimeExtender extender = new FakeNotificationLifetimeExtender();
@@ -561,9 +560,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {


    @Test
    @Test
    public void testRemoveInterceptor_notInterceptedGetsRemoved() {
    public void testRemoveInterceptor_notInterceptedGetsRemoved() {
        // Row inflation happens off thread, so pretend that this test looper is main
        Assert.sMainLooper = TestableLooper.get(this).getLooper();

        // GIVEN an entry manager with a notification
        // GIVEN an entry manager with a notification
        mEntryManager.addActiveNotificationForTest(mEntry);
        mEntryManager.addActiveNotificationForTest(mEntry);


@@ -626,7 +622,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {


    @Test
    @Test
    public void testGetNotificationsForCurrentUser_shouldFilterNonCurrentUserNotifications() {
    public void testGetNotificationsForCurrentUser_shouldFilterNonCurrentUserNotifications() {
        Assert.sMainLooper = TestableLooper.get(this).getLooper();
        Notification.Builder n = new Notification.Builder(mContext, "di")
        Notification.Builder n = new Notification.Builder(mContext, "di")
                .setSmallIcon(R.drawable.ic_person)
                .setSmallIcon(R.drawable.ic_person)
                .setContentTitle("Title")
                .setContentTitle("Title")
+3 −1
Original line number Original line Diff line number Diff line
@@ -234,7 +234,9 @@ public class TestableLooper {
            try {
            try {
                mLooper = setAsMain ? Looper.getMainLooper() : createLooper();
                mLooper = setAsMain ? Looper.getMainLooper() : createLooper();
                mTestableLooper = new TestableLooper(mLooper, false);
                mTestableLooper = new TestableLooper(mLooper, false);
                if (!setAsMain) {
                    mTestableLooper.getLooper().getThread().setName(test.getClass().getName());
                    mTestableLooper.getLooper().getThread().setName(test.getClass().getName());
                }
            } catch (Exception e) {
            } catch (Exception e) {
                throw new RuntimeException(e);
                throw new RuntimeException(e);
            }
            }