Commit 3f7d16e6 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Hide system priority notification popups.

When Chrome OS System Tray is open, all notification popups should be
hidden. After it's closed, system priority notifications should be shown
again. The behavior was broken after new MessagePopupCollection and
subsequent fix https://crrev.com/c/1158118 .

TEST=MessagePopupCollectionTest.HighPriorityNotificationShownAgain
BUG=874345

Change-Id: I979adfe1c4632fec356a8ee23ea3544cb1024114
Reviewed-on: https://chromium-review.googlesource.com/1177294Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583921}
parent a92d0b5c
......@@ -170,6 +170,10 @@ void MessagePopupCollection::OnNotificationUpdated(
Update();
}
void MessagePopupCollection::OnCenterVisibilityChanged(Visibility visibility) {
Update();
}
void MessagePopupCollection::AnimationEnded(const gfx::Animation* animation) {
Update();
}
......@@ -412,6 +416,12 @@ bool MessagePopupCollection::AddPopup() {
}
void MessagePopupCollection::MarkRemovedPopup() {
if (MessageCenter::Get()->IsMessageCenterVisible()) {
for (auto& item : popup_items_)
item.is_animating = true;
return;
}
std::set<std::string> existing_ids;
for (Notification* notification :
MessageCenter::Get()->GetPopupNotifications()) {
......@@ -524,6 +534,9 @@ bool MessagePopupCollection::CollapseAllPopups() {
}
bool MessagePopupCollection::HasAddedPopup() const {
if (MessageCenter::Get()->IsMessageCenterVisible())
return false;
std::set<std::string> existing_ids;
for (const auto& item : popup_items_)
existing_ids.insert(item.id);
......@@ -543,6 +556,9 @@ bool MessagePopupCollection::HasRemovedPopup() const {
existing_ids.insert(notification->id());
}
if (MessageCenter::Get()->IsMessageCenterVisible())
return !popup_items_.empty();
for (const auto& item : popup_items_) {
if (!existing_ids.count(item.id))
return true;
......
......@@ -53,6 +53,7 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
void OnNotificationRemoved(const std::string& notification_id,
bool by_user) override;
void OnNotificationUpdated(const std::string& notification_id) override;
void OnCenterVisibilityChanged(Visibility visibility) override;
// AnimationDelegate:
void AnimationEnded(const gfx::Animation* animation) override;
......
......@@ -917,4 +917,34 @@ TEST_F(MessagePopupCollectionTest, PopupWidgetClosedOutsideDuringFadeOut) {
EXPECT_FALSE(IsAnimating());
}
TEST_F(MessagePopupCollectionTest, HighPriorityNotificationShownAgain) {
// It only applies to a platform with MessageCenterView i.e. Chrome OS.
MessageCenter::Get()->SetHasMessageCenterView(true);
// Create a notification with system priority.
auto notification = CreateNotification("id");
notification->SetSystemPriority();
MessageCenter::Get()->AddNotification(std::move(notification));
AnimateUntilIdle();
EXPECT_EQ(1u, GetPopupCounts());
// The notification with system priority should not be dismissed by
// MarkAllPopupsShown.
popup_collection()->MarkAllPopupsShown();
EXPECT_FALSE(IsAnimating());
EXPECT_EQ(1u, GetPopupCounts());
// The notification should be hidden when MessageCenterView is visible.
MessageCenter::Get()->SetVisibility(Visibility::VISIBILITY_MESSAGE_CENTER);
EXPECT_TRUE(IsAnimating());
AnimateUntilIdle();
EXPECT_EQ(0u, GetPopupCounts());
// The notification should be shown again when MessageCenterView is hidden.
MessageCenter::Get()->SetVisibility(Visibility::VISIBILITY_TRANSIENT);
EXPECT_TRUE(IsAnimating());
AnimateUntilIdle();
EXPECT_EQ(1u, GetPopupCounts());
}
} // namespace message_center
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