Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: ui/message_center/notification_list_unittest.cc

Issue 1292003004: Elide origins displayed on web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Style nit Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/message_center/notification.cc ('k') | ui/message_center/views/constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 std::string AddNotification() { 46 std::string AddNotification() {
47 return AddNotification(message_center::RichNotificationData()); 47 return AddNotification(message_center::RichNotificationData());
48 } 48 }
49 49
50 // Construct a new notification for testing, but don't add it to the list yet. 50 // Construct a new notification for testing, but don't add it to the list yet.
51 scoped_ptr<Notification> MakeNotification( 51 scoped_ptr<Notification> MakeNotification(
52 const message_center::RichNotificationData& optional_fields, 52 const message_center::RichNotificationData& optional_fields,
53 std::string* id_out) { 53 std::string* id_out) {
54 *id_out = base::StringPrintf(kIdFormat, counter_); 54 *id_out = base::StringPrintf(kIdFormat, counter_);
55 scoped_ptr<Notification> notification(new Notification( 55 scoped_ptr<Notification> notification(new Notification(
56 message_center::NOTIFICATION_TYPE_SIMPLE, 56 message_center::NOTIFICATION_TYPE_SIMPLE, *id_out,
57 *id_out,
58 UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)), 57 UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)),
59 UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)), 58 UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)), gfx::Image(),
60 gfx::Image(), 59 UTF8ToUTF16(kDisplaySource), GURL(),
61 UTF8ToUTF16(kDisplaySource), 60 NotifierId(NotifierId::APPLICATION, kExtensionId), optional_fields,
62 NotifierId(NotifierId::APPLICATION, kExtensionId),
63 optional_fields,
64 NULL)); 61 NULL));
65 return notification.Pass(); 62 return notification.Pass();
66 } 63 }
67 64
68 scoped_ptr<Notification> MakeNotification(std::string* id_out) { 65 scoped_ptr<Notification> MakeNotification(std::string* id_out) {
69 return MakeNotification(message_center::RichNotificationData(), id_out); 66 return MakeNotification(message_center::RichNotificationData(), id_out);
70 } 67 }
71 68
72 // Utility methods of AddNotification. 69 // Utility methods of AddNotification.
73 std::string AddPriorityNotification(NotificationPriority priority) { 70 std::string AddPriorityNotification(NotificationPriority priority) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 176 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers()));
180 notification_list()->MarkSinglePopupAsDisplayed(id1); 177 notification_list()->MarkSinglePopupAsDisplayed(id1);
181 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); 178 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers()));
182 } 179 }
183 180
184 TEST_F(NotificationListTest, UpdateNotification) { 181 TEST_F(NotificationListTest, UpdateNotification) {
185 std::string id0 = AddNotification(); 182 std::string id0 = AddNotification();
186 std::string replaced = id0 + "_replaced"; 183 std::string replaced = id0 + "_replaced";
187 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 184 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers()));
188 scoped_ptr<Notification> notification( 185 scoped_ptr<Notification> notification(
189 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 186 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, replaced,
190 replaced, 187 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"),
191 UTF8ToUTF16("newtitle"), 188 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(),
192 UTF8ToUTF16("newbody"),
193 gfx::Image(),
194 UTF8ToUTF16(kDisplaySource),
195 NotifierId(NotifierId::APPLICATION, kExtensionId), 189 NotifierId(NotifierId::APPLICATION, kExtensionId),
196 message_center::RichNotificationData(), 190 message_center::RichNotificationData(), NULL));
197 NULL));
198 notification_list()->UpdateNotificationMessage(id0, notification.Pass()); 191 notification_list()->UpdateNotificationMessage(id0, notification.Pass());
199 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 192 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers()));
200 const NotificationList::Notifications notifications = 193 const NotificationList::Notifications notifications =
201 notification_list()->GetVisibleNotifications(blockers()); 194 notification_list()->GetVisibleNotifications(blockers());
202 EXPECT_EQ(replaced, (*notifications.begin())->id()); 195 EXPECT_EQ(replaced, (*notifications.begin())->id());
203 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); 196 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title());
204 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); 197 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message());
205 } 198 }
206 199
207 TEST_F(NotificationListTest, GetNotificationsByNotifierId) { 200 TEST_F(NotificationListTest, GetNotificationsByNotifierId) {
208 NotifierId id0(NotifierId::APPLICATION, "ext0"); 201 NotifierId id0(NotifierId::APPLICATION, "ext0");
209 NotifierId id1(NotifierId::APPLICATION, "ext1"); 202 NotifierId id1(NotifierId::APPLICATION, "ext1");
210 NotifierId id2(GURL("http://example.com")); 203 NotifierId id2(GURL("http://example.com"));
211 NotifierId id3(NotifierId::SYSTEM_COMPONENT, "system-notifier"); 204 NotifierId id3(NotifierId::SYSTEM_COMPONENT, "system-notifier");
212 scoped_ptr<Notification> notification( 205 scoped_ptr<Notification> notification(new Notification(
213 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 206 message_center::NOTIFICATION_TYPE_SIMPLE, "id0", UTF8ToUTF16("title0"),
214 "id0", 207 UTF8ToUTF16("message0"), gfx::Image(), UTF8ToUTF16("source0"), GURL(),
215 UTF8ToUTF16("title0"), 208 id0, message_center::RichNotificationData(), NULL));
216 UTF8ToUTF16("message0"),
217 gfx::Image(),
218 UTF8ToUTF16("source0"),
219 id0,
220 message_center::RichNotificationData(),
221 NULL));
222 notification_list()->AddNotification(notification.Pass()); 209 notification_list()->AddNotification(notification.Pass());
223 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 210 notification.reset(new Notification(
224 "id1", 211 message_center::NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title1"),
225 UTF8ToUTF16("title1"), 212 UTF8ToUTF16("message1"), gfx::Image(), UTF8ToUTF16("source0"), GURL(),
226 UTF8ToUTF16("message1"), 213 id0, message_center::RichNotificationData(), NULL));
227 gfx::Image(),
228 UTF8ToUTF16("source0"),
229 id0,
230 message_center::RichNotificationData(),
231 NULL));
232 notification_list()->AddNotification(notification.Pass()); 214 notification_list()->AddNotification(notification.Pass());
233 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 215 notification.reset(new Notification(
234 "id2", 216 message_center::NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title1"),
235 UTF8ToUTF16("title1"), 217 UTF8ToUTF16("message1"), gfx::Image(), UTF8ToUTF16("source1"), GURL(),
236 UTF8ToUTF16("message1"), 218 id0, message_center::RichNotificationData(), NULL));
237 gfx::Image(),
238 UTF8ToUTF16("source1"),
239 id0,
240 message_center::RichNotificationData(),
241 NULL));
242 notification_list()->AddNotification(notification.Pass()); 219 notification_list()->AddNotification(notification.Pass());
243 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 220 notification.reset(new Notification(
244 "id3", 221 message_center::NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title1"),
245 UTF8ToUTF16("title1"), 222 UTF8ToUTF16("message1"), gfx::Image(), UTF8ToUTF16("source2"), GURL(),
246 UTF8ToUTF16("message1"), 223 id1, message_center::RichNotificationData(), NULL));
247 gfx::Image(),
248 UTF8ToUTF16("source2"),
249 id1,
250 message_center::RichNotificationData(),
251 NULL));
252 notification_list()->AddNotification(notification.Pass()); 224 notification_list()->AddNotification(notification.Pass());
253 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 225 notification.reset(new Notification(
254 "id4", 226 message_center::NOTIFICATION_TYPE_SIMPLE, "id4", UTF8ToUTF16("title1"),
255 UTF8ToUTF16("title1"), 227 UTF8ToUTF16("message1"), gfx::Image(), UTF8ToUTF16("source2"), GURL(),
256 UTF8ToUTF16("message1"), 228 id2, message_center::RichNotificationData(), NULL));
257 gfx::Image(),
258 UTF8ToUTF16("source2"),
259 id2,
260 message_center::RichNotificationData(),
261 NULL));
262 notification_list()->AddNotification(notification.Pass()); 229 notification_list()->AddNotification(notification.Pass());
263 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 230 notification.reset(new Notification(
264 "id5", 231 message_center::NOTIFICATION_TYPE_SIMPLE, "id5", UTF8ToUTF16("title1"),
265 UTF8ToUTF16("title1"), 232 UTF8ToUTF16("message1"), gfx::Image(), UTF8ToUTF16("source2"), GURL(),
266 UTF8ToUTF16("message1"), 233 id3, message_center::RichNotificationData(), NULL));
267 gfx::Image(),
268 UTF8ToUTF16("source2"),
269 id3,
270 message_center::RichNotificationData(),
271 NULL));
272 notification_list()->AddNotification(notification.Pass()); 234 notification_list()->AddNotification(notification.Pass());
273 235
274 NotificationList::Notifications by_notifier_id = 236 NotificationList::Notifications by_notifier_id =
275 notification_list()->GetNotificationsByNotifierId(id0); 237 notification_list()->GetNotificationsByNotifierId(id0);
276 EXPECT_TRUE(IsInNotifications(by_notifier_id, "id0")); 238 EXPECT_TRUE(IsInNotifications(by_notifier_id, "id0"));
277 EXPECT_TRUE(IsInNotifications(by_notifier_id, "id1")); 239 EXPECT_TRUE(IsInNotifications(by_notifier_id, "id1"));
278 EXPECT_TRUE(IsInNotifications(by_notifier_id, "id2")); 240 EXPECT_TRUE(IsInNotifications(by_notifier_id, "id2"));
279 EXPECT_FALSE(IsInNotifications(by_notifier_id, "id3")); 241 EXPECT_FALSE(IsInNotifications(by_notifier_id, "id3"));
280 EXPECT_FALSE(IsInNotifications(by_notifier_id, "id4")); 242 EXPECT_FALSE(IsInNotifications(by_notifier_id, "id4"));
281 EXPECT_FALSE(IsInNotifications(by_notifier_id, "id5")); 243 EXPECT_FALSE(IsInNotifications(by_notifier_id, "id5"));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 EXPECT_EQ(0u, GetPopupCounts()); 373 EXPECT_EQ(0u, GetPopupCounts());
412 } 374 }
413 375
414 TEST_F(NotificationListTest, PriorityPromotion) { 376 TEST_F(NotificationListTest, PriorityPromotion) {
415 std::string id0 = AddPriorityNotification(LOW_PRIORITY); 377 std::string id0 = AddPriorityNotification(LOW_PRIORITY);
416 std::string replaced = id0 + "_replaced"; 378 std::string replaced = id0 + "_replaced";
417 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 379 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers()));
418 EXPECT_EQ(0u, GetPopupCounts()); 380 EXPECT_EQ(0u, GetPopupCounts());
419 message_center::RichNotificationData optional; 381 message_center::RichNotificationData optional;
420 optional.priority = 1; 382 optional.priority = 1;
421 scoped_ptr<Notification> notification( 383 scoped_ptr<Notification> notification(new Notification(
422 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 384 message_center::NOTIFICATION_TYPE_SIMPLE, replaced,
423 replaced, 385 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), gfx::Image(),
424 UTF8ToUTF16("newtitle"), 386 UTF8ToUTF16(kDisplaySource), GURL(),
425 UTF8ToUTF16("newbody"), 387 NotifierId(NotifierId::APPLICATION, kExtensionId), optional, NULL));
426 gfx::Image(),
427 UTF8ToUTF16(kDisplaySource),
428 NotifierId(NotifierId::APPLICATION, kExtensionId),
429 optional,
430 NULL));
431 notification_list()->UpdateNotificationMessage(id0, notification.Pass()); 388 notification_list()->UpdateNotificationMessage(id0, notification.Pass());
432 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 389 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers()));
433 EXPECT_EQ(1u, GetPopupCounts()); 390 EXPECT_EQ(1u, GetPopupCounts());
434 const NotificationList::Notifications notifications = 391 const NotificationList::Notifications notifications =
435 notification_list()->GetVisibleNotifications(blockers()); 392 notification_list()->GetVisibleNotifications(blockers());
436 EXPECT_EQ(replaced, (*notifications.begin())->id()); 393 EXPECT_EQ(replaced, (*notifications.begin())->id());
437 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); 394 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title());
438 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); 395 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message());
439 EXPECT_EQ(1, (*notifications.begin())->priority()); 396 EXPECT_EQ(1, (*notifications.begin())->priority());
440 } 397 }
441 398
442 TEST_F(NotificationListTest, PriorityPromotionWithPopups) { 399 TEST_F(NotificationListTest, PriorityPromotionWithPopups) {
443 std::string id0 = AddPriorityNotification(LOW_PRIORITY); 400 std::string id0 = AddPriorityNotification(LOW_PRIORITY);
444 std::string id1 = AddPriorityNotification(DEFAULT_PRIORITY); 401 std::string id1 = AddPriorityNotification(DEFAULT_PRIORITY);
445 EXPECT_EQ(1u, GetPopupCounts()); 402 EXPECT_EQ(1u, GetPopupCounts());
446 notification_list()->MarkSinglePopupAsShown(id1, true); 403 notification_list()->MarkSinglePopupAsShown(id1, true);
447 EXPECT_EQ(0u, GetPopupCounts()); 404 EXPECT_EQ(0u, GetPopupCounts());
448 405
449 // id0 promoted to LOW->DEFAULT, it'll appear as toast (popup). 406 // id0 promoted to LOW->DEFAULT, it'll appear as toast (popup).
450 message_center::RichNotificationData priority; 407 message_center::RichNotificationData priority;
451 priority.priority = DEFAULT_PRIORITY; 408 priority.priority = DEFAULT_PRIORITY;
452 scoped_ptr<Notification> notification( 409 scoped_ptr<Notification> notification(new Notification(
453 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 410 message_center::NOTIFICATION_TYPE_SIMPLE, id0, UTF8ToUTF16("newtitle"),
454 id0, 411 UTF8ToUTF16("newbody"), gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(),
455 UTF8ToUTF16("newtitle"), 412 NotifierId(NotifierId::APPLICATION, kExtensionId), priority, NULL));
456 UTF8ToUTF16("newbody"),
457 gfx::Image(),
458 UTF8ToUTF16(kDisplaySource),
459 NotifierId(NotifierId::APPLICATION, kExtensionId),
460 priority,
461 NULL));
462 notification_list()->UpdateNotificationMessage(id0, notification.Pass()); 413 notification_list()->UpdateNotificationMessage(id0, notification.Pass());
463 EXPECT_EQ(1u, GetPopupCounts()); 414 EXPECT_EQ(1u, GetPopupCounts());
464 notification_list()->MarkSinglePopupAsShown(id0, true); 415 notification_list()->MarkSinglePopupAsShown(id0, true);
465 EXPECT_EQ(0u, GetPopupCounts()); 416 EXPECT_EQ(0u, GetPopupCounts());
466 417
467 // update with no promotion change for id0, it won't appear as a toast. 418 // update with no promotion change for id0, it won't appear as a toast.
468 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 419 notification.reset(new Notification(
469 id0, 420 message_center::NOTIFICATION_TYPE_SIMPLE, id0, UTF8ToUTF16("newtitle2"),
470 UTF8ToUTF16("newtitle2"), 421 UTF8ToUTF16("newbody2"), gfx::Image(), UTF8ToUTF16(kDisplaySource),
471 UTF8ToUTF16("newbody2"), 422 GURL(), NotifierId(NotifierId::APPLICATION, kExtensionId), priority,
472 gfx::Image(), 423 NULL));
473 UTF8ToUTF16(kDisplaySource),
474 NotifierId(NotifierId::APPLICATION,
475 kExtensionId),
476 priority,
477 NULL));
478 notification_list()->UpdateNotificationMessage(id0, notification.Pass()); 424 notification_list()->UpdateNotificationMessage(id0, notification.Pass());
479 EXPECT_EQ(0u, GetPopupCounts()); 425 EXPECT_EQ(0u, GetPopupCounts());
480 426
481 // id1 promoted to DEFAULT->HIGH, it'll appear as toast (popup). 427 // id1 promoted to DEFAULT->HIGH, it'll appear as toast (popup).
482 priority.priority = HIGH_PRIORITY; 428 priority.priority = HIGH_PRIORITY;
483 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 429 notification.reset(new Notification(
484 id1, 430 message_center::NOTIFICATION_TYPE_SIMPLE, id1, UTF8ToUTF16("newtitle"),
485 UTF8ToUTF16("newtitle"), 431 UTF8ToUTF16("newbody"), gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(),
486 UTF8ToUTF16("newbody"), 432 NotifierId(NotifierId::APPLICATION, kExtensionId), priority, NULL));
487 gfx::Image(),
488 UTF8ToUTF16(kDisplaySource),
489 NotifierId(NotifierId::APPLICATION,
490 kExtensionId),
491 priority,
492 NULL));
493 notification_list()->UpdateNotificationMessage(id1, notification.Pass()); 433 notification_list()->UpdateNotificationMessage(id1, notification.Pass());
494 EXPECT_EQ(1u, GetPopupCounts()); 434 EXPECT_EQ(1u, GetPopupCounts());
495 notification_list()->MarkSinglePopupAsShown(id1, true); 435 notification_list()->MarkSinglePopupAsShown(id1, true);
496 EXPECT_EQ(0u, GetPopupCounts()); 436 EXPECT_EQ(0u, GetPopupCounts());
497 437
498 // id1 promoted to HIGH->MAX, it'll appear as toast again. 438 // id1 promoted to HIGH->MAX, it'll appear as toast again.
499 priority.priority = MAX_PRIORITY; 439 priority.priority = MAX_PRIORITY;
500 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 440 notification.reset(new Notification(
501 id1, 441 message_center::NOTIFICATION_TYPE_SIMPLE, id1, UTF8ToUTF16("newtitle2"),
502 UTF8ToUTF16("newtitle2"), 442 UTF8ToUTF16("newbody2"), gfx::Image(), UTF8ToUTF16(kDisplaySource),
503 UTF8ToUTF16("newbody2"), 443 GURL(), NotifierId(NotifierId::APPLICATION, kExtensionId), priority,
504 gfx::Image(), 444 NULL));
505 UTF8ToUTF16(kDisplaySource),
506 NotifierId(NotifierId::APPLICATION,
507 kExtensionId),
508 priority,
509 NULL));
510 notification_list()->UpdateNotificationMessage(id1, notification.Pass()); 445 notification_list()->UpdateNotificationMessage(id1, notification.Pass());
511 EXPECT_EQ(1u, GetPopupCounts()); 446 EXPECT_EQ(1u, GetPopupCounts());
512 notification_list()->MarkSinglePopupAsShown(id1, true); 447 notification_list()->MarkSinglePopupAsShown(id1, true);
513 EXPECT_EQ(0u, GetPopupCounts()); 448 EXPECT_EQ(0u, GetPopupCounts());
514 449
515 // id1 demoted to MAX->DEFAULT, no appearing as toast. 450 // id1 demoted to MAX->DEFAULT, no appearing as toast.
516 priority.priority = DEFAULT_PRIORITY; 451 priority.priority = DEFAULT_PRIORITY;
517 notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 452 notification.reset(new Notification(
518 id1, 453 message_center::NOTIFICATION_TYPE_SIMPLE, id1, UTF8ToUTF16("newtitle3"),
519 UTF8ToUTF16("newtitle3"), 454 UTF8ToUTF16("newbody3"), gfx::Image(), UTF8ToUTF16(kDisplaySource),
520 UTF8ToUTF16("newbody3"), 455 GURL(), NotifierId(NotifierId::APPLICATION, kExtensionId), priority,
521 gfx::Image(), 456 NULL));
522 UTF8ToUTF16(kDisplaySource),
523 NotifierId(NotifierId::APPLICATION,
524 kExtensionId),
525 priority,
526 NULL));
527 notification_list()->UpdateNotificationMessage(id1, notification.Pass()); 457 notification_list()->UpdateNotificationMessage(id1, notification.Pass());
528 EXPECT_EQ(0u, GetPopupCounts()); 458 EXPECT_EQ(0u, GetPopupCounts());
529 } 459 }
530 460
531 TEST_F(NotificationListTest, WebNotificationUpdatePromotion) { 461 TEST_F(NotificationListTest, WebNotificationUpdatePromotion) {
532 std::string notification_id = "replaced-web-notification"; 462 std::string notification_id = "replaced-web-notification";
533 scoped_ptr<Notification> original_notification( 463 scoped_ptr<Notification> original_notification(new Notification(
534 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 464 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
535 notification_id, 465 UTF8ToUTF16("Web Notification"), UTF8ToUTF16("Notification contents"),
536 UTF8ToUTF16("Web Notification"), 466 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(),
537 UTF8ToUTF16("Notification contents"), 467 NotifierId(GURL("https://example.com/")),
538 gfx::Image(), 468 message_center::RichNotificationData(), NULL));
539 UTF8ToUTF16(kDisplaySource),
540 NotifierId(GURL("https://example.com/")),
541 message_center::RichNotificationData(),
542 NULL));
543 469
544 EXPECT_EQ(0u, GetPopupCounts()); 470 EXPECT_EQ(0u, GetPopupCounts());
545 notification_list()->AddNotification(original_notification.Pass()); 471 notification_list()->AddNotification(original_notification.Pass());
546 EXPECT_EQ(1u, GetPopupCounts()); 472 EXPECT_EQ(1u, GetPopupCounts());
547 473
548 notification_list()->MarkSinglePopupAsShown(notification_id, true); 474 notification_list()->MarkSinglePopupAsShown(notification_id, true);
549 EXPECT_EQ(0u, GetPopupCounts()); 475 EXPECT_EQ(0u, GetPopupCounts());
550 476
551 scoped_ptr<Notification> replaced_notification( 477 scoped_ptr<Notification> replaced_notification(new Notification(
552 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 478 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
553 notification_id, 479 UTF8ToUTF16("Web Notification Replacement"),
554 UTF8ToUTF16("Web Notification Replacement"), 480 UTF8ToUTF16("New notification contents"), gfx::Image(),
555 UTF8ToUTF16("New notification contents"), 481 UTF8ToUTF16(kDisplaySource), GURL(),
556 gfx::Image(), 482 NotifierId(GURL("https://example.com/")),
557 UTF8ToUTF16(kDisplaySource), 483 message_center::RichNotificationData(), NULL));
558 NotifierId(GURL("https://example.com/")),
559 message_center::RichNotificationData(),
560 NULL));
561 484
562 // Web Notifications will be re-shown as popups even if their priority didn't 485 // Web Notifications will be re-shown as popups even if their priority didn't
563 // change, to match the behavior of the Web Notification API. 486 // change, to match the behavior of the Web Notification API.
564 notification_list()->UpdateNotificationMessage(notification_id, 487 notification_list()->UpdateNotificationMessage(notification_id,
565 replaced_notification.Pass()); 488 replaced_notification.Pass());
566 EXPECT_EQ(1u, GetPopupCounts()); 489 EXPECT_EQ(1u, GetPopupCounts());
567 } 490 }
568 491
569 TEST_F(NotificationListTest, NotificationOrderAndPriority) { 492 TEST_F(NotificationListTest, NotificationOrderAndPriority) {
570 base::Time now = base::Time::Now(); 493 base::Time now = base::Time::Now();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 EXPECT_TRUE(n1->IsRead()); 575 EXPECT_TRUE(n1->IsRead());
653 576
654 notification_list()->MarkSinglePopupAsShown(id1, true); 577 notification_list()->MarkSinglePopupAsShown(id1, true);
655 578
656 n1 = GetNotification(id1); 579 n1 = GetNotification(id1);
657 EXPECT_TRUE(n1->shown_as_popup()); 580 EXPECT_TRUE(n1->shown_as_popup());
658 EXPECT_TRUE(n1->IsRead()); 581 EXPECT_TRUE(n1->IsRead());
659 582
660 const std::string replaced("test-replaced-id"); 583 const std::string replaced("test-replaced-id");
661 scoped_ptr<Notification> notification( 584 scoped_ptr<Notification> notification(
662 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, 585 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, replaced,
663 replaced, 586 UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"),
664 UTF8ToUTF16("newtitle"), 587 gfx::Image(), UTF8ToUTF16(kDisplaySource), GURL(),
665 UTF8ToUTF16("newbody"),
666 gfx::Image(),
667 UTF8ToUTF16(kDisplaySource),
668 NotifierId(NotifierId::APPLICATION, kExtensionId), 588 NotifierId(NotifierId::APPLICATION, kExtensionId),
669 message_center::RichNotificationData(), 589 message_center::RichNotificationData(), NULL));
670 NULL));
671 notification_list()->UpdateNotificationMessage(id1, notification.Pass()); 590 notification_list()->UpdateNotificationMessage(id1, notification.Pass());
672 n1 = GetNotification(id1); 591 n1 = GetNotification(id1);
673 EXPECT_TRUE(n1 == NULL); 592 EXPECT_TRUE(n1 == NULL);
674 const Notification* nr = GetNotification(replaced); 593 const Notification* nr = GetNotification(replaced);
675 EXPECT_TRUE(nr->shown_as_popup()); 594 EXPECT_TRUE(nr->shown_as_popup());
676 EXPECT_TRUE(nr->IsRead()); 595 EXPECT_TRUE(nr->IsRead());
677 } 596 }
678 597
679 TEST_F(NotificationListTest, QuietMode) { 598 TEST_F(NotificationListTest, QuietMode) {
680 notification_list()->SetQuietMode(true); 599 notification_list()->SetQuietMode(true);
(...skipping 17 matching lines...) Expand all
698 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 617 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers()));
699 618
700 notification_list()->MarkSinglePopupAsDisplayed(id); 619 notification_list()->MarkSinglePopupAsDisplayed(id);
701 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); 620 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers()));
702 notification_list()->MarkSinglePopupAsShown( 621 notification_list()->MarkSinglePopupAsShown(
703 id, false /* mark_notification_as_read */); 622 id, false /* mark_notification_as_read */);
704 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 623 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers()));
705 624
706 // Updates the notification and verifies unread_count doesn't change. 625 // Updates the notification and verifies unread_count doesn't change.
707 scoped_ptr<Notification> updated_notification(new Notification( 626 scoped_ptr<Notification> updated_notification(new Notification(
708 message_center::NOTIFICATION_TYPE_SIMPLE, 627 message_center::NOTIFICATION_TYPE_SIMPLE, id, UTF8ToUTF16("updated"),
709 id, 628 UTF8ToUTF16("updated"), gfx::Image(), base::string16(), GURL(),
710 UTF8ToUTF16("updated"), 629 NotifierId(), RichNotificationData(), NULL));
711 UTF8ToUTF16("updated"),
712 gfx::Image(),
713 base::string16(),
714 NotifierId(),
715 RichNotificationData(),
716 NULL));
717 notification_list()->AddNotification(updated_notification.Pass()); 630 notification_list()->AddNotification(updated_notification.Pass());
718 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 631 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers()));
719 } 632 }
720 633
721 TEST_F(NotificationListTest, TestPushingShownNotification) { 634 TEST_F(NotificationListTest, TestPushingShownNotification) {
722 // Create a notification and mark it as shown. 635 // Create a notification and mark it as shown.
723 std::string id1; 636 std::string id1;
724 scoped_ptr<Notification> notification(MakeNotification(&id1)); 637 scoped_ptr<Notification> notification(MakeNotification(&id1));
725 notification->set_shown_as_popup(true); 638 notification->set_shown_as_popup(true);
726 639
727 // Call PushNotification on this notification. 640 // Call PushNotification on this notification.
728 notification_list()->PushNotification(notification.Pass()); 641 notification_list()->PushNotification(notification.Pass());
729 642
730 // Ensure it is still marked as shown. 643 // Ensure it is still marked as shown.
731 EXPECT_TRUE(GetNotification(id1)->shown_as_popup()); 644 EXPECT_TRUE(GetNotification(id1)->shown_as_popup());
732 } 645 }
733 646
734 TEST_F(NotificationListTest, TestHasNotificationOfType) { 647 TEST_F(NotificationListTest, TestHasNotificationOfType) {
735 std::string id = AddNotification(); 648 std::string id = AddNotification();
736 649
737 EXPECT_TRUE(notification_list()->HasNotificationOfType( 650 EXPECT_TRUE(notification_list()->HasNotificationOfType(
738 id, message_center::NOTIFICATION_TYPE_SIMPLE)); 651 id, message_center::NOTIFICATION_TYPE_SIMPLE));
739 EXPECT_FALSE(notification_list()->HasNotificationOfType( 652 EXPECT_FALSE(notification_list()->HasNotificationOfType(
740 id, message_center::NOTIFICATION_TYPE_PROGRESS)); 653 id, message_center::NOTIFICATION_TYPE_PROGRESS));
741 654
742 scoped_ptr<Notification> updated_notification(new Notification( 655 scoped_ptr<Notification> updated_notification(new Notification(
743 message_center::NOTIFICATION_TYPE_PROGRESS, 656 message_center::NOTIFICATION_TYPE_PROGRESS, id, UTF8ToUTF16("updated"),
744 id, 657 UTF8ToUTF16("updated"), gfx::Image(), base::string16(), GURL(),
745 UTF8ToUTF16("updated"), 658 NotifierId(), RichNotificationData(), NULL));
746 UTF8ToUTF16("updated"),
747 gfx::Image(),
748 base::string16(),
749 NotifierId(),
750 RichNotificationData(),
751 NULL));
752 notification_list()->AddNotification(updated_notification.Pass()); 659 notification_list()->AddNotification(updated_notification.Pass());
753 660
754 EXPECT_FALSE(notification_list()->HasNotificationOfType( 661 EXPECT_FALSE(notification_list()->HasNotificationOfType(
755 id, message_center::NOTIFICATION_TYPE_SIMPLE)); 662 id, message_center::NOTIFICATION_TYPE_SIMPLE));
756 EXPECT_TRUE(notification_list()->HasNotificationOfType( 663 EXPECT_TRUE(notification_list()->HasNotificationOfType(
757 id, message_center::NOTIFICATION_TYPE_PROGRESS)); 664 id, message_center::NOTIFICATION_TYPE_PROGRESS));
758 } 665 }
759 666
760 } // namespace message_center 667 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/notification.cc ('k') | ui/message_center/views/constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698