summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java29
-rw-r--r--tests/testables/src/android/testing/TestableLooper.java4
3 files changed, 19 insertions, 19 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java b/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java
index 2ecc8ea8400c..b3071f957fdb 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java
@@ -19,8 +19,11 @@ import static org.mockito.Mockito.mock;
import android.content.Context;
import android.util.ArrayMap;
import android.util.ArraySet;
+import android.util.Log;
public class TestableDependency extends Dependency {
+ private static final String TAG = "TestableDependency";
+
private final ArrayMap<Object, Object> mObjs = new ArrayMap<>();
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) {
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);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
index d852fa151fd3..b8599fac1681 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
@@ -45,7 +45,6 @@ import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.os.Handler;
-import android.os.Looper;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
@@ -87,7 +86,6 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.NotifRemoteViewCache;
import com.android.systemui.statusbar.notification.row.NotificationContentInflater;
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.stack.NotificationListContainer;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
@@ -97,6 +95,7 @@ import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.util.Assert;
import com.android.systemui.util.leak.LeakDetector;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -185,15 +184,14 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- if (!mDependency.hasInstantiatedDependency(SmartReplyController.class)) {
- mDependency.injectMockDependency(SmartReplyController.class);
- }
+ mDependency.injectMockDependency(SmartReplyController.class);
mDependency.injectMockDependency(NotificationMediaManager.class);
mCountDownLatch = new CountDownLatch(1);
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
- Handler.createAsync(Looper.myLooper()));
+ Handler.createAsync(TestableLooper.get(this).getLooper()));
when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
when(mListContainer.getViewParentForNotification(any())).thenReturn(
new FrameLayout(mContext));
@@ -203,9 +201,10 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
mEntry.expandedIcon = mock(StatusBarIconView.class);
- NotificationRowContentBinder contentBinder = new NotificationContentInflater(
+ NotificationContentInflater contentBinder = new NotificationContentInflater(
mock(NotifRemoteViewCache.class),
mRemoteInputManager);
+ contentBinder.setInflateSynchronously(true);
NotificationRowBinderImpl notificationRowBinder =
new NotificationRowBinderImpl(mContext,
@@ -253,6 +252,12 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
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
public void testAddNotification() throws Exception {
TestableLooper.get(this).processAllMessages();
@@ -338,9 +343,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
@Test
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);
mEntryManager.addActiveNotificationForTest(mEntry);
@@ -458,9 +460,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
@Test
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
mEntryManager.addActiveNotificationForTest(mEntry);
final FakeNotificationLifetimeExtender extender = new FakeNotificationLifetimeExtender();
@@ -551,9 +550,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
@Test
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
mEntryManager.addActiveNotificationForTest(mEntry);
@@ -616,7 +612,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
@Test
public void testGetNotificationsForCurrentUser_shouldFilterNonCurrentUserNotifications() {
- Assert.sMainLooper = TestableLooper.get(this).getLooper();
Notification.Builder n = new Notification.Builder(mContext, "di")
.setSmallIcon(R.drawable.ic_person)
.setContentTitle("Title")
diff --git a/tests/testables/src/android/testing/TestableLooper.java b/tests/testables/src/android/testing/TestableLooper.java
index 8eac3ea13a23..fe0224a27c80 100644
--- a/tests/testables/src/android/testing/TestableLooper.java
+++ b/tests/testables/src/android/testing/TestableLooper.java
@@ -234,7 +234,9 @@ public class TestableLooper {
try {
mLooper = setAsMain ? Looper.getMainLooper() : createLooper();
mTestableLooper = new TestableLooper(mLooper, false);
- mTestableLooper.getLooper().getThread().setName(test.getClass().getName());
+ if (!setAsMain) {
+ mTestableLooper.getLooper().getThread().setName(test.getClass().getName());
+ }
} catch (Exception e) {
throw new RuntimeException(e);
}