summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 21:20:23 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 21:20:23 +0000
commite8eecbf087af308f5dd0440923ea85f877041e2b (patch)
tree826649a0d1c60cde50480f7560078cbc5d15f742
parentd9551eaa68a55f771798771f05ee8a9e88d73b3b (diff)
downloadchromium_src-e8eecbf087af308f5dd0440923ea85f877041e2b.zip
chromium_src-e8eecbf087af308f5dd0440923ea85f877041e2b.tar.gz
chromium_src-e8eecbf087af308f5dd0440923ea85f877041e2b.tar.bz2
Introduces SYSTEM_PRIORITY
This new priority is expected for system-level high priority notifications such like low-battery notifications. BUG=244525 TEST=covered by the new test cases R=dewittj@chromium.org Review URL: https://chromiumcodereview.appspot.com/15777008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205635 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/message_center/message_center_tray.cc4
-rw-r--r--ui/message_center/message_center_tray_unittest.cc32
-rw-r--r--ui/message_center/notification.cc12
-rw-r--r--ui/message_center/notification.h4
-rw-r--r--ui/message_center/notification_list.cc8
-rw-r--r--ui/message_center/notification_list_unittest.cc25
-rw-r--r--ui/message_center/notification_types.h5
7 files changed, 86 insertions, 4 deletions
diff --git a/ui/message_center/message_center_tray.cc b/ui/message_center/message_center_tray.cc
index 7ee43aa..fc3e148 100644
--- a/ui/message_center/message_center_tray.cc
+++ b/ui/message_center/message_center_tray.cc
@@ -52,6 +52,10 @@ bool MessageCenterTray::HideMessageCenterBubble() {
delegate_->HideMessageCenter();
message_center_visible_ = false;
message_center_->SetMessageCenterVisible(false);
+ // Some notifications (like system ones) should appear as popups again
+ // after the message center is closed.
+ if (message_center_->HasPopupNotifications())
+ ShowPopupBubble();
NotifyMessageCenterTrayChanged();
return true;
}
diff --git a/ui/message_center/message_center_tray_unittest.cc b/ui/message_center/message_center_tray_unittest.cc
index 0235fa7..431c4913c0 100644
--- a/ui/message_center/message_center_tray_unittest.cc
+++ b/ui/message_center/message_center_tray_unittest.cc
@@ -154,6 +154,38 @@ TEST_F(MessageCenterTrayTest, MessageCenterClosesPopups) {
ASSERT_FALSE(message_center_tray_->message_center_visible());
}
+TEST_F(MessageCenterTrayTest, MessageCenterReopenPopupsForSystemPriority) {
+ ASSERT_FALSE(message_center_tray_->popups_visible());
+ ASSERT_FALSE(message_center_tray_->message_center_visible());
+
+ scoped_ptr<Notification> notification(
+ new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
+ "MessageCenterReopnPopupsForSystemPriority",
+ ASCIIToUTF16("Test Web Notification"),
+ ASCIIToUTF16("Notification message body."),
+ gfx::Image(),
+ ASCIIToUTF16("www.test.org"),
+ "" /* extension id */,
+ NULL /* optional_fields */,
+ NULL /* delegate */));
+ notification->SetSystemPriority();
+ message_center_->AddNotification(notification.Pass());
+
+ ASSERT_TRUE(message_center_tray_->popups_visible());
+ ASSERT_FALSE(message_center_tray_->message_center_visible());
+
+ bool shown = message_center_tray_->ShowMessageCenterBubble();
+ EXPECT_TRUE(shown);
+
+ ASSERT_FALSE(message_center_tray_->popups_visible());
+ ASSERT_TRUE(message_center_tray_->message_center_visible());
+
+ message_center_tray_->HideMessageCenterBubble();
+
+ ASSERT_TRUE(message_center_tray_->popups_visible());
+ ASSERT_FALSE(message_center_tray_->message_center_visible());
+}
+
TEST_F(MessageCenterTrayTest, ShowBubbleFails) {
// Now the delegate will signal that it was unable to show a bubble.
delegate_->show_popups_success_ = false;
diff --git a/ui/message_center/notification.cc b/ui/message_center/notification.cc
index 43e3de7..9c9099b 100644
--- a/ui/message_center/notification.cc
+++ b/ui/message_center/notification.cc
@@ -134,11 +134,21 @@ void Notification::SetButtonIcon(size_t index, const gfx::Image& icon) {
optional_fields_.buttons[index].icon = icon;
}
+void Notification::SetSystemPriority() {
+ optional_fields_.priority = SYSTEM_PRIORITY;
+ optional_fields_.never_timeout = true;
+}
+
void Notification::ApplyOptionalFields(const DictionaryValue* fields) {
if (!fields)
return;
- fields->GetInteger(kPriorityKey, &optional_fields_.priority);
+ int priority = DEFAULT_PRIORITY;
+ if (fields->GetInteger(kPriorityKey, &priority)) {
+ optional_fields_.priority =
+ std::max(std::min(priority, static_cast<int>(MAX_PRIORITY)),
+ static_cast<int>(MIN_PRIORITY));
+ }
if (fields->HasKey(kTimestampKey)) {
std::string time_string;
fields->GetString(kTimestampKey, &time_string);
diff --git a/ui/message_center/notification.h b/ui/message_center/notification.h
index 49db7bf..ab3f42e 100644
--- a/ui/message_center/notification.h
+++ b/ui/message_center/notification.h
@@ -142,6 +142,10 @@ class MESSAGE_CENTER_EXPORT Notification {
return optional_fields_;
}
+ // Set the priority to SYSTEM. The system priority user needs to call this
+ // method explicitly, to avoid setting it accidentally.
+ void SetSystemPriority();
+
// Delegate actions.
void Display() const { delegate()->Display(); }
void Error() const { delegate()->Error(); }
diff --git a/ui/message_center/notification_list.cc b/ui/message_center/notification_list.cc
index 7b44da7..49f1244 100644
--- a/ui/message_center/notification_list.cc
+++ b/ui/message_center/notification_list.cc
@@ -62,7 +62,8 @@ void NotificationList::SetMessageCenterVisible(
for (Notifications::iterator iter = notifications_.begin();
iter != notifications_.end(); ++iter) {
Notification* notification = *iter;
- notification->set_shown_as_popup(true);
+ if (notification->priority() < SYSTEM_PRIORITY)
+ notification->set_shown_as_popup(true);
notification->set_is_read(true);
if (updated_ids &&
!(notification->shown_as_popup() && notification->is_read())) {
@@ -195,7 +196,6 @@ NotificationList::PopupNotifications NotificationList::GetPopupNotifications() {
// Collect notifications that should be shown as popups. Start from oldest.
for (Notifications::const_reverse_iterator iter = notifications_.rbegin();
iter != notifications_.rend(); iter++) {
-
if ((*iter)->shown_as_popup())
continue;
@@ -244,7 +244,9 @@ void NotificationList::MarkSinglePopupAsShown(
if ((*iter)->shown_as_popup())
return;
- (*iter)->set_shown_as_popup(true);
+ // System notification is marked as shown only when marked as read.
+ if ((*iter)->priority() != SYSTEM_PRIORITY || mark_notification_as_read)
+ (*iter)->set_shown_as_popup(true);
// The popup notification is already marked as read when it's displayed.
// Set the is_read() back to false if necessary.
diff --git a/ui/message_center/notification_list_unittest.cc b/ui/message_center/notification_list_unittest.cc
index 13c3132..1f8ed72 100644
--- a/ui/message_center/notification_list_unittest.cc
+++ b/ui/message_center/notification_list_unittest.cc
@@ -317,6 +317,31 @@ TEST_F(NotificationListTest, HasPopupsWithPriority) {
EXPECT_EQ(1u, GetPopupCounts());
}
+TEST_F(NotificationListTest, HasPopupsWithSystemPriority) {
+ ASSERT_EQ(0u, notification_list()->NotificationCount());
+ ASSERT_EQ(0u, notification_list()->unread_count());
+
+ std::string normal_id = AddPriorityNotification(DEFAULT_PRIORITY);
+ std::string system_id = AddNotification(NULL);
+ GetNotification(system_id)->SetSystemPriority();
+
+ EXPECT_EQ(2u, GetPopupCounts());
+
+ notification_list()->MarkSinglePopupAsDisplayed(normal_id);
+ notification_list()->MarkSinglePopupAsDisplayed(system_id);
+
+ notification_list()->MarkSinglePopupAsShown(normal_id, false);
+ notification_list()->MarkSinglePopupAsShown(system_id, false);
+
+ notification_list()->SetMessageCenterVisible(true, NULL);
+ notification_list()->SetMessageCenterVisible(false, NULL);
+ EXPECT_EQ(1u, GetPopupCounts());
+
+ // Mark as read -- emulation of mouse click.
+ notification_list()->MarkSinglePopupAsShown(system_id, true);
+ EXPECT_EQ(0u, GetPopupCounts());
+}
+
TEST_F(NotificationListTest, PriorityPromotion) {
std::string id0 = AddPriorityNotification(LOW_PRIORITY);
std::string replaced = id0 + "_replaced";
diff --git a/ui/message_center/notification_types.h b/ui/message_center/notification_types.h
index c935cfa..eb4bd68 100644
--- a/ui/message_center/notification_types.h
+++ b/ui/message_center/notification_types.h
@@ -41,6 +41,11 @@ enum NotificationPriority {
DEFAULT_PRIORITY = 0,
HIGH_PRIORITY = 1,
MAX_PRIORITY = 2,
+
+ // Top priority for system-level notifications.. This can't be set from
+ // kPriorityKey, instead you have to call SetSystemPriority() of
+ // Notification object.
+ SYSTEM_PRIORITY = 3,
};
} // namespace message_center