+
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestLastUsage) {
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+
+ HostContentSettingsMap* settings_map =
+ browser()->profile()->GetHostContentSettingsMap();
+ base::SimpleTestClock* clock = new base::SimpleTestClock();
+ settings_map->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock));
+ clock->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10));
+
+ // Creates a simple notification.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
+
+ std::string result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(),
+ GetTestPageURL().GetOrigin(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ .ToDoubleT(),
+ 10);
+
+ clock->Advance(base::TimeDelta::FromSeconds(3));
+
+ result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(),
+ GetTestPageURL().GetOrigin(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ .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());
+}