Chromium Code Reviews| 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/views/message_center_view.h" | 5 #include "ui/message_center/views/message_center_view.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 bool remove_all_closable_notification_called_ = false; | 110 bool remove_all_closable_notification_called_ = false; |
| 111 NotificationList::Notifications visible_notifications_; | 111 NotificationList::Notifications visible_notifications_; |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 /* Test fixture ***************************************************************/ | 114 /* Test fixture ***************************************************************/ |
| 115 | 115 |
| 116 class MessageCenterViewTest : public views::ViewsTestBase, | 116 class MessageCenterViewTest : public views::ViewsTestBase, |
| 117 public MockNotificationView::Test, | 117 public MockNotificationView::Test, |
| 118 public MessageCenterController { | 118 public MessageCenterController { |
| 119 public: | 119 public: |
| 120 // Expose the private enum class MessageCenter::Mode for this test. | |
| 121 typedef MessageCenterView::Mode Mode; | |
| 122 | |
| 120 MessageCenterViewTest(); | 123 MessageCenterViewTest(); |
| 121 ~MessageCenterViewTest() override; | 124 ~MessageCenterViewTest() override; |
| 122 | 125 |
| 123 void SetUp() override; | 126 void SetUp() override; |
| 124 void TearDown() override; | 127 void TearDown() override; |
| 125 | 128 |
| 126 MessageCenterView* GetMessageCenterView(); | 129 MessageCenterView* GetMessageCenterView(); |
| 127 MessageListView* GetMessageListView(); | 130 MessageListView* GetMessageListView(); |
| 128 FakeMessageCenterImpl* GetMessageCenter() const; | 131 FakeMessageCenterImpl* GetMessageCenter() const; |
| 129 NotificationView* GetNotificationView(const std::string& id); | 132 NotificationView* GetNotificationView(const std::string& id); |
| 130 views::BoundsAnimator* GetAnimator(); | 133 views::BoundsAnimator* GetAnimator(); |
| 131 int GetNotificationCount(); | 134 int GetNotificationCount(); |
| 132 int GetCallCount(CallType type); | 135 int GetCallCount(CallType type); |
| 133 int GetCalculatedMessageListViewHeight(); | 136 int GetCalculatedMessageListViewHeight(); |
| 137 Mode GetMessageCenterViewInternalMode(); | |
| 134 void AddNotification(std::unique_ptr<Notification> notification); | 138 void AddNotification(std::unique_ptr<Notification> notification); |
| 135 void UpdateNotification(const std::string& notification_id, | 139 void UpdateNotification(const std::string& notification_id, |
| 136 std::unique_ptr<Notification> notification); | 140 std::unique_ptr<Notification> notification); |
| 137 | 141 |
| 138 // Overridden from MessageCenterController: | 142 // Overridden from MessageCenterController: |
| 139 void ClickOnNotification(const std::string& notification_id) override; | 143 void ClickOnNotification(const std::string& notification_id) override; |
| 140 void RemoveNotification(const std::string& notification_id, | 144 void RemoveNotification(const std::string& notification_id, |
| 141 bool by_user) override; | 145 bool by_user) override; |
| 142 std::unique_ptr<ui::MenuModel> CreateMenuModel( | 146 std::unique_ptr<ui::MenuModel> CreateMenuModel( |
| 143 const NotifierId& notifier_id, | 147 const NotifierId& notifier_id, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 | 234 |
| 231 NotificationView* MessageCenterViewTest::GetNotificationView( | 235 NotificationView* MessageCenterViewTest::GetNotificationView( |
| 232 const std::string& id) { | 236 const std::string& id) { |
| 233 return message_center_view_->notification_views_[id]; | 237 return message_center_view_->notification_views_[id]; |
| 234 } | 238 } |
| 235 | 239 |
| 236 int MessageCenterViewTest::GetCalculatedMessageListViewHeight() { | 240 int MessageCenterViewTest::GetCalculatedMessageListViewHeight() { |
| 237 return GetMessageListView()->GetHeightForWidth(GetMessageListView()->width()); | 241 return GetMessageListView()->GetHeightForWidth(GetMessageListView()->width()); |
| 238 } | 242 } |
| 239 | 243 |
| 244 MessageCenterViewTest::Mode | |
| 245 MessageCenterViewTest::GetMessageCenterViewInternalMode() { | |
| 246 return GetMessageCenterView()->mode_; | |
| 247 } | |
| 248 | |
| 240 views::BoundsAnimator* MessageCenterViewTest::GetAnimator() { | 249 views::BoundsAnimator* MessageCenterViewTest::GetAnimator() { |
| 241 return &GetMessageListView()->animator_; | 250 return &GetMessageListView()->animator_; |
| 242 } | 251 } |
| 243 | 252 |
| 244 int MessageCenterViewTest::GetNotificationCount() { | 253 int MessageCenterViewTest::GetNotificationCount() { |
| 245 return 2; | 254 return 2; |
| 246 } | 255 } |
| 247 | 256 |
| 248 int MessageCenterViewTest::GetCallCount(CallType type) { | 257 int MessageCenterViewTest::GetCallCount(CallType type) { |
| 249 return callCounts_[type]; | 258 return callCounts_[type]; |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 | 602 |
| 594 AddNotification( | 603 AddNotification( |
| 595 std::unique_ptr<Notification>(new Notification(pinned_notification))); | 604 std::unique_ptr<Notification>(new Notification(pinned_notification))); |
| 596 | 605 |
| 597 // There should be 1 pinned notification. | 606 // There should be 1 pinned notification. |
| 598 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); | 607 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
| 599 EXPECT_FALSE(close_button->enabled()); | 608 EXPECT_FALSE(close_button->enabled()); |
| 600 #endif // defined(OS_CHROMEOS) | 609 #endif // defined(OS_CHROMEOS) |
| 601 } | 610 } |
| 602 | 611 |
| 612 TEST_F(MessageCenterViewTest, CheckModeWithSettingsVisibleAndHidden) { | |
| 613 // Check the initial state. | |
| 614 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); | |
| 615 // Show the settings. | |
| 616 GetMessageCenterView()->SetSettingsVisible(true); | |
| 617 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); | |
| 618 // Hide the settings. | |
| 619 GetMessageCenterView()->SetSettingsVisible(false); | |
| 620 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); | |
| 621 } | |
| 622 | |
| 623 TEST_F(MessageCenterViewTest, CheckModeWithRemovingAndAddingNotifications) { | |
| 624 // Check the initial state. | |
| 625 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); | |
| 626 | |
| 627 // Remove notifications. | |
| 628 RemoveNotification(kNotificationId1, false); | |
|
dewittj
2016/05/13 19:54:13
nit: make a helper function that just removes all
yoshiki
2016/05/16 15:05:53
Done.
| |
| 629 RemoveNotification(kNotificationId2, false); | |
| 630 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); | |
| 631 | |
| 632 // Add a notification. | |
| 633 Notification normal_notification( | |
| 634 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), | |
| 635 base::UTF8ToUTF16("title2"), | |
| 636 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), | |
| 637 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), | |
| 638 NotifierId(NotifierId::APPLICATION, "extension_id"), | |
| 639 message_center::RichNotificationData(), NULL); | |
| 640 AddNotification( | |
| 641 std::unique_ptr<Notification>(new Notification(normal_notification))); | |
| 642 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); | |
| 643 } | |
| 644 | |
| 645 TEST_F(MessageCenterViewTest, CheckModeWithSettingsVisibleAndHiddenOnEmpty) { | |
| 646 // Set up by removing all existing notifications. | |
| 647 RemoveNotification(kNotificationId1, false); | |
| 648 RemoveNotification(kNotificationId2, false); | |
| 649 | |
| 650 // Check the initial state. | |
| 651 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); | |
| 652 // Show the settings. | |
| 653 GetMessageCenterView()->SetSettingsVisible(true); | |
| 654 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); | |
| 655 // Hide the settings. | |
| 656 GetMessageCenterView()->SetSettingsVisible(false); | |
| 657 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); | |
| 658 } | |
| 659 | |
| 660 TEST_F(MessageCenterViewTest, | |
| 661 CheckModeWithRemovingNotificationDuringSettingsVisible) { | |
| 662 // Check the initial state. | |
| 663 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); | |
| 664 | |
| 665 // Show the settings. | |
| 666 GetMessageCenterView()->SetSettingsVisible(true); | |
| 667 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); | |
| 668 | |
| 669 // Remove a notification during settings is visible. | |
| 670 RemoveNotification(kNotificationId1, false); | |
| 671 RemoveNotification(kNotificationId2, false); | |
| 672 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); | |
| 673 | |
| 674 // Hide the settings. | |
| 675 GetMessageCenterView()->SetSettingsVisible(false); | |
| 676 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); | |
| 677 } | |
| 678 | |
| 679 TEST_F(MessageCenterViewTest, | |
| 680 CheckModeWithAddingNotificationDuringSettingsVisible) { | |
| 681 // Set up by removing all existing notifications. | |
| 682 RemoveNotification(kNotificationId1, false); | |
| 683 RemoveNotification(kNotificationId2, false); | |
| 684 | |
| 685 // Check the initial state. | |
| 686 EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); | |
| 687 | |
| 688 // Show the settings. | |
| 689 GetMessageCenterView()->SetSettingsVisible(true); | |
| 690 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); | |
| 691 | |
| 692 // Add a notification during settings is visible. | |
| 693 Notification normal_notification( | |
| 694 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), | |
| 695 base::UTF8ToUTF16("title2"), | |
| 696 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), | |
| 697 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), | |
| 698 NotifierId(NotifierId::APPLICATION, "extension_id"), | |
| 699 message_center::RichNotificationData(), NULL); | |
| 700 AddNotification( | |
| 701 std::unique_ptr<Notification>(new Notification(normal_notification))); | |
| 702 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); | |
| 703 | |
| 704 // Hide the settings. | |
| 705 GetMessageCenterView()->SetSettingsVisible(false); | |
| 706 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); | |
| 707 } | |
| 708 | |
| 603 } // namespace message_center | 709 } // namespace message_center |
| OLD | NEW |