Merge "Deflake NotificationEntryManagerInflationTest" into rvc-dev am: 027d35a002 am: 2d369b56e5
Change-Id: Id6f53ec321ce0b987dd77954e95180e22e277d28
This commit is contained in:
@@ -64,7 +64,6 @@ import com.android.systemui.statusbar.notification.collection.inflation.Notifica
|
|||||||
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider;
|
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider;
|
||||||
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
|
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
|
||||||
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
|
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
|
||||||
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
|
|
||||||
import com.android.systemui.statusbar.notification.row.dagger.ExpandableNotificationRowComponent;
|
import com.android.systemui.statusbar.notification.row.dagger.ExpandableNotificationRowComponent;
|
||||||
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;
|
||||||
@@ -77,7 +76,6 @@ import com.android.systemui.util.time.FakeSystemClock;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
@@ -86,11 +84,12 @@ import org.mockito.Mockito;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functional tests for notification inflation from {@link NotificationEntryManager}.
|
* Functional tests for notification inflation from {@link NotificationEntryManager}.
|
||||||
*/
|
*/
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@Ignore("Flaking")
|
|
||||||
@RunWith(AndroidTestingRunner.class)
|
@RunWith(AndroidTestingRunner.class)
|
||||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||||
public class NotificationEntryManagerInflationTest extends SysuiTestCase {
|
public class NotificationEntryManagerInflationTest extends SysuiTestCase {
|
||||||
@@ -132,6 +131,7 @@ public class NotificationEntryManagerInflationTest extends SysuiTestCase {
|
|||||||
private NotificationEntryManager mEntryManager;
|
private NotificationEntryManager mEntryManager;
|
||||||
private NotificationRowBinderImpl mRowBinder;
|
private NotificationRowBinderImpl mRowBinder;
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
private CountDownLatch mCountDownLatch;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -305,9 +305,7 @@ public class NotificationEntryManagerInflationTest extends SysuiTestCase {
|
|||||||
verify(mEntryListener).onPendingEntryAdded(entryCaptor.capture());
|
verify(mEntryListener).onPendingEntryAdded(entryCaptor.capture());
|
||||||
NotificationEntry entry = entryCaptor.getValue();
|
NotificationEntry entry = entryCaptor.getValue();
|
||||||
|
|
||||||
// Wait for inflation
|
waitForInflation();
|
||||||
// row inflation, system notification, remote views, contracted view
|
|
||||||
waitForMessages(4);
|
|
||||||
|
|
||||||
// THEN the notification has its row inflated
|
// THEN the notification has its row inflated
|
||||||
assertNotNull(entry.getRow());
|
assertNotNull(entry.getRow());
|
||||||
@@ -334,7 +332,7 @@ public class NotificationEntryManagerInflationTest extends SysuiTestCase {
|
|||||||
NotificationEntry.class);
|
NotificationEntry.class);
|
||||||
verify(mEntryListener).onPendingEntryAdded(entryCaptor.capture());
|
verify(mEntryListener).onPendingEntryAdded(entryCaptor.capture());
|
||||||
NotificationEntry entry = entryCaptor.getValue();
|
NotificationEntry entry = entryCaptor.getValue();
|
||||||
waitForMessages(4);
|
waitForInflation();
|
||||||
|
|
||||||
Mockito.reset(mEntryListener);
|
Mockito.reset(mEntryListener);
|
||||||
Mockito.reset(mPresenter);
|
Mockito.reset(mPresenter);
|
||||||
@@ -342,9 +340,7 @@ public class NotificationEntryManagerInflationTest extends SysuiTestCase {
|
|||||||
// WHEN the notification is updated
|
// WHEN the notification is updated
|
||||||
mEntryManager.updateNotification(mSbn, mRankingMap);
|
mEntryManager.updateNotification(mSbn, mRankingMap);
|
||||||
|
|
||||||
// Wait for inflation
|
waitForInflation();
|
||||||
// remote views, contracted view
|
|
||||||
waitForMessages(2);
|
|
||||||
|
|
||||||
// THEN the notification has its row and inflated
|
// THEN the notification has its row and inflated
|
||||||
assertNotNull(entry.getRow());
|
assertNotNull(entry.getRow());
|
||||||
@@ -357,32 +353,31 @@ public class NotificationEntryManagerInflationTest extends SysuiTestCase {
|
|||||||
verify(mPresenter).updateNotificationViews();
|
verify(mPresenter).updateNotificationViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void waitForInflation() {
|
||||||
* Wait for a certain number of messages to finish before continuing, timing out if they never
|
|
||||||
* occur.
|
|
||||||
*
|
|
||||||
* As part of the inflation pipeline, the main thread is forced to deal with several callbacks
|
|
||||||
* due to the nature of the API used (generally because they're {@link android.os.AsyncTask}
|
|
||||||
* callbacks). In order, these are
|
|
||||||
*
|
|
||||||
* 1) Callback after row inflation. See {@link RowInflaterTask}.
|
|
||||||
* 2) Callback checking if row is system notification. See
|
|
||||||
* {@link ExpandableNotificationRow#setEntry}
|
|
||||||
* 3) Callback after remote views are created. See
|
|
||||||
* {@link NotificationContentInflater.AsyncInflationTask}.
|
|
||||||
* 4-6) Callback after each content view is inflated/rebound from remote view. See
|
|
||||||
* {@link NotificationContentInflater#applyRemoteView} and {@link InflationFlag}.
|
|
||||||
*
|
|
||||||
* Depending on the test, only some of these will be necessary. For example, generally, not
|
|
||||||
* every content view is inflated or the row may not be inflated if one already exists.
|
|
||||||
*
|
|
||||||
* Currently, the burden is on the developer to figure these out until we have a much more
|
|
||||||
* test-friendly way of executing inflation logic (i.e. pass in an executor).
|
|
||||||
*/
|
|
||||||
private void waitForMessages(int numMessages) {
|
|
||||||
mHandler.postDelayed(TIMEOUT_RUNNABLE, TIMEOUT_TIME);
|
mHandler.postDelayed(TIMEOUT_RUNNABLE, TIMEOUT_TIME);
|
||||||
TestableLooper.get(this).processMessages(numMessages);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
NotificationEntryListener inflationListener = new NotificationEntryListener() {
|
||||||
|
@Override
|
||||||
|
public void onEntryInflated(NotificationEntry entry) {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEntryReinflated(NotificationEntry entry) {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInflationError(StatusBarNotification notification, Exception exception) {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mEntryManager.addNotificationEntryListener(inflationListener);
|
||||||
|
while (latch.getCount() != 0) {
|
||||||
|
TestableLooper.get(this).processMessages(1);
|
||||||
|
}
|
||||||
mHandler.removeCallbacks(TIMEOUT_RUNNABLE);
|
mHandler.removeCallbacks(TIMEOUT_RUNNABLE);
|
||||||
|
mEntryManager.removeNotificationEntryListener(inflationListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user