| OLD | NEW |
| 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 <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
| 15 #include "ui/message_center/message_center_types.h" | 17 #include "ui/message_center/message_center_types.h" |
| 16 #include "ui/message_center/notification_blocker.h" | 18 #include "ui/message_center/notification_blocker.h" |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 612 |
| 611 TEST_F(MessageCenterImplTest, ForceNotificationFlush_InconsistentUpdate) { | 613 TEST_F(MessageCenterImplTest, ForceNotificationFlush_InconsistentUpdate) { |
| 612 std::string id1("id1"); | 614 std::string id1("id1"); |
| 613 std::string id2("id2"); | 615 std::string id2("id2"); |
| 614 std::string id3("id3"); | 616 std::string id3("id3"); |
| 615 | 617 |
| 616 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 618 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 617 | 619 |
| 618 // Add -> Update (with ID change) | 620 // Add -> Update (with ID change) |
| 619 scoped_ptr<Notification> notification(CreateSimpleNotification(id1)); | 621 scoped_ptr<Notification> notification(CreateSimpleNotification(id1)); |
| 620 message_center()->AddNotification(notification.Pass()); | 622 message_center()->AddNotification(std::move(notification)); |
| 621 notification.reset(CreateSimpleNotification(id2)); | 623 notification.reset(CreateSimpleNotification(id2)); |
| 622 message_center()->UpdateNotification(id1, notification.Pass()); | 624 message_center()->UpdateNotification(id1, std::move(notification)); |
| 623 | 625 |
| 624 // Add (although the same ID exists) -> Update (with ID change) -> Remove | 626 // Add (although the same ID exists) -> Update (with ID change) -> Remove |
| 625 notification.reset(CreateSimpleNotification(id2)); | 627 notification.reset(CreateSimpleNotification(id2)); |
| 626 message_center()->AddNotification(notification.Pass()); | 628 message_center()->AddNotification(std::move(notification)); |
| 627 notification.reset(CreateSimpleNotification(id3)); | 629 notification.reset(CreateSimpleNotification(id3)); |
| 628 message_center()->UpdateNotification(id2, notification.Pass()); | 630 message_center()->UpdateNotification(id2, std::move(notification)); |
| 629 message_center()->RemoveNotification(id3, false); | 631 message_center()->RemoveNotification(id3, false); |
| 630 | 632 |
| 631 // Remove (although the ID has already removed) | 633 // Remove (although the ID has already removed) |
| 632 message_center()->RemoveNotification(id3, false); | 634 message_center()->RemoveNotification(id3, false); |
| 633 | 635 |
| 634 // Notification is not added since the message center has opened. | 636 // Notification is not added since the message center has opened. |
| 635 ASSERT_EQ(0u, message_center()->NotificationCount()); | 637 ASSERT_EQ(0u, message_center()->NotificationCount()); |
| 636 | 638 |
| 637 // Forced to update. | 639 // Forced to update. |
| 638 ForceNotificationFlush(id3); | 640 ForceNotificationFlush(id3); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 } | 723 } |
| 722 | 724 |
| 723 TEST_F(MessageCenterImplTestWithChangeQueue, QueueUpdatesWithCenterVisible) { | 725 TEST_F(MessageCenterImplTestWithChangeQueue, QueueUpdatesWithCenterVisible) { |
| 724 std::string id("id1"); | 726 std::string id("id1"); |
| 725 std::string id2("id2"); | 727 std::string id2("id2"); |
| 726 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 728 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
| 727 | 729 |
| 728 // First, add and update a notification to ensure updates happen | 730 // First, add and update a notification to ensure updates happen |
| 729 // normally. | 731 // normally. |
| 730 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 732 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); |
| 731 message_center()->AddNotification(notification.Pass()); | 733 message_center()->AddNotification(std::move(notification)); |
| 732 notification.reset(CreateSimpleNotification(id2)); | 734 notification.reset(CreateSimpleNotification(id2)); |
| 733 message_center()->UpdateNotification(id, notification.Pass()); | 735 message_center()->UpdateNotification(id, std::move(notification)); |
| 734 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); | 736 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); |
| 735 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 737 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
| 736 | 738 |
| 737 // Then open the message center. | 739 // Then open the message center. |
| 738 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 740 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 739 | 741 |
| 740 // Then update a notification; nothing should have happened. | 742 // Then update a notification; nothing should have happened. |
| 741 notification.reset(CreateSimpleNotification(id)); | 743 notification.reset(CreateSimpleNotification(id)); |
| 742 message_center()->UpdateNotification(id2, notification.Pass()); | 744 message_center()->UpdateNotification(id2, std::move(notification)); |
| 743 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); | 745 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); |
| 744 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 746 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
| 745 | 747 |
| 746 // Close the message center; then the update should have propagated. | 748 // Close the message center; then the update should have propagated. |
| 747 message_center()->SetVisibility(VISIBILITY_TRANSIENT); | 749 message_center()->SetVisibility(VISIBILITY_TRANSIENT); |
| 748 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); | 750 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); |
| 749 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 751 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
| 750 } | 752 } |
| 751 | 753 |
| 752 TEST_F(MessageCenterImplTestWithChangeQueue, ComplexQueueing) { | 754 TEST_F(MessageCenterImplTestWithChangeQueue, ComplexQueueing) { |
| 753 std::string ids[6] = {"0", "1", "2", "3", "4p", "5"}; | 755 std::string ids[6] = {"0", "1", "2", "3", "4p", "5"}; |
| 754 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 756 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
| 755 | 757 |
| 756 scoped_ptr<Notification> notification; | 758 scoped_ptr<Notification> notification; |
| 757 // Add some notifications | 759 // Add some notifications |
| 758 int i = 0; | 760 int i = 0; |
| 759 for (; i < 3; i++) { | 761 for (; i < 3; i++) { |
| 760 notification.reset(CreateSimpleNotification(ids[i])); | 762 notification.reset(CreateSimpleNotification(ids[i])); |
| 761 message_center()->AddNotification(notification.Pass()); | 763 message_center()->AddNotification(std::move(notification)); |
| 762 } | 764 } |
| 763 for (i = 0; i < 3; i++) { | 765 for (i = 0; i < 3; i++) { |
| 764 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i])); | 766 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i])); |
| 765 } | 767 } |
| 766 for (; i < 6; i++) { | 768 for (; i < 6; i++) { |
| 767 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[i])); | 769 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[i])); |
| 768 } | 770 } |
| 769 | 771 |
| 770 notification.reset(CreateNotification(ids[4], NOTIFICATION_TYPE_PROGRESS)); | 772 notification.reset(CreateNotification(ids[4], NOTIFICATION_TYPE_PROGRESS)); |
| 771 message_center()->AddNotification(notification.Pass()); | 773 message_center()->AddNotification(std::move(notification)); |
| 772 | 774 |
| 773 // Now start queueing. | 775 // Now start queueing. |
| 774 // NL: ["0", "1", "2", "4p"] | 776 // NL: ["0", "1", "2", "4p"] |
| 775 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 777 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 776 | 778 |
| 777 // This should update notification "1" to have id "3". | 779 // This should update notification "1" to have id "3". |
| 778 notification.reset(CreateSimpleNotification(ids[3])); | 780 notification.reset(CreateSimpleNotification(ids[3])); |
| 779 message_center()->UpdateNotification(ids[1], notification.Pass()); | 781 message_center()->UpdateNotification(ids[1], std::move(notification)); |
| 780 | 782 |
| 781 // Change the ID: "4p" -> "5", "5" -> "1", "1" -> "4p". They shouldn't | 783 // Change the ID: "4p" -> "5", "5" -> "1", "1" -> "4p". They shouldn't |
| 782 // override the previous change ("1" -> "3") nor the next one ("3" -> "5"). | 784 // override the previous change ("1" -> "3") nor the next one ("3" -> "5"). |
| 783 notification.reset(CreateSimpleNotification(ids[5])); | 785 notification.reset(CreateSimpleNotification(ids[5])); |
| 784 message_center()->UpdateNotification(ids[4], notification.Pass()); | 786 message_center()->UpdateNotification(ids[4], std::move(notification)); |
| 785 notification.reset(CreateSimpleNotification(ids[1])); | 787 notification.reset(CreateSimpleNotification(ids[1])); |
| 786 message_center()->UpdateNotification(ids[5], notification.Pass()); | 788 message_center()->UpdateNotification(ids[5], std::move(notification)); |
| 787 notification.reset(CreateNotification(ids[4], NOTIFICATION_TYPE_PROGRESS)); | 789 notification.reset(CreateNotification(ids[4], NOTIFICATION_TYPE_PROGRESS)); |
| 788 message_center()->UpdateNotification(ids[1], notification.Pass()); | 790 message_center()->UpdateNotification(ids[1], std::move(notification)); |
| 789 | 791 |
| 790 // This should update notification "3" to "5" after we go TRANSIENT. | 792 // This should update notification "3" to "5" after we go TRANSIENT. |
| 791 notification.reset(CreateSimpleNotification(ids[5])); | 793 notification.reset(CreateSimpleNotification(ids[5])); |
| 792 message_center()->UpdateNotification(ids[3], notification.Pass()); | 794 message_center()->UpdateNotification(ids[3], std::move(notification)); |
| 793 | 795 |
| 794 // This should create a new "3", that doesn't overwrite the update to 3 | 796 // This should create a new "3", that doesn't overwrite the update to 3 |
| 795 // before. | 797 // before. |
| 796 notification.reset(CreateSimpleNotification(ids[3])); | 798 notification.reset(CreateSimpleNotification(ids[3])); |
| 797 message_center()->AddNotification(notification.Pass()); | 799 message_center()->AddNotification(std::move(notification)); |
| 798 | 800 |
| 799 // The NL should still be the same: ["0", "1", "2", "4p"] | 801 // The NL should still be the same: ["0", "1", "2", "4p"] |
| 800 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[0])); | 802 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[0])); |
| 801 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[1])); | 803 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[1])); |
| 802 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[2])); | 804 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[2])); |
| 803 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[3])); | 805 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[3])); |
| 804 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[4])); | 806 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[4])); |
| 805 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[5])); | 807 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[5])); |
| 806 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 4u); | 808 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 4u); |
| 807 message_center()->SetVisibility(VISIBILITY_TRANSIENT); | 809 message_center()->SetVisibility(VISIBILITY_TRANSIENT); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 819 std::string ids[11] = | 821 std::string ids[11] = |
| 820 {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10p"}; | 822 {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10p"}; |
| 821 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 823 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
| 822 | 824 |
| 823 scoped_ptr<Notification> notification; | 825 scoped_ptr<Notification> notification; |
| 824 // Add some notifications | 826 // Add some notifications |
| 825 int i = 0; | 827 int i = 0; |
| 826 for (; i < 6; i++) { | 828 for (; i < 6; i++) { |
| 827 notification.reset(CreateSimpleNotification(ids[i])); | 829 notification.reset(CreateSimpleNotification(ids[i])); |
| 828 notification->set_title(base::ASCIIToUTF16("ORIGINAL TITLE")); | 830 notification->set_title(base::ASCIIToUTF16("ORIGINAL TITLE")); |
| 829 message_center()->AddNotification(notification.Pass()); | 831 message_center()->AddNotification(std::move(notification)); |
| 830 } | 832 } |
| 831 for (i = 0; i < 6; i++) { | 833 for (i = 0; i < 6; i++) { |
| 832 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i])); | 834 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i])); |
| 833 } | 835 } |
| 834 for (; i < 8; i++) { | 836 for (; i < 8; i++) { |
| 835 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[i])); | 837 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[i])); |
| 836 } | 838 } |
| 837 | 839 |
| 838 notification.reset(CreateNotification(ids[10], NOTIFICATION_TYPE_PROGRESS)); | 840 notification.reset(CreateNotification(ids[10], NOTIFICATION_TYPE_PROGRESS)); |
| 839 notification->set_progress(10); | 841 notification->set_progress(10); |
| 840 message_center()->AddNotification(notification.Pass()); | 842 message_center()->AddNotification(std::move(notification)); |
| 841 | 843 |
| 842 // Now start queueing. | 844 // Now start queueing. |
| 843 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 845 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 844 | 846 |
| 845 // Notification 0: (Exists) -> Removed | 847 // Notification 0: (Exists) -> Removed |
| 846 message_center()->RemoveNotification(ids[0], false); | 848 message_center()->RemoveNotification(ids[0], false); |
| 847 | 849 |
| 848 // Notification 1: (Exists) -> Removed (by user) | 850 // Notification 1: (Exists) -> Removed (by user) |
| 849 message_center()->RemoveNotification(ids[1], true); // removed immediately | 851 message_center()->RemoveNotification(ids[1], true); // removed immediately |
| 850 | 852 |
| 851 // Notification 2: (Exists) -> Removed -> Added | 853 // Notification 2: (Exists) -> Removed -> Added |
| 852 message_center()->RemoveNotification(ids[2], false); | 854 message_center()->RemoveNotification(ids[2], false); |
| 853 notification.reset(CreateSimpleNotification(ids[2])); | 855 notification.reset(CreateSimpleNotification(ids[2])); |
| 854 notification->set_title(base::ASCIIToUTF16("NEW TITLE 2")); | 856 notification->set_title(base::ASCIIToUTF16("NEW TITLE 2")); |
| 855 message_center()->UpdateNotification(ids[2], notification.Pass()); | 857 message_center()->UpdateNotification(ids[2], std::move(notification)); |
| 856 | 858 |
| 857 // Notification 3: (Exists) -> Removed -> Updated | 859 // Notification 3: (Exists) -> Removed -> Updated |
| 858 message_center()->RemoveNotification(ids[3], false); | 860 message_center()->RemoveNotification(ids[3], false); |
| 859 notification.reset(CreateSimpleNotification(ids[3])); | 861 notification.reset(CreateSimpleNotification(ids[3])); |
| 860 notification->set_title(base::ASCIIToUTF16("NEW TITLE 3")); | 862 notification->set_title(base::ASCIIToUTF16("NEW TITLE 3")); |
| 861 message_center()->UpdateNotification(ids[3], notification.Pass()); | 863 message_center()->UpdateNotification(ids[3], std::move(notification)); |
| 862 | 864 |
| 863 // Notification 4: (Exists) -> Removed -> Added -> Removed | 865 // Notification 4: (Exists) -> Removed -> Added -> Removed |
| 864 message_center()->RemoveNotification(ids[4], false); | 866 message_center()->RemoveNotification(ids[4], false); |
| 865 notification.reset(CreateSimpleNotification(ids[4])); | 867 notification.reset(CreateSimpleNotification(ids[4])); |
| 866 message_center()->AddNotification(notification.Pass()); | 868 message_center()->AddNotification(std::move(notification)); |
| 867 message_center()->RemoveNotification(ids[4], false); | 869 message_center()->RemoveNotification(ids[4], false); |
| 868 | 870 |
| 869 // Notification 5: (Exists) -> Updated | 871 // Notification 5: (Exists) -> Updated |
| 870 notification.reset(CreateSimpleNotification(ids[5])); | 872 notification.reset(CreateSimpleNotification(ids[5])); |
| 871 notification->set_title(base::ASCIIToUTF16("NEW TITLE 5")); | 873 notification->set_title(base::ASCIIToUTF16("NEW TITLE 5")); |
| 872 message_center()->UpdateNotification(ids[5], notification.Pass()); | 874 message_center()->UpdateNotification(ids[5], std::move(notification)); |
| 873 | 875 |
| 874 // Notification 6: Updated | 876 // Notification 6: Updated |
| 875 notification.reset(CreateSimpleNotification(ids[6])); | 877 notification.reset(CreateSimpleNotification(ids[6])); |
| 876 message_center()->UpdateNotification(ids[6], notification.Pass()); | 878 message_center()->UpdateNotification(ids[6], std::move(notification)); |
| 877 | 879 |
| 878 // Notification 7: Updated -> Removed | 880 // Notification 7: Updated -> Removed |
| 879 notification.reset(CreateSimpleNotification(ids[7])); | 881 notification.reset(CreateSimpleNotification(ids[7])); |
| 880 message_center()->UpdateNotification(ids[7], notification.Pass()); | 882 message_center()->UpdateNotification(ids[7], std::move(notification)); |
| 881 message_center()->RemoveNotification(ids[7], false); | 883 message_center()->RemoveNotification(ids[7], false); |
| 882 | 884 |
| 883 // Notification 8: Added -> Updated | 885 // Notification 8: Added -> Updated |
| 884 notification.reset(CreateSimpleNotification(ids[8])); | 886 notification.reset(CreateSimpleNotification(ids[8])); |
| 885 notification->set_title(base::ASCIIToUTF16("UPDATING 8-1")); | 887 notification->set_title(base::ASCIIToUTF16("UPDATING 8-1")); |
| 886 message_center()->AddNotification(notification.Pass()); | 888 message_center()->AddNotification(std::move(notification)); |
| 887 notification.reset(CreateSimpleNotification(ids[8])); | 889 notification.reset(CreateSimpleNotification(ids[8])); |
| 888 notification->set_title(base::ASCIIToUTF16("NEW TITLE 8")); | 890 notification->set_title(base::ASCIIToUTF16("NEW TITLE 8")); |
| 889 message_center()->UpdateNotification(ids[8], notification.Pass()); | 891 message_center()->UpdateNotification(ids[8], std::move(notification)); |
| 890 | 892 |
| 891 // Notification 9: Added -> Updated -> Removed | 893 // Notification 9: Added -> Updated -> Removed |
| 892 notification.reset(CreateSimpleNotification(ids[9])); | 894 notification.reset(CreateSimpleNotification(ids[9])); |
| 893 message_center()->AddNotification(notification.Pass()); | 895 message_center()->AddNotification(std::move(notification)); |
| 894 notification.reset(CreateSimpleNotification(ids[9])); | 896 notification.reset(CreateSimpleNotification(ids[9])); |
| 895 message_center()->UpdateNotification(ids[9], notification.Pass()); | 897 message_center()->UpdateNotification(ids[9], std::move(notification)); |
| 896 message_center()->RemoveNotification(ids[9], false); | 898 message_center()->RemoveNotification(ids[9], false); |
| 897 | 899 |
| 898 // Notification 10 (TYPE_PROGRESS): Updated -> Removed -> Added -> Updated | 900 // Notification 10 (TYPE_PROGRESS): Updated -> Removed -> Added -> Updated |
| 899 // Step 1) Progress is updated immediately before removed. | 901 // Step 1) Progress is updated immediately before removed. |
| 900 notification.reset(CreateNotification(ids[10], NOTIFICATION_TYPE_PROGRESS)); | 902 notification.reset(CreateNotification(ids[10], NOTIFICATION_TYPE_PROGRESS)); |
| 901 notification->set_progress(20); | 903 notification->set_progress(20); |
| 902 message_center()->UpdateNotification(ids[10], notification.Pass()); | 904 message_center()->UpdateNotification(ids[10], std::move(notification)); |
| 903 EXPECT_EQ(20, | 905 EXPECT_EQ(20, |
| 904 message_center()->FindVisibleNotificationById(ids[10])->progress()); | 906 message_center()->FindVisibleNotificationById(ids[10])->progress()); |
| 905 message_center()->RemoveNotification(ids[10], false); | 907 message_center()->RemoveNotification(ids[10], false); |
| 906 // Step 2) Progress isn't updated after removed. | 908 // Step 2) Progress isn't updated after removed. |
| 907 notification.reset(CreateSimpleNotification(ids[10])); | 909 notification.reset(CreateSimpleNotification(ids[10])); |
| 908 message_center()->AddNotification(notification.Pass()); | 910 message_center()->AddNotification(std::move(notification)); |
| 909 EXPECT_EQ(20, | 911 EXPECT_EQ(20, |
| 910 message_center()->FindVisibleNotificationById(ids[10])->progress()); | 912 message_center()->FindVisibleNotificationById(ids[10])->progress()); |
| 911 notification.reset(CreateSimpleNotification(ids[10])); | 913 notification.reset(CreateSimpleNotification(ids[10])); |
| 912 notification->set_progress(40); | 914 notification->set_progress(40); |
| 913 message_center()->UpdateNotification(ids[10], notification.Pass()); | 915 message_center()->UpdateNotification(ids[10], std::move(notification)); |
| 914 EXPECT_EQ(20, | 916 EXPECT_EQ(20, |
| 915 message_center()->FindVisibleNotificationById(ids[10])->progress()); | 917 message_center()->FindVisibleNotificationById(ids[10])->progress()); |
| 916 | 918 |
| 917 // All changes except the notification 1 and 10 are not refrected. | 919 // All changes except the notification 1 and 10 are not refrected. |
| 918 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[0])); | 920 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[0])); |
| 919 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"), | 921 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"), |
| 920 message_center()->FindVisibleNotificationById(ids[0])->title()); | 922 message_center()->FindVisibleNotificationById(ids[0])->title()); |
| 921 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[1])); | 923 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids[1])); |
| 922 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[2])); | 924 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[2])); |
| 923 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"), | 925 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 | 981 |
| 980 // Double-check that sizes all match. | 982 // Double-check that sizes all match. |
| 981 const std::vector<ButtonInfo>& original_buttons = notification->buttons(); | 983 const std::vector<ButtonInfo>& original_buttons = notification->buttons(); |
| 982 ASSERT_EQ(2u, original_buttons.size()); | 984 ASSERT_EQ(2u, original_buttons.size()); |
| 983 | 985 |
| 984 EXPECT_EQ(original_size, notification->icon().Size()); | 986 EXPECT_EQ(original_size, notification->icon().Size()); |
| 985 EXPECT_EQ(original_size, notification->image().Size()); | 987 EXPECT_EQ(original_size, notification->image().Size()); |
| 986 EXPECT_EQ(original_size, original_buttons[0].icon.Size()); | 988 EXPECT_EQ(original_size, original_buttons[0].icon.Size()); |
| 987 EXPECT_EQ(original_size, original_buttons[1].icon.Size()); | 989 EXPECT_EQ(original_size, original_buttons[1].icon.Size()); |
| 988 | 990 |
| 989 message_center()->AddNotification(notification.Pass()); | 991 message_center()->AddNotification(std::move(notification)); |
| 990 | 992 |
| 991 // The notification should be in the queue. | 993 // The notification should be in the queue. |
| 992 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 994 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
| 993 | 995 |
| 994 // Now try setting the icon to a different size. | 996 // Now try setting the icon to a different size. |
| 995 gfx::Size new_size(16, 16); | 997 gfx::Size new_size(16, 16); |
| 996 EXPECT_NE(original_size, new_size); | 998 EXPECT_NE(original_size, new_size); |
| 997 | 999 |
| 998 gfx::Canvas canvas(new_size, 1.0f, true); | 1000 gfx::Canvas canvas(new_size, 1.0f, true); |
| 999 canvas.DrawColor(SK_ColorBLUE); | 1001 canvas.DrawColor(SK_ColorBLUE); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 // Notification is added. | 1038 // Notification is added. |
| 1037 ASSERT_EQ(1u, message_center()->NotificationCount()); | 1039 ASSERT_EQ(1u, message_center()->NotificationCount()); |
| 1038 } | 1040 } |
| 1039 | 1041 |
| 1040 | 1042 |
| 1041 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushUpdate) { | 1043 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushUpdate) { |
| 1042 std::string id("id1"); | 1044 std::string id("id1"); |
| 1043 std::string id2("id2"); | 1045 std::string id2("id2"); |
| 1044 | 1046 |
| 1045 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1047 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); |
| 1046 message_center()->AddNotification(notification.Pass()); | 1048 message_center()->AddNotification(std::move(notification)); |
| 1047 | 1049 |
| 1048 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1050 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 1049 | 1051 |
| 1050 notification.reset(CreateSimpleNotification(id2)); | 1052 notification.reset(CreateSimpleNotification(id2)); |
| 1051 message_center()->UpdateNotification(id, notification.Pass()); | 1053 message_center()->UpdateNotification(id, std::move(notification)); |
| 1052 | 1054 |
| 1053 // Nothing is changed. | 1055 // Nothing is changed. |
| 1054 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); | 1056 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); |
| 1055 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1057 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
| 1056 | 1058 |
| 1057 // Forced to update ID1. | 1059 // Forced to update ID1. |
| 1058 ForceNotificationFlush(id); | 1060 ForceNotificationFlush(id); |
| 1059 | 1061 |
| 1060 // Nothing is changed, since the ID is changed. | 1062 // Nothing is changed, since the ID is changed. |
| 1061 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); | 1063 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); |
| 1062 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1064 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
| 1063 | 1065 |
| 1064 // Forced to update ID2. | 1066 // Forced to update ID2. |
| 1065 ForceNotificationFlush(id2); | 1067 ForceNotificationFlush(id2); |
| 1066 | 1068 |
| 1067 // The ID is changed. | 1069 // The ID is changed. |
| 1068 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); | 1070 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); |
| 1069 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 1071 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
| 1070 | 1072 |
| 1071 // Makes sure if there is only one notification. | 1073 // Makes sure if there is only one notification. |
| 1072 ASSERT_EQ(1u, message_center()->NotificationCount()); | 1074 ASSERT_EQ(1u, message_center()->NotificationCount()); |
| 1073 } | 1075 } |
| 1074 | 1076 |
| 1075 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushRemove) { | 1077 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushRemove) { |
| 1076 std::string id("id1"); | 1078 std::string id("id1"); |
| 1077 | 1079 |
| 1078 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1080 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); |
| 1079 message_center()->AddNotification(notification.Pass()); | 1081 message_center()->AddNotification(std::move(notification)); |
| 1080 | 1082 |
| 1081 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1083 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 1082 message_center()->RemoveNotification(id, false); | 1084 message_center()->RemoveNotification(id, false); |
| 1083 | 1085 |
| 1084 // Notification is not removed yet. | 1086 // Notification is not removed yet. |
| 1085 ASSERT_EQ(1u, message_center()->NotificationCount()); | 1087 ASSERT_EQ(1u, message_center()->NotificationCount()); |
| 1086 | 1088 |
| 1087 // Forced to update. | 1089 // Forced to update. |
| 1088 ForceNotificationFlush(id); | 1090 ForceNotificationFlush(id); |
| 1089 | 1091 |
| 1090 // Notification is removed. | 1092 // Notification is removed. |
| 1091 ASSERT_EQ(0u, message_center()->NotificationCount()); | 1093 ASSERT_EQ(0u, message_center()->NotificationCount()); |
| 1092 } | 1094 } |
| 1093 | 1095 |
| 1094 TEST_F(MessageCenterImplTestWithChangeQueue, | 1096 TEST_F(MessageCenterImplTestWithChangeQueue, |
| 1095 ForceNotificationFlush_ComplexUpdate) { | 1097 ForceNotificationFlush_ComplexUpdate) { |
| 1096 std::string id1("id1"); | 1098 std::string id1("id1"); |
| 1097 std::string id2("id2"); | 1099 std::string id2("id2"); |
| 1098 std::string id3("id3"); | 1100 std::string id3("id3"); |
| 1099 | 1101 |
| 1100 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1102 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 1101 | 1103 |
| 1102 // Add -> Update (with ID change) -> Remove | 1104 // Add -> Update (with ID change) -> Remove |
| 1103 scoped_ptr<Notification> notification(CreateSimpleNotification(id1)); | 1105 scoped_ptr<Notification> notification(CreateSimpleNotification(id1)); |
| 1104 message_center()->AddNotification(notification.Pass()); | 1106 message_center()->AddNotification(std::move(notification)); |
| 1105 notification.reset(CreateSimpleNotification(id2)); | 1107 notification.reset(CreateSimpleNotification(id2)); |
| 1106 message_center()->UpdateNotification(id1, notification.Pass()); | 1108 message_center()->UpdateNotification(id1, std::move(notification)); |
| 1107 message_center()->RemoveNotification(id2, false); | 1109 message_center()->RemoveNotification(id2, false); |
| 1108 | 1110 |
| 1109 // Add -> Update (with ID change) | 1111 // Add -> Update (with ID change) |
| 1110 notification.reset(CreateSimpleNotification(id2)); | 1112 notification.reset(CreateSimpleNotification(id2)); |
| 1111 message_center()->AddNotification(notification.Pass()); | 1113 message_center()->AddNotification(std::move(notification)); |
| 1112 notification.reset(CreateSimpleNotification(id3)); | 1114 notification.reset(CreateSimpleNotification(id3)); |
| 1113 message_center()->UpdateNotification(id2, notification.Pass()); | 1115 message_center()->UpdateNotification(id2, std::move(notification)); |
| 1114 | 1116 |
| 1115 // Notification is not added since the message center has opened. | 1117 // Notification is not added since the message center has opened. |
| 1116 ASSERT_EQ(0u, message_center()->NotificationCount()); | 1118 ASSERT_EQ(0u, message_center()->NotificationCount()); |
| 1117 | 1119 |
| 1118 // Forced to update. | 1120 // Forced to update. |
| 1119 ForceNotificationFlush(id3); | 1121 ForceNotificationFlush(id3); |
| 1120 | 1122 |
| 1121 // Confirms the chagnes are applied. | 1123 // Confirms the chagnes are applied. |
| 1122 ASSERT_EQ(1u, message_center()->NotificationCount()); | 1124 ASSERT_EQ(1u, message_center()->NotificationCount()); |
| 1123 } | 1125 } |
| 1124 | 1126 |
| 1125 TEST_F(MessageCenterImplTestWithoutChangeQueue, | 1127 TEST_F(MessageCenterImplTestWithoutChangeQueue, |
| 1126 UpdateWhileMessageCenterVisible) { | 1128 UpdateWhileMessageCenterVisible) { |
| 1127 std::string id("id1"); | 1129 std::string id("id1"); |
| 1128 std::string id2("id2"); | 1130 std::string id2("id2"); |
| 1129 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 1131 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
| 1130 | 1132 |
| 1131 // First, add and update a notification to ensure updates happen | 1133 // First, add and update a notification to ensure updates happen |
| 1132 // normally. | 1134 // normally. |
| 1133 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1135 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); |
| 1134 message_center()->AddNotification(notification.Pass()); | 1136 message_center()->AddNotification(std::move(notification)); |
| 1135 notification.reset(CreateSimpleNotification(id2)); | 1137 notification.reset(CreateSimpleNotification(id2)); |
| 1136 message_center()->UpdateNotification(id, notification.Pass()); | 1138 message_center()->UpdateNotification(id, std::move(notification)); |
| 1137 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); | 1139 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); |
| 1138 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 1140 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
| 1139 | 1141 |
| 1140 // Then open the message center. | 1142 // Then open the message center. |
| 1141 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1143 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 1142 | 1144 |
| 1143 // Then update a notification; the update should have propagated. | 1145 // Then update a notification; the update should have propagated. |
| 1144 notification.reset(CreateSimpleNotification(id)); | 1146 notification.reset(CreateSimpleNotification(id)); |
| 1145 message_center()->UpdateNotification(id2, notification.Pass()); | 1147 message_center()->UpdateNotification(id2, std::move(notification)); |
| 1146 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); | 1148 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); |
| 1147 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1149 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
| 1148 } | 1150 } |
| 1149 | 1151 |
| 1150 TEST_F(MessageCenterImplTestWithoutChangeQueue, AddWhileMessageCenterVisible) { | 1152 TEST_F(MessageCenterImplTestWithoutChangeQueue, AddWhileMessageCenterVisible) { |
| 1151 std::string id("id1"); | 1153 std::string id("id1"); |
| 1152 | 1154 |
| 1153 // Then open the message center. | 1155 // Then open the message center. |
| 1154 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1156 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 1155 | 1157 |
| 1156 // Add a notification and confirm the adding should have propagated. | 1158 // Add a notification and confirm the adding should have propagated. |
| 1157 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1159 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); |
| 1158 message_center()->AddNotification(notification.Pass()); | 1160 message_center()->AddNotification(std::move(notification)); |
| 1159 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1161 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
| 1160 } | 1162 } |
| 1161 | 1163 |
| 1162 TEST_F(MessageCenterImplTestWithoutChangeQueue, | 1164 TEST_F(MessageCenterImplTestWithoutChangeQueue, |
| 1163 RemoveWhileMessageCenterVisible) { | 1165 RemoveWhileMessageCenterVisible) { |
| 1164 std::string id("id1"); | 1166 std::string id("id1"); |
| 1165 | 1167 |
| 1166 // First, add a notification to ensure updates happen normally. | 1168 // First, add a notification to ensure updates happen normally. |
| 1167 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1169 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); |
| 1168 message_center()->AddNotification(notification.Pass()); | 1170 message_center()->AddNotification(std::move(notification)); |
| 1169 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1171 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
| 1170 | 1172 |
| 1171 // Then open the message center. | 1173 // Then open the message center. |
| 1172 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1174 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
| 1173 | 1175 |
| 1174 // Then update a notification; the update should have propagated. | 1176 // Then update a notification; the update should have propagated. |
| 1175 message_center()->RemoveNotification(id, false); | 1177 message_center()->RemoveNotification(id, false); |
| 1176 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 1178 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
| 1177 } | 1179 } |
| 1178 | 1180 |
| 1179 } // namespace internal | 1181 } // namespace internal |
| 1180 } // namespace message_center | 1182 } // namespace message_center |
| OLD | NEW |