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

Unified Diff: ui/message_center/views/message_center_view_unittest.cc

Issue 1961803002: Remove NoNotificationMessageView from empty message center (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/message_center/views/message_center_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 79b2d1113cbf030b70dd565c079ae6570d8096cd..b60f144c61c450ac40741aaa150e9cd42f5bedaa 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);
@@ -156,6 +160,8 @@ class MessageCenterViewTest : public views::ViewsTestBase,
MessageCenterButtonBar* GetButtonBar() const;
+ void RemoveDefaultNotifications();
+
private:
views::View* MakeParent(views::View* child1, views::View* child2);
@@ -235,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_;
}
@@ -347,6 +358,11 @@ MessageCenterButtonBar* MessageCenterViewTest::GetButtonBar() const {
return message_center_view_->button_bar_;
}
+void MessageCenterViewTest::RemoveDefaultNotifications() {
+ RemoveNotification(kNotificationId1, false);
+ RemoveNotification(kNotificationId2, false);
+}
+
/* Unit tests *****************************************************************/
TEST_F(MessageCenterViewTest, CallTest) {
@@ -598,4 +614,97 @@ 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.
+ RemoveDefaultNotifications();
+ 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.
+ RemoveDefaultNotifications();
+
+ // 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.
+ RemoveDefaultNotifications();
+ 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.
+ RemoveDefaultNotifications();
+
+ // 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
« no previous file with comments | « ui/message_center/views/message_center_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698