Chromium Code Reviews| Index: ui/message_center/views/message_center_view_unittest.cc |
| diff --git a/ui/message_center/views/message_center_view_unittest.cc b/ui/message_center/views/message_center_view_unittest.cc |
| index 27883ae9fbce79faa9208a4ca8b205d0cc2ecfd9..a211641267346532015675993699773d9090fbb0 100644 |
| --- a/ui/message_center/views/message_center_view_unittest.cc |
| +++ b/ui/message_center/views/message_center_view_unittest.cc |
| @@ -117,6 +117,9 @@ class MessageCenterViewTest : public views::ViewsTestBase, |
| public MockNotificationView::Test, |
| public MessageCenterController { |
| public: |
| + // Expose the private enum class MessageCenter::Mode for this test. |
| + typedef MessageCenterView::Mode Mode; |
| + |
| MessageCenterViewTest(); |
| ~MessageCenterViewTest() override; |
| @@ -131,6 +134,7 @@ class MessageCenterViewTest : public views::ViewsTestBase, |
| int GetNotificationCount(); |
| int GetCallCount(CallType type); |
| int GetCalculatedMessageListViewHeight(); |
| + Mode GetMessageCenterViewInternalMode(); |
| void AddNotification(std::unique_ptr<Notification> notification); |
| void UpdateNotification(const std::string& notification_id, |
| std::unique_ptr<Notification> notification); |
| @@ -237,6 +241,11 @@ int MessageCenterViewTest::GetCalculatedMessageListViewHeight() { |
| return GetMessageListView()->GetHeightForWidth(GetMessageListView()->width()); |
| } |
| +MessageCenterViewTest::Mode |
| +MessageCenterViewTest::GetMessageCenterViewInternalMode() { |
| + return GetMessageCenterView()->mode_; |
| +} |
| + |
| views::BoundsAnimator* MessageCenterViewTest::GetAnimator() { |
| return &GetMessageListView()->animator_; |
| } |
| @@ -600,4 +609,101 @@ TEST_F(MessageCenterViewTest, CloseButtonEnablity) { |
| #endif // defined(OS_CHROMEOS) |
| } |
| +TEST_F(MessageCenterViewTest, CheckModeWithSettingsVisibleAndHidden) { |
| + // Check the initial state. |
| + EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); |
| + // Show the settings. |
| + GetMessageCenterView()->SetSettingsVisible(true); |
| + EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); |
| + // Hide the settings. |
| + GetMessageCenterView()->SetSettingsVisible(false); |
| + EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); |
| +} |
| + |
| +TEST_F(MessageCenterViewTest, CheckModeWithRemovingAndAddingNotifications) { |
| + // Check the initial state. |
| + EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); |
| + |
| + // Remove notifications. |
| + 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.
|
| + RemoveNotification(kNotificationId2, false); |
| + EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); |
| + |
| + // Add a notification. |
| + Notification normal_notification( |
| + NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), |
| + base::UTF8ToUTF16("title2"), |
| + base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), |
| + gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
| + NotifierId(NotifierId::APPLICATION, "extension_id"), |
| + message_center::RichNotificationData(), NULL); |
| + AddNotification( |
| + std::unique_ptr<Notification>(new Notification(normal_notification))); |
| + EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); |
| +} |
| + |
| +TEST_F(MessageCenterViewTest, CheckModeWithSettingsVisibleAndHiddenOnEmpty) { |
| + // Set up by removing all existing notifications. |
| + RemoveNotification(kNotificationId1, false); |
| + RemoveNotification(kNotificationId2, false); |
| + |
| + // Check the initial state. |
| + EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); |
| + // Show the settings. |
| + GetMessageCenterView()->SetSettingsVisible(true); |
| + EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); |
| + // Hide the settings. |
| + GetMessageCenterView()->SetSettingsVisible(false); |
| + EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); |
| +} |
| + |
| +TEST_F(MessageCenterViewTest, |
| + CheckModeWithRemovingNotificationDuringSettingsVisible) { |
| + // Check the initial state. |
| + EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); |
| + |
| + // Show the settings. |
| + GetMessageCenterView()->SetSettingsVisible(true); |
| + EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); |
| + |
| + // Remove a notification during settings is visible. |
| + RemoveNotification(kNotificationId1, false); |
| + RemoveNotification(kNotificationId2, false); |
| + EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); |
| + |
| + // Hide the settings. |
| + GetMessageCenterView()->SetSettingsVisible(false); |
| + EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); |
| +} |
| + |
| +TEST_F(MessageCenterViewTest, |
| + CheckModeWithAddingNotificationDuringSettingsVisible) { |
| + // Set up by removing all existing notifications. |
| + RemoveNotification(kNotificationId1, false); |
| + RemoveNotification(kNotificationId2, false); |
| + |
| + // Check the initial state. |
| + EXPECT_EQ(Mode::BUTTONS_ONLY, GetMessageCenterViewInternalMode()); |
| + |
| + // Show the settings. |
| + GetMessageCenterView()->SetSettingsVisible(true); |
| + EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); |
| + |
| + // Add a notification during settings is visible. |
| + Notification normal_notification( |
| + NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), |
| + base::UTF8ToUTF16("title2"), |
| + base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), |
| + gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
| + NotifierId(NotifierId::APPLICATION, "extension_id"), |
| + message_center::RichNotificationData(), NULL); |
| + AddNotification( |
| + std::unique_ptr<Notification>(new Notification(normal_notification))); |
| + EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); |
| + |
| + // Hide the settings. |
| + GetMessageCenterView()->SetSettingsVisible(false); |
| + EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); |
| +} |
| + |
| } // namespace message_center |