Commit c22819ba authored by Tim Song's avatar Tim Song Committed by Commit Bot

Ash Tray: Fix message center visibility when collapsing with no notifications.

This CL also adds unit tests for the collapse/expand behaviour for the message
center.

TEST=manual + new unit tests
BUG=1019405

Change-Id: I1189549e41e6f11f2d513c4d041de6e5ac108caf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1888187
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: default avatarAhmed Mehfooz <amehfooz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711131}
parent 696b04ea
...@@ -259,6 +259,7 @@ TEST_F(UnifiedMessageCenterBubbleTest, ReverseFocusCycle) { ...@@ -259,6 +259,7 @@ TEST_F(UnifiedMessageCenterBubbleTest, ReverseFocusCycle) {
TEST_F(UnifiedMessageCenterBubbleTest, CollapseState) { TEST_F(UnifiedMessageCenterBubbleTest, CollapseState) {
EnableMessageCenterRefactor(); EnableMessageCenterRefactor();
AddNotification();
GetPrimaryUnifiedSystemTray()->ShowBubble(true); GetPrimaryUnifiedSystemTray()->ShowBubble(true);
int small_display_height = int small_display_height =
......
...@@ -122,7 +122,7 @@ void UnifiedMessageCenterView::SetAvailableHeight(int available_height) { ...@@ -122,7 +122,7 @@ void UnifiedMessageCenterView::SetAvailableHeight(int available_height) {
} }
void UnifiedMessageCenterView::SetExpanded() { void UnifiedMessageCenterView::SetExpanded() {
if (!collapsed_) if (!GetVisible() || !collapsed_)
return; return;
collapsed_ = false; collapsed_ = false;
...@@ -132,7 +132,7 @@ void UnifiedMessageCenterView::SetExpanded() { ...@@ -132,7 +132,7 @@ void UnifiedMessageCenterView::SetExpanded() {
} }
void UnifiedMessageCenterView::SetCollapsed(bool animate) { void UnifiedMessageCenterView::SetCollapsed(bool animate) {
if (collapsed_) if (!GetVisible() || collapsed_)
return; return;
collapsed_ = true; collapsed_ = true;
......
...@@ -163,18 +163,22 @@ class UnifiedMessageCenterViewTest : public AshTestBase, ...@@ -163,18 +163,22 @@ class UnifiedMessageCenterViewTest : public AshTestBase,
return message_center_view()->scroller_->contents(); return message_center_view()->scroller_->contents();
} }
views::View* GetStackingCounter() { StackedNotificationBar* GetNotificationBar() {
return message_center_view()->notification_bar_; return message_center_view()->notification_bar_;
} }
views::View* GetStackingCounterLabel() { views::View* GetNotificationBarLabel() {
return message_center_view()->notification_bar_->count_label_; return message_center_view()->notification_bar_->count_label_;
} }
views::View* GetStackingCounterClearAllButton() { views::View* GetNotificationBarClearAllButton() {
return message_center_view()->notification_bar_->clear_all_button_; return message_center_view()->notification_bar_->clear_all_button_;
} }
views::View* GetNotificationBarExpandAllButton() {
return message_center_view()->notification_bar_->expand_all_button_;
}
message_center::MessageView* ToggleFocusToMessageView(size_t index, message_center::MessageView* ToggleFocusToMessageView(size_t index,
bool reverse) { bool reverse) {
auto* focus_manager = message_center_view()->GetFocusManager(); auto* focus_manager = message_center_view()->GetFocusManager();
...@@ -349,7 +353,7 @@ TEST_F(UnifiedMessageCenterViewTest, ClearAllPressed) { ...@@ -349,7 +353,7 @@ TEST_F(UnifiedMessageCenterViewTest, ClearAllPressed) {
AddNotification(); AddNotification();
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
// When Clear All button is pressed, all notifications are removed and the // When Clear All button is pressed, all notifications are removed and the
// view becomes invisible. // view becomes invisible.
...@@ -449,19 +453,19 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLayout) { ...@@ -449,19 +453,19 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLayout) {
EXPECT_GT(GetMessageListView()->bounds().height(), EXPECT_GT(GetMessageListView()->bounds().height(),
message_center_view()->bounds().height()); message_center_view()->bounds().height());
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
EXPECT_EQ(0, GetStackingCounter()->bounds().y()); EXPECT_EQ(0, GetNotificationBar()->bounds().y());
EXPECT_EQ(GetStackingCounter()->bounds().bottom(), EXPECT_EQ(GetNotificationBar()->bounds().bottom(),
GetScroller()->bounds().y()); GetScroller()->bounds().y());
EXPECT_TRUE(GetStackingCounterLabel()->GetVisible()); EXPECT_TRUE(GetNotificationBarLabel()->GetVisible());
EXPECT_TRUE(GetStackingCounterClearAllButton()->GetVisible()); EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
// Scroll to the top, making the counter label invisible. // Scroll to the top, making the counter label invisible.
GetScroller()->ScrollToPosition(GetScrollBar(), 0); GetScroller()->ScrollToPosition(GetScrollBar(), 0);
message_center_view()->OnMessageCenterScrolled(); message_center_view()->OnMessageCenterScrolled();
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
EXPECT_FALSE(GetStackingCounterLabel()->GetVisible()); EXPECT_FALSE(GetNotificationBarLabel()->GetVisible());
EXPECT_TRUE(GetStackingCounterClearAllButton()->GetVisible()); EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
} }
TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) { TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) {
...@@ -469,8 +473,8 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) { ...@@ -469,8 +473,8 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) {
AddNotification(); AddNotification();
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
EXPECT_TRUE(GetStackingCounterLabel()->GetVisible()); EXPECT_TRUE(GetNotificationBarLabel()->GetVisible());
EXPECT_TRUE(GetStackingCounterClearAllButton()->GetVisible()); EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
// MessageCenterView is maxed out. // MessageCenterView is maxed out.
EXPECT_GT(GetMessageListView()->bounds().height(), EXPECT_GT(GetMessageListView()->bounds().height(),
...@@ -479,24 +483,24 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) { ...@@ -479,24 +483,24 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) {
// Scroll to the top, making the counter label invisible. // Scroll to the top, making the counter label invisible.
GetScroller()->ScrollToPosition(GetScrollBar(), 0); GetScroller()->ScrollToPosition(GetScrollBar(), 0);
message_center_view()->OnMessageCenterScrolled(); message_center_view()->OnMessageCenterScrolled();
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
EXPECT_FALSE(GetStackingCounterLabel()->GetVisible()); EXPECT_FALSE(GetNotificationBarLabel()->GetVisible());
EXPECT_TRUE(GetStackingCounterClearAllButton()->GetVisible()); EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
// Scrolling past 5 notifications should make the counter label visible. // Scrolling past 5 notifications should make the counter label visible.
const int scroll_amount = (GetMessageViewVisibleBounds(0).height() * 5) + 1; const int scroll_amount = (GetMessageViewVisibleBounds(0).height() * 5) + 1;
GetScroller()->ScrollToPosition(GetScrollBar(), scroll_amount); GetScroller()->ScrollToPosition(GetScrollBar(), scroll_amount);
message_center_view()->OnMessageCenterScrolled(); message_center_view()->OnMessageCenterScrolled();
EXPECT_TRUE(GetStackingCounterLabel()->GetVisible()); EXPECT_TRUE(GetNotificationBarLabel()->GetVisible());
// Scrolling back to the top should make the // Scrolling back to the top should make the
// counter label invisible again. // counter label invisible again.
GetScroller()->ScrollToPosition(GetScrollBar(), 0); GetScroller()->ScrollToPosition(GetScrollBar(), 0);
message_center_view()->OnMessageCenterScrolled(); message_center_view()->OnMessageCenterScrolled();
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
EXPECT_FALSE(GetStackingCounterLabel()->GetVisible()); EXPECT_FALSE(GetNotificationBarLabel()->GetVisible());
EXPECT_TRUE(GetStackingCounterClearAllButton()->GetVisible()); EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
} }
TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) { TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) {
...@@ -511,14 +515,14 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) { ...@@ -511,14 +515,14 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) {
message_center_view()->bounds().height()); message_center_view()->bounds().height());
// Dismiss until there are 2 notifications. The bar should still be visible. // Dismiss until there are 2 notifications. The bar should still be visible.
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
for (size_t i = 0; i < 4; ++i) { for (size_t i = 0; i < 4; ++i) {
MessageCenter::Get()->RemoveNotification(ids[i], true /* by_user */); MessageCenter::Get()->RemoveNotification(ids[i], true /* by_user */);
AnimateMessageListToEnd(); AnimateMessageListToEnd();
} }
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
EXPECT_FALSE(GetStackingCounterLabel()->GetVisible()); EXPECT_FALSE(GetNotificationBarLabel()->GetVisible());
EXPECT_TRUE(GetStackingCounterClearAllButton()->GetVisible()); EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
// The MessageCenterView should be tall enough to contain the bar, two // The MessageCenterView should be tall enough to contain the bar, two
// notifications, and extra padding. // notifications, and extra padding.
...@@ -532,24 +536,24 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) { ...@@ -532,24 +536,24 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) {
// Dismiss until there is only 1 notification left. The bar should be // Dismiss until there is only 1 notification left. The bar should be
// hidden after an animation. // hidden after an animation.
MessageCenter::Get()->RemoveNotification(ids[4], true /* by_user */); MessageCenter::Get()->RemoveNotification(ids[4], true /* by_user */);
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
// The HIDE_STACKING_BAR animation starts after the notification is slid out. // The HIDE_STACKING_BAR animation starts after the notification is slid out.
AnimateMessageListToEnd(); AnimateMessageListToEnd();
auto* hide_animation = GetMessageCenterAnimation(); auto* hide_animation = GetMessageCenterAnimation();
EXPECT_TRUE(hide_animation->is_animating()); EXPECT_TRUE(hide_animation->is_animating());
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
// Animate to middle. The bar should still be visible. // Animate to middle. The bar should still be visible.
AnimateMessageListToMiddle(); AnimateMessageListToMiddle();
hide_animation->SetCurrentValue(0.5); hide_animation->SetCurrentValue(0.5);
message_center_view()->AnimationProgressed(hide_animation); message_center_view()->AnimationProgressed(hide_animation);
EXPECT_TRUE(GetStackingCounter()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
// Animate to end. The bar should now be hidden. // Animate to end. The bar should now be hidden.
AnimateMessageListToEnd(); AnimateMessageListToEnd();
hide_animation->End(); hide_animation->End();
EXPECT_FALSE(GetStackingCounter()->GetVisible()); EXPECT_FALSE(GetNotificationBar()->GetVisible());
} }
TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) { TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) {
...@@ -561,14 +565,14 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) { ...@@ -561,14 +565,14 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) {
model()->SetTargetNotification(id); model()->SetTargetNotification(id);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_FALSE(GetStackingCounterLabel()->GetVisible()); EXPECT_FALSE(GetNotificationBarLabel()->GetVisible());
// Scroll past 5 notifications so the count label becomes visible // Scroll past 5 notifications so the count label becomes visible
int scroll_amount = (GetMessageViewVisibleBounds(0).height() * 5) + 1; int scroll_amount = (GetMessageViewVisibleBounds(0).height() * 5) + 1;
GetScroller()->ScrollToPosition(GetScrollBar(), scroll_amount); GetScroller()->ScrollToPosition(GetScrollBar(), scroll_amount);
message_center_view()->OnMessageCenterScrolled(); message_center_view()->OnMessageCenterScrolled();
EXPECT_TRUE(GetStackingCounterLabel()->GetVisible()); EXPECT_TRUE(GetNotificationBarLabel()->GetVisible());
int label_width = GetStackingCounterLabel()->bounds().width(); int label_width = GetNotificationBarLabel()->bounds().width();
EXPECT_GT(label_width, 0); EXPECT_GT(label_width, 0);
// Scroll past 14 notifications so the label width must be expanded to // Scroll past 14 notifications so the label width must be expanded to
...@@ -576,7 +580,7 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) { ...@@ -576,7 +580,7 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) {
scroll_amount = (GetMessageViewVisibleBounds(0).height() * 14) + 1; scroll_amount = (GetMessageViewVisibleBounds(0).height() * 14) + 1;
GetScroller()->ScrollToPosition(GetScrollBar(), scroll_amount); GetScroller()->ScrollToPosition(GetScrollBar(), scroll_amount);
message_center_view()->OnMessageCenterScrolled(); message_center_view()->OnMessageCenterScrolled();
EXPECT_GT(GetStackingCounterLabel()->bounds().width(), label_width); EXPECT_GT(GetNotificationBarLabel()->bounds().width(), label_width);
} }
TEST_F(UnifiedMessageCenterViewTest, RectBelowScroll) { TEST_F(UnifiedMessageCenterViewTest, RectBelowScroll) {
...@@ -709,4 +713,69 @@ TEST_F(UnifiedMessageCenterViewTest, FocusClearedAfterNotificationRemoval) { ...@@ -709,4 +713,69 @@ TEST_F(UnifiedMessageCenterViewTest, FocusClearedAfterNotificationRemoval) {
widget->GetRootView()->RemoveChildView(message_center_view()); widget->GetRootView()->RemoveChildView(message_center_view());
} }
TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_NonAnimated) {
AddNotification();
AddNotification();
CreateMessageCenterView();
EXPECT_TRUE(GetScroller()->GetVisible());
EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
EXPECT_FALSE(GetNotificationBarExpandAllButton()->GetVisible());
// Set to collapsed state.
message_center_view()->SetCollapsed(false /* animate */);
EXPECT_FALSE(GetScroller()->GetVisible());
EXPECT_TRUE(GetNotificationBar()->GetVisible());
EXPECT_TRUE(GetNotificationBarExpandAllButton()->GetVisible());
EXPECT_FALSE(GetNotificationBarClearAllButton()->GetVisible());
// Set back to expanded state.
message_center_view()->SetExpanded();
EXPECT_FALSE(GetNotificationBarExpandAllButton()->GetVisible());
EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
EXPECT_TRUE(GetScroller()->GetVisible());
}
TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_Animated) {
AddNotification();
CreateMessageCenterView();
EXPECT_TRUE(GetScroller()->GetVisible());
EXPECT_FALSE(GetNotificationBar()->GetVisible());
// Set to collapsed state with animation.
message_center_view()->SetCollapsed(true /* animate */);
auto* collapse_animation = GetMessageCenterAnimation();
EXPECT_TRUE(collapse_animation->is_animating());
// The scroller should be hidden at the half way point.
collapse_animation->SetCurrentValue(0.5);
message_center_view()->AnimationProgressed(collapse_animation);
EXPECT_FALSE(GetScroller()->GetVisible());
EXPECT_TRUE(GetNotificationBar()->GetVisible());
collapse_animation->End();
AnimateMessageListToEnd();
EXPECT_TRUE(GetNotificationBarExpandAllButton()->GetVisible());
EXPECT_FALSE(GetNotificationBarClearAllButton()->GetVisible());
// Set back to expanded state.
message_center_view()->SetExpanded();
EXPECT_FALSE(GetNotificationBarExpandAllButton()->GetVisible());
EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
EXPECT_TRUE(GetScroller()->GetVisible());
EXPECT_FALSE(GetNotificationBar()->GetVisible());
}
TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_NoNotifications) {
CreateMessageCenterView();
EXPECT_FALSE(message_center_view()->GetVisible());
// Setting to the collapsed state should do nothing.
message_center_view()->SetCollapsed(true /* animate */);
EXPECT_FALSE(message_center_view()->GetVisible());
// Same with setting it back to the expanded state.
message_center_view()->SetExpanded();
EXPECT_FALSE(message_center_view()->GetVisible());
}
} // namespace ash } // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment