Commit 1adc855a authored by Andre Le's avatar Andre Le Committed by Commit Bot

Ash Notification: Add unpinned notification count in ash message center.

Add the logic to update visibility for "Clear all" button depends on the
count of total and unpinned notification.

BUG=1111167

Change-Id: Ie609ae1225c0041e3c45815b1f4c2550136ace77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339942
Commit-Queue: Andre Le <leandre@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799890}
parent 6facaf56
...@@ -295,25 +295,29 @@ StackedNotificationBar::~StackedNotificationBar() { ...@@ -295,25 +295,29 @@ StackedNotificationBar::~StackedNotificationBar() {
bool StackedNotificationBar::Update( bool StackedNotificationBar::Update(
int total_notification_count, int total_notification_count,
int pinned_notification_count,
std::vector<message_center::Notification*> stacked_notifications) { std::vector<message_center::Notification*> stacked_notifications) {
int stacked_notification_count = stacked_notifications.size(); int stacked_notification_count = stacked_notifications.size();
if (total_notification_count == total_notification_count_ && if (total_notification_count == total_notification_count_ &&
pinned_notification_count == pinned_notification_count_ &&
stacked_notification_count == stacked_notification_count_) stacked_notification_count == stacked_notification_count_)
return false; return false;
total_notification_count_ = total_notification_count; total_notification_count_ = total_notification_count;
pinned_notification_count_ = pinned_notification_count;
UpdateStackedNotifications(stacked_notifications);
UpdateVisibility(); UpdateVisibility();
int unpinned_count = total_notification_count_ - pinned_notification_count_;
auto tooltip = l10n_util::GetStringFUTF16Int( auto tooltip = l10n_util::GetStringFUTF16Int(
IDS_ASH_MESSAGE_CENTER_STACKING_BAR_CLEAR_ALL_BUTTON_TOOLTIP, IDS_ASH_MESSAGE_CENTER_STACKING_BAR_CLEAR_ALL_BUTTON_TOOLTIP,
total_notification_count_); unpinned_count);
clear_all_button_->SetTooltipText(tooltip); clear_all_button_->SetTooltipText(tooltip);
clear_all_button_->SetAccessibleName(tooltip); clear_all_button_->SetAccessibleName(tooltip);
UpdateStackedNotifications(stacked_notifications);
return true; return true;
} }
...@@ -484,16 +488,26 @@ const char* StackedNotificationBar::GetClassName() const { ...@@ -484,16 +488,26 @@ const char* StackedNotificationBar::GetClassName() const {
} }
void StackedNotificationBar::UpdateVisibility() { void StackedNotificationBar::UpdateVisibility() {
int unpinned_count = total_notification_count_ - pinned_notification_count_;
// In expanded state, clear all button should be visible when (rule is subject
// to change):
// 1. There are more than one notification.
// 2. There is at least one unpinned notification
bool show_clear_all = total_notification_count_ > 1 && unpinned_count >= 1;
if (!expand_all_button_->GetVisible())
clear_all_button_->SetVisible(show_clear_all);
switch (animation_state_) { switch (animation_state_) {
case UnifiedMessageCenterAnimationState::IDLE: case UnifiedMessageCenterAnimationState::IDLE:
SetVisible(total_notification_count_ > 1 || SetVisible(stacked_notification_count_ || show_clear_all ||
expand_all_button_->GetVisible()); expand_all_button_->GetVisible());
break; break;
case UnifiedMessageCenterAnimationState::HIDE_STACKING_BAR: case UnifiedMessageCenterAnimationState::HIDE_STACKING_BAR:
SetVisible(true); SetVisible(true);
break; break;
case UnifiedMessageCenterAnimationState::COLLAPSE: case UnifiedMessageCenterAnimationState::COLLAPSE:
SetVisible(total_notification_count_ > 1 || SetVisible(stacked_notification_count_ || show_clear_all ||
expand_all_button_->GetVisible()); expand_all_button_->GetVisible());
break; break;
} }
......
...@@ -37,9 +37,10 @@ class StackedNotificationBar : public views::View, ...@@ -37,9 +37,10 @@ class StackedNotificationBar : public views::View,
~StackedNotificationBar() override; ~StackedNotificationBar() override;
// Sets the icons and overflow count for hidden notifications as well as the // Sets the icons and overflow count for hidden notifications as well as the
// total notifications count. Returns true if the state of the bar has // total/pinned notifications count. Returns true if the state of the bar
// changed. // has changed.
bool Update(int total_notification_count, bool Update(int total_notification_count,
int pinned_notification_count,
std::vector<message_center::Notification*> stacked_notifications); std::vector<message_center::Notification*> stacked_notifications);
// Sets the current animation state. // Sets the current animation state.
...@@ -98,6 +99,7 @@ class StackedNotificationBar : public views::View, ...@@ -98,6 +99,7 @@ class StackedNotificationBar : public views::View,
std::vector<message_center::Notification*> stacked_notifications); std::vector<message_center::Notification*> stacked_notifications);
int total_notification_count_ = 0; int total_notification_count_ = 0;
int pinned_notification_count_ = 0;
int stacked_notification_count_ = 0; int stacked_notification_count_ = 0;
UnifiedMessageCenterAnimationState animation_state_ = UnifiedMessageCenterAnimationState animation_state_ =
......
...@@ -94,7 +94,9 @@ UnifiedMessageCenterView::UnifiedMessageCenterView( ...@@ -94,7 +94,9 @@ UnifiedMessageCenterView::UnifiedMessageCenterView(
scroller_->SetDrawOverflowIndicator(false); scroller_->SetDrawOverflowIndicator(false);
AddChildView(scroller_); AddChildView(scroller_);
notification_bar_->Update(message_list_view_->GetTotalNotificationCount(), notification_bar_->Update(
message_list_view_->GetTotalNotificationCount(),
message_list_view_->GetTotalPinnedNotificationCount(),
GetStackedNotifications()); GetStackedNotifications());
} }
...@@ -163,16 +165,16 @@ bool UnifiedMessageCenterView::IsNotificationBarVisible() { ...@@ -163,16 +165,16 @@ bool UnifiedMessageCenterView::IsNotificationBarVisible() {
} }
void UnifiedMessageCenterView::OnNotificationSlidOut() { void UnifiedMessageCenterView::OnNotificationSlidOut() {
if (collapsed_) { if (notification_bar_->GetVisible()) {
if (!message_list_view_->GetTotalNotificationCount()) notification_bar_->Update(
message_list_view_->GetTotalNotificationCount(),
message_list_view_->GetTotalPinnedNotificationCount(),
GetStackedNotifications());
if (!notification_bar_->GetVisible())
StartHideStackingBarAnimation(); StartHideStackingBarAnimation();
return;
} }
if (notification_bar_->GetVisible() && if (!message_list_view_->GetTotalNotificationCount()) {
message_list_view_->GetTotalNotificationCount() <= 1) {
StartHideStackingBarAnimation();
} else if (!message_list_view_->GetTotalNotificationCount()) {
StartCollapseAnimation(); StartCollapseAnimation();
} }
} }
...@@ -270,8 +272,9 @@ void UnifiedMessageCenterView::OnMessageCenterScrolled() { ...@@ -270,8 +272,9 @@ void UnifiedMessageCenterView::OnMessageCenterScrolled() {
model_->set_notification_target_mode( model_->set_notification_target_mode(
UnifiedSystemTrayModel::NotificationTargetMode::LAST_POSITION); UnifiedSystemTrayModel::NotificationTargetMode::LAST_POSITION);
bool was_count_updated = bool was_count_updated = notification_bar_->Update(
notification_bar_->Update(message_list_view_->GetTotalNotificationCount(), message_list_view_->GetTotalNotificationCount(),
message_list_view_->GetTotalPinnedNotificationCount(),
GetStackedNotifications()); GetStackedNotifications());
if (was_count_updated) { if (was_count_updated) {
const int previous_y = scroller_->y(); const int previous_y = scroller_->y();
...@@ -451,7 +454,9 @@ void UnifiedMessageCenterView::ScrollToTarget() { ...@@ -451,7 +454,9 @@ void UnifiedMessageCenterView::ScrollToTarget() {
} }
scroller_->ScrollToPosition(scroll_bar_, position); scroller_->ScrollToPosition(scroll_bar_, position);
notification_bar_->Update(message_list_view_->GetTotalNotificationCount(), notification_bar_->Update(
message_list_view_->GetTotalNotificationCount(),
message_list_view_->GetTotalPinnedNotificationCount(),
GetStackedNotifications()); GetStackedNotifications());
last_scroll_position_from_bottom_ = last_scroll_position_from_bottom_ =
scroll_bar_->GetMaxPosition() - scroller_->GetVisibleRect().y(); scroll_bar_->GetMaxPosition() - scroller_->GetVisibleRect().y();
...@@ -464,6 +469,13 @@ UnifiedMessageCenterView::GetStackedNotifications() const { ...@@ -464,6 +469,13 @@ UnifiedMessageCenterView::GetStackedNotifications() const {
if (scroller_->bounds().IsEmpty()) if (scroller_->bounds().IsEmpty())
scroller_->SetBoundsRect(GetContentsBounds()); scroller_->SetBoundsRect(GetContentsBounds());
// If nothing is hidden in the scroller view, this means notification bar is
// not shown. Thus, we should not consider it in the calculation.
int notification_bar_height =
scroller_->GetVisibleRect().y() == scroller_->y()
? 0
: kStackedNotificationBarHeight;
// Use this y offset to count number of hidden notifications. // Use this y offset to count number of hidden notifications.
// Set to the bottom of the last notification when message center is // Set to the bottom of the last notification when message center is
// collapsed. Set below stacked notification bar when message center is // collapsed. Set below stacked notification bar when message center is
...@@ -474,12 +486,11 @@ UnifiedMessageCenterView::GetStackedNotifications() const { ...@@ -474,12 +486,11 @@ UnifiedMessageCenterView::GetStackedNotifications() const {
y_offset = last_bounds.y() + last_bounds.height(); y_offset = last_bounds.y() + last_bounds.height();
} else { } else {
y_offset = scroller_->GetVisibleRect().y() - scroller_->y() + y_offset = scroller_->GetVisibleRect().y() - scroller_->y() +
kStackedNotificationBarHeight; notification_bar_height;
} }
return message_list_view_->GetNotificationsAboveY(y_offset); return message_list_view_->GetNotificationsAboveY(y_offset);
} }
void UnifiedMessageCenterView::FocusOut(bool reverse) { void UnifiedMessageCenterView::FocusOut(bool reverse) {
if (message_center_bubble_ && message_center_bubble_->FocusOut(reverse)) { if (message_center_bubble_ && message_center_bubble_->FocusOut(reverse)) {
GetFocusManager()->ClearFocus(); GetFocusManager()->ClearFocus();
......
...@@ -85,13 +85,15 @@ class UnifiedMessageCenterViewTest : public AshTestBase, ...@@ -85,13 +85,15 @@ class UnifiedMessageCenterViewTest : public AshTestBase,
} }
protected: protected:
std::string AddNotification() { std::string AddNotification(bool pinned) {
std::string id = base::NumberToString(id_++); std::string id = base::NumberToString(id_++);
message_center::RichNotificationData data;
data.pinned = pinned;
MessageCenter::Get()->AddNotification(std::make_unique<Notification>( MessageCenter::Get()->AddNotification(std::make_unique<Notification>(
message_center::NOTIFICATION_TYPE_BASE_FORMAT, id, message_center::NOTIFICATION_TYPE_BASE_FORMAT, id,
base::UTF8ToUTF16("test title"), base::UTF8ToUTF16("test message"), base::UTF8ToUTF16("test title"), base::UTF8ToUTF16("test message"),
gfx::Image(), base::string16() /* display_source */, GURL(), gfx::Image(), base::string16() /* display_source */, GURL(),
message_center::NotifierId(), message_center::RichNotificationData(), message_center::NotifierId(), data,
new message_center::NotificationDelegate())); new message_center::NotificationDelegate()));
return id; return id;
} }
...@@ -253,7 +255,7 @@ TEST_F(UnifiedMessageCenterViewTest, AddAndRemoveNotification) { ...@@ -253,7 +255,7 @@ TEST_F(UnifiedMessageCenterViewTest, AddAndRemoveNotification) {
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_FALSE(message_center_view()->GetVisible()); EXPECT_FALSE(message_center_view()->GetVisible());
auto id0 = AddNotification(); auto id0 = AddNotification(false /* pinned */);
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
// The notification first slides out of the list. // The notification first slides out of the list.
...@@ -276,13 +278,13 @@ TEST_F(UnifiedMessageCenterViewTest, AddAndRemoveNotification) { ...@@ -276,13 +278,13 @@ TEST_F(UnifiedMessageCenterViewTest, AddAndRemoveNotification) {
TEST_F(UnifiedMessageCenterViewTest, RemoveNotificationAtTail) { TEST_F(UnifiedMessageCenterViewTest, RemoveNotificationAtTail) {
// Show message center with multiple notifications. // Show message center with multiple notifications.
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
// The message center should autoscroll to the bottom of the list (with some // The message center should autoscroll to the bottom of the list (with some
// padding) after adding a new notification. // padding) after adding a new notification.
auto id_to_remove = AddNotification(); auto id_to_remove = AddNotification(false /* pinned */);
int spacing = 0; int spacing = 0;
int scroll_position = GetScroller()->GetVisibleRect().y(); int scroll_position = GetScroller()->GetVisibleRect().y();
EXPECT_EQ(GetMessageListView()->height() - GetScroller()->height() + spacing, EXPECT_EQ(GetMessageListView()->height() - GetScroller()->height() + spacing,
...@@ -306,7 +308,7 @@ TEST_F(UnifiedMessageCenterViewTest, RemoveNotificationAtTail) { ...@@ -306,7 +308,7 @@ TEST_F(UnifiedMessageCenterViewTest, RemoveNotificationAtTail) {
TEST_F(UnifiedMessageCenterViewTest, ContentsRelayout) { TEST_F(UnifiedMessageCenterViewTest, ContentsRelayout) {
std::vector<std::string> ids; std::vector<std::string> ids;
for (size_t i = 0; i < 10; ++i) for (size_t i = 0; i < 10; ++i)
ids.push_back(AddNotification()); ids.push_back(AddNotification(false /* pinned */));
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
// MessageCenterView is maxed out. // MessageCenterView is maxed out.
...@@ -324,7 +326,7 @@ TEST_F(UnifiedMessageCenterViewTest, ContentsRelayout) { ...@@ -324,7 +326,7 @@ TEST_F(UnifiedMessageCenterViewTest, ContentsRelayout) {
TEST_F(UnifiedMessageCenterViewTest, InsufficientHeight) { TEST_F(UnifiedMessageCenterViewTest, InsufficientHeight) {
CreateMessageCenterView(); CreateMessageCenterView();
AddNotification(); AddNotification(false /* pinned */);
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
message_center_view()->SetAvailableHeight(kUnifiedNotificationMinimumHeight - message_center_view()->SetAvailableHeight(kUnifiedNotificationMinimumHeight -
...@@ -344,8 +346,8 @@ TEST_F(UnifiedMessageCenterViewTest, NotVisibleWhenLocked) { ...@@ -344,8 +346,8 @@ TEST_F(UnifiedMessageCenterViewTest, NotVisibleWhenLocked) {
ASSERT_FALSE(AshMessageCenterLockScreenController::IsEnabled()); ASSERT_FALSE(AshMessageCenterLockScreenController::IsEnabled());
AddNotification(); AddNotification(false /* pinned */);
AddNotification(); AddNotification(false /* pinned */);
BlockUserSession(BLOCKED_BY_LOCK_SCREEN); BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
CreateMessageCenterView(); CreateMessageCenterView();
...@@ -367,8 +369,8 @@ TEST_F(UnifiedMessageCenterViewTest, VisibleWhenLocked) { ...@@ -367,8 +369,8 @@ TEST_F(UnifiedMessageCenterViewTest, VisibleWhenLocked) {
ASSERT_TRUE(AshMessageCenterLockScreenController::IsEnabled()); ASSERT_TRUE(AshMessageCenterLockScreenController::IsEnabled());
AddNotification(); AddNotification(false /* pinned */);
AddNotification(); AddNotification(false /* pinned */);
BlockUserSession(BLOCKED_BY_LOCK_SCREEN); BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
CreateMessageCenterView(); CreateMessageCenterView();
...@@ -377,8 +379,8 @@ TEST_F(UnifiedMessageCenterViewTest, VisibleWhenLocked) { ...@@ -377,8 +379,8 @@ TEST_F(UnifiedMessageCenterViewTest, VisibleWhenLocked) {
} }
TEST_F(UnifiedMessageCenterViewTest, ClearAllPressed) { TEST_F(UnifiedMessageCenterViewTest, ClearAllPressed) {
AddNotification(); AddNotification(false /* pinned */);
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
EXPECT_TRUE(GetNotificationBar()->GetVisible()); EXPECT_TRUE(GetNotificationBar()->GetVisible());
...@@ -391,8 +393,8 @@ TEST_F(UnifiedMessageCenterViewTest, ClearAllPressed) { ...@@ -391,8 +393,8 @@ TEST_F(UnifiedMessageCenterViewTest, ClearAllPressed) {
} }
TEST_F(UnifiedMessageCenterViewTest, InitialPosition) { TEST_F(UnifiedMessageCenterViewTest, InitialPosition) {
AddNotification(); AddNotification(false /* pinned */);
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
...@@ -403,7 +405,7 @@ TEST_F(UnifiedMessageCenterViewTest, InitialPosition) { ...@@ -403,7 +405,7 @@ TEST_F(UnifiedMessageCenterViewTest, InitialPosition) {
TEST_F(UnifiedMessageCenterViewTest, InitialPositionMaxOut) { TEST_F(UnifiedMessageCenterViewTest, InitialPositionMaxOut) {
for (size_t i = 0; i < 6; ++i) for (size_t i = 0; i < 6; ++i)
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
...@@ -413,8 +415,8 @@ TEST_F(UnifiedMessageCenterViewTest, InitialPositionMaxOut) { ...@@ -413,8 +415,8 @@ TEST_F(UnifiedMessageCenterViewTest, InitialPositionMaxOut) {
} }
TEST_F(UnifiedMessageCenterViewTest, InitialPositionWithLargeNotification) { TEST_F(UnifiedMessageCenterViewTest, InitialPositionWithLargeNotification) {
AddNotification(); AddNotification(false /* pinned */);
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(80 /* max_height */); CreateMessageCenterView(80 /* max_height */);
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
...@@ -429,7 +431,7 @@ TEST_F(UnifiedMessageCenterViewTest, InitialPositionWithLargeNotification) { ...@@ -429,7 +431,7 @@ TEST_F(UnifiedMessageCenterViewTest, InitialPositionWithLargeNotification) {
TEST_F(UnifiedMessageCenterViewTest, ScrollPositionWhenResized) { TEST_F(UnifiedMessageCenterViewTest, ScrollPositionWhenResized) {
for (size_t i = 0; i < 6; ++i) for (size_t i = 0; i < 6; ++i)
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
...@@ -460,7 +462,7 @@ TEST_F(UnifiedMessageCenterViewTest, ScrollPositionWhenResized) { ...@@ -460,7 +462,7 @@ TEST_F(UnifiedMessageCenterViewTest, ScrollPositionWhenResized) {
TEST_F(UnifiedMessageCenterViewTest, StackingCounterLayout) { TEST_F(UnifiedMessageCenterViewTest, StackingCounterLayout) {
for (size_t i = 0; i < 10; ++i) for (size_t i = 0; i < 10; ++i)
AddNotification(); AddNotification(false /* pinned */);
// MessageCenterView is maxed out. // MessageCenterView is maxed out.
CreateMessageCenterView(); CreateMessageCenterView();
...@@ -486,7 +488,7 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLayout) { ...@@ -486,7 +488,7 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLayout) {
TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) { TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) {
for (size_t i = 0; i < 10; ++i) for (size_t i = 0; i < 10; ++i)
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
EXPECT_TRUE(GetNotificationBarLabel()->GetVisible()); EXPECT_TRUE(GetNotificationBarLabel()->GetVisible());
...@@ -522,7 +524,7 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) { ...@@ -522,7 +524,7 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterMessageListScrolled) {
TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) { TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) {
std::vector<std::string> ids; std::vector<std::string> ids;
for (size_t i = 0; i < 6; ++i) for (size_t i = 0; i < 6; ++i)
ids.push_back(AddNotification()); ids.push_back(AddNotification(false /* pinned */));
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->GetVisible()); EXPECT_TRUE(message_center_view()->GetVisible());
...@@ -571,9 +573,9 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) { ...@@ -571,9 +573,9 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterNotificationRemoval) {
TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) { TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) {
// Open the message center at the top of the notification list so the stacking // Open the message center at the top of the notification list so the stacking
// bar is hidden by default. // bar is hidden by default.
std::string id = AddNotification(); std::string id = AddNotification(false /* pinned */);
for (size_t i = 0; i < 30; ++i) for (size_t i = 0; i < 30; ++i)
AddNotification(); AddNotification(false /* pinned */);
model()->SetTargetNotification(id); model()->SetTargetNotification(id);
CreateMessageCenterView(); CreateMessageCenterView();
...@@ -595,6 +597,44 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) { ...@@ -595,6 +597,44 @@ TEST_F(UnifiedMessageCenterViewTest, StackingCounterLabelRelaidOutOnScroll) {
EXPECT_GT(GetNotificationBarLabel()->bounds().width(), label_width); EXPECT_GT(GetNotificationBarLabel()->bounds().width(), label_width);
} }
TEST_F(UnifiedMessageCenterViewTest, StackingCounterVisibility) {
std::string id0 = AddNotification(false /* pinned */);
std::string id1 = AddNotification(false /* pinned */);
CreateMessageCenterView();
// The bar should be visible with 2 unpinned notifications.
EXPECT_TRUE(GetNotificationBar()->GetVisible());
EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
MessageCenter::Get()->RemoveNotification(id0, true /* by_user */);
AnimateMessageListToEnd();
auto* hide_animation = GetMessageCenterAnimation();
hide_animation->End();
// The bar should be hidden with 1 notification.
EXPECT_FALSE(GetNotificationBar()->GetVisible());
MessageCenter::Get()->RemoveNotification(id1, true /* by_user */);
AddNotification(true /* pinned */);
AddNotification(true /* pinned */);
// The bar should not be visible with 2 pinned notifications (none of the
// notifications are hidden).
EXPECT_FALSE(GetNotificationBar()->GetVisible());
for (size_t i = 0; i < 4; ++i)
AddNotification(true /* pinned */);
// The bar should be visible with 6 pinned notifications (some of the
// notifications are hidden). However, clear all button should not be shown.
EXPECT_TRUE(GetNotificationBar()->GetVisible());
EXPECT_FALSE(GetNotificationBarClearAllButton()->GetVisible());
// Add 1 unpinned notifications. Clear all should now be shown.
AddNotification(false /* pinned */);
EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
}
// We need a widget to initialize a FocusManager. // We need a widget to initialize a FocusManager.
TEST_F(UnifiedMessageCenterViewInWidgetTest, TEST_F(UnifiedMessageCenterViewInWidgetTest,
FocusClearedAfterNotificationRemoval) { FocusClearedAfterNotificationRemoval) {
...@@ -603,8 +643,8 @@ TEST_F(UnifiedMessageCenterViewInWidgetTest, ...@@ -603,8 +643,8 @@ TEST_F(UnifiedMessageCenterViewInWidgetTest,
widget()->Show(); widget()->Show();
// Add notifications and focus on a child view in the last notification. // Add notifications and focus on a child view in the last notification.
AddNotification(); AddNotification(false /* pinned */);
auto id1 = AddNotification(); auto id1 = AddNotification(false /* pinned */);
// Toggle focus to the last notification MessageView. // Toggle focus to the last notification MessageView.
auto* focused_message_view = auto* focused_message_view =
...@@ -619,8 +659,8 @@ TEST_F(UnifiedMessageCenterViewInWidgetTest, ...@@ -619,8 +659,8 @@ TEST_F(UnifiedMessageCenterViewInWidgetTest,
} }
TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_NonAnimated) { TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_NonAnimated) {
AddNotification(); AddNotification(false /* pinned */);
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(GetScroller()->GetVisible()); EXPECT_TRUE(GetScroller()->GetVisible());
EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible()); EXPECT_TRUE(GetNotificationBarClearAllButton()->GetVisible());
...@@ -641,8 +681,8 @@ TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_NonAnimated) { ...@@ -641,8 +681,8 @@ TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_NonAnimated) {
} }
TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_Animated) { TEST_F(UnifiedMessageCenterViewTest, CollapseAndExpand_Animated) {
AddNotification(); AddNotification(false /* pinned */);
AddNotification(); AddNotification(false /* pinned */);
CreateMessageCenterView(); CreateMessageCenterView();
EXPECT_TRUE(GetScroller()->GetVisible()); EXPECT_TRUE(GetScroller()->GetVisible());
......
...@@ -304,6 +304,15 @@ int UnifiedMessageListView::GetTotalNotificationCount() const { ...@@ -304,6 +304,15 @@ int UnifiedMessageListView::GetTotalNotificationCount() const {
return int{children().size()}; return int{children().size()};
} }
int UnifiedMessageListView::GetTotalPinnedNotificationCount() const {
int count = 0;
for (auto* child : children()) {
if (AsMVC(child)->IsPinned())
count++;
}
return count;
}
bool UnifiedMessageListView::IsAnimating() const { bool UnifiedMessageListView::IsAnimating() const {
return animation_->is_animating(); return animation_->is_animating();
} }
......
...@@ -66,6 +66,9 @@ class ASH_EXPORT UnifiedMessageListView ...@@ -66,6 +66,9 @@ class ASH_EXPORT UnifiedMessageListView
// Returns the total number of notifications in the list. // Returns the total number of notifications in the list.
int GetTotalNotificationCount() const; int GetTotalNotificationCount() const;
// Returns the total number of pinned notifications in the list.
int GetTotalPinnedNotificationCount() const;
// Returns true if an animation is currently in progress. // Returns true if an animation is currently in progress.
bool IsAnimating() const; bool IsAnimating() const;
......
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