| Index: ui/message_center/notification_list_unittest.cc
|
| diff --git a/ui/message_center/notification_list_unittest.cc b/ui/message_center/notification_list_unittest.cc
|
| index 02e3a5d288f95634f9deafedac9a53115a246729..710b229d16ced7d3fa1d66fd566afd09ae573759 100644
|
| --- a/ui/message_center/notification_list_unittest.cc
|
| +++ b/ui/message_center/notification_list_unittest.cc
|
| @@ -32,15 +32,17 @@ class NotificationListTest : public testing::Test {
|
| // notification.
|
| std::string AddNotification(const base::DictionaryValue* optional_fields) {
|
| std::string new_id = base::StringPrintf(kIdFormat, counter_);
|
| - notification_list_->AddNotification(
|
| + scoped_ptr<Notification> notification(new Notification(
|
| message_center::NOTIFICATION_TYPE_SIMPLE,
|
| new_id,
|
| UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)),
|
| UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)),
|
| + gfx::Image(),
|
| UTF8ToUTF16(kDisplaySource),
|
| kExtensionId,
|
| optional_fields,
|
| - NULL);
|
| + NULL));
|
| + notification_list_->AddNotification(notification.Pass());
|
| counter_++;
|
| return new_id;
|
| }
|
| @@ -72,13 +74,13 @@ class NotificationListTest : public testing::Test {
|
|
|
| NotificationList* notification_list() { return notification_list_.get(); }
|
|
|
| - private:
|
| static const char kIdFormat[];
|
| static const char kTitleFormat[];
|
| static const char kMessageFormat[];
|
| static const char kDisplaySource[];
|
| static const char kExtensionId[];
|
|
|
| + private:
|
| scoped_ptr<NotificationList> notification_list_;
|
| size_t counter_;
|
|
|
| @@ -164,12 +166,17 @@ TEST_F(NotificationListTest, UpdateNotification) {
|
| std::string id0 = AddNotification(NULL);
|
| std::string replaced = id0 + "_replaced";
|
| EXPECT_EQ(1u, notification_list()->NotificationCount());
|
| - notification_list()->UpdateNotificationMessage(id0,
|
| - replaced,
|
| - UTF8ToUTF16("newtitle"),
|
| - UTF8ToUTF16("newbody"),
|
| - NULL,
|
| - NULL);
|
| + scoped_ptr<Notification> notification(
|
| + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + replaced,
|
| + UTF8ToUTF16("newtitle"),
|
| + UTF8ToUTF16("newbody"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16(kDisplaySource),
|
| + kExtensionId,
|
| + NULL,
|
| + NULL));
|
| + notification_list()->UpdateNotificationMessage(id0, notification.Pass());
|
| EXPECT_EQ(1u, notification_list()->NotificationCount());
|
| const NotificationList::Notifications& notifications =
|
| notification_list()->GetNotifications();
|
| @@ -179,38 +186,47 @@ TEST_F(NotificationListTest, UpdateNotification) {
|
| }
|
|
|
| TEST_F(NotificationListTest, GetNotificationsBySourceOrExtensions) {
|
| - notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| - "id0",
|
| - UTF8ToUTF16("title0"),
|
| - UTF8ToUTF16("message0"),
|
| - UTF8ToUTF16("source0"),
|
| - "ext0",
|
| - NULL,
|
| - NULL);
|
| - notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| - "id1",
|
| - UTF8ToUTF16("title1"),
|
| - UTF8ToUTF16("message1"),
|
| - UTF8ToUTF16("source0"),
|
| - "ext0",
|
| - NULL,
|
| - NULL);
|
| - notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| - "id2",
|
| - UTF8ToUTF16("title1"),
|
| - UTF8ToUTF16("message1"),
|
| - UTF8ToUTF16("source1"),
|
| - "ext0",
|
| - NULL,
|
| - NULL);
|
| - notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| - "id3",
|
| - UTF8ToUTF16("title1"),
|
| - UTF8ToUTF16("message1"),
|
| - UTF8ToUTF16("source2"),
|
| - "ext1",
|
| - NULL,
|
| - NULL);
|
| + scoped_ptr<Notification> notification(
|
| + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + "id0",
|
| + UTF8ToUTF16("title0"),
|
| + UTF8ToUTF16("message0"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16("source0"),
|
| + "ext0",
|
| + NULL,
|
| + NULL));
|
| + notification_list()->AddNotification(notification.Pass());
|
| + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + "id1",
|
| + UTF8ToUTF16("title1"),
|
| + UTF8ToUTF16("message1"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16("source0"),
|
| + "ext0",
|
| + NULL,
|
| + NULL));
|
| + notification_list()->AddNotification(notification.Pass());
|
| + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + "id2",
|
| + UTF8ToUTF16("title1"),
|
| + UTF8ToUTF16("message1"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16("source1"),
|
| + "ext0",
|
| + NULL,
|
| + NULL));
|
| + notification_list()->AddNotification(notification.Pass());
|
| + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + "id3",
|
| + UTF8ToUTF16("title1"),
|
| + UTF8ToUTF16("message1"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16("source2"),
|
| + "ext1",
|
| + NULL,
|
| + NULL));
|
| + notification_list()->AddNotification(notification.Pass());
|
|
|
| NotificationList::Notifications by_source =
|
| notification_list()->GetNotificationsBySource("id0");
|
| @@ -308,12 +324,17 @@ TEST_F(NotificationListTest, PriorityPromotion) {
|
| EXPECT_EQ(0u, GetPopupCounts());
|
| base::DictionaryValue optional;
|
| optional.SetInteger(message_center::kPriorityKey, 1);
|
| - notification_list()->UpdateNotificationMessage(id0,
|
| - replaced,
|
| - UTF8ToUTF16("newtitle"),
|
| - UTF8ToUTF16("newbody"),
|
| - &optional,
|
| - NULL);
|
| + scoped_ptr<Notification> notification(
|
| + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + replaced,
|
| + UTF8ToUTF16("newtitle"),
|
| + UTF8ToUTF16("newbody"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16(kDisplaySource),
|
| + kExtensionId,
|
| + &optional,
|
| + NULL));
|
| + notification_list()->UpdateNotificationMessage(id0, notification.Pass());
|
| EXPECT_EQ(1u, notification_list()->NotificationCount());
|
| EXPECT_EQ(1u, GetPopupCounts());
|
| const NotificationList::Notifications& notifications =
|
| @@ -335,31 +356,48 @@ TEST_F(NotificationListTest, PriorityPromotionWithPopups) {
|
| base::DictionaryValue priority_default;
|
| priority_default.SetInteger(message_center::kPriorityKey,
|
| static_cast<int>(DEFAULT_PRIORITY));
|
| - notification_list()->UpdateNotificationMessage(id0,
|
| - id0,
|
| - UTF8ToUTF16("newtitle"),
|
| - UTF8ToUTF16("newbody"),
|
| - &priority_default,
|
| - NULL);
|
| + scoped_ptr<Notification> notification(
|
| + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + id0,
|
| + UTF8ToUTF16("newtitle"),
|
| + UTF8ToUTF16("newbody"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16(kDisplaySource),
|
| + kExtensionId,
|
| + &priority_default,
|
| + NULL));
|
| + notification_list()->UpdateNotificationMessage(id0, notification.Pass());
|
| EXPECT_EQ(1u, GetPopupCounts());
|
| notification_list()->MarkSinglePopupAsShown(id0, true);
|
| EXPECT_EQ(0u, GetPopupCounts());
|
|
|
| // update with no promotion change for id0, it won't appear as a toast.
|
| - notification_list()->UpdateNotificationMessage(
|
| - id0, id0, UTF8ToUTF16("newtitle2"), UTF8ToUTF16("newbody2"), NULL, NULL);
|
| + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + id0,
|
| + UTF8ToUTF16("newtitle2"),
|
| + UTF8ToUTF16("newbody2"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16(kDisplaySource),
|
| + kExtensionId,
|
| + NULL,
|
| + NULL));
|
| + notification_list()->UpdateNotificationMessage(id0, notification.Pass());
|
| EXPECT_EQ(0u, GetPopupCounts());
|
|
|
| // id1 promoted to DEFAULT->HIGH, it'll appear as toast (popup).
|
| base::DictionaryValue priority_high;
|
| priority_high.SetInteger(message_center::kPriorityKey,
|
| static_cast<int>(HIGH_PRIORITY));
|
| - notification_list()->UpdateNotificationMessage(id1,
|
| - id1,
|
| - UTF8ToUTF16("newtitle"),
|
| - UTF8ToUTF16("newbody"),
|
| - &priority_high,
|
| - NULL);
|
| + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + id1,
|
| + UTF8ToUTF16("newtitle"),
|
| + UTF8ToUTF16("newbody"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16(kDisplaySource),
|
| + kExtensionId,
|
| + &priority_high,
|
| + NULL));
|
| + notification_list()->UpdateNotificationMessage(id1, notification.Pass());
|
| EXPECT_EQ(1u, GetPopupCounts());
|
| notification_list()->MarkSinglePopupAsShown(id1, true);
|
| EXPECT_EQ(0u, GetPopupCounts());
|
| @@ -368,23 +406,31 @@ TEST_F(NotificationListTest, PriorityPromotionWithPopups) {
|
| base::DictionaryValue priority_max;
|
| priority_max.SetInteger(message_center::kPriorityKey,
|
| static_cast<int>(MAX_PRIORITY));
|
| - notification_list()->UpdateNotificationMessage(id1,
|
| - id1,
|
| - UTF8ToUTF16("newtitle2"),
|
| - UTF8ToUTF16("newbody2"),
|
| - &priority_max,
|
| - NULL);
|
| + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + id1,
|
| + UTF8ToUTF16("newtitle2"),
|
| + UTF8ToUTF16("newbody2"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16(kDisplaySource),
|
| + kExtensionId,
|
| + &priority_max,
|
| + NULL));
|
| + notification_list()->UpdateNotificationMessage(id1, notification.Pass());
|
| EXPECT_EQ(1u, GetPopupCounts());
|
| notification_list()->MarkSinglePopupAsShown(id1, true);
|
| EXPECT_EQ(0u, GetPopupCounts());
|
|
|
| // id1 demoted to MAX->DEFAULT, no appearing as toast.
|
| - notification_list()->UpdateNotificationMessage(id1,
|
| - id1,
|
| - UTF8ToUTF16("newtitle3"),
|
| - UTF8ToUTF16("newbody3"),
|
| - &priority_default,
|
| - NULL);
|
| + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + id1,
|
| + UTF8ToUTF16("newtitle3"),
|
| + UTF8ToUTF16("newbody3"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16(kDisplaySource),
|
| + kExtensionId,
|
| + &priority_default,
|
| + NULL));
|
| + notification_list()->UpdateNotificationMessage(id1, notification.Pass());
|
| EXPECT_EQ(0u, GetPopupCounts());
|
| }
|
|
|
| @@ -513,12 +559,17 @@ TEST_F(NotificationListTest, UpdateAfterMarkedAsShown) {
|
| EXPECT_TRUE(n1->is_read());
|
|
|
| const std::string replaced("test-replaced-id");
|
| - notification_list()->UpdateNotificationMessage(id1,
|
| - replaced,
|
| - UTF8ToUTF16("newtitle"),
|
| - UTF8ToUTF16("newbody"),
|
| - NULL,
|
| - NULL);
|
| + scoped_ptr<Notification> notification(
|
| + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
|
| + replaced,
|
| + UTF8ToUTF16("newtitle"),
|
| + UTF8ToUTF16("newbody"),
|
| + gfx::Image(),
|
| + UTF8ToUTF16(kDisplaySource),
|
| + kExtensionId,
|
| + NULL,
|
| + NULL));
|
| + notification_list()->UpdateNotificationMessage(id1, notification.Pass());
|
| n1 = GetNotification(id1);
|
| EXPECT_TRUE(n1 == NULL);
|
| const Notification* nr = GetNotification(replaced);
|
|
|