| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/notifications/notification_types.h" | 13 #include "ui/message_center/notification_types.h" |
| 14 | 14 |
| 15 namespace message_center { | 15 namespace message_center { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class MockNotificationListDelegate : public NotificationList::Delegate { | 18 class MockNotificationListDelegate : public NotificationList::Delegate { |
| 19 public: | 19 public: |
| 20 MockNotificationListDelegate() : send_remove_count_(0) {} | 20 MockNotificationListDelegate() : send_remove_count_(0) {} |
| 21 virtual ~MockNotificationListDelegate() {} | 21 virtual ~MockNotificationListDelegate() {} |
| 22 | 22 |
| 23 size_t GetSendRemoveCountAndReset() { | 23 size_t GetSendRemoveCountAndReset() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 counter_ = 0; | 77 counter_ = 0; |
| 78 } | 78 } |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 // Currently NotificationListTest doesn't care about some fields like title or | 81 // Currently NotificationListTest doesn't care about some fields like title or |
| 82 // message, so put a simple template on it. Returns the id of the new | 82 // message, so put a simple template on it. Returns the id of the new |
| 83 // notification. | 83 // notification. |
| 84 std::string AddNotification(const base::DictionaryValue* optional_fields) { | 84 std::string AddNotification(const base::DictionaryValue* optional_fields) { |
| 85 std::string new_id = base::StringPrintf(kIdFormat, counter_); | 85 std::string new_id = base::StringPrintf(kIdFormat, counter_); |
| 86 notification_list_->AddNotification( | 86 notification_list_->AddNotification( |
| 87 ui::notifications::NOTIFICATION_TYPE_SIMPLE, new_id, | 87 message_center::NOTIFICATION_TYPE_SIMPLE, new_id, |
| 88 UTF8ToUTF16(StringPrintf(kTitleFormat, counter_)), | 88 UTF8ToUTF16(StringPrintf(kTitleFormat, counter_)), |
| 89 UTF8ToUTF16(StringPrintf(kMessageFormat, counter_)), | 89 UTF8ToUTF16(StringPrintf(kMessageFormat, counter_)), |
| 90 UTF8ToUTF16(kDisplaySource), kExtensionId, | 90 UTF8ToUTF16(kDisplaySource), kExtensionId, |
| 91 optional_fields); | 91 optional_fields); |
| 92 counter_++; | 92 counter_++; |
| 93 return new_id; | 93 return new_id; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Utility methods of AddNotification. | 96 // Utility methods of AddNotification. |
| 97 std::string AddPriorityNotification(int priority) { | 97 std::string AddPriorityNotification(int priority) { |
| 98 base::DictionaryValue optional; | 98 base::DictionaryValue optional; |
| 99 optional.SetInteger(ui::notifications::kPriorityKey, priority); | 99 optional.SetInteger(message_center::kPriorityKey, priority); |
| 100 return AddNotification(&optional); | 100 return AddNotification(&optional); |
| 101 } | 101 } |
| 102 void SetupTimestampKey(const base::Time& time, | 102 void SetupTimestampKey(const base::Time& time, |
| 103 base::DictionaryValue* optional) { | 103 base::DictionaryValue* optional) { |
| 104 string16 time_formatted = base::TimeFormatShortDateAndTime(time); | 104 string16 time_formatted = base::TimeFormatShortDateAndTime(time); |
| 105 optional->SetString(ui::notifications::kTimestampKey, time_formatted); | 105 optional->SetString(message_center::kTimestampKey, time_formatted); |
| 106 } | 106 } |
| 107 | 107 |
| 108 size_t GetPopupCounts() { | 108 size_t GetPopupCounts() { |
| 109 NotificationList::Notifications popups; | 109 return notification_list()->GetPopupNotifications().size(); |
| 110 notification_list()->GetPopupNotifications(&popups); | |
| 111 return popups.size(); | |
| 112 } | 110 } |
| 113 | 111 |
| 114 MockNotificationListDelegate* delegate() { return delegate_.get(); } | 112 MockNotificationListDelegate* delegate() { return delegate_.get(); } |
| 115 NotificationList* notification_list() { return notification_list_.get(); } | 113 NotificationList* notification_list() { return notification_list_.get(); } |
| 116 | 114 |
| 117 private: | 115 private: |
| 118 static const char kIdFormat[]; | 116 static const char kIdFormat[]; |
| 119 static const char kTitleFormat[]; | 117 static const char kTitleFormat[]; |
| 120 static const char kMessageFormat[]; | 118 static const char kMessageFormat[]; |
| 121 static const char kDisplaySource[]; | 119 static const char kDisplaySource[]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 150 EXPECT_TRUE(notification_list()->HasNotification(id0)); | 148 EXPECT_TRUE(notification_list()->HasNotification(id0)); |
| 151 EXPECT_TRUE(notification_list()->HasNotification(id1)); | 149 EXPECT_TRUE(notification_list()->HasNotification(id1)); |
| 152 EXPECT_FALSE(notification_list()->HasNotification(id1 + "foo")); | 150 EXPECT_FALSE(notification_list()->HasNotification(id1 + "foo")); |
| 153 | 151 |
| 154 EXPECT_EQ(2u, GetPopupCounts()); | 152 EXPECT_EQ(2u, GetPopupCounts()); |
| 155 | 153 |
| 156 notification_list()->MarkPopupsAsShown(0); | 154 notification_list()->MarkPopupsAsShown(0); |
| 157 EXPECT_EQ(2u, notification_list()->NotificationCount()); | 155 EXPECT_EQ(2u, notification_list()->NotificationCount()); |
| 158 EXPECT_EQ(0u, GetPopupCounts()); | 156 EXPECT_EQ(0u, GetPopupCounts()); |
| 159 | 157 |
| 160 EXPECT_TRUE(notification_list()->RemoveNotification(id0)); | 158 notification_list()->RemoveNotification(id0); |
| 161 EXPECT_EQ(1u, notification_list()->NotificationCount()); | 159 EXPECT_EQ(1u, notification_list()->NotificationCount()); |
| 162 EXPECT_EQ(1u, notification_list()->unread_count()); | 160 EXPECT_EQ(1u, notification_list()->unread_count()); |
| 163 | 161 |
| 164 AddNotification(NULL); | 162 AddNotification(NULL); |
| 165 EXPECT_EQ(2u, notification_list()->NotificationCount()); | 163 EXPECT_EQ(2u, notification_list()->NotificationCount()); |
| 166 | 164 |
| 167 notification_list()->RemoveAllNotifications(); | 165 notification_list()->RemoveAllNotifications(); |
| 168 EXPECT_EQ(0u, notification_list()->NotificationCount()); | 166 EXPECT_EQ(0u, notification_list()->NotificationCount()); |
| 169 EXPECT_EQ(0u, notification_list()->unread_count()); | 167 EXPECT_EQ(0u, notification_list()->unread_count()); |
| 170 } | 168 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 182 ASSERT_EQ(0u, notification_list()->unread_count()); | 180 ASSERT_EQ(0u, notification_list()->unread_count()); |
| 183 } | 181 } |
| 184 | 182 |
| 185 TEST_F(NotificationListTest, UpdateNotification) { | 183 TEST_F(NotificationListTest, UpdateNotification) { |
| 186 std::string id0 = AddNotification(NULL); | 184 std::string id0 = AddNotification(NULL); |
| 187 std::string replaced = id0 + "_replaced"; | 185 std::string replaced = id0 + "_replaced"; |
| 188 EXPECT_EQ(1u, notification_list()->NotificationCount()); | 186 EXPECT_EQ(1u, notification_list()->NotificationCount()); |
| 189 notification_list()->UpdateNotificationMessage( | 187 notification_list()->UpdateNotificationMessage( |
| 190 id0, replaced, UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), NULL); | 188 id0, replaced, UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), NULL); |
| 191 EXPECT_EQ(1u, notification_list()->NotificationCount()); | 189 EXPECT_EQ(1u, notification_list()->NotificationCount()); |
| 192 NotificationList::Notifications notifications; | 190 const NotificationList::Notifications& notifications = |
| 193 notification_list()->GetNotifications(¬ifications); | 191 notification_list()->GetNotifications(); |
| 194 EXPECT_EQ(replaced, notifications.begin()->id); | 192 EXPECT_EQ(replaced, (*notifications.begin())->id()); |
| 195 EXPECT_EQ(UTF8ToUTF16("newtitle"), notifications.begin()->title); | 193 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); |
| 196 EXPECT_EQ(UTF8ToUTF16("newbody"), notifications.begin()->message); | 194 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); |
| 197 } | 195 } |
| 198 | 196 |
| 199 TEST_F(NotificationListTest, SendRemoveNotifications) { | 197 TEST_F(NotificationListTest, SendRemoveNotifications) { |
| 200 notification_list()->AddNotification( | 198 notification_list()->AddNotification( |
| 201 ui::notifications::NOTIFICATION_TYPE_SIMPLE, "id0", UTF8ToUTF16("title0"), | 199 message_center::NOTIFICATION_TYPE_SIMPLE, "id0", UTF8ToUTF16("title0"), |
| 202 UTF8ToUTF16("message0"), UTF8ToUTF16("source0"), "ext0", NULL); | 200 UTF8ToUTF16("message0"), UTF8ToUTF16("source0"), "ext0", NULL); |
| 203 notification_list()->AddNotification( | 201 notification_list()->AddNotification( |
| 204 ui::notifications::NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title1"), | 202 message_center::NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title1"), |
| 205 UTF8ToUTF16("message1"), UTF8ToUTF16("source0"), "ext0", NULL); | 203 UTF8ToUTF16("message1"), UTF8ToUTF16("source0"), "ext0", NULL); |
| 206 notification_list()->AddNotification( | 204 notification_list()->AddNotification( |
| 207 ui::notifications::NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title1"), | 205 message_center::NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title1"), |
| 208 UTF8ToUTF16("message1"), UTF8ToUTF16("source1"), "ext0", NULL); | 206 UTF8ToUTF16("message1"), UTF8ToUTF16("source1"), "ext0", NULL); |
| 209 notification_list()->AddNotification( | 207 notification_list()->AddNotification( |
| 210 ui::notifications::NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title1"), | 208 message_center::NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title1"), |
| 211 UTF8ToUTF16("message1"), UTF8ToUTF16("source2"), "ext1", NULL); | 209 UTF8ToUTF16("message1"), UTF8ToUTF16("source2"), "ext1", NULL); |
| 212 | 210 |
| 213 notification_list()->SendRemoveNotificationsBySource("id0"); | 211 notification_list()->SendRemoveNotificationsBySource("id0"); |
| 214 EXPECT_EQ(2u, delegate()->GetSendRemoveCountAndReset()); | 212 EXPECT_EQ(2u, delegate()->GetSendRemoveCountAndReset()); |
| 215 notification_list()->SendRemoveNotificationsByExtension("id0"); | 213 notification_list()->SendRemoveNotificationsByExtension("id0"); |
| 216 EXPECT_EQ(3u, delegate()->GetSendRemoveCountAndReset()); | 214 EXPECT_EQ(3u, delegate()->GetSendRemoveCountAndReset()); |
| 217 } | 215 } |
| 218 | 216 |
| 219 TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) { | 217 TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) { |
| 220 std::vector<std::string> ids; | 218 std::vector<std::string> ids; |
| 221 for (size_t i = 0; i <= NotificationList::kMaxVisiblePopupNotifications; | 219 for (size_t i = 0; i <= NotificationList::kMaxVisiblePopupNotifications; |
| 222 i++) { | 220 i++) { |
| 223 ids.push_back(AddNotification(NULL)); | 221 ids.push_back(AddNotification(NULL)); |
| 224 } | 222 } |
| 225 | 223 |
| 226 NotificationList::Notifications popups; | 224 NotificationList::PopupNotifications popups = |
| 227 notification_list()->GetPopupNotifications(&popups); | 225 notification_list()->GetPopupNotifications(); |
| 228 // The popup should contain the oldest kMaxVisiblePopupNotifications. Newer | 226 // The popup should contain the oldest kMaxVisiblePopupNotifications. Newer |
| 229 // one should come earlier in the popup list. It means, the last element | 227 // one should come earlier in the popup list. It means, the last element |
| 230 // of |popups| should be the firstly added one, and so on. | 228 // of |popups| should be the firstly added one, and so on. |
| 231 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, popups.size()); | 229 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, popups.size()); |
| 232 NotificationList::Notifications::const_reverse_iterator iter = | 230 NotificationList::PopupNotifications::const_reverse_iterator iter = |
| 233 popups.rbegin(); | 231 popups.rbegin(); |
| 234 for (size_t i = 0; i < NotificationList::kMaxVisiblePopupNotifications; | 232 for (size_t i = 0; i < NotificationList::kMaxVisiblePopupNotifications; |
| 235 ++i, ++iter) { | 233 ++i, ++iter) { |
| 236 EXPECT_EQ(ids[i], iter->id) << i; | 234 EXPECT_EQ(ids[i], (*iter)->id()) << i; |
| 237 } | 235 } |
| 238 | 236 |
| 239 notification_list()->MarkPopupsAsShown(ui::notifications::DEFAULT_PRIORITY); | 237 notification_list()->MarkPopupsAsShown(message_center::DEFAULT_PRIORITY); |
| 240 popups.clear(); | 238 popups.clear(); |
| 241 notification_list()->GetPopupNotifications(&popups); | 239 popups = notification_list()->GetPopupNotifications(); |
| 242 EXPECT_EQ(1u, popups.size()); | 240 EXPECT_EQ(1u, popups.size()); |
| 243 EXPECT_EQ(ids[ids.size() - 1], popups.begin()->id); | 241 EXPECT_EQ(ids[ids.size() - 1], (*popups.begin())->id()); |
| 244 } | 242 } |
| 245 | 243 |
| 246 TEST_F(NotificationListTest, Priority) { | 244 TEST_F(NotificationListTest, Priority) { |
| 247 ASSERT_EQ(0u, notification_list()->NotificationCount()); | 245 ASSERT_EQ(0u, notification_list()->NotificationCount()); |
| 248 ASSERT_EQ(0u, notification_list()->unread_count()); | 246 ASSERT_EQ(0u, notification_list()->unread_count()); |
| 249 | 247 |
| 250 // Default priority has the limit on the number of the popups. | 248 // Default priority has the limit on the number of the popups. |
| 251 for (size_t i = 0; i <= NotificationList::kMaxVisiblePopupNotifications; | 249 for (size_t i = 0; i <= NotificationList::kMaxVisiblePopupNotifications; |
| 252 ++i) { | 250 ++i) { |
| 253 AddNotification(NULL); | 251 AddNotification(NULL); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications * 4, | 287 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications * 4, |
| 290 GetPopupCounts()); | 288 GetPopupCounts()); |
| 291 } | 289 } |
| 292 | 290 |
| 293 TEST_F(NotificationListTest, PriorityPromotion) { | 291 TEST_F(NotificationListTest, PriorityPromotion) { |
| 294 std::string id0 = AddPriorityNotification(-1); | 292 std::string id0 = AddPriorityNotification(-1); |
| 295 std::string replaced = id0 + "_replaced"; | 293 std::string replaced = id0 + "_replaced"; |
| 296 EXPECT_EQ(1u, notification_list()->NotificationCount()); | 294 EXPECT_EQ(1u, notification_list()->NotificationCount()); |
| 297 EXPECT_EQ(0u, GetPopupCounts()); | 295 EXPECT_EQ(0u, GetPopupCounts()); |
| 298 base::DictionaryValue optional; | 296 base::DictionaryValue optional; |
| 299 optional.SetInteger(ui::notifications::kPriorityKey, 1); | 297 optional.SetInteger(message_center::kPriorityKey, 1); |
| 300 notification_list()->UpdateNotificationMessage( | 298 notification_list()->UpdateNotificationMessage( |
| 301 id0, replaced, UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), | 299 id0, replaced, UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), |
| 302 &optional); | 300 &optional); |
| 303 EXPECT_EQ(1u, notification_list()->NotificationCount()); | 301 EXPECT_EQ(1u, notification_list()->NotificationCount()); |
| 304 EXPECT_EQ(1u, GetPopupCounts()); | 302 EXPECT_EQ(1u, GetPopupCounts()); |
| 305 NotificationList::Notifications notifications; | 303 const NotificationList::Notifications& notifications = |
| 306 notification_list()->GetNotifications(¬ifications); | 304 notification_list()->GetNotifications(); |
| 307 EXPECT_EQ(replaced, notifications.begin()->id); | 305 EXPECT_EQ(replaced, (*notifications.begin())->id()); |
| 308 EXPECT_EQ(UTF8ToUTF16("newtitle"), notifications.begin()->title); | 306 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); |
| 309 EXPECT_EQ(UTF8ToUTF16("newbody"), notifications.begin()->message); | 307 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); |
| 310 EXPECT_EQ(1, notifications.begin()->priority); | 308 EXPECT_EQ(1, (*notifications.begin())->priority()); |
| 311 } | 309 } |
| 312 | 310 |
| 313 TEST_F(NotificationListTest, NotificationOrderAndPriority) { | 311 TEST_F(NotificationListTest, NotificationOrderAndPriority) { |
| 314 base::Time now = base::Time::Now(); | 312 base::Time now = base::Time::Now(); |
| 315 base::DictionaryValue optional; | 313 base::DictionaryValue optional; |
| 316 SetupTimestampKey(now, &optional); | 314 SetupTimestampKey(now, &optional); |
| 317 optional.SetInteger(ui::notifications::kPriorityKey, 2); | 315 optional.SetInteger(message_center::kPriorityKey, 2); |
| 318 std::string max_id = AddNotification(&optional); | 316 std::string max_id = AddNotification(&optional); |
| 319 now += base::TimeDelta::FromSeconds(1); | 317 now += base::TimeDelta::FromSeconds(1); |
| 320 SetupTimestampKey(now, &optional); | 318 SetupTimestampKey(now, &optional); |
| 321 optional.SetInteger(ui::notifications::kPriorityKey, 1); | 319 optional.SetInteger(message_center::kPriorityKey, 1); |
| 322 std::string high_id = AddNotification(&optional); | 320 std::string high_id = AddNotification(&optional); |
| 323 now += base::TimeDelta::FromSeconds(1); | 321 now += base::TimeDelta::FromSeconds(1); |
| 324 SetupTimestampKey(now, &optional); | 322 SetupTimestampKey(now, &optional); |
| 325 optional.SetInteger(ui::notifications::kPriorityKey, 0); | 323 optional.SetInteger(message_center::kPriorityKey, 0); |
| 326 std::string default_id = AddNotification(&optional); | 324 std::string default_id = AddNotification(&optional); |
| 327 | 325 |
| 328 // Popups: latest comes first. | 326 { |
| 329 NotificationList::Notifications popups; | 327 // Popups: latest comes first. |
| 330 notification_list()->GetPopupNotifications(&popups); | 328 NotificationList::PopupNotifications popups = |
| 331 EXPECT_EQ(3u, popups.size()); | 329 notification_list()->GetPopupNotifications(); |
| 332 NotificationList::Notifications::const_iterator iter = popups.begin(); | 330 EXPECT_EQ(3u, popups.size()); |
| 333 EXPECT_EQ(default_id, iter->id); | 331 NotificationList::PopupNotifications::const_iterator iter = popups.begin(); |
| 334 iter++; | 332 EXPECT_EQ(default_id, (*iter)->id()); |
| 335 EXPECT_EQ(high_id, iter->id); | 333 iter++; |
| 336 iter++; | 334 EXPECT_EQ(high_id, (*iter)->id()); |
| 337 EXPECT_EQ(max_id, iter->id); | 335 iter++; |
| 338 | 336 EXPECT_EQ(max_id, (*iter)->id()); |
| 339 // Notifications: high priority comes ealier. | 337 } |
| 340 NotificationList::Notifications notifications; | 338 { |
| 341 notification_list()->GetNotifications(¬ifications); | 339 // Notifications: high priority comes ealier. |
| 342 EXPECT_EQ(3u, notifications.size()); | 340 const NotificationList::Notifications& notifications = |
| 343 iter = notifications.begin(); | 341 notification_list()->GetNotifications(); |
| 344 EXPECT_EQ(max_id, iter->id); | 342 EXPECT_EQ(3u, notifications.size()); |
| 345 iter++; | 343 NotificationList::Notifications::const_iterator iter = |
| 346 EXPECT_EQ(high_id, iter->id); | 344 notifications.begin(); |
| 347 iter++; | 345 EXPECT_EQ(max_id, (*iter)->id()); |
| 348 EXPECT_EQ(default_id, iter->id); | 346 iter++; |
| 347 EXPECT_EQ(high_id, (*iter)->id()); |
| 348 iter++; |
| 349 EXPECT_EQ(default_id, (*iter)->id()); |
| 350 } |
| 349 } | 351 } |
| 350 | 352 |
| 351 TEST_F(NotificationListTest, MarkSinglePopupAsShown) { | 353 TEST_F(NotificationListTest, MarkSinglePopupAsShown) { |
| 352 std::string id1 = AddNotification(NULL); | 354 std::string id1 = AddNotification(NULL); |
| 353 std::string id2 = AddNotification(NULL); | 355 std::string id2 = AddNotification(NULL); |
| 354 std::string id3 = AddNotification(NULL); | 356 std::string id3 = AddNotification(NULL); |
| 355 ASSERT_EQ(3u, notification_list()->NotificationCount()); | 357 ASSERT_EQ(3u, notification_list()->NotificationCount()); |
| 356 ASSERT_EQ(std::min(static_cast<size_t>(3u), | 358 ASSERT_EQ(std::min(static_cast<size_t>(3u), |
| 357 NotificationList::kMaxVisiblePopupNotifications), | 359 NotificationList::kMaxVisiblePopupNotifications), |
| 358 GetPopupCounts()); | 360 GetPopupCounts()); |
| 359 | 361 |
| 360 notification_list()->MarkSinglePopupAsShown(id2, true); | 362 notification_list()->MarkSinglePopupAsShown(id2, true); |
| 361 notification_list()->MarkSinglePopupAsShown(id3, false); | 363 notification_list()->MarkSinglePopupAsShown(id3, false); |
| 362 EXPECT_EQ(3u, notification_list()->NotificationCount()); | 364 EXPECT_EQ(3u, notification_list()->NotificationCount()); |
| 363 EXPECT_EQ(2u, notification_list()->unread_count()); | 365 EXPECT_EQ(2u, notification_list()->unread_count()); |
| 364 EXPECT_EQ(1u, GetPopupCounts()); | 366 EXPECT_EQ(1u, GetPopupCounts()); |
| 365 NotificationList::Notifications popups; | 367 NotificationList::PopupNotifications popups = |
| 366 notification_list()->GetPopupNotifications(&popups); | 368 notification_list()->GetPopupNotifications(); |
| 367 EXPECT_EQ(id1, popups.begin()->id); | 369 EXPECT_EQ(id1, (*popups.begin())->id()); |
| 368 | 370 |
| 369 // Reorder happens -- popup-notifications should be at the beginning of the | 371 // The notifications in the NotificationCenter are unaffected by popups shown. |
| 370 // list. | 372 NotificationList::Notifications notifications = |
| 371 // TODO(mukai): confirm this behavior is expected. | 373 notification_list()->GetNotifications(); |
| 372 NotificationList::Notifications notifications; | |
| 373 notification_list()->GetNotifications(¬ifications); | |
| 374 NotificationList::Notifications::const_iterator iter = notifications.begin(); | 374 NotificationList::Notifications::const_iterator iter = notifications.begin(); |
| 375 EXPECT_EQ(id1, iter->id); | 375 EXPECT_EQ(id3, (*iter)->id()); |
| 376 iter++; | 376 iter++; |
| 377 EXPECT_EQ(id3, iter->id); | 377 EXPECT_EQ(id2, (*iter)->id()); |
| 378 iter++; | 378 iter++; |
| 379 EXPECT_EQ(id2, iter->id); | 379 EXPECT_EQ(id1, (*iter)->id()); |
| 380 | 380 |
| 381 // Trickier scenario. | 381 // Trickier scenario. |
| 382 notification_list()->MarkPopupsAsShown(ui::notifications::DEFAULT_PRIORITY); | 382 notification_list()->MarkPopupsAsShown(message_center::DEFAULT_PRIORITY); |
| 383 std::string id4 = AddNotification(NULL); | 383 std::string id4 = AddNotification(NULL); |
| 384 std::string id5 = AddNotification(NULL); | 384 std::string id5 = AddNotification(NULL); |
| 385 std::string id6 = AddNotification(NULL); | 385 std::string id6 = AddNotification(NULL); |
| 386 notification_list()->MarkSinglePopupAsShown(id5, true); | 386 notification_list()->MarkSinglePopupAsShown(id5, true); |
| 387 popups.clear(); | 387 |
| 388 { |
| 389 popups.clear(); |
| 390 popups = notification_list()->GetPopupNotifications(); |
| 391 EXPECT_EQ(2u, popups.size()); |
| 392 NotificationList::PopupNotifications::const_iterator iter = popups.begin(); |
| 393 EXPECT_EQ(id6, (*iter)->id()); |
| 394 iter++; |
| 395 EXPECT_EQ(id4, (*iter)->id()); |
| 396 } |
| 397 |
| 388 notifications.clear(); | 398 notifications.clear(); |
| 389 notification_list()->GetPopupNotifications(&popups); | 399 notifications = notification_list()->GetNotifications(); |
| 390 notification_list()->GetNotifications(¬ifications); | |
| 391 EXPECT_EQ(2u, popups.size()); | |
| 392 iter = popups.begin(); | |
| 393 EXPECT_EQ(id6, iter->id); | |
| 394 iter++; | |
| 395 EXPECT_EQ(id4, iter->id); | |
| 396 EXPECT_EQ(6u, notifications.size()); | 400 EXPECT_EQ(6u, notifications.size()); |
| 397 iter = notifications.begin(); | 401 iter = notifications.begin(); |
| 398 EXPECT_EQ(id6, iter->id); | 402 EXPECT_EQ(id6, (*iter)->id()); |
| 399 iter++; | 403 iter++; |
| 400 EXPECT_EQ(id4, iter->id); | 404 EXPECT_EQ(id5, (*iter)->id()); |
| 401 iter++; | 405 iter++; |
| 402 EXPECT_EQ(id5, iter->id); | 406 EXPECT_EQ(id4, (*iter)->id()); |
| 403 iter++; | 407 iter++; |
| 404 EXPECT_EQ(id1, iter->id); | 408 EXPECT_EQ(id3, (*iter)->id()); |
| 405 iter++; | 409 iter++; |
| 406 EXPECT_EQ(id3, iter->id); | 410 EXPECT_EQ(id2, (*iter)->id()); |
| 407 iter++; | 411 iter++; |
| 408 EXPECT_EQ(id2, iter->id); | 412 EXPECT_EQ(id1, (*iter)->id()); |
| 409 } | 413 } |
| 410 | 414 |
| 411 TEST_F(NotificationListTest, QuietMode) { | 415 TEST_F(NotificationListTest, QuietMode) { |
| 412 notification_list()->SetQuietMode(true); | 416 notification_list()->SetQuietMode(true); |
| 413 AddNotification(NULL); | 417 AddNotification(NULL); |
| 414 AddPriorityNotification(1); | 418 AddPriorityNotification(1); |
| 415 AddPriorityNotification(2); | 419 AddPriorityNotification(2); |
| 416 EXPECT_EQ(3u, notification_list()->NotificationCount()); | 420 EXPECT_EQ(3u, notification_list()->NotificationCount()); |
| 417 EXPECT_EQ(0u, GetPopupCounts()); | 421 EXPECT_EQ(0u, GetPopupCounts()); |
| 418 // TODO(mukai): fix here when notification_list distinguish dismiss by quiet | 422 // TODO(mukai): fix here when notification_list distinguish dismiss by quiet |
| 419 // mode and by user operation. | 423 // mode and by user operation. |
| 420 EXPECT_EQ(0u, notification_list()->unread_count()); | 424 EXPECT_EQ(0u, notification_list()->unread_count()); |
| 421 | 425 |
| 422 notification_list()->SetQuietMode(false); | 426 notification_list()->SetQuietMode(false); |
| 423 AddNotification(NULL); | 427 AddNotification(NULL); |
| 424 EXPECT_EQ(4u, notification_list()->NotificationCount()); | 428 EXPECT_EQ(4u, notification_list()->NotificationCount()); |
| 425 EXPECT_EQ(1u, GetPopupCounts()); | 429 EXPECT_EQ(1u, GetPopupCounts()); |
| 426 | 430 |
| 427 // TODO(mukai): Add test of quiet mode with expiration. | 431 // TODO(mukai): Add test of quiet mode with expiration. |
| 428 } | 432 } |
| 429 | 433 |
| 430 } // namespace message_center | 434 } // namespace message_center |
| OLD | NEW |