Commit 29ed80bf authored by peter@chromium.org's avatar peter@chromium.org

Web Notifications should always reappear as popups when updated.

The message center already does this for notifications with a higher
priority than the notification they replace, but this makes it explicit
for Web Notifications (which cannot indicate priority).

TBR=dewittj (reviewed in cl 301713002)
BUG=366102

Review URL: https://codereview.chromium.org/439073002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287682 0039d316-1c4b-4281-b951-d872f2087c98
parent 52e02aa9
......@@ -122,6 +122,7 @@ class NotificationsTest : public InProcessBrowserTest {
protected:
int GetNotificationCount();
int GetNotificationPopupCount();
void CloseBrowserWindow(Browser* browser);
void CrashTab(Browser* browser, int index);
......@@ -164,6 +165,10 @@ int NotificationsTest::GetNotificationCount() {
return message_center::MessageCenter::Get()->NotificationCount();
}
int NotificationsTest::GetNotificationPopupCount() {
return message_center::MessageCenter::Get()->GetPopupNotifications().size();
}
void NotificationsTest::CloseBrowserWindow(Browser* browser) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
......@@ -802,3 +807,35 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestLastUsage) {
.ToDoubleT(),
13);
}
IN_PROC_BROWSER_TEST_F(NotificationsTest,
TestNotificationReplacementReappearance) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
// Test that we can replace a notification using the tag, and that it will
// cause the notification to reappear as a popup again.
AllowAllOrigins();
ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
ASSERT_EQ(0, GetNotificationPopupCount());
std::string result = CreateNotification(
browser(), true, "abc.png", "Title1", "Body1", "chat");
EXPECT_NE("-1", result);
ASSERT_EQ(1, GetNotificationPopupCount());
message_center::NotificationList::Notifications notifications =
message_center::MessageCenter::Get()->GetVisibleNotifications();
message_center::MessageCenter::Get()->ClickOnNotification(
(*notifications.rbegin())->id());
ASSERT_EQ(0, GetNotificationPopupCount());
result = CreateNotification(
browser(), true, "abc.png", "Title2", "Body2", "chat");
EXPECT_NE("-1", result);
ASSERT_EQ(1, GetNotificationPopupCount());
}
......@@ -100,8 +100,10 @@ void NotificationList::UpdateNotificationMessage(
// Handles priority promotion. If the notification is already dismissed but
// the updated notification has higher priority, it should re-appear as a
// toast.
if ((*iter)->priority() < new_notification->priority()) {
// toast. Notifications coming from websites through the Web Notification API
// will always re-appear on update.
if ((*iter)->priority() < new_notification->priority() ||
new_notification->notifier_id().type == NotifierId::WEB_PAGE) {
new_notification->set_is_read(false);
new_notification->set_shown_as_popup(false);
}
......
......@@ -528,6 +528,44 @@ TEST_F(NotificationListTest, PriorityPromotionWithPopups) {
EXPECT_EQ(0u, GetPopupCounts());
}
TEST_F(NotificationListTest, WebNotificationUpdatePromotion) {
std::string notification_id = "replaced-web-notification";
scoped_ptr<Notification> original_notification(
new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
notification_id,
UTF8ToUTF16("Web Notification"),
UTF8ToUTF16("Notification contents"),
gfx::Image(),
UTF8ToUTF16(kDisplaySource),
NotifierId(GURL("https://example.com/")),
message_center::RichNotificationData(),
NULL));
EXPECT_EQ(0u, GetPopupCounts());
notification_list()->AddNotification(original_notification.Pass());
EXPECT_EQ(1u, GetPopupCounts());
notification_list()->MarkSinglePopupAsShown(notification_id, true);
EXPECT_EQ(0u, GetPopupCounts());
scoped_ptr<Notification> replaced_notification(
new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
notification_id,
UTF8ToUTF16("Web Notification Replacement"),
UTF8ToUTF16("New notification contents"),
gfx::Image(),
UTF8ToUTF16(kDisplaySource),
NotifierId(GURL("https://example.com/")),
message_center::RichNotificationData(),
NULL));
// Web Notifications will be re-shown as popups even if their priority didn't
// change, to match the behavior of the Web Notification API.
notification_list()->UpdateNotificationMessage(notification_id,
replaced_notification.Pass());
EXPECT_EQ(1u, GetPopupCounts());
}
TEST_F(NotificationListTest, NotificationOrderAndPriority) {
base::Time now = base::Time::Now();
message_center::RichNotificationData optional;
......
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