| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/message_center/notification_list.h" | 5 #include "ui/message_center/notification_list.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 counter_ = 0; | 33 counter_ = 0; |
| 34 } | 34 } |
| 35 | 35 |
| 36 protected: | 36 protected: |
| 37 // Currently NotificationListTest doesn't care about some fields like title or | 37 // Currently NotificationListTest doesn't care about some fields like title or |
| 38 // message, so put a simple template on it. Returns the id of the new | 38 // message, so put a simple template on it. Returns the id of the new |
| 39 // notification. | 39 // notification. |
| 40 std::string AddNotification( | 40 std::string AddNotification( |
| 41 const message_center::RichNotificationData& optional_fields) { | 41 const message_center::RichNotificationData& optional_fields) { |
| 42 std::string new_id; | 42 std::string new_id; |
| 43 scoped_ptr<Notification> notification( | 43 std::unique_ptr<Notification> notification( |
| 44 MakeNotification(optional_fields, &new_id)); | 44 MakeNotification(optional_fields, &new_id)); |
| 45 notification_list_->AddNotification(std::move(notification)); | 45 notification_list_->AddNotification(std::move(notification)); |
| 46 counter_++; | 46 counter_++; |
| 47 return new_id; | 47 return new_id; |
| 48 } | 48 } |
| 49 | 49 |
| 50 std::string AddNotification() { | 50 std::string AddNotification() { |
| 51 return AddNotification(message_center::RichNotificationData()); | 51 return AddNotification(message_center::RichNotificationData()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Construct a new notification for testing, but don't add it to the list yet. | 54 // Construct a new notification for testing, but don't add it to the list yet. |
| 55 scoped_ptr<Notification> MakeNotification( | 55 std::unique_ptr<Notification> MakeNotification( |
| 56 const message_center::RichNotificationData& optional_fields, | 56 const message_center::RichNotificationData& optional_fields, |
| 57 std::string* id_out) { | 57 std::string* id_out) { |
| 58 *id_out = base::StringPrintf(kIdFormat, counter_); | 58 *id_out = base::StringPrintf(kIdFormat, counter_); |
| 59 scoped_ptr<Notification> notification(new Notification( | 59 std::unique_ptr<Notification> notification(new Notification( |
| 60 message_center::NOTIFICATION_TYPE_SIMPLE, *id_out, | 60 message_center::NOTIFICATION_TYPE_SIMPLE, *id_out, |
| 61 UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)), | 61 UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)), |
| 62 UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)), gfx::Image(), | 62 UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)), gfx::Image(), |
| 63 UTF8ToUTF16(kDisplaySource), GURL(), | 63 UTF8ToUTF16(kDisplaySource), GURL(), |
| 64 NotifierId(NotifierId::APPLICATION, kExtensionId), optional_fields, | 64 NotifierId(NotifierId::APPLICATION, kExtensionId), optional_fields, |
| 65 NULL)); | 65 NULL)); |
| 66 return notification; | 66 return notification; |
| 67 } | 67 } |
| 68 | 68 |
| 69 scoped_ptr<Notification> MakeNotification(std::string* id_out) { | 69 std::unique_ptr<Notification> MakeNotification(std::string* id_out) { |
| 70 return MakeNotification(message_center::RichNotificationData(), id_out); | 70 return MakeNotification(message_center::RichNotificationData(), id_out); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Utility methods of AddNotification. | 73 // Utility methods of AddNotification. |
| 74 std::string AddPriorityNotification(NotificationPriority priority) { | 74 std::string AddPriorityNotification(NotificationPriority priority) { |
| 75 message_center::RichNotificationData optional; | 75 message_center::RichNotificationData optional; |
| 76 optional.priority = priority; | 76 optional.priority = priority; |
| 77 return AddNotification(optional); | 77 return AddNotification(optional); |
| 78 } | 78 } |
| 79 | 79 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 NotificationList* notification_list() { return notification_list_.get(); } | 96 NotificationList* notification_list() { return notification_list_.get(); } |
| 97 const NotificationBlockers& blockers() const { return blockers_; } | 97 const NotificationBlockers& blockers() const { return blockers_; } |
| 98 | 98 |
| 99 static const char kIdFormat[]; | 99 static const char kIdFormat[]; |
| 100 static const char kTitleFormat[]; | 100 static const char kTitleFormat[]; |
| 101 static const char kMessageFormat[]; | 101 static const char kMessageFormat[]; |
| 102 static const char kDisplaySource[]; | 102 static const char kDisplaySource[]; |
| 103 static const char kExtensionId[]; | 103 static const char kExtensionId[]; |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 scoped_ptr<NotificationList> notification_list_; | 106 std::unique_ptr<NotificationList> notification_list_; |
| 107 NotificationBlockers blockers_; | 107 NotificationBlockers blockers_; |
| 108 size_t counter_; | 108 size_t counter_; |
| 109 | 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(NotificationListTest); | 110 DISALLOW_COPY_AND_ASSIGN(NotificationListTest); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 bool IsInNotifications(const NotificationList::Notifications& notifications, | 113 bool IsInNotifications(const NotificationList::Notifications& notifications, |
| 114 const std::string& id) { | 114 const std::string& id) { |
| 115 for (NotificationList::Notifications::const_iterator iter = | 115 for (NotificationList::Notifications::const_iterator iter = |
| 116 notifications.begin(); iter != notifications.end(); ++iter) { | 116 notifications.begin(); iter != notifications.end(); ++iter) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 notification_list()->MarkSinglePopupAsDisplayed(id0); | 179 notification_list()->MarkSinglePopupAsDisplayed(id0); |
| 180 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); | 180 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); |
| 181 notification_list()->MarkSinglePopupAsDisplayed(id1); | 181 notification_list()->MarkSinglePopupAsDisplayed(id1); |
| 182 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); | 182 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); |
| 183 } | 183 } |
| 184 | 184 |
| 185 TEST_F(NotificationListTest, UpdateNotification) { | 185 TEST_F(NotificationListTest, UpdateNotification) { |
| 186 std::string id0 = AddNotification(); | 186 std::string id0 = AddNotification(); |
| 187 std::string replaced = id0 + "_replaced"; | 187 std::string replaced = id0 + "_replaced"; |
| 188 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); | 188 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); |
| 189 scoped_ptr<Notification> notification( | 189 std::unique_ptr<Notification> notification( |
| 190 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, replaced, | 190 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, replaced, |
| 191 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), | 191 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), |
| 192 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(), | 192 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(), |
| 193 NotifierId(NotifierId::APPLICATION, kExtensionId), | 193 NotifierId(NotifierId::APPLICATION, kExtensionId), |
| 194 message_center::RichNotificationData(), NULL)); | 194 message_center::RichNotificationData(), NULL)); |
| 195 notification_list()->UpdateNotificationMessage(id0, std::move(notification)); | 195 notification_list()->UpdateNotificationMessage(id0, std::move(notification)); |
| 196 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); | 196 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); |
| 197 const NotificationList::Notifications notifications = | 197 const NotificationList::Notifications notifications = |
| 198 notification_list()->GetVisibleNotifications(blockers()); | 198 notification_list()->GetVisibleNotifications(blockers()); |
| 199 EXPECT_EQ(replaced, (*notifications.begin())->id()); | 199 EXPECT_EQ(replaced, (*notifications.begin())->id()); |
| 200 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); | 200 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); |
| 201 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); | 201 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 TEST_F(NotificationListTest, GetNotificationsByNotifierId) { | 204 TEST_F(NotificationListTest, GetNotificationsByNotifierId) { |
| 205 NotifierId id0(NotifierId::APPLICATION, "ext0"); | 205 NotifierId id0(NotifierId::APPLICATION, "ext0"); |
| 206 NotifierId id1(NotifierId::APPLICATION, "ext1"); | 206 NotifierId id1(NotifierId::APPLICATION, "ext1"); |
| 207 NotifierId id2(GURL("http://example.com")); | 207 NotifierId id2(GURL("http://example.com")); |
| 208 NotifierId id3(NotifierId::SYSTEM_COMPONENT, "system-notifier"); | 208 NotifierId id3(NotifierId::SYSTEM_COMPONENT, "system-notifier"); |
| 209 scoped_ptr<Notification> notification(new Notification( | 209 std::unique_ptr<Notification> notification(new Notification( |
| 210 message_center::NOTIFICATION_TYPE_SIMPLE, "id0", UTF8ToUTF16("title0"), | 210 message_center::NOTIFICATION_TYPE_SIMPLE, "id0", UTF8ToUTF16("title0"), |
| 211 UTF8ToUTF16("message0"), gfx::Image(), UTF8ToUTF16("source0"), GURL(), | 211 UTF8ToUTF16("message0"), gfx::Image(), UTF8ToUTF16("source0"), GURL(), |
| 212 id0, message_center::RichNotificationData(), NULL)); | 212 id0, message_center::RichNotificationData(), NULL)); |
| 213 notification_list()->AddNotification(std::move(notification)); | 213 notification_list()->AddNotification(std::move(notification)); |
| 214 notification.reset(new Notification( | 214 notification.reset(new Notification( |
| 215 message_center::NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title1"), | 215 message_center::NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title1"), |
| 216 UTF8ToUTF16("message1"), gfx::Image(), UTF8ToUTF16("source0"), GURL(), | 216 UTF8ToUTF16("message1"), gfx::Image(), UTF8ToUTF16("source0"), GURL(), |
| 217 id0, message_center::RichNotificationData(), NULL)); | 217 id0, message_center::RichNotificationData(), NULL)); |
| 218 notification_list()->AddNotification(std::move(notification)); | 218 notification_list()->AddNotification(std::move(notification)); |
| 219 notification.reset(new Notification( | 219 notification.reset(new Notification( |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 EXPECT_EQ(0u, GetPopupCounts()); | 377 EXPECT_EQ(0u, GetPopupCounts()); |
| 378 } | 378 } |
| 379 | 379 |
| 380 TEST_F(NotificationListTest, PriorityPromotion) { | 380 TEST_F(NotificationListTest, PriorityPromotion) { |
| 381 std::string id0 = AddPriorityNotification(LOW_PRIORITY); | 381 std::string id0 = AddPriorityNotification(LOW_PRIORITY); |
| 382 std::string replaced = id0 + "_replaced"; | 382 std::string replaced = id0 + "_replaced"; |
| 383 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); | 383 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); |
| 384 EXPECT_EQ(0u, GetPopupCounts()); | 384 EXPECT_EQ(0u, GetPopupCounts()); |
| 385 message_center::RichNotificationData optional; | 385 message_center::RichNotificationData optional; |
| 386 optional.priority = 1; | 386 optional.priority = 1; |
| 387 scoped_ptr<Notification> notification(new Notification( | 387 std::unique_ptr<Notification> notification(new Notification( |
| 388 message_center::NOTIFICATION_TYPE_SIMPLE, replaced, | 388 message_center::NOTIFICATION_TYPE_SIMPLE, replaced, |
| 389 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), gfx::Image(), | 389 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), gfx::Image(), |
| 390 UTF8ToUTF16(kDisplaySource), GURL(), | 390 UTF8ToUTF16(kDisplaySource), GURL(), |
| 391 NotifierId(NotifierId::APPLICATION, kExtensionId), optional, NULL)); | 391 NotifierId(NotifierId::APPLICATION, kExtensionId), optional, NULL)); |
| 392 notification_list()->UpdateNotificationMessage(id0, std::move(notification)); | 392 notification_list()->UpdateNotificationMessage(id0, std::move(notification)); |
| 393 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); | 393 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); |
| 394 EXPECT_EQ(1u, GetPopupCounts()); | 394 EXPECT_EQ(1u, GetPopupCounts()); |
| 395 const NotificationList::Notifications notifications = | 395 const NotificationList::Notifications notifications = |
| 396 notification_list()->GetVisibleNotifications(blockers()); | 396 notification_list()->GetVisibleNotifications(blockers()); |
| 397 EXPECT_EQ(replaced, (*notifications.begin())->id()); | 397 EXPECT_EQ(replaced, (*notifications.begin())->id()); |
| 398 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); | 398 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); |
| 399 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); | 399 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); |
| 400 EXPECT_EQ(1, (*notifications.begin())->priority()); | 400 EXPECT_EQ(1, (*notifications.begin())->priority()); |
| 401 } | 401 } |
| 402 | 402 |
| 403 TEST_F(NotificationListTest, PriorityPromotionWithPopups) { | 403 TEST_F(NotificationListTest, PriorityPromotionWithPopups) { |
| 404 std::string id0 = AddPriorityNotification(LOW_PRIORITY); | 404 std::string id0 = AddPriorityNotification(LOW_PRIORITY); |
| 405 std::string id1 = AddPriorityNotification(DEFAULT_PRIORITY); | 405 std::string id1 = AddPriorityNotification(DEFAULT_PRIORITY); |
| 406 EXPECT_EQ(1u, GetPopupCounts()); | 406 EXPECT_EQ(1u, GetPopupCounts()); |
| 407 notification_list()->MarkSinglePopupAsShown(id1, true); | 407 notification_list()->MarkSinglePopupAsShown(id1, true); |
| 408 EXPECT_EQ(0u, GetPopupCounts()); | 408 EXPECT_EQ(0u, GetPopupCounts()); |
| 409 | 409 |
| 410 // id0 promoted to LOW->DEFAULT, it'll appear as toast (popup). | 410 // id0 promoted to LOW->DEFAULT, it'll appear as toast (popup). |
| 411 message_center::RichNotificationData priority; | 411 message_center::RichNotificationData priority; |
| 412 priority.priority = DEFAULT_PRIORITY; | 412 priority.priority = DEFAULT_PRIORITY; |
| 413 scoped_ptr<Notification> notification(new Notification( | 413 std::unique_ptr<Notification> notification(new Notification( |
| 414 message_center::NOTIFICATION_TYPE_SIMPLE, id0, UTF8ToUTF16("newtitle"), | 414 message_center::NOTIFICATION_TYPE_SIMPLE, id0, UTF8ToUTF16("newtitle"), |
| 415 UTF8ToUTF16("newbody"), gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(), | 415 UTF8ToUTF16("newbody"), gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(), |
| 416 NotifierId(NotifierId::APPLICATION, kExtensionId), priority, NULL)); | 416 NotifierId(NotifierId::APPLICATION, kExtensionId), priority, NULL)); |
| 417 notification_list()->UpdateNotificationMessage(id0, std::move(notification)); | 417 notification_list()->UpdateNotificationMessage(id0, std::move(notification)); |
| 418 EXPECT_EQ(1u, GetPopupCounts()); | 418 EXPECT_EQ(1u, GetPopupCounts()); |
| 419 notification_list()->MarkSinglePopupAsShown(id0, true); | 419 notification_list()->MarkSinglePopupAsShown(id0, true); |
| 420 EXPECT_EQ(0u, GetPopupCounts()); | 420 EXPECT_EQ(0u, GetPopupCounts()); |
| 421 | 421 |
| 422 // update with no promotion change for id0, it won't appear as a toast. | 422 // update with no promotion change for id0, it won't appear as a toast. |
| 423 notification.reset(new Notification( | 423 notification.reset(new Notification( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 message_center::NOTIFICATION_TYPE_SIMPLE, id1, UTF8ToUTF16("newtitle3"), | 457 message_center::NOTIFICATION_TYPE_SIMPLE, id1, UTF8ToUTF16("newtitle3"), |
| 458 UTF8ToUTF16("newbody3"), gfx::Image(), UTF8ToUTF16(kDisplaySource), | 458 UTF8ToUTF16("newbody3"), gfx::Image(), UTF8ToUTF16(kDisplaySource), |
| 459 GURL(), NotifierId(NotifierId::APPLICATION, kExtensionId), priority, | 459 GURL(), NotifierId(NotifierId::APPLICATION, kExtensionId), priority, |
| 460 NULL)); | 460 NULL)); |
| 461 notification_list()->UpdateNotificationMessage(id1, std::move(notification)); | 461 notification_list()->UpdateNotificationMessage(id1, std::move(notification)); |
| 462 EXPECT_EQ(0u, GetPopupCounts()); | 462 EXPECT_EQ(0u, GetPopupCounts()); |
| 463 } | 463 } |
| 464 | 464 |
| 465 TEST_F(NotificationListTest, WebNotificationUpdatePromotion) { | 465 TEST_F(NotificationListTest, WebNotificationUpdatePromotion) { |
| 466 std::string notification_id = "replaced-web-notification"; | 466 std::string notification_id = "replaced-web-notification"; |
| 467 scoped_ptr<Notification> original_notification(new Notification( | 467 std::unique_ptr<Notification> original_notification(new Notification( |
| 468 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, | 468 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, |
| 469 UTF8ToUTF16("Web Notification"), UTF8ToUTF16("Notification contents"), | 469 UTF8ToUTF16("Web Notification"), UTF8ToUTF16("Notification contents"), |
| 470 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(), | 470 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(), |
| 471 NotifierId(GURL("https://example.com/")), | 471 NotifierId(GURL("https://example.com/")), |
| 472 message_center::RichNotificationData(), NULL)); | 472 message_center::RichNotificationData(), NULL)); |
| 473 | 473 |
| 474 EXPECT_EQ(0u, GetPopupCounts()); | 474 EXPECT_EQ(0u, GetPopupCounts()); |
| 475 notification_list()->AddNotification(std::move(original_notification)); | 475 notification_list()->AddNotification(std::move(original_notification)); |
| 476 EXPECT_EQ(1u, GetPopupCounts()); | 476 EXPECT_EQ(1u, GetPopupCounts()); |
| 477 | 477 |
| 478 notification_list()->MarkSinglePopupAsShown(notification_id, true); | 478 notification_list()->MarkSinglePopupAsShown(notification_id, true); |
| 479 EXPECT_EQ(0u, GetPopupCounts()); | 479 EXPECT_EQ(0u, GetPopupCounts()); |
| 480 | 480 |
| 481 scoped_ptr<Notification> replaced_notification(new Notification( | 481 std::unique_ptr<Notification> replaced_notification(new Notification( |
| 482 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, | 482 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, |
| 483 UTF8ToUTF16("Web Notification Replacement"), | 483 UTF8ToUTF16("Web Notification Replacement"), |
| 484 UTF8ToUTF16("New notification contents"), gfx::Image(), | 484 UTF8ToUTF16("New notification contents"), gfx::Image(), |
| 485 UTF8ToUTF16(kDisplaySource), GURL(), | 485 UTF8ToUTF16(kDisplaySource), GURL(), |
| 486 NotifierId(GURL("https://example.com/")), | 486 NotifierId(GURL("https://example.com/")), |
| 487 message_center::RichNotificationData(), NULL)); | 487 message_center::RichNotificationData(), NULL)); |
| 488 | 488 |
| 489 // Web Notifications will be re-shown as popups even if their priority didn't | 489 // Web Notifications will be re-shown as popups even if their priority didn't |
| 490 // change, to match the behavior of the Web Notification API. | 490 // change, to match the behavior of the Web Notification API. |
| 491 notification_list()->UpdateNotificationMessage( | 491 notification_list()->UpdateNotificationMessage( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 EXPECT_FALSE(n1->shown_as_popup()); | 578 EXPECT_FALSE(n1->shown_as_popup()); |
| 579 EXPECT_TRUE(n1->IsRead()); | 579 EXPECT_TRUE(n1->IsRead()); |
| 580 | 580 |
| 581 notification_list()->MarkSinglePopupAsShown(id1, true); | 581 notification_list()->MarkSinglePopupAsShown(id1, true); |
| 582 | 582 |
| 583 n1 = GetNotification(id1); | 583 n1 = GetNotification(id1); |
| 584 EXPECT_TRUE(n1->shown_as_popup()); | 584 EXPECT_TRUE(n1->shown_as_popup()); |
| 585 EXPECT_TRUE(n1->IsRead()); | 585 EXPECT_TRUE(n1->IsRead()); |
| 586 | 586 |
| 587 const std::string replaced("test-replaced-id"); | 587 const std::string replaced("test-replaced-id"); |
| 588 scoped_ptr<Notification> notification( | 588 std::unique_ptr<Notification> notification( |
| 589 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, replaced, | 589 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, replaced, |
| 590 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), | 590 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), |
| 591 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(), | 591 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(), |
| 592 NotifierId(NotifierId::APPLICATION, kExtensionId), | 592 NotifierId(NotifierId::APPLICATION, kExtensionId), |
| 593 message_center::RichNotificationData(), NULL)); | 593 message_center::RichNotificationData(), NULL)); |
| 594 notification_list()->UpdateNotificationMessage(id1, std::move(notification)); | 594 notification_list()->UpdateNotificationMessage(id1, std::move(notification)); |
| 595 n1 = GetNotification(id1); | 595 n1 = GetNotification(id1); |
| 596 EXPECT_TRUE(n1 == NULL); | 596 EXPECT_TRUE(n1 == NULL); |
| 597 const Notification* nr = GetNotification(replaced); | 597 const Notification* nr = GetNotification(replaced); |
| 598 EXPECT_TRUE(nr->shown_as_popup()); | 598 EXPECT_TRUE(nr->shown_as_popup()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 620 std::string id = AddNotification(); | 620 std::string id = AddNotification(); |
| 621 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); | 621 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); |
| 622 | 622 |
| 623 notification_list()->MarkSinglePopupAsDisplayed(id); | 623 notification_list()->MarkSinglePopupAsDisplayed(id); |
| 624 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); | 624 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); |
| 625 notification_list()->MarkSinglePopupAsShown( | 625 notification_list()->MarkSinglePopupAsShown( |
| 626 id, false /* mark_notification_as_read */); | 626 id, false /* mark_notification_as_read */); |
| 627 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); | 627 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); |
| 628 | 628 |
| 629 // Updates the notification and verifies unread_count doesn't change. | 629 // Updates the notification and verifies unread_count doesn't change. |
| 630 scoped_ptr<Notification> updated_notification(new Notification( | 630 std::unique_ptr<Notification> updated_notification(new Notification( |
| 631 message_center::NOTIFICATION_TYPE_SIMPLE, id, UTF8ToUTF16("updated"), | 631 message_center::NOTIFICATION_TYPE_SIMPLE, id, UTF8ToUTF16("updated"), |
| 632 UTF8ToUTF16("updated"), gfx::Image(), base::string16(), GURL(), | 632 UTF8ToUTF16("updated"), gfx::Image(), base::string16(), GURL(), |
| 633 NotifierId(), RichNotificationData(), NULL)); | 633 NotifierId(), RichNotificationData(), NULL)); |
| 634 notification_list()->AddNotification(std::move(updated_notification)); | 634 notification_list()->AddNotification(std::move(updated_notification)); |
| 635 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); | 635 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); |
| 636 } | 636 } |
| 637 | 637 |
| 638 TEST_F(NotificationListTest, TestPushingShownNotification) { | 638 TEST_F(NotificationListTest, TestPushingShownNotification) { |
| 639 // Create a notification and mark it as shown. | 639 // Create a notification and mark it as shown. |
| 640 std::string id1; | 640 std::string id1; |
| 641 scoped_ptr<Notification> notification(MakeNotification(&id1)); | 641 std::unique_ptr<Notification> notification(MakeNotification(&id1)); |
| 642 notification->set_shown_as_popup(true); | 642 notification->set_shown_as_popup(true); |
| 643 | 643 |
| 644 // Call PushNotification on this notification. | 644 // Call PushNotification on this notification. |
| 645 notification_list()->PushNotification(std::move(notification)); | 645 notification_list()->PushNotification(std::move(notification)); |
| 646 | 646 |
| 647 // Ensure it is still marked as shown. | 647 // Ensure it is still marked as shown. |
| 648 EXPECT_TRUE(GetNotification(id1)->shown_as_popup()); | 648 EXPECT_TRUE(GetNotification(id1)->shown_as_popup()); |
| 649 } | 649 } |
| 650 | 650 |
| 651 TEST_F(NotificationListTest, TestHasNotificationOfType) { | 651 TEST_F(NotificationListTest, TestHasNotificationOfType) { |
| 652 std::string id = AddNotification(); | 652 std::string id = AddNotification(); |
| 653 | 653 |
| 654 EXPECT_TRUE(notification_list()->HasNotificationOfType( | 654 EXPECT_TRUE(notification_list()->HasNotificationOfType( |
| 655 id, message_center::NOTIFICATION_TYPE_SIMPLE)); | 655 id, message_center::NOTIFICATION_TYPE_SIMPLE)); |
| 656 EXPECT_FALSE(notification_list()->HasNotificationOfType( | 656 EXPECT_FALSE(notification_list()->HasNotificationOfType( |
| 657 id, message_center::NOTIFICATION_TYPE_PROGRESS)); | 657 id, message_center::NOTIFICATION_TYPE_PROGRESS)); |
| 658 | 658 |
| 659 scoped_ptr<Notification> updated_notification(new Notification( | 659 std::unique_ptr<Notification> updated_notification(new Notification( |
| 660 message_center::NOTIFICATION_TYPE_PROGRESS, id, UTF8ToUTF16("updated"), | 660 message_center::NOTIFICATION_TYPE_PROGRESS, id, UTF8ToUTF16("updated"), |
| 661 UTF8ToUTF16("updated"), gfx::Image(), base::string16(), GURL(), | 661 UTF8ToUTF16("updated"), gfx::Image(), base::string16(), GURL(), |
| 662 NotifierId(), RichNotificationData(), NULL)); | 662 NotifierId(), RichNotificationData(), NULL)); |
| 663 notification_list()->AddNotification(std::move(updated_notification)); | 663 notification_list()->AddNotification(std::move(updated_notification)); |
| 664 | 664 |
| 665 EXPECT_FALSE(notification_list()->HasNotificationOfType( | 665 EXPECT_FALSE(notification_list()->HasNotificationOfType( |
| 666 id, message_center::NOTIFICATION_TYPE_SIMPLE)); | 666 id, message_center::NOTIFICATION_TYPE_SIMPLE)); |
| 667 EXPECT_TRUE(notification_list()->HasNotificationOfType( | 667 EXPECT_TRUE(notification_list()->HasNotificationOfType( |
| 668 id, message_center::NOTIFICATION_TYPE_PROGRESS)); | 668 id, message_center::NOTIFICATION_TYPE_PROGRESS)); |
| 669 } | 669 } |
| 670 | 670 |
| 671 } // namespace message_center | 671 } // namespace message_center |
| OLD | NEW |