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

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

Issue 324583002: The 1st patch to disambiguate message center notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 6 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/message_center_impl.cc ('k') | ui/message_center/notification.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/message_center_impl.h" 5 #include "ui/message_center/message_center_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 std::string id("id1"); 610 std::string id("id1");
611 std::string id2("id2"); 611 std::string id2("id2");
612 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); 612 NotifierId notifier_id1(NotifierId::APPLICATION, "app1");
613 613
614 // First, add and update a notification to ensure updates happen 614 // First, add and update a notification to ensure updates happen
615 // normally. 615 // normally.
616 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); 616 scoped_ptr<Notification> notification(CreateSimpleNotification(id));
617 message_center()->AddNotification(notification.Pass()); 617 message_center()->AddNotification(notification.Pass());
618 notification.reset(CreateSimpleNotification(id2)); 618 notification.reset(CreateSimpleNotification(id2));
619 message_center()->UpdateNotification(id, notification.Pass()); 619 message_center()->UpdateNotification(id, notification.Pass());
620 EXPECT_TRUE(message_center()->HasNotification(id2)); 620 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2));
621 EXPECT_FALSE(message_center()->HasNotification(id)); 621 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id));
622 622
623 // Then open the message center. 623 // Then open the message center.
624 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); 624 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER);
625 625
626 // Then update a notification; nothing should have happened. 626 // Then update a notification; nothing should have happened.
627 notification.reset(CreateSimpleNotification(id)); 627 notification.reset(CreateSimpleNotification(id));
628 message_center()->UpdateNotification(id2, notification.Pass()); 628 message_center()->UpdateNotification(id2, notification.Pass());
629 EXPECT_TRUE(message_center()->HasNotification(id2)); 629 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2));
630 EXPECT_FALSE(message_center()->HasNotification(id)); 630 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id));
631 631
632 // Close the message center; then the update should have propagated. 632 // Close the message center; then the update should have propagated.
633 message_center()->SetVisibility(VISIBILITY_TRANSIENT); 633 message_center()->SetVisibility(VISIBILITY_TRANSIENT);
634 EXPECT_FALSE(message_center()->HasNotification(id2)); 634 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2));
635 EXPECT_TRUE(message_center()->HasNotification(id)); 635 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id));
636 } 636 }
637 637
638 TEST_F(MessageCenterImplTest, ComplexQueueing) { 638 TEST_F(MessageCenterImplTest, ComplexQueueing) {
639 std::string ids[5] = {"0", "1", "2", "3", "4p"}; 639 std::string ids[5] = {"0", "1", "2", "3", "4p"};
640 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); 640 NotifierId notifier_id1(NotifierId::APPLICATION, "app1");
641 641
642 scoped_ptr<Notification> notification; 642 scoped_ptr<Notification> notification;
643 // Add some notifications 643 // Add some notifications
644 int i = 0; 644 int i = 0;
645 for (; i < 3; i++) { 645 for (; i < 3; i++) {
646 notification.reset(CreateSimpleNotification(ids[i])); 646 notification.reset(CreateSimpleNotification(ids[i]));
647 message_center()->AddNotification(notification.Pass()); 647 message_center()->AddNotification(notification.Pass());
648 } 648 }
649 for (i = 0; i < 3; i++) { 649 for (i = 0; i < 3; i++) {
650 EXPECT_TRUE(message_center()->HasNotification(ids[i])); 650 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i]));
651 } 651 }
652 for (; i < 5; i++) { 652 for (; i < 5; i++) {
653 EXPECT_FALSE(message_center()->HasNotification(ids[i])); 653 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[i]));
654 } 654 }
655 655
656 notification.reset(CreateNotification(ids[4], NOTIFICATION_TYPE_PROGRESS)); 656 notification.reset(CreateNotification(ids[4], NOTIFICATION_TYPE_PROGRESS));
657 message_center()->AddNotification(notification.Pass()); 657 message_center()->AddNotification(notification.Pass());
658 658
659 // Now start queueing. 659 // Now start queueing.
660 // NL: ["0", "1", "2", "4p"] 660 // NL: ["0", "1", "2", "4p"]
661 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); 661 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER);
662 662
663 // This should update notification "1" to have id "3". 663 // This should update notification "1" to have id "3".
664 notification.reset(CreateSimpleNotification(ids[3])); 664 notification.reset(CreateSimpleNotification(ids[3]));
665 message_center()->UpdateNotification(ids[1], notification.Pass()); 665 message_center()->UpdateNotification(ids[1], notification.Pass());
666 666
667 notification.reset(CreateSimpleNotification(ids[4])); 667 notification.reset(CreateSimpleNotification(ids[4]));
668 message_center()->UpdateNotification(ids[4], notification.Pass()); 668 message_center()->UpdateNotification(ids[4], notification.Pass());
669 669
670 notification.reset(CreateNotification(ids[4], NOTIFICATION_TYPE_PROGRESS)); 670 notification.reset(CreateNotification(ids[4], NOTIFICATION_TYPE_PROGRESS));
671 message_center()->UpdateNotification(ids[4], notification.Pass()); 671 message_center()->UpdateNotification(ids[4], notification.Pass());
672 672
673 // This should update notification "3" to a new ID after we go TRANSIENT. 673 // This should update notification "3" to a new ID after we go TRANSIENT.
674 notification.reset(CreateSimpleNotification("New id")); 674 notification.reset(CreateSimpleNotification("New id"));
675 message_center()->UpdateNotification(ids[3], notification.Pass()); 675 message_center()->UpdateNotification(ids[3], notification.Pass());
676 676
677 // This should create a new "3", that doesn't overwrite the update to 3 677 // This should create a new "3", that doesn't overwrite the update to 3
678 // before. 678 // before.
679 notification.reset(CreateSimpleNotification(ids[3])); 679 notification.reset(CreateSimpleNotification(ids[3]));
680 message_center()->AddNotification(notification.Pass()); 680 message_center()->AddNotification(notification.Pass());
681 681
682 // The NL should still be the same: ["0", "1", "2", "4p"] 682 // The NL should still be the same: ["0", "1", "2", "4p"]
683 EXPECT_TRUE(message_center()->HasNotification(ids[0])); 683 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[0]));
684 EXPECT_TRUE(message_center()->HasNotification(ids[1])); 684 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[1]));
685 EXPECT_TRUE(message_center()->HasNotification(ids[2])); 685 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[2]));
686 EXPECT_FALSE(message_center()->HasNotification(ids[3])); 686 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[3]));
687 EXPECT_TRUE(message_center()->HasNotification(ids[4])); 687 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[4]));
688 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 4u); 688 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 4u);
689 message_center()->SetVisibility(VISIBILITY_TRANSIENT); 689 message_center()->SetVisibility(VISIBILITY_TRANSIENT);
690 690
691 EXPECT_TRUE(message_center()->HasNotification(ids[0])); 691 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[0]));
692 EXPECT_FALSE(message_center()->HasNotification(ids[1])); 692 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[1]));
693 EXPECT_TRUE(message_center()->HasNotification(ids[2])); 693 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[2]));
694 EXPECT_TRUE(message_center()->HasNotification(ids[3])); 694 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[3]));
695 EXPECT_TRUE(message_center()->HasNotification(ids[4])); 695 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[4]));
696 EXPECT_TRUE(message_center()->HasNotification("New id")); 696 EXPECT_TRUE(message_center()->FindVisibleNotificationById("New id"));
697 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 5u); 697 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 5u);
698 } 698 }
699 699
700 TEST_F(MessageCenterImplTest, QueuedDirectUpdates) { 700 TEST_F(MessageCenterImplTest, QueuedDirectUpdates) {
701 std::string id("id1"); 701 std::string id("id1");
702 std::string id2("id2"); 702 std::string id2("id2");
703 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); 703 NotifierId notifier_id1(NotifierId::APPLICATION, "app1");
704 704
705 gfx::Size original_size(0, 0); 705 gfx::Size original_size(0, 0);
706 // Open the message center to prevent adding notifications 706 // Open the message center to prevent adding notifications
707 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); 707 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER);
708 708
709 // Create new notification to be added to the queue; images all have the same 709 // Create new notification to be added to the queue; images all have the same
710 // original size. 710 // original size.
711 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); 711 scoped_ptr<Notification> notification(CreateSimpleNotification(id));
712 712
713 // Double-check that sizes all match. 713 // Double-check that sizes all match.
714 const std::vector<ButtonInfo>& original_buttons = notification->buttons(); 714 const std::vector<ButtonInfo>& original_buttons = notification->buttons();
715 ASSERT_EQ(2u, original_buttons.size()); 715 ASSERT_EQ(2u, original_buttons.size());
716 716
717 EXPECT_EQ(original_size, notification->icon().Size()); 717 EXPECT_EQ(original_size, notification->icon().Size());
718 EXPECT_EQ(original_size, notification->image().Size()); 718 EXPECT_EQ(original_size, notification->image().Size());
719 EXPECT_EQ(original_size, original_buttons[0].icon.Size()); 719 EXPECT_EQ(original_size, original_buttons[0].icon.Size());
720 EXPECT_EQ(original_size, original_buttons[1].icon.Size()); 720 EXPECT_EQ(original_size, original_buttons[1].icon.Size());
721 721
722 message_center()->AddNotification(notification.Pass()); 722 message_center()->AddNotification(notification.Pass());
723 723
724 // The notification should be in the queue. 724 // The notification should be in the queue.
725 EXPECT_FALSE(message_center()->HasNotification(id)); 725 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id));
726 726
727 // Now try setting the icon to a different size. 727 // Now try setting the icon to a different size.
728 gfx::Size new_size(16, 16); 728 gfx::Size new_size(16, 16);
729 EXPECT_NE(original_size, new_size); 729 EXPECT_NE(original_size, new_size);
730 730
731 gfx::Canvas canvas(new_size, 1.0f, true); 731 gfx::Canvas canvas(new_size, 1.0f, true);
732 canvas.DrawColor(SK_ColorBLUE); 732 canvas.DrawColor(SK_ColorBLUE);
733 gfx::Image testImage(gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep()))); 733 gfx::Image testImage(gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())));
734 message_center()->SetNotificationIcon(id, testImage); 734 message_center()->SetNotificationIcon(id, testImage);
735 message_center()->SetNotificationImage(id, testImage); 735 message_center()->SetNotificationImage(id, testImage);
736 message_center()->SetNotificationButtonIcon(id, 0, testImage); 736 message_center()->SetNotificationButtonIcon(id, 0, testImage);
737 message_center()->SetNotificationButtonIcon(id, 1, testImage); 737 message_center()->SetNotificationButtonIcon(id, 1, testImage);
738 738
739 // The notification should be in the queue. 739 // The notification should be in the queue.
740 EXPECT_FALSE(message_center()->HasNotification(id)); 740 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id));
741 741
742 // Close the message center; then the update should have propagated. 742 // Close the message center; then the update should have propagated.
743 message_center()->SetVisibility(VISIBILITY_TRANSIENT); 743 message_center()->SetVisibility(VISIBILITY_TRANSIENT);
744 // The notification should no longer be in the queue. 744 // The notification should no longer be in the queue.
745 EXPECT_TRUE(message_center()->HasNotification(id)); 745 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id));
746 746
747 Notification* mc_notification = 747 Notification* mc_notification =
748 *(message_center()->GetVisibleNotifications().begin()); 748 *(message_center()->GetVisibleNotifications().begin());
749 const std::vector<ButtonInfo>& buttons = mc_notification->buttons(); 749 const std::vector<ButtonInfo>& buttons = mc_notification->buttons();
750 ASSERT_EQ(2u, buttons.size()); 750 ASSERT_EQ(2u, buttons.size());
751 751
752 EXPECT_EQ(new_size, mc_notification->icon().Size()); 752 EXPECT_EQ(new_size, mc_notification->icon().Size());
753 EXPECT_EQ(new_size, mc_notification->image().Size()); 753 EXPECT_EQ(new_size, mc_notification->image().Size());
754 EXPECT_EQ(new_size, buttons[0].icon.Size()); 754 EXPECT_EQ(new_size, buttons[0].icon.Size());
755 EXPECT_EQ(new_size, buttons[1].icon.Size()); 755 EXPECT_EQ(new_size, buttons[1].icon.Size());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 ASSERT_EQ(3u, message_center()->NotificationCount()); 862 ASSERT_EQ(3u, message_center()->NotificationCount());
863 863
864 // Now we remove the remaining notifications. 864 // Now we remove the remaining notifications.
865 notifier_settings_observer()->NotifierEnabledChanged( 865 notifier_settings_observer()->NotifierEnabledChanged(
866 NotifierId(NotifierId::APPLICATION, "app1"), false); 866 NotifierId(NotifierId::APPLICATION, "app1"), false);
867 ASSERT_EQ(0u, message_center()->NotificationCount()); 867 ASSERT_EQ(0u, message_center()->NotificationCount());
868 } 868 }
869 869
870 } // namespace internal 870 } // namespace internal
871 } // namespace message_center 871 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_center_impl.cc ('k') | ui/message_center/notification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698