Merge "Cleanup in ExpandableNotificationRowTest" into tm-qpr-dev

This commit is contained in:
András Kurucz
2023-01-30 21:40:43 +00:00
committed by Android (Google) Code Review
2 changed files with 246 additions and 229 deletions

View File

@@ -82,19 +82,14 @@ import org.mockito.junit.MockitoRule;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
@SmallTest @SmallTest
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@RunWithLooper @RunWithLooper
public class ExpandableNotificationRowTest extends SysuiTestCase { public class ExpandableNotificationRowTest extends SysuiTestCase {
private ExpandableNotificationRow mGroupRow;
private ExpandableNotificationRow mNotifRow;
private ExpandableNotificationRow mPublicRow;
private NotificationTestHelper mNotificationTestHelper; private NotificationTestHelper mNotificationTestHelper;
boolean mHeadsUpAnimatingAway = false;
@Rule public MockitoRule mockito = MockitoJUnit.rule(); @Rule public MockitoRule mockito = MockitoJUnit.rule();
@Before @Before
@@ -105,112 +100,108 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
mDependency, mDependency,
TestableLooper.get(this)); TestableLooper.get(this));
mNotificationTestHelper.setDefaultInflationFlags(FLAG_CONTENT_VIEW_ALL); mNotificationTestHelper.setDefaultInflationFlags(FLAG_CONTENT_VIEW_ALL);
FakeFeatureFlags fakeFeatureFlags = new FakeFeatureFlags(); FakeFeatureFlags fakeFeatureFlags = new FakeFeatureFlags();
fakeFeatureFlags.set(Flags.NOTIFICATION_ANIMATE_BIG_PICTURE, true); fakeFeatureFlags.set(Flags.NOTIFICATION_ANIMATE_BIG_PICTURE, true);
mNotificationTestHelper.setFeatureFlags(fakeFeatureFlags); mNotificationTestHelper.setFeatureFlags(fakeFeatureFlags);
// create a standard private notification row }
Notification normalNotif = mNotificationTestHelper.createNotification();
normalNotif.publicVersion = null; @Test
mNotifRow = mNotificationTestHelper.createRow(normalNotif); public void testUpdateBackgroundColors_isRecursive() throws Exception {
ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
group.setTintColor(Color.RED);
group.getChildNotificationAt(0).setTintColor(Color.GREEN);
group.getChildNotificationAt(1).setTintColor(Color.BLUE);
assertThat(group.getCurrentBackgroundTint()).isEqualTo(Color.RED);
assertThat(group.getChildNotificationAt(0).getCurrentBackgroundTint())
.isEqualTo(Color.GREEN);
assertThat(group.getChildNotificationAt(1).getCurrentBackgroundTint())
.isEqualTo(Color.BLUE);
group.updateBackgroundColors();
int resetTint = group.getCurrentBackgroundTint();
assertThat(resetTint).isNotEqualTo(Color.RED);
assertThat(group.getChildNotificationAt(0).getCurrentBackgroundTint())
.isEqualTo(resetTint);
assertThat(group.getChildNotificationAt(1).getCurrentBackgroundTint())
.isEqualTo(resetTint);
}
@Test
public void testSetSensitiveOnNotifRowNotifiesOfHeightChange() throws Exception {
// GIVEN a sensitive notification row that's currently redacted
ExpandableNotificationRow row = mNotificationTestHelper.createRow();
measureAndLayout(row);
row.setHideSensitiveForIntrinsicHeight(true);
row.setSensitive(true, true);
assertThat(row.getShowingLayout()).isSameInstanceAs(row.getPublicLayout());
assertThat(row.getIntrinsicHeight()).isGreaterThan(0);
// GIVEN that the row has a height change listener
OnHeightChangedListener listener = mock(OnHeightChangedListener.class);
row.setOnHeightChangedListener(listener);
// WHEN the row is set to no longer be sensitive
row.setSensitive(false, true);
// VERIFY that the height change listener is invoked
assertThat(row.getShowingLayout()).isSameInstanceAs(row.getPrivateLayout());
assertThat(row.getIntrinsicHeight()).isGreaterThan(0);
verify(listener).onHeightChanged(eq(row), eq(false));
}
@Test
public void testSetSensitiveOnGroupRowNotifiesOfHeightChange() throws Exception {
// GIVEN a sensitive group row that's currently redacted
ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
measureAndLayout(group);
group.setHideSensitiveForIntrinsicHeight(true);
group.setSensitive(true, true);
assertThat(group.getShowingLayout()).isSameInstanceAs(group.getPublicLayout());
assertThat(group.getIntrinsicHeight()).isGreaterThan(0);
// GIVEN that the row has a height change listener
OnHeightChangedListener listener = mock(OnHeightChangedListener.class);
group.setOnHeightChangedListener(listener);
// WHEN the row is set to no longer be sensitive
group.setSensitive(false, true);
// VERIFY that the height change listener is invoked
assertThat(group.getShowingLayout()).isSameInstanceAs(group.getPrivateLayout());
assertThat(group.getIntrinsicHeight()).isGreaterThan(0);
verify(listener).onHeightChanged(eq(group), eq(false));
}
@Test
public void testSetSensitiveOnPublicRowDoesNotNotifyOfHeightChange() throws Exception {
// create a notification row whose public version is identical // create a notification row whose public version is identical
Notification publicNotif = mNotificationTestHelper.createNotification(); Notification publicNotif = mNotificationTestHelper.createNotification();
publicNotif.publicVersion = mNotificationTestHelper.createNotification(); publicNotif.publicVersion = mNotificationTestHelper.createNotification();
mPublicRow = mNotificationTestHelper.createRow(publicNotif); ExpandableNotificationRow publicRow = mNotificationTestHelper.createRow(publicNotif);
// create a group row
mGroupRow = mNotificationTestHelper.createGroup();
mGroupRow.setHeadsUpAnimatingAwayListener(
animatingAway -> mHeadsUpAnimatingAway = animatingAway);
}
@Test
public void testUpdateBackgroundColors_isRecursive() {
mGroupRow.setTintColor(Color.RED);
mGroupRow.getChildNotificationAt(0).setTintColor(Color.GREEN);
mGroupRow.getChildNotificationAt(1).setTintColor(Color.BLUE);
assertThat(mGroupRow.getCurrentBackgroundTint()).isEqualTo(Color.RED);
assertThat(mGroupRow.getChildNotificationAt(0).getCurrentBackgroundTint())
.isEqualTo(Color.GREEN);
assertThat(mGroupRow.getChildNotificationAt(1).getCurrentBackgroundTint())
.isEqualTo(Color.BLUE);
mGroupRow.updateBackgroundColors();
int resetTint = mGroupRow.getCurrentBackgroundTint();
assertThat(resetTint).isNotEqualTo(Color.RED);
assertThat(mGroupRow.getChildNotificationAt(0).getCurrentBackgroundTint())
.isEqualTo(resetTint);
assertThat(mGroupRow.getChildNotificationAt(1).getCurrentBackgroundTint())
.isEqualTo(resetTint);
}
@Test
public void testSetSensitiveOnNotifRowNotifiesOfHeightChange() throws InterruptedException {
// GIVEN a sensitive notification row that's currently redacted
measureAndLayout(mNotifRow);
mNotifRow.setHideSensitiveForIntrinsicHeight(true);
mNotifRow.setSensitive(true, true);
assertThat(mNotifRow.getShowingLayout()).isSameInstanceAs(mNotifRow.getPublicLayout());
assertThat(mNotifRow.getIntrinsicHeight()).isGreaterThan(0);
// GIVEN that the row has a height change listener
OnHeightChangedListener listener = mock(OnHeightChangedListener.class);
mNotifRow.setOnHeightChangedListener(listener);
// WHEN the row is set to no longer be sensitive
mNotifRow.setSensitive(false, true);
// VERIFY that the height change listener is invoked
assertThat(mNotifRow.getShowingLayout()).isSameInstanceAs(mNotifRow.getPrivateLayout());
assertThat(mNotifRow.getIntrinsicHeight()).isGreaterThan(0);
verify(listener).onHeightChanged(eq(mNotifRow), eq(false));
}
@Test
public void testSetSensitiveOnGroupRowNotifiesOfHeightChange() {
// GIVEN a sensitive group row that's currently redacted
measureAndLayout(mGroupRow);
mGroupRow.setHideSensitiveForIntrinsicHeight(true);
mGroupRow.setSensitive(true, true);
assertThat(mGroupRow.getShowingLayout()).isSameInstanceAs(mGroupRow.getPublicLayout());
assertThat(mGroupRow.getIntrinsicHeight()).isGreaterThan(0);
// GIVEN that the row has a height change listener
OnHeightChangedListener listener = mock(OnHeightChangedListener.class);
mGroupRow.setOnHeightChangedListener(listener);
// WHEN the row is set to no longer be sensitive
mGroupRow.setSensitive(false, true);
// VERIFY that the height change listener is invoked
assertThat(mGroupRow.getShowingLayout()).isSameInstanceAs(mGroupRow.getPrivateLayout());
assertThat(mGroupRow.getIntrinsicHeight()).isGreaterThan(0);
verify(listener).onHeightChanged(eq(mGroupRow), eq(false));
}
@Test
public void testSetSensitiveOnPublicRowDoesNotNotifyOfHeightChange() {
// GIVEN a sensitive public row that's currently redacted // GIVEN a sensitive public row that's currently redacted
measureAndLayout(mPublicRow); measureAndLayout(publicRow);
mPublicRow.setHideSensitiveForIntrinsicHeight(true); publicRow.setHideSensitiveForIntrinsicHeight(true);
mPublicRow.setSensitive(true, true); publicRow.setSensitive(true, true);
assertThat(mPublicRow.getShowingLayout()).isSameInstanceAs(mPublicRow.getPublicLayout()); assertThat(publicRow.getShowingLayout()).isSameInstanceAs(publicRow.getPublicLayout());
assertThat(mPublicRow.getIntrinsicHeight()).isGreaterThan(0); assertThat(publicRow.getIntrinsicHeight()).isGreaterThan(0);
// GIVEN that the row has a height change listener // GIVEN that the row has a height change listener
OnHeightChangedListener listener = mock(OnHeightChangedListener.class); OnHeightChangedListener listener = mock(OnHeightChangedListener.class);
mPublicRow.setOnHeightChangedListener(listener); publicRow.setOnHeightChangedListener(listener);
// WHEN the row is set to no longer be sensitive // WHEN the row is set to no longer be sensitive
mPublicRow.setSensitive(false, true); publicRow.setSensitive(false, true);
// VERIFY that the height change listener is not invoked, because the height didn't change // VERIFY that the height change listener is not invoked, because the height didn't change
assertThat(mPublicRow.getShowingLayout()).isSameInstanceAs(mPublicRow.getPrivateLayout()); assertThat(publicRow.getShowingLayout()).isSameInstanceAs(publicRow.getPrivateLayout());
assertThat(mPublicRow.getIntrinsicHeight()).isGreaterThan(0); assertThat(publicRow.getIntrinsicHeight()).isGreaterThan(0);
assertThat(mPublicRow.getPrivateLayout().getMinHeight()) assertThat(publicRow.getPrivateLayout().getMinHeight())
.isEqualTo(mPublicRow.getPublicLayout().getMinHeight()); .isEqualTo(publicRow.getPublicLayout().getMinHeight());
verify(listener, never()).onHeightChanged(eq(mPublicRow), eq(false)); verify(listener, never()).onHeightChanged(eq(publicRow), eq(false));
} }
private void measureAndLayout(ExpandableNotificationRow row) { private void measureAndLayout(ExpandableNotificationRow row) {
@@ -227,36 +218,43 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
} }
@Test @Test
public void testGroupSummaryNotShowingIconWhenPublic() { public void testGroupSummaryNotShowingIconWhenPublic() throws Exception {
mGroupRow.setSensitive(true, true); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
mGroupRow.setHideSensitiveForIntrinsicHeight(true);
assertTrue(mGroupRow.isSummaryWithChildren()); group.setSensitive(true, true);
assertFalse(mGroupRow.isShowingIcon()); group.setHideSensitiveForIntrinsicHeight(true);
assertTrue(group.isSummaryWithChildren());
assertFalse(group.isShowingIcon());
} }
@Test @Test
public void testNotificationHeaderVisibleWhenAnimating() { public void testNotificationHeaderVisibleWhenAnimating() throws Exception {
mGroupRow.setSensitive(true, true); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
mGroupRow.setHideSensitive(true, false, 0, 0);
mGroupRow.setHideSensitive(false, true, 0, 0); group.setSensitive(true, true);
assertEquals(View.VISIBLE, mGroupRow.getChildrenContainer().getVisibleWrapper() group.setHideSensitive(true, false, 0, 0);
group.setHideSensitive(false, true, 0, 0);
assertEquals(View.VISIBLE, group.getChildrenContainer().getVisibleWrapper()
.getNotificationHeader().getVisibility()); .getNotificationHeader().getVisibility());
} }
@Test @Test
public void testUserLockedResetEvenWhenNoChildren() { public void testUserLockedResetEvenWhenNoChildren() throws Exception {
mGroupRow.setUserLocked(true); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
mGroupRow.setUserLocked(false);
group.setUserLocked(true);
group.setUserLocked(false);
assertFalse("The childrencontainer should not be userlocked but is, the state " assertFalse("The childrencontainer should not be userlocked but is, the state "
+ "seems out of sync.", mGroupRow.getChildrenContainer().isUserLocked()); + "seems out of sync.", group.getChildrenContainer().isUserLocked());
} }
@Test @Test
public void testReinflatedOnDensityChange() { public void testReinflatedOnDensityChange() throws Exception {
ExpandableNotificationRow row = mNotificationTestHelper.createRow();
NotificationChildrenContainer mockContainer = mock(NotificationChildrenContainer.class); NotificationChildrenContainer mockContainer = mock(NotificationChildrenContainer.class);
mNotifRow.setChildrenContainer(mockContainer); row.setChildrenContainer(mockContainer);
mNotifRow.onDensityOrFontScaleChanged(); row.onDensityOrFontScaleChanged();
verify(mockContainer).reInflateViews(any(), any()); verify(mockContainer).reInflateViews(any(), any());
} }
@@ -299,64 +297,73 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
@Test @Test
public void testAboveShelfChangedListenerCalledWhenGoingBelow() throws Exception { public void testAboveShelfChangedListenerCalledWhenGoingBelow() throws Exception {
ExpandableNotificationRow row = mNotificationTestHelper.createRow(); ExpandableNotificationRow row = mNotificationTestHelper.createRow();
row.setHeadsUp(true);
AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class);
row.setAboveShelfChangedListener(listener); row.setAboveShelfChangedListener(listener);
Mockito.reset(listener);
row.setHeadsUp(true);
row.setAboveShelf(false); row.setAboveShelf(false);
verify(listener).onAboveShelfStateChanged(false); verify(listener).onAboveShelfStateChanged(false);
} }
@Test @Test
public void testClickSound() throws Exception { public void testClickSound() throws Exception {
assertTrue("Should play sounds by default.", mGroupRow.isSoundEffectsEnabled()); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
assertTrue("Should play sounds by default.", group.isSoundEffectsEnabled());
StatusBarStateController mock = mNotificationTestHelper.getStatusBarStateController(); StatusBarStateController mock = mNotificationTestHelper.getStatusBarStateController();
when(mock.isDozing()).thenReturn(true); when(mock.isDozing()).thenReturn(true);
mGroupRow.setSecureStateProvider(()-> false); group.setSecureStateProvider(()-> false);
assertFalse("Shouldn't play sounds when dark and trusted.", assertFalse("Shouldn't play sounds when dark and trusted.",
mGroupRow.isSoundEffectsEnabled()); group.isSoundEffectsEnabled());
mGroupRow.setSecureStateProvider(()-> true); group.setSecureStateProvider(()-> true);
assertTrue("Should always play sounds when not trusted.", assertTrue("Should always play sounds when not trusted.",
mGroupRow.isSoundEffectsEnabled()); group.isSoundEffectsEnabled());
} }
@Test @Test
public void testSetDismissed_longPressListenerRemoved() { public void testSetDismissed_longPressListenerRemoved() throws Exception {
ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
ExpandableNotificationRow.LongPressListener listener = ExpandableNotificationRow.LongPressListener listener =
mock(ExpandableNotificationRow.LongPressListener.class); mock(ExpandableNotificationRow.LongPressListener.class);
mGroupRow.setLongPressListener(listener); group.setLongPressListener(listener);
mGroupRow.doLongClickCallback(0,0); group.doLongClickCallback(0, 0);
verify(listener, times(1)).onLongPress(eq(mGroupRow), eq(0), eq(0), verify(listener, times(1)).onLongPress(eq(group), eq(0), eq(0),
any(NotificationMenuRowPlugin.MenuItem.class)); any(NotificationMenuRowPlugin.MenuItem.class));
reset(listener); reset(listener);
mGroupRow.dismiss(true); group.dismiss(true);
mGroupRow.doLongClickCallback(0,0); group.doLongClickCallback(0, 0);
verify(listener, times(0)).onLongPress(eq(mGroupRow), eq(0), eq(0), verify(listener, times(0)).onLongPress(eq(group), eq(0), eq(0),
any(NotificationMenuRowPlugin.MenuItem.class)); any(NotificationMenuRowPlugin.MenuItem.class));
} }
@Test @Test
public void testFeedback_noHeader() { public void testFeedback_noHeader() throws Exception {
ExpandableNotificationRow groupRow = mNotificationTestHelper.createGroup();
// public notification is custom layout - no header // public notification is custom layout - no header
mGroupRow.setSensitive(true, true); groupRow.setSensitive(true, true);
mGroupRow.setOnFeedbackClickListener(null); groupRow.setOnFeedbackClickListener(null);
mGroupRow.setFeedbackIcon(null); groupRow.setFeedbackIcon(null);
} }
@Test @Test
public void testFeedback_header() { public void testFeedback_header() throws Exception {
ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
NotificationContentView publicLayout = mock(NotificationContentView.class); NotificationContentView publicLayout = mock(NotificationContentView.class);
mGroupRow.setPublicLayout(publicLayout); group.setPublicLayout(publicLayout);
NotificationContentView privateLayout = mock(NotificationContentView.class); NotificationContentView privateLayout = mock(NotificationContentView.class);
mGroupRow.setPrivateLayout(privateLayout); group.setPrivateLayout(privateLayout);
NotificationChildrenContainer mockContainer = mock(NotificationChildrenContainer.class); NotificationChildrenContainer mockContainer = mock(NotificationChildrenContainer.class);
when(mockContainer.getNotificationChildCount()).thenReturn(1); when(mockContainer.getNotificationChildCount()).thenReturn(1);
mGroupRow.setChildrenContainer(mockContainer); group.setChildrenContainer(mockContainer);
final boolean show = true; final boolean show = true;
final FeedbackIcon icon = new FeedbackIcon( final FeedbackIcon icon = new FeedbackIcon(
R.drawable.ic_feedback_alerted, R.string.notification_feedback_indicator_alerted); R.drawable.ic_feedback_alerted, R.string.notification_feedback_indicator_alerted);
mGroupRow.setFeedbackIcon(icon); group.setFeedbackIcon(icon);
verify(mockContainer, times(1)).setFeedbackIcon(icon); verify(mockContainer, times(1)).setFeedbackIcon(icon);
verify(privateLayout, times(1)).setFeedbackIcon(icon); verify(privateLayout, times(1)).setFeedbackIcon(icon);
@@ -364,43 +371,60 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
} }
@Test @Test
public void testFeedbackOnClick() { public void testFeedbackOnClick() throws Exception {
ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
ExpandableNotificationRow.CoordinateOnClickListener l = mock( ExpandableNotificationRow.CoordinateOnClickListener l = mock(
ExpandableNotificationRow.CoordinateOnClickListener.class); ExpandableNotificationRow.CoordinateOnClickListener.class);
View view = mock(View.class); View view = mock(View.class);
mGroupRow.setOnFeedbackClickListener(l); group.setOnFeedbackClickListener(l);
mGroupRow.getFeedbackOnClickListener().onClick(view); group.getFeedbackOnClickListener().onClick(view);
verify(l, times(1)).onClick(any(), anyInt(), anyInt(), any()); verify(l, times(1)).onClick(any(), anyInt(), anyInt(), any());
} }
@Test @Test
public void testHeadsUpAnimatingAwayListener() { public void testHeadsUpAnimatingAwayListener() throws Exception {
mGroupRow.setHeadsUpAnimatingAway(true); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
Assert.assertEquals(true, mHeadsUpAnimatingAway); Consumer<Boolean> headsUpListener = mock(Consumer.class);
mGroupRow.setHeadsUpAnimatingAway(false); AboveShelfChangedListener aboveShelfChangedListener = mock(AboveShelfChangedListener.class);
Assert.assertEquals(false, mHeadsUpAnimatingAway); group.setHeadsUpAnimatingAwayListener(headsUpListener);
group.setAboveShelfChangedListener(aboveShelfChangedListener);
group.setHeadsUpAnimatingAway(true);
verify(headsUpListener).accept(true);
verify(aboveShelfChangedListener).onAboveShelfStateChanged(true);
group.setHeadsUpAnimatingAway(false);
verify(headsUpListener).accept(false);
verify(aboveShelfChangedListener).onAboveShelfStateChanged(false);
} }
@Test @Test
public void testIsBlockingHelperShowing_isCorrectlyUpdated() { public void testIsBlockingHelperShowing_isCorrectlyUpdated() throws Exception {
mGroupRow.setBlockingHelperShowing(true); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
assertTrue(mGroupRow.isBlockingHelperShowing());
mGroupRow.setBlockingHelperShowing(false); group.setBlockingHelperShowing(true);
assertFalse(mGroupRow.isBlockingHelperShowing()); assertTrue(group.isBlockingHelperShowing());
group.setBlockingHelperShowing(false);
assertFalse(group.isBlockingHelperShowing());
} }
@Test @Test
public void testGetNumUniqueChildren_defaultChannel() { public void testGetNumUniqueChildren_defaultChannel() throws Exception {
assertEquals(1, mGroupRow.getNumUniqueChannels()); ExpandableNotificationRow groupRow = mNotificationTestHelper.createGroup();
assertEquals(1, groupRow.getNumUniqueChannels());
} }
@Test @Test
public void testGetNumUniqueChildren_multiChannel() { public void testGetNumUniqueChildren_multiChannel() throws Exception {
ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
List<ExpandableNotificationRow> childRows = List<ExpandableNotificationRow> childRows =
mGroupRow.getChildrenContainer().getAttachedChildren(); group.getChildrenContainer().getAttachedChildren();
// Give each child a unique channel id/name. // Give each child a unique channel id/name.
int i = 0; int i = 0;
for (ExpandableNotificationRow childRow : childRows) { for (ExpandableNotificationRow childRow : childRows) {
@@ -412,25 +436,29 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
i++; i++;
} }
assertEquals(3, mGroupRow.getNumUniqueChannels()); assertEquals(3, group.getNumUniqueChannels());
} }
@Test @Test
public void testIconScrollXAfterTranslationAndReset() throws Exception { public void testIconScrollXAfterTranslationAndReset() throws Exception {
mGroupRow.setDismissUsingRowTranslationX(false); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
mGroupRow.setTranslation(50);
assertEquals(50, -mGroupRow.getEntry().getIcons().getShelfIcon().getScrollX());
mGroupRow.resetTranslation(); group.setDismissUsingRowTranslationX(false);
assertEquals(0, mGroupRow.getEntry().getIcons().getShelfIcon().getScrollX()); group.setTranslation(50);
assertEquals(50, -group.getEntry().getIcons().getShelfIcon().getScrollX());
group.resetTranslation();
assertEquals(0, group.getEntry().getIcons().getShelfIcon().getScrollX());
} }
@Test @Test
public void testIsExpanded_userExpanded() { public void testIsExpanded_userExpanded() throws Exception {
mGroupRow.setExpandable(true); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
Assert.assertFalse(mGroupRow.isExpanded());
mGroupRow.setUserExpanded(true); group.setExpandable(true);
Assert.assertTrue(mGroupRow.isExpanded()); Assert.assertFalse(group.isExpanded());
group.setUserExpanded(true);
Assert.assertTrue(group.isExpanded());
} }
@Test @Test
@@ -549,72 +577,80 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
} }
@Test @Test
public void applyRoundnessAndInv_should_be_immediately_applied_on_childrenContainer_legacy() { public void applyRoundnessAndInv_should_be_immediately_applied_on_childrenContainer_legacy()
mGroupRow.useRoundnessSourceTypes(false); throws Exception {
Assert.assertEquals(0f, mGroupRow.getBottomRoundness(), 0.001f); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
Assert.assertEquals(0f, mGroupRow.getChildrenContainer().getBottomRoundness(), 0.001f); group.useRoundnessSourceTypes(false);
Assert.assertEquals(0f, group.getBottomRoundness(), 0.001f);
Assert.assertEquals(0f, group.getChildrenContainer().getBottomRoundness(), 0.001f);
mGroupRow.requestBottomRoundness(1f, SourceType.from(""), false); group.requestBottomRoundness(1f, SourceType.from(""), false);
Assert.assertEquals(1f, mGroupRow.getBottomRoundness(), 0.001f); Assert.assertEquals(1f, group.getBottomRoundness(), 0.001f);
Assert.assertEquals(1f, mGroupRow.getChildrenContainer().getBottomRoundness(), 0.001f); Assert.assertEquals(1f, group.getChildrenContainer().getBottomRoundness(), 0.001f);
} }
@Test @Test
public void applyRoundnessAndInvalidate_should_be_immediately_applied_on_childrenContainer() { public void applyRoundnessAndInvalidate_should_be_immediately_applied_on_childrenContainer()
mGroupRow.useRoundnessSourceTypes(true); throws Exception {
Assert.assertEquals(0f, mGroupRow.getBottomRoundness(), 0.001f); ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
Assert.assertEquals(0f, mGroupRow.getChildrenContainer().getBottomRoundness(), 0.001f); group.useRoundnessSourceTypes(true);
Assert.assertEquals(0f, group.getBottomRoundness(), 0.001f);
Assert.assertEquals(0f, group.getChildrenContainer().getBottomRoundness(), 0.001f);
mGroupRow.requestBottomRoundness(1f, SourceType.from(""), false); group.requestBottomRoundness(1f, SourceType.from(""), false);
Assert.assertEquals(1f, mGroupRow.getBottomRoundness(), 0.001f); Assert.assertEquals(1f, group.getBottomRoundness(), 0.001f);
Assert.assertEquals(1f, mGroupRow.getChildrenContainer().getBottomRoundness(), 0.001f); Assert.assertEquals(1f, group.getChildrenContainer().getBottomRoundness(), 0.001f);
} }
@Test @Test
public void testSetContentAnimationRunning_Run() throws Exception { public void testSetContentAnimationRunning_Run() throws Exception {
// Create views for the notification row. // Create views for the notification row.
ExpandableNotificationRow row = mNotificationTestHelper.createRow();
NotificationContentView publicLayout = mock(NotificationContentView.class); NotificationContentView publicLayout = mock(NotificationContentView.class);
mNotifRow.setPublicLayout(publicLayout); row.setPublicLayout(publicLayout);
NotificationContentView privateLayout = mock(NotificationContentView.class); NotificationContentView privateLayout = mock(NotificationContentView.class);
mNotifRow.setPrivateLayout(privateLayout); row.setPrivateLayout(privateLayout);
mNotifRow.setAnimationRunning(true); row.setAnimationRunning(true);
verify(publicLayout, times(1)).setContentAnimationRunning(true); verify(publicLayout, times(1)).setContentAnimationRunning(true);
verify(privateLayout, times(1)).setContentAnimationRunning(true); verify(privateLayout, times(1)).setContentAnimationRunning(true);
} }
@Test @Test
public void testSetContentAnimationRunning_Stop() { public void testSetContentAnimationRunning_Stop() throws Exception {
// Create views for the notification row. // Create views for the notification row.
ExpandableNotificationRow row = mNotificationTestHelper.createRow();
NotificationContentView publicLayout = mock(NotificationContentView.class); NotificationContentView publicLayout = mock(NotificationContentView.class);
mNotifRow.setPublicLayout(publicLayout); row.setPublicLayout(publicLayout);
NotificationContentView privateLayout = mock(NotificationContentView.class); NotificationContentView privateLayout = mock(NotificationContentView.class);
mNotifRow.setPrivateLayout(privateLayout); row.setPrivateLayout(privateLayout);
mNotifRow.setAnimationRunning(false); row.setAnimationRunning(false);
verify(publicLayout, times(1)).setContentAnimationRunning(false); verify(publicLayout, times(1)).setContentAnimationRunning(false);
verify(privateLayout, times(1)).setContentAnimationRunning(false); verify(privateLayout, times(1)).setContentAnimationRunning(false);
} }
@Test @Test
public void testSetContentAnimationRunningInGroupChild_Run() { public void testSetContentAnimationRunningInGroupChild_Run() throws Exception {
// Creates parent views on mGroupRow. // Creates parent views on groupRow.
ExpandableNotificationRow groupRow = mNotificationTestHelper.createGroup();
NotificationContentView publicParentLayout = mock(NotificationContentView.class); NotificationContentView publicParentLayout = mock(NotificationContentView.class);
mGroupRow.setPublicLayout(publicParentLayout); groupRow.setPublicLayout(publicParentLayout);
NotificationContentView privateParentLayout = mock(NotificationContentView.class); NotificationContentView privateParentLayout = mock(NotificationContentView.class);
mGroupRow.setPrivateLayout(privateParentLayout); groupRow.setPrivateLayout(privateParentLayout);
// Create child views on mNotifRow. // Create child views on row.
ExpandableNotificationRow row = mNotificationTestHelper.createRow();
NotificationContentView publicChildLayout = mock(NotificationContentView.class); NotificationContentView publicChildLayout = mock(NotificationContentView.class);
mNotifRow.setPublicLayout(publicChildLayout); row.setPublicLayout(publicChildLayout);
NotificationContentView privateChildLayout = mock(NotificationContentView.class); NotificationContentView privateChildLayout = mock(NotificationContentView.class);
mNotifRow.setPrivateLayout(privateChildLayout); row.setPrivateLayout(privateChildLayout);
when(mNotifRow.isGroupExpanded()).thenReturn(true); when(row.isGroupExpanded()).thenReturn(true);
setMockChildrenContainer(mGroupRow, mNotifRow); setMockChildrenContainer(groupRow, row);
mGroupRow.setAnimationRunning(true); groupRow.setAnimationRunning(true);
verify(publicParentLayout, times(1)).setContentAnimationRunning(true); verify(publicParentLayout, times(1)).setContentAnimationRunning(true);
verify(privateParentLayout, times(1)).setContentAnimationRunning(true); verify(privateParentLayout, times(1)).setContentAnimationRunning(true);
// The child layouts should be started too. // The child layouts should be started too.
@@ -624,23 +660,25 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
@Test @Test
public void testSetIconAnimationRunningGroup_Run() { public void testSetIconAnimationRunningGroup_Run() throws Exception {
// Create views for a group row. // Create views for a group row.
ExpandableNotificationRow group = mNotificationTestHelper.createGroup();
ExpandableNotificationRow child = mNotificationTestHelper.createRow();
NotificationContentView publicParentLayout = mock(NotificationContentView.class); NotificationContentView publicParentLayout = mock(NotificationContentView.class);
mGroupRow.setPublicLayout(publicParentLayout); group.setPublicLayout(publicParentLayout);
NotificationContentView privateParentLayout = mock(NotificationContentView.class); NotificationContentView privateParentLayout = mock(NotificationContentView.class);
mGroupRow.setPrivateLayout(privateParentLayout); group.setPrivateLayout(privateParentLayout);
when(mGroupRow.isGroupExpanded()).thenReturn(true); when(group.isGroupExpanded()).thenReturn(true);
// Sets up mNotifRow as a child ExpandableNotificationRow. // Add the child to the group.
NotificationContentView publicChildLayout = mock(NotificationContentView.class); NotificationContentView publicChildLayout = mock(NotificationContentView.class);
mNotifRow.setPublicLayout(publicChildLayout); child.setPublicLayout(publicChildLayout);
NotificationContentView privateChildLayout = mock(NotificationContentView.class); NotificationContentView privateChildLayout = mock(NotificationContentView.class);
mNotifRow.setPrivateLayout(privateChildLayout); child.setPrivateLayout(privateChildLayout);
when(mNotifRow.isGroupExpanded()).thenReturn(true); when(child.isGroupExpanded()).thenReturn(true);
NotificationChildrenContainer mockContainer = NotificationChildrenContainer mockContainer =
setMockChildrenContainer(mGroupRow, mNotifRow); setMockChildrenContainer(group, child);
// Mock the children view wrappers, and give them each an icon. // Mock the children view wrappers, and give them each an icon.
NotificationViewWrapper mockViewWrapper = mock(NotificationViewWrapper.class); NotificationViewWrapper mockViewWrapper = mock(NotificationViewWrapper.class);
@@ -663,7 +701,7 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
AnimatedVectorDrawable lowPriVectorDrawable = mock(AnimatedVectorDrawable.class); AnimatedVectorDrawable lowPriVectorDrawable = mock(AnimatedVectorDrawable.class);
setDrawableIconsInImageView(mockLowPriorityIcon, lowPriDrawable, lowPriVectorDrawable); setDrawableIconsInImageView(mockLowPriorityIcon, lowPriDrawable, lowPriVectorDrawable);
mGroupRow.setAnimationRunning(true); group.setAnimationRunning(true);
verify(drawable, times(1)).start(); verify(drawable, times(1)).start();
verify(vectorDrawable, times(1)).start(); verify(vectorDrawable, times(1)).start();
verify(lowPriDrawable, times(1)).start(); verify(lowPriDrawable, times(1)).start();

View File

@@ -40,7 +40,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.LauncherApps; import android.content.pm.LauncherApps;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.os.Handler;
import android.os.UserHandle; import android.os.UserHandle;
import android.service.notification.StatusBarNotification; import android.service.notification.StatusBarNotification;
import android.testing.TestableLooper; import android.testing.TestableLooper;
@@ -49,7 +48,6 @@ import android.view.LayoutInflater;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.TestableDependency; import com.android.systemui.TestableDependency;
import com.android.systemui.classifier.FalsingCollectorFake; import com.android.systemui.classifier.FalsingCollectorFake;
import com.android.systemui.classifier.FalsingManagerFake; import com.android.systemui.classifier.FalsingManagerFake;
@@ -57,7 +55,6 @@ import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.media.controls.util.MediaFeatureFlag; import com.android.systemui.media.controls.util.MediaFeatureFlag;
import com.android.systemui.media.dialog.MediaOutputDialogFactory; import com.android.systemui.media.dialog.MediaOutputDialogFactory;
import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shade.ShadeExpansionStateManager;
import com.android.systemui.statusbar.NotificationMediaManager; import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.NotificationRemoteInputManager; import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.NotificationShadeWindowController;
@@ -68,7 +65,6 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener;
import com.android.systemui.statusbar.notification.collection.provider.VisualStabilityProvider;
import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager; import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager;
import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager; import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager;
import com.android.systemui.statusbar.notification.icon.IconBuilder; import com.android.systemui.statusbar.notification.icon.IconBuilder;
@@ -77,11 +73,8 @@ import com.android.systemui.statusbar.notification.people.PeopleNotificationIden
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.ExpandableNotificationRowLogger; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.ExpandableNotificationRowLogger;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.OnExpandClickListener; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.OnExpandClickListener;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag; import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import com.android.systemui.statusbar.policy.InflatedSmartReplyState; import com.android.systemui.statusbar.policy.InflatedSmartReplyState;
import com.android.systemui.statusbar.policy.InflatedSmartReplyViewHolder; import com.android.systemui.statusbar.policy.InflatedSmartReplyViewHolder;
import com.android.systemui.statusbar.policy.SmartReplyConstants; import com.android.systemui.statusbar.policy.SmartReplyConstants;
@@ -121,12 +114,12 @@ public class NotificationTestHelper {
private final GroupMembershipManager mGroupMembershipManager; private final GroupMembershipManager mGroupMembershipManager;
private final GroupExpansionManager mGroupExpansionManager; private final GroupExpansionManager mGroupExpansionManager;
private ExpandableNotificationRow mRow; private ExpandableNotificationRow mRow;
private HeadsUpManagerPhone mHeadsUpManager; private final HeadsUpManagerPhone mHeadsUpManager;
private final NotifBindPipeline mBindPipeline; private final NotifBindPipeline mBindPipeline;
private final NotifCollectionListener mBindPipelineEntryListener; private final NotifCollectionListener mBindPipelineEntryListener;
private final RowContentBindStage mBindStage; private final RowContentBindStage mBindStage;
private final IconManager mIconManager; private final IconManager mIconManager;
private StatusBarStateController mStatusBarStateController; private final StatusBarStateController mStatusBarStateController;
private final PeopleNotificationIdentifier mPeopleNotificationIdentifier; private final PeopleNotificationIdentifier mPeopleNotificationIdentifier;
public final OnUserInteractionCallback mOnUserInteractionCallback; public final OnUserInteractionCallback mOnUserInteractionCallback;
public final Runnable mFutureDismissalRunnable; public final Runnable mFutureDismissalRunnable;
@@ -146,21 +139,7 @@ public class NotificationTestHelper {
mStatusBarStateController = mock(StatusBarStateController.class); mStatusBarStateController = mock(StatusBarStateController.class);
mGroupMembershipManager = mock(GroupMembershipManager.class); mGroupMembershipManager = mock(GroupMembershipManager.class);
mGroupExpansionManager = mock(GroupExpansionManager.class); mGroupExpansionManager = mock(GroupExpansionManager.class);
mHeadsUpManager = new HeadsUpManagerPhone( mHeadsUpManager = mock(HeadsUpManagerPhone.class);
mContext,
mock(HeadsUpManagerLogger.class),
mStatusBarStateController,
mock(KeyguardBypassController.class),
mock(GroupMembershipManager.class),
mock(VisualStabilityProvider.class),
mock(ConfigurationControllerImpl.class),
new Handler(mTestLooper.getLooper()),
mock(AccessibilityManagerWrapper.class),
mock(UiEventLogger.class),
mock(ShadeExpansionStateManager.class)
);
mHeadsUpManager.mHandler.removeCallbacksAndMessages(null);
mHeadsUpManager.mHandler = new Handler(mTestLooper.getLooper());
mIconManager = new IconManager( mIconManager = new IconManager(
mock(CommonNotifCollection.class), mock(CommonNotifCollection.class),
mock(LauncherApps.class), mock(LauncherApps.class),