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

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

Issue 2313923002: Don't close pinned notification by the close all button (Closed)
Patch Set: Created 4 years, 3 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') | no next file » | 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 EXPECT_TRUE(NotificationsContain(notifications, "id3")); 569 EXPECT_TRUE(NotificationsContain(notifications, "id3"));
570 EXPECT_FALSE(NotificationsContain(notifications, "id4")); 570 EXPECT_FALSE(NotificationsContain(notifications, "id4"));
571 571
572 // And remove all including invisible notifications. 572 // And remove all including invisible notifications.
573 blocker.SetNotificationsEnabled(false); 573 blocker.SetNotificationsEnabled(false);
574 message_center()->RemoveAllNotifications(false /* by_user */, 574 message_center()->RemoveAllNotifications(false /* by_user */,
575 MessageCenter::RemoveType::ALL); 575 MessageCenter::RemoveType::ALL);
576 EXPECT_EQ(0u, message_center()->NotificationCount()); 576 EXPECT_EQ(0u, message_center()->NotificationCount());
577 } 577 }
578 578
579 TEST_F(MessageCenterImplTest, RemoveAllNotifications) {
580 NotifierId notifier_id1(NotifierId::APPLICATION, "app1");
581 NotifierId notifier_id2(NotifierId::APPLICATION, "app2");
582
583 TotalNotificationBlocker blocker(message_center(), notifier_id1);
584 blocker.SetNotificationsEnabled(false);
585
586 // Notification 1: Visible, non-pinned
587 message_center()->AddNotification(std::unique_ptr<Notification>(
588 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"),
589 UTF8ToUTF16("message"), gfx::Image() /* icon */,
590 base::string16() /* display_source */, GURL(),
591 notifier_id1, RichNotificationData(), NULL)));
592
593 // Notification 2: Invisible, non-pinned
594 message_center()->AddNotification(std::unique_ptr<Notification>(
595 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"),
596 UTF8ToUTF16("message"), gfx::Image() /* icon */,
597 base::string16() /* display_source */, GURL(),
598 notifier_id2, RichNotificationData(), NULL)));
599
600 // Remove all the notifications which are visible and non-pinned.
601 message_center()->RemoveAllNotifications(
602 false /* by_user */, MessageCenter::RemoveType::NON_PINNED);
603
604 EXPECT_EQ(0u, message_center()->NotificationCount());
605 blocker.SetNotificationsEnabled(true); // Show invisible notifications.
606 EXPECT_EQ(1u, message_center()->NotificationCount());
607
608 NotificationList::Notifications notifications =
609 message_center()->GetVisibleNotifications();
610 // Notification 1 should be removed.
611 EXPECT_FALSE(NotificationsContain(notifications, "id1"));
612 // Notification 2 shouldn't be removed since it was invisible.
613 EXPECT_TRUE(NotificationsContain(notifications, "id2"));
614 }
615
616 #if defined(OS_CHROMEOS)
617 TEST_F(MessageCenterImplTest, RemoveAllNotificationsWithPinned) {
618 NotifierId notifier_id1(NotifierId::APPLICATION, "app1");
619 NotifierId notifier_id2(NotifierId::APPLICATION, "app2");
620
621 TotalNotificationBlocker blocker(message_center(), notifier_id1);
622 blocker.SetNotificationsEnabled(false);
623
624 // Notification 1: Visible, non-pinned
625 message_center()->AddNotification(std::unique_ptr<Notification>(
626 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"),
627 UTF8ToUTF16("message"), gfx::Image() /* icon */,
628 base::string16() /* display_source */, GURL(),
629 notifier_id1, RichNotificationData(), NULL)));
630
631 // Notification 2: Invisible, non-pinned
632 message_center()->AddNotification(std::unique_ptr<Notification>(
633 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"),
634 UTF8ToUTF16("message"), gfx::Image() /* icon */,
635 base::string16() /* display_source */, GURL(),
636 notifier_id2, RichNotificationData(), NULL)));
637
638 // Notification 3: Visible, pinned
639 std::unique_ptr<Notification> notification3(
640 new Notification(NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title"),
641 UTF8ToUTF16("message"), gfx::Image() /* icon */,
642 base::string16() /* display_source */, GURL(),
643 notifier_id1, RichNotificationData(), NULL));
644 notification3->set_pinned(true);
645 message_center()->AddNotification(std::move(notification3));
646
647 // Notification 4: Invisible, pinned
648 std::unique_ptr<Notification> notification4(
649 new Notification(NOTIFICATION_TYPE_SIMPLE, "id4", UTF8ToUTF16("title"),
650 UTF8ToUTF16("message"), gfx::Image() /* icon */,
651 base::string16() /* display_source */, GURL(),
652 notifier_id2, RichNotificationData(), NULL));
653 notification4->set_pinned(true);
654 message_center()->AddNotification(std::move(notification4));
655
656 // Remove all the notifications which are visible and non-pinned.
657 message_center()->RemoveAllNotifications(
658 false /* by_user */, MessageCenter::RemoveType::NON_PINNED);
659
660 EXPECT_EQ(1u, message_center()->NotificationCount());
661 blocker.SetNotificationsEnabled(true); // Show invisible notifications.
662 EXPECT_EQ(3u, message_center()->NotificationCount());
663
664 NotificationList::Notifications notifications =
665 message_center()->GetVisibleNotifications();
666 // Notification 1 should be removed.
667 EXPECT_FALSE(NotificationsContain(notifications, "id1"));
668 // Notification 2 shouldn't be removed since it was invisible.
669 EXPECT_TRUE(NotificationsContain(notifications, "id2"));
670 // Notification 3 shouldn't be removed since it was pinned.
671 EXPECT_TRUE(NotificationsContain(notifications, "id3"));
672 // Notification 4 shouldn't be removed since it was invisible and pinned.
673 EXPECT_TRUE(NotificationsContain(notifications, "id4"));
674 }
675 #endif
676
579 #if defined(OS_CHROMEOS) 677 #if defined(OS_CHROMEOS)
580 TEST_F(MessageCenterImplTest, CachedUnreadCount) { 678 TEST_F(MessageCenterImplTest, CachedUnreadCount) {
581 message_center()->AddNotification( 679 message_center()->AddNotification(
582 std::unique_ptr<Notification>(CreateSimpleNotification("id1"))); 680 std::unique_ptr<Notification>(CreateSimpleNotification("id1")));
583 message_center()->AddNotification( 681 message_center()->AddNotification(
584 std::unique_ptr<Notification>(CreateSimpleNotification("id2"))); 682 std::unique_ptr<Notification>(CreateSimpleNotification("id2")));
585 message_center()->AddNotification( 683 message_center()->AddNotification(
586 std::unique_ptr<Notification>(CreateSimpleNotification("id3"))); 684 std::unique_ptr<Notification>(CreateSimpleNotification("id3")));
587 ASSERT_EQ(3u, message_center()->UnreadNotificationCount()); 685 ASSERT_EQ(3u, message_center()->UnreadNotificationCount());
588 686
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 // Then open the message center. 1259 // Then open the message center.
1162 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); 1260 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER);
1163 1261
1164 // Then update a notification; the update should have propagated. 1262 // Then update a notification; the update should have propagated.
1165 message_center()->RemoveNotification(id, false); 1263 message_center()->RemoveNotification(id, false);
1166 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); 1264 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id));
1167 } 1265 }
1168 1266
1169 } // namespace internal 1267 } // namespace internal
1170 } // namespace message_center 1268 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_center_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698