12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notification_list.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/i18n/time_formatting.h" 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/stringprintf.h" 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/values.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/message_center/message_center_style.h" 1458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/message_center/notification_blocker.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notification_types.h" 1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/message_center/notifier_settings.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace message_center { 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NotificationListTest : public testing::Test { 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationListTest() {} 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~NotificationListTest() {} 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUp() { 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list_.reset(new NotificationList()); 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) counter_ = 0; 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Currently NotificationListTest doesn't care about some fields like title or 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // message, so put a simple template on it. Returns the id of the new 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // notification. 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string AddNotification( 357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const message_center::RichNotificationData& optional_fields) { 364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string new_id; 374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<Notification> notification( 384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) MakeNotification(optional_fields, &new_id)); 394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) notification_list_->AddNotification(notification.Pass()); 404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) counter_++; 414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return new_id; 424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string AddNotification() { 454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return AddNotification(message_center::RichNotificationData()); 464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Construct a new notification for testing, but don't add it to the list yet. 494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<Notification> MakeNotification( 504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const message_center::RichNotificationData& optional_fields, 514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string* id_out) { 524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) *id_out = base::StringPrintf(kIdFormat, counter_); 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<Notification> notification(new Notification( 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) message_center::NOTIFICATION_TYPE_SIMPLE, 554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) *id_out, 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)), 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)), 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) UTF8ToUTF16(kDisplaySource), 60424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, kExtensionId), 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) optional_fields, 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return notification.Pass(); 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<Notification> MakeNotification(std::string* id_out) { 674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return MakeNotification(message_center::RichNotificationData(), id_out); 687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Utility methods of AddNotification. 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string AddPriorityNotification(NotificationPriority priority) { 727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData optional; 737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional.priority = priority; 747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return AddNotification(optional); 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) NotificationList::PopupNotifications GetPopups() { 78a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return notification_list()->GetPopupNotifications(blockers_, NULL); 7958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 8058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) size_t GetPopupCounts() { 8258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return GetPopups().size(); 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Notification* GetNotification(const std::string& id) { 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NotificationList::Notifications::iterator iter = 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->GetNotification(id); 88a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (iter == notification_list()->notifications_.end()) 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return NULL; 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return *iter; 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationList* notification_list() { return notification_list_.get(); } 94a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const NotificationBlockers& blockers() const { return blockers_; } 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static const char kIdFormat[]; 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static const char kTitleFormat[]; 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static const char kMessageFormat[]; 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static const char kDisplaySource[]; 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static const char kExtensionId[]; 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private: 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<NotificationList> notification_list_; 104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NotificationBlockers blockers_; 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) size_t counter_; 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(NotificationListTest); 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool IsInNotifications(const NotificationList::Notifications& notifications, 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string& id) { 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (NotificationList::Notifications::const_iterator iter = 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notifications.begin(); iter != notifications.end(); ++iter) { 114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if ((*iter)->id() == id) 115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return true; 116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return false; 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char NotificationListTest::kIdFormat[] = "id%ld"; 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char NotificationListTest::kTitleFormat[] = "id%ld"; 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char NotificationListTest::kMessageFormat[] = "message%ld"; 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char NotificationListTest::kDisplaySource[] = "source"; 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char NotificationListTest::kExtensionId[] = "ext"; 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, Basic) { 127a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->NotificationCount(blockers())); 128a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id0 = AddNotification(); 131a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 1327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id1 = AddNotification(); 133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(2u, notification_list()->NotificationCount(blockers())); 134a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(2u, notification_list()->UnreadCount(blockers())); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(notification_list()->HasPopupNotifications(blockers())); 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(notification_list()->HasNotification(id0)); 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(notification_list()->HasNotification(id1)); 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(notification_list()->HasNotification(id1 + "foo")); 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2u, GetPopupCounts()); 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id0, true); 14458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id1, true); 145a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(2u, notification_list()->NotificationCount(blockers())); 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_list()->RemoveNotification(id0); 149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AddNotification(); 153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(2u, notification_list()->NotificationCount(blockers())); 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, MessageCenterVisible) { 1577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AddNotification(); 158a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 159a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(1u, notification_list()->UnreadCount(blockers())); 160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_EQ(1u, GetPopupCounts()); 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Make the message center visible. It resets the unread count and popup 163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // counts. 164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->SetMessageCenterVisible(true, NULL); 165a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_EQ(0u, GetPopupCounts()); 167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(NotificationListTest, UnreadCount) { 1707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id0 = AddNotification(); 1717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id1 = AddNotification(); 172a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(2u, notification_list()->UnreadCount(blockers())); 173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(id0); 175a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(id0); 177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(id1); 179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, UpdateNotification) { 1837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id0 = AddNotification(); 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string replaced = id0 + "_replaced"; 185a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<Notification> notification( 187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) replaced, 189868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newtitle"), 190868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newbody"), 191868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 192868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16(kDisplaySource), 193424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, kExtensionId), 1947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData(), 195868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 196868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->UpdateNotificationMessage(id0, notification.Pass()); 197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const NotificationList::Notifications notifications = 199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->GetVisibleNotifications(blockers()); 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(replaced, (*notifications.begin())->id()); 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 205424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(NotificationListTest, GetNotificationsByNotifierId) { 206424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId id0(NotifierId::APPLICATION, "ext0"); 207424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId id1(NotifierId::APPLICATION, "ext1"); 208424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId id2(GURL("http://example.com")); 209a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NotifierId id3(NotifierId::SYSTEM_COMPONENT, "system-notifier"); 210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<Notification> notification( 211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "id0", 213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("title0"), 214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("message0"), 215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("source0"), 217424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) id0, 2187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData(), 219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 220868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->AddNotification(notification.Pass()); 221868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 222868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "id1", 223868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("title1"), 224868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("message1"), 225868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 226868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("source0"), 227424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) id0, 2287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData(), 229868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 230868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->AddNotification(notification.Pass()); 231868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 232868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "id2", 233868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("title1"), 234868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("message1"), 235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("source1"), 237424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) id0, 2387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData(), 239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 240868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->AddNotification(notification.Pass()); 241868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 242868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "id3", 243868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("title1"), 244868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("message1"), 245868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 246868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("source2"), 247424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) id1, 248424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) message_center::RichNotificationData(), 249424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NULL)); 250424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) notification_list()->AddNotification(notification.Pass()); 251424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 252424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) "id4", 253424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) UTF8ToUTF16("title1"), 254424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) UTF8ToUTF16("message1"), 255424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Image(), 256424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) UTF8ToUTF16("source2"), 257424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) id2, 258424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) message_center::RichNotificationData(), 259424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NULL)); 260424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) notification_list()->AddNotification(notification.Pass()); 261424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 262424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) "id5", 263424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) UTF8ToUTF16("title1"), 264424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) UTF8ToUTF16("message1"), 265424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) gfx::Image(), 266424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) UTF8ToUTF16("source2"), 267424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) id3, 2687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData(), 269868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 270868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->AddNotification(notification.Pass()); 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 272424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotificationList::Notifications by_notifier_id = 273424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) notification_list()->GetNotificationsByNotifierId(id0); 274424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(IsInNotifications(by_notifier_id, "id0")); 275424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(IsInNotifications(by_notifier_id, "id1")); 276424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(IsInNotifications(by_notifier_id, "id2")); 277424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id3")); 278424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id4")); 279424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id5")); 280424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 281424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) by_notifier_id = notification_list()->GetNotificationsByNotifierId(id1); 282424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id0")); 283424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id1")); 284424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id2")); 285424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(IsInNotifications(by_notifier_id, "id3")); 286424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id4")); 287424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id5")); 288424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 289424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) by_notifier_id = notification_list()->GetNotificationsByNotifierId(id2); 290424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id0")); 291424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id1")); 292424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id2")); 293424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id3")); 294424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(IsInNotifications(by_notifier_id, "id4")); 295424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id5")); 296424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 297424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) by_notifier_id = notification_list()->GetNotificationsByNotifierId(id3); 298424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id0")); 299424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id1")); 300424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id2")); 301424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id3")); 302424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_FALSE(IsInNotifications(by_notifier_id, "id4")); 303424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) EXPECT_TRUE(IsInNotifications(by_notifier_id, "id5")); 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) { 3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<std::string> ids; 308c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i <= kMaxVisiblePopupNotifications; i++) 3097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ids.push_back(AddNotification()); 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 31158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) NotificationList::PopupNotifications popups = GetPopups(); 3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The popup should contain the oldest kMaxVisiblePopupNotifications. Newer 3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // one should come earlier in the popup list. It means, the last element 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // of |popups| should be the firstly added one, and so on. 315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kMaxVisiblePopupNotifications, popups.size()); 3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationList::PopupNotifications::const_reverse_iterator iter = 3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) popups.rbegin(); 318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < kMaxVisiblePopupNotifications; ++i, ++iter) { 3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ids[i], (*iter)->id()) << i; 3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 32258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) for (NotificationList::PopupNotifications::const_iterator iter = 32358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) popups.begin(); iter != popups.end(); ++iter) { 32458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown((*iter)->id(), false); 32558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) popups.clear(); 32758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) popups = GetPopups(); 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1u, popups.size()); 3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ids[ids.size() - 1], (*popups.begin())->id()); 3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, Priority) { 333a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->NotificationCount(blockers())); 334a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Default priority has the limit on the number of the popups. 337c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i <= kMaxVisiblePopupNotifications; ++i) 3387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AddNotification(); 339c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kMaxVisiblePopupNotifications + 1, 340a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->NotificationCount(blockers())); 341c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kMaxVisiblePopupNotifications, GetPopupCounts()); 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Low priority: not visible to popups. 344c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->SetMessageCenterVisible(true, NULL); 345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->SetMessageCenterVisible(false, NULL); 346a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); 347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddPriorityNotification(LOW_PRIORITY); 348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kMaxVisiblePopupNotifications + 2, 349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->NotificationCount(blockers())); 350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Minimum priority: doesn't update the unread count. 354c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddPriorityNotification(MIN_PRIORITY); 355c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kMaxVisiblePopupNotifications + 3, 356a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->NotificationCount(blockers())); 357a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 360a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NotificationList::Notifications notifications = 361a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->GetVisibleNotifications(blockers()); 362a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (NotificationList::Notifications::const_iterator iter = 363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notifications.begin(); iter != notifications.end(); ++iter) { 364a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->RemoveNotification((*iter)->id()); 365a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Higher priority: no limits to the number of popups. 368c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < kMaxVisiblePopupNotifications * 2; ++i) 369c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddPriorityNotification(HIGH_PRIORITY); 370c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (size_t i = 0; i < kMaxVisiblePopupNotifications * 2; ++i) 371c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddPriorityNotification(MAX_PRIORITY); 372c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kMaxVisiblePopupNotifications * 4, 373a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->NotificationCount(blockers())); 374c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(kMaxVisiblePopupNotifications * 4, GetPopupCounts()); 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, HasPopupsWithPriority) { 378a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->NotificationCount(blockers())); 379a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 381c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddPriorityNotification(MIN_PRIORITY); 382c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddPriorityNotification(MAX_PRIORITY); 3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(NotificationListTest, HasPopupsWithSystemPriority) { 388a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->NotificationCount(blockers())); 389a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 3907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string normal_id = AddPriorityNotification(DEFAULT_PRIORITY); 3927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string system_id = AddNotification(); 3937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) GetNotification(system_id)->SetSystemPriority(); 3947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_EQ(2u, GetPopupCounts()); 3967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(normal_id); 3987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(system_id); 3997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) notification_list()->MarkSinglePopupAsShown(normal_id, false); 4017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) notification_list()->MarkSinglePopupAsShown(system_id, false); 4027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) notification_list()->SetMessageCenterVisible(true, NULL); 4047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) notification_list()->SetMessageCenterVisible(false, NULL); 4057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 4067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Mark as read -- emulation of mouse click. 4087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) notification_list()->MarkSinglePopupAsShown(system_id, true); 4097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 4107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 4117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, PriorityPromotion) { 413c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string id0 = AddPriorityNotification(LOW_PRIORITY); 4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string replaced = id0 + "_replaced"; 415a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 4177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData optional; 4187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional.priority = 1; 419868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<Notification> notification( 420868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 421868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) replaced, 422868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newtitle"), 423868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newbody"), 424868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 425868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16(kDisplaySource), 426424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, kExtensionId), 4277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional, 428868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 429868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->UpdateNotificationMessage(id0, notification.Pass()); 430a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 432a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const NotificationList::Notifications notifications = 433a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->GetVisibleNotifications(blockers()); 4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(replaced, (*notifications.begin())->id()); 4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); 4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, (*notifications.begin())->priority()); 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 440c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(NotificationListTest, PriorityPromotionWithPopups) { 441c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string id0 = AddPriorityNotification(LOW_PRIORITY); 442c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string id1 = AddPriorityNotification(DEFAULT_PRIORITY); 443c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 444c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id1, true); 445c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 446c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 447c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // id0 promoted to LOW->DEFAULT, it'll appear as toast (popup). 4487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData priority; 4497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority.priority = DEFAULT_PRIORITY; 450868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<Notification> notification( 451868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 452868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) id0, 453868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newtitle"), 454868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newbody"), 455868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 456868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16(kDisplaySource), 457424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, kExtensionId), 4587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority, 459868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 460868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->UpdateNotificationMessage(id0, notification.Pass()); 461c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 462c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id0, true); 463c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 464c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 465c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // update with no promotion change for id0, it won't appear as a toast. 466868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 467868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) id0, 468868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newtitle2"), 469868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newbody2"), 470868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 471868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16(kDisplaySource), 472424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, 473424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) kExtensionId), 4747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority, 475868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 476868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->UpdateNotificationMessage(id0, notification.Pass()); 477c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 478c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 479c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // id1 promoted to DEFAULT->HIGH, it'll appear as toast (popup). 4807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority.priority = HIGH_PRIORITY; 481868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 482868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) id1, 483868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newtitle"), 484868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newbody"), 485868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 486868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16(kDisplaySource), 487424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, 488424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) kExtensionId), 4897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority, 490868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 491868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->UpdateNotificationMessage(id1, notification.Pass()); 492c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 493c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id1, true); 494c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 495c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 496c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // id1 promoted to HIGH->MAX, it'll appear as toast again. 4977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority.priority = MAX_PRIORITY; 498868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 499868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) id1, 500868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newtitle2"), 501868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newbody2"), 502868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 503868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16(kDisplaySource), 504424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, 505424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) kExtensionId), 5067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority, 507868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 508868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->UpdateNotificationMessage(id1, notification.Pass()); 509c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 510c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id1, true); 511c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 512c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 513c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // id1 demoted to MAX->DEFAULT, no appearing as toast. 5147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority.priority = DEFAULT_PRIORITY; 515868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 516868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) id1, 517868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newtitle3"), 518868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newbody3"), 519868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 520868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16(kDisplaySource), 521424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, 522424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) kExtensionId), 5237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) priority, 524868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 525868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->UpdateNotificationMessage(id1, notification.Pass()); 526c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 527c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, NotificationOrderAndPriority) { 5302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Time now = base::Time::Now(); 5317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData optional; 5327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional.timestamp = now; 5337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional.priority = 2; 5347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string max_id = AddNotification(optional); 5357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) now += base::TimeDelta::FromSeconds(1); 5377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional.timestamp = now; 5387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional.priority = 1; 5397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string high_id = AddNotification(optional); 5407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) now += base::TimeDelta::FromSeconds(1); 5427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional.timestamp = now; 5437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) optional.priority = 0; 5447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string default_id = AddNotification(optional); 5452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 5472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Popups: latest comes first. 54858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) NotificationList::PopupNotifications popups = GetPopups(); 5492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3u, popups.size()); 5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationList::PopupNotifications::const_iterator iter = popups.begin(); 5512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(default_id, (*iter)->id()); 5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) iter++; 5532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(high_id, (*iter)->id()); 5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) iter++; 5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(max_id, (*iter)->id()); 5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notifications: high priority comes ealier. 559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const NotificationList::Notifications notifications = 560a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->GetVisibleNotifications(blockers()); 5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3u, notifications.size()); 5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationList::Notifications::const_iterator iter = 5632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notifications.begin(); 5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(max_id, (*iter)->id()); 5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) iter++; 5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(high_id, (*iter)->id()); 5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) iter++; 5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(default_id, (*iter)->id()); 5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, MarkSinglePopupAsShown) { 5737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id1 = AddNotification(); 5747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id2 = AddNotification(); 5757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id3 = AddNotification(); 576a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(3u, notification_list()->NotificationCount(blockers())); 577c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_EQ(std::min(static_cast<size_t>(3u), kMaxVisiblePopupNotifications), 5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetPopupCounts()); 579c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(id1); 580c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(id2); 581c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(id3); 5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id2, true); 5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id3, false); 585a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(3u, notification_list()->NotificationCount(blockers())); 586a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 58858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) NotificationList::PopupNotifications popups = GetPopups(); 5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(id1, (*popups.begin())->id()); 5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The notifications in the NotificationCenter are unaffected by popups shown. 5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationList::Notifications notifications = 593a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) notification_list()->GetVisibleNotifications(blockers()); 5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationList::Notifications::const_iterator iter = notifications.begin(); 5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(id3, (*iter)->id()); 5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) iter++; 5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(id2, (*iter)->id()); 5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) iter++; 5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(id1, (*iter)->id()); 6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 602c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(NotificationListTest, UpdateAfterMarkedAsShown) { 6037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id1 = AddNotification(); 6047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string id2 = AddNotification(); 605c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(id1); 606c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsDisplayed(id2); 607c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 608c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(2u, GetPopupCounts()); 609c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 610c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const Notification* n1 = GetNotification(id1); 611c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(n1->shown_as_popup()); 612a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(n1->IsRead()); 613c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 614c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_list()->MarkSinglePopupAsShown(id1, true); 615c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 616c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) n1 = GetNotification(id1); 617c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(n1->shown_as_popup()); 618a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(n1->IsRead()); 619c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 620c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string replaced("test-replaced-id"); 621868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<Notification> notification( 622868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 623868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) replaced, 624868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newtitle"), 625868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16("newbody"), 626868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Image(), 627868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UTF8ToUTF16(kDisplaySource), 628424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(NotifierId::APPLICATION, kExtensionId), 6297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) message_center::RichNotificationData(), 630868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NULL)); 631868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) notification_list()->UpdateNotificationMessage(id1, notification.Pass()); 632c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) n1 = GetNotification(id1); 633c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(n1 == NULL); 634c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const Notification* nr = GetNotification(replaced); 635c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(nr->shown_as_popup()); 636a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(nr->IsRead()); 637c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 638c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(NotificationListTest, QuietMode) { 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_list()->SetQuietMode(true); 6417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AddNotification(); 642c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddPriorityNotification(HIGH_PRIORITY); 643c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddPriorityNotification(MAX_PRIORITY); 644a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(3u, notification_list()->NotificationCount(blockers())); 6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0u, GetPopupCounts()); 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_list()->SetQuietMode(false); 6487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AddNotification(); 649a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(4u, notification_list()->NotificationCount(blockers())); 6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1u, GetPopupCounts()); 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(mukai): Add test of quiet mode with expiration. 6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6553240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch// Verifies that unread_count doesn't become negative. 6563240926e260ce088908e02ac07a6cf7b0c0cbf44Ben MurdochTEST_F(NotificationListTest, UnreadCountNoNegative) { 6573240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch std::string id = AddNotification(); 658a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 6593240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 6603240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch notification_list()->MarkSinglePopupAsDisplayed(id); 661a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); 6623240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch notification_list()->MarkSinglePopupAsShown( 6633240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch id, false /* mark_notification_as_read */); 664a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 6653240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 6663240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // Updates the notification and verifies unread_count doesn't change. 6673240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch scoped_ptr<Notification> updated_notification(new Notification( 6683240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch message_center::NOTIFICATION_TYPE_SIMPLE, 6693240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch id, 6703240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch UTF8ToUTF16("updated"), 6713240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch UTF8ToUTF16("updated"), 6723240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch gfx::Image(), 6733240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch base::string16(), 674424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NotifierId(), 6753240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch RichNotificationData(), 6763240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch NULL)); 6773240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch notification_list()->AddNotification(updated_notification.Pass()); 678a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 6793240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch} 6803240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 6814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(NotificationListTest, TestPushingShownNotification) { 6824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Create a notification and mark it as shown. 6834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string id1; 6844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<Notification> notification(MakeNotification(&id1)); 6854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) notification->set_shown_as_popup(true); 6864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Call PushNotification on this notification. 6884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) notification_list()->PushNotification(notification.Pass()); 6894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Ensure it is still marked as shown. 6914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(GetNotification(id1)->shown_as_popup()); 6924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 6934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 694d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)TEST_F(NotificationListTest, TestHasNotificationOfType) { 695d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) std::string id = AddNotification(); 696d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 697d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_TRUE(notification_list()->HasNotificationOfType( 698d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) id, message_center::NOTIFICATION_TYPE_SIMPLE)); 699d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_FALSE(notification_list()->HasNotificationOfType( 700d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) id, message_center::NOTIFICATION_TYPE_PROGRESS)); 701d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 702d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) scoped_ptr<Notification> updated_notification(new Notification( 703d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) message_center::NOTIFICATION_TYPE_PROGRESS, 704d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) id, 705d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) UTF8ToUTF16("updated"), 706d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) UTF8ToUTF16("updated"), 707d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) gfx::Image(), 708d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::string16(), 709d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) NotifierId(), 710d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) RichNotificationData(), 711d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) NULL)); 712d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) notification_list()->AddNotification(updated_notification.Pass()); 713d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 714d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_FALSE(notification_list()->HasNotificationOfType( 715d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) id, message_center::NOTIFICATION_TYPE_SIMPLE)); 716d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_TRUE(notification_list()->HasNotificationOfType( 717d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) id, message_center::NOTIFICATION_TYPE_PROGRESS)); 718d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 719d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 7202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace message_center 721