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/message_center/message_center_constants.h" |
13 #include "ui/message_center/notification_types.h" | 14 #include "ui/message_center/notification_types.h" |
14 | 15 |
15 namespace message_center { | 16 namespace message_center { |
16 namespace test { | 17 namespace test { |
17 | 18 |
18 class NotificationListTest : public testing::Test { | 19 class NotificationListTest : public testing::Test { |
19 public: | 20 public: |
20 NotificationListTest() {} | 21 NotificationListTest() {} |
21 virtual ~NotificationListTest() {} | 22 virtual ~NotificationListTest() {} |
22 | 23 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 NotificationList::Notifications by_extension = | 182 NotificationList::Notifications by_extension = |
182 notification_list()->GetNotificationsByExtension("id0"); | 183 notification_list()->GetNotificationsByExtension("id0"); |
183 EXPECT_TRUE(IsInNotifications(by_extension, "id0")); | 184 EXPECT_TRUE(IsInNotifications(by_extension, "id0")); |
184 EXPECT_TRUE(IsInNotifications(by_extension, "id1")); | 185 EXPECT_TRUE(IsInNotifications(by_extension, "id1")); |
185 EXPECT_TRUE(IsInNotifications(by_extension, "id2")); | 186 EXPECT_TRUE(IsInNotifications(by_extension, "id2")); |
186 EXPECT_FALSE(IsInNotifications(by_extension, "id3")); | 187 EXPECT_FALSE(IsInNotifications(by_extension, "id3")); |
187 } | 188 } |
188 | 189 |
189 TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) { | 190 TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) { |
190 std::vector<std::string> ids; | 191 std::vector<std::string> ids; |
191 for (size_t i = 0; i <= NotificationList::kMaxVisiblePopupNotifications; | 192 for (size_t i = 0; i <= kMaxVisiblePopupNotifications; i++) |
192 i++) { | |
193 ids.push_back(AddNotification(NULL)); | 193 ids.push_back(AddNotification(NULL)); |
194 } | |
195 | 194 |
196 NotificationList::PopupNotifications popups = | 195 NotificationList::PopupNotifications popups = |
197 notification_list()->GetPopupNotifications(); | 196 notification_list()->GetPopupNotifications(); |
198 // The popup should contain the oldest kMaxVisiblePopupNotifications. Newer | 197 // The popup should contain the oldest kMaxVisiblePopupNotifications. Newer |
199 // one should come earlier in the popup list. It means, the last element | 198 // one should come earlier in the popup list. It means, the last element |
200 // of |popups| should be the firstly added one, and so on. | 199 // of |popups| should be the firstly added one, and so on. |
201 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, popups.size()); | 200 EXPECT_EQ(kMaxVisiblePopupNotifications, popups.size()); |
202 NotificationList::PopupNotifications::const_reverse_iterator iter = | 201 NotificationList::PopupNotifications::const_reverse_iterator iter = |
203 popups.rbegin(); | 202 popups.rbegin(); |
204 for (size_t i = 0; i < NotificationList::kMaxVisiblePopupNotifications; | 203 for (size_t i = 0; i < kMaxVisiblePopupNotifications; ++i, ++iter) { |
205 ++i, ++iter) { | |
206 EXPECT_EQ(ids[i], (*iter)->id()) << i; | 204 EXPECT_EQ(ids[i], (*iter)->id()) << i; |
207 } | 205 } |
208 | 206 |
209 notification_list()->MarkPopupsAsShown(message_center::DEFAULT_PRIORITY); | 207 notification_list()->MarkPopupsAsShown(message_center::DEFAULT_PRIORITY); |
210 popups.clear(); | 208 popups.clear(); |
211 popups = notification_list()->GetPopupNotifications(); | 209 popups = notification_list()->GetPopupNotifications(); |
212 EXPECT_EQ(1u, popups.size()); | 210 EXPECT_EQ(1u, popups.size()); |
213 EXPECT_EQ(ids[ids.size() - 1], (*popups.begin())->id()); | 211 EXPECT_EQ(ids[ids.size() - 1], (*popups.begin())->id()); |
214 } | 212 } |
215 | 213 |
216 TEST_F(NotificationListTest, Priority) { | 214 TEST_F(NotificationListTest, Priority) { |
217 ASSERT_EQ(0u, notification_list()->NotificationCount()); | 215 ASSERT_EQ(0u, notification_list()->NotificationCount()); |
218 ASSERT_EQ(0u, notification_list()->unread_count()); | 216 ASSERT_EQ(0u, notification_list()->unread_count()); |
219 | 217 |
220 // Default priority has the limit on the number of the popups. | 218 // Default priority has the limit on the number of the popups. |
221 for (size_t i = 0; i <= NotificationList::kMaxVisiblePopupNotifications; | 219 for (size_t i = 0; i <= kMaxVisiblePopupNotifications; ++i) |
222 ++i) { | |
223 AddNotification(NULL); | 220 AddNotification(NULL); |
224 } | 221 EXPECT_EQ(kMaxVisiblePopupNotifications + 1, |
225 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications + 1, | |
226 notification_list()->NotificationCount()); | 222 notification_list()->NotificationCount()); |
227 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, GetPopupCounts()); | 223 EXPECT_EQ(kMaxVisiblePopupNotifications, GetPopupCounts()); |
228 | 224 |
229 // Low priority: not visible to popups. | 225 // Low priority: not visible to popups. |
230 notification_list()->SetMessageCenterVisible(true, NULL); | 226 notification_list()->SetMessageCenterVisible(true, NULL); |
231 notification_list()->SetMessageCenterVisible(false, NULL); | 227 notification_list()->SetMessageCenterVisible(false, NULL); |
232 EXPECT_EQ(0u, notification_list()->unread_count()); | 228 EXPECT_EQ(0u, notification_list()->unread_count()); |
233 AddPriorityNotification(LOW_PRIORITY); | 229 AddPriorityNotification(LOW_PRIORITY); |
234 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications + 2, | 230 EXPECT_EQ(kMaxVisiblePopupNotifications + 2, |
235 notification_list()->NotificationCount()); | 231 notification_list()->NotificationCount()); |
236 EXPECT_EQ(1u, notification_list()->unread_count()); | 232 EXPECT_EQ(1u, notification_list()->unread_count()); |
237 EXPECT_EQ(0u, GetPopupCounts()); | 233 EXPECT_EQ(0u, GetPopupCounts()); |
238 | 234 |
239 // Minimum priority: doesn't update the unread count. | 235 // Minimum priority: doesn't update the unread count. |
240 AddPriorityNotification(MIN_PRIORITY); | 236 AddPriorityNotification(MIN_PRIORITY); |
241 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications + 3, | 237 EXPECT_EQ(kMaxVisiblePopupNotifications + 3, |
242 notification_list()->NotificationCount()); | 238 notification_list()->NotificationCount()); |
243 EXPECT_EQ(1u, notification_list()->unread_count()); | 239 EXPECT_EQ(1u, notification_list()->unread_count()); |
244 EXPECT_EQ(0u, GetPopupCounts()); | 240 EXPECT_EQ(0u, GetPopupCounts()); |
245 | 241 |
246 notification_list()->RemoveAllNotifications(); | 242 notification_list()->RemoveAllNotifications(); |
247 | 243 |
248 // Higher priority: no limits to the number of popups. | 244 // Higher priority: no limits to the number of popups. |
249 for (size_t i = 0; i < NotificationList::kMaxVisiblePopupNotifications * 2; | 245 for (size_t i = 0; i < kMaxVisiblePopupNotifications * 2; ++i) |
250 ++i) { | |
251 AddPriorityNotification(HIGH_PRIORITY); | 246 AddPriorityNotification(HIGH_PRIORITY); |
252 } | 247 for (size_t i = 0; i < kMaxVisiblePopupNotifications * 2; ++i) |
253 for (size_t i = 0; i < NotificationList::kMaxVisiblePopupNotifications * 2; | |
254 ++i) { | |
255 AddPriorityNotification(MAX_PRIORITY); | 248 AddPriorityNotification(MAX_PRIORITY); |
256 } | 249 EXPECT_EQ(kMaxVisiblePopupNotifications * 4, |
257 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications * 4, | |
258 notification_list()->NotificationCount()); | 250 notification_list()->NotificationCount()); |
259 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications * 4, | 251 EXPECT_EQ(kMaxVisiblePopupNotifications * 4, GetPopupCounts()); |
260 GetPopupCounts()); | |
261 } | 252 } |
262 | 253 |
263 TEST_F(NotificationListTest, HasPopupsWithPriority) { | 254 TEST_F(NotificationListTest, HasPopupsWithPriority) { |
264 ASSERT_EQ(0u, notification_list()->NotificationCount()); | 255 ASSERT_EQ(0u, notification_list()->NotificationCount()); |
265 ASSERT_EQ(0u, notification_list()->unread_count()); | 256 ASSERT_EQ(0u, notification_list()->unread_count()); |
266 | 257 |
267 AddPriorityNotification(MIN_PRIORITY); | 258 AddPriorityNotification(MIN_PRIORITY); |
268 AddPriorityNotification(MAX_PRIORITY); | 259 AddPriorityNotification(MAX_PRIORITY); |
269 | 260 |
270 EXPECT_EQ(1u, GetPopupCounts()); | 261 EXPECT_EQ(1u, GetPopupCounts()); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 iter++; | 374 iter++; |
384 EXPECT_EQ(default_id, (*iter)->id()); | 375 EXPECT_EQ(default_id, (*iter)->id()); |
385 } | 376 } |
386 } | 377 } |
387 | 378 |
388 TEST_F(NotificationListTest, MarkSinglePopupAsShown) { | 379 TEST_F(NotificationListTest, MarkSinglePopupAsShown) { |
389 std::string id1 = AddNotification(NULL); | 380 std::string id1 = AddNotification(NULL); |
390 std::string id2 = AddNotification(NULL); | 381 std::string id2 = AddNotification(NULL); |
391 std::string id3 = AddNotification(NULL); | 382 std::string id3 = AddNotification(NULL); |
392 ASSERT_EQ(3u, notification_list()->NotificationCount()); | 383 ASSERT_EQ(3u, notification_list()->NotificationCount()); |
393 ASSERT_EQ(std::min(static_cast<size_t>(3u), | 384 ASSERT_EQ(std::min(static_cast<size_t>(3u), kMaxVisiblePopupNotifications), |
394 NotificationList::kMaxVisiblePopupNotifications), | |
395 GetPopupCounts()); | 385 GetPopupCounts()); |
396 | 386 |
397 notification_list()->MarkSinglePopupAsShown(id2, true); | 387 notification_list()->MarkSinglePopupAsShown(id2, true); |
398 notification_list()->MarkSinglePopupAsShown(id3, false); | 388 notification_list()->MarkSinglePopupAsShown(id3, false); |
399 EXPECT_EQ(3u, notification_list()->NotificationCount()); | 389 EXPECT_EQ(3u, notification_list()->NotificationCount()); |
400 EXPECT_EQ(2u, notification_list()->unread_count()); | 390 EXPECT_EQ(2u, notification_list()->unread_count()); |
401 EXPECT_EQ(1u, GetPopupCounts()); | 391 EXPECT_EQ(1u, GetPopupCounts()); |
402 NotificationList::PopupNotifications popups = | 392 NotificationList::PopupNotifications popups = |
403 notification_list()->GetPopupNotifications(); | 393 notification_list()->GetPopupNotifications(); |
404 EXPECT_EQ(id1, (*popups.begin())->id()); | 394 EXPECT_EQ(id1, (*popups.begin())->id()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 notification_list()->SetQuietMode(false); | 477 notification_list()->SetQuietMode(false); |
488 AddNotification(NULL); | 478 AddNotification(NULL); |
489 EXPECT_EQ(4u, notification_list()->NotificationCount()); | 479 EXPECT_EQ(4u, notification_list()->NotificationCount()); |
490 EXPECT_EQ(1u, GetPopupCounts()); | 480 EXPECT_EQ(1u, GetPopupCounts()); |
491 | 481 |
492 // TODO(mukai): Add test of quiet mode with expiration. | 482 // TODO(mukai): Add test of quiet mode with expiration. |
493 } | 483 } |
494 | 484 |
495 } // namespace test | 485 } // namespace test |
496 } // namespace message_center | 486 } // namespace message_center |
OLD | NEW |