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 d412cb044167d77d2fff8f898175825ff41e5a0a..1d592a3312c9f6911fb6616f1f91310f46f30d7e 100644 |
--- a/ui/message_center/views/message_center_view_unittest.cc |
+++ b/ui/message_center/views/message_center_view_unittest.cc |
@@ -17,9 +17,11 @@ |
#include "ui/message_center/notification.h" |
#include "ui/message_center/notification_list.h" |
#include "ui/message_center/notification_types.h" |
+#include "ui/message_center/views/message_center_button_bar.h" |
#include "ui/message_center/views/message_center_controller.h" |
#include "ui/message_center/views/message_list_view.h" |
#include "ui/message_center/views/notification_view.h" |
+#include "ui/views/controls/slide_out_view.h" |
namespace message_center { |
@@ -34,6 +36,12 @@ enum CallType { |
LAYOUT |
}; |
+class DummyEvent : public ui::Event { |
+ public: |
+ DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {} |
+ ~DummyEvent() override {} |
+}; |
+ |
/* Instrumented/Mock NotificationView subclass ********************************/ |
class MockNotificationView : public NotificationView { |
@@ -94,6 +102,11 @@ class FakeMessageCenterImpl : public FakeMessageCenter { |
void SetVisibleNotifications(NotificationList::Notifications notifications) { |
visible_notifications_ = notifications; |
} |
+ void RemoveAllNotifications(bool by_user, RemoveType type) override { |
+ if (type == RemoveType::NON_PINNED) |
+ remove_all_closable_notification_called_ = true; |
+ } |
+ bool remove_all_closable_notification_called_ = false; |
NotificationList::Notifications visible_notifications_; |
}; |
@@ -111,6 +124,7 @@ class MessageCenterViewTest : public testing::Test, |
MessageCenterView* GetMessageCenterView(); |
MessageListView* GetMessageListView(); |
+ FakeMessageCenterImpl* GetMessageCenter() const; |
NotificationView* GetNotificationView(const std::string& id); |
views::BoundsAnimator* GetAnimator(); |
int GetNotificationCount(); |
@@ -139,6 +153,8 @@ class MessageCenterViewTest : public testing::Test, |
void LogBounds(int depth, views::View* view); |
+ MessageCenterButtonBar* GetButtonBar() const; |
+ |
private: |
views::View* MakeParent(views::View* child1, views::View* child2); |
@@ -146,7 +162,7 @@ class MessageCenterViewTest : public testing::Test, |
NotificationList::Notifications notifications_; |
scoped_ptr<MessageCenterView> message_center_view_; |
- FakeMessageCenterImpl message_center_; |
+ scoped_ptr<FakeMessageCenterImpl> message_center_; |
std::map<CallType,int> callCounts_; |
DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); |
@@ -159,6 +175,8 @@ MessageCenterViewTest::~MessageCenterViewTest() { |
} |
void MessageCenterViewTest::SetUp() { |
+ message_center_.reset(new FakeMessageCenterImpl()); |
+ |
// Create a dummy notification. |
Notification* notification1 = new Notification( |
NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), |
@@ -177,12 +195,12 @@ void MessageCenterViewTest::SetUp() { |
// ...and a list for it. |
notifications_.insert(notification1); |
notifications_.insert(notification2); |
- message_center_.SetVisibleNotifications(notifications_); |
+ message_center_->SetVisibleNotifications(notifications_); |
// Then create a new MessageCenterView with that single notification. |
base::string16 title; |
message_center_view_.reset(new MessageCenterView( |
- &message_center_, NULL, 100, false, /*top_down =*/false, title)); |
+ message_center_.get(), NULL, 100, false, /*top_down =*/false, title)); |
GetMessageListView()->quit_message_loop_after_animation_for_test_ = true; |
GetMessageCenterView()->SetBounds(0, 0, 380, 600); |
message_center_view_->SetNotifications(notifications_); |
@@ -205,6 +223,10 @@ MessageListView* MessageCenterViewTest::GetMessageListView() { |
return message_center_view_->message_list_view_.get(); |
} |
+FakeMessageCenterImpl* MessageCenterViewTest::GetMessageCenter() const { |
+ return message_center_.get(); |
+} |
+ |
NotificationView* MessageCenterViewTest::GetNotificationView( |
const std::string& id) { |
return message_center_view_->notification_views_[id]; |
@@ -236,7 +258,7 @@ void MessageCenterViewTest::AddNotification( |
scoped_ptr<Notification> notification) { |
std::string notification_id = notification->id(); |
notifications_.insert(notification.release()); |
- message_center_.SetVisibleNotifications(notifications_); |
+ message_center_->SetVisibleNotifications(notifications_); |
message_center_view_->OnNotificationAdded(notification_id); |
} |
@@ -253,7 +275,7 @@ void MessageCenterViewTest::UpdateNotification( |
// |notifications| is a "set" container so we don't need to be aware the |
// order. |
notifications_.insert(notification.release()); |
- message_center_.SetVisibleNotifications(notifications_); |
+ message_center_->SetVisibleNotifications(notifications_); |
message_center_view_->OnNotificationUpdated(notification_id); |
} |
@@ -267,7 +289,7 @@ void MessageCenterViewTest::RemoveNotification( |
break; |
} |
} |
- message_center_.SetVisibleNotifications(notifications_); |
+ message_center_->SetVisibleNotifications(notifications_); |
message_center_view_->OnNotificationRemoved(notification_id, by_user); |
} |
@@ -322,6 +344,10 @@ void MessageCenterViewTest::LogBounds(int depth, views::View* view) { |
LogBounds(depth + 1, view->child_at(i)); |
} |
+MessageCenterButtonBar* MessageCenterViewTest::GetButtonBar() const { |
+ return message_center_view_->button_bar_; |
+} |
+ |
/* Unit tests *****************************************************************/ |
TEST_F(MessageCenterViewTest, CallTest) { |
@@ -488,4 +514,89 @@ TEST_F(MessageCenterViewTest, PositionAfterRemove) { |
GetMessageListView()->height()); |
} |
+TEST_F(MessageCenterViewTest, CloseButton) { |
+ views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest(); |
+ EXPECT_NE(nullptr, close_button); |
+ |
+ ((views::ButtonListener*)GetButtonBar()) |
+ ->ButtonPressed(close_button, DummyEvent()); |
+ base::MessageLoop::current()->Run(); |
+ EXPECT_TRUE(GetMessageCenter()->remove_all_closable_notification_called_); |
+} |
+ |
+TEST_F(MessageCenterViewTest, CloseButtonEnablity) { |
+ views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest(); |
+ EXPECT_NE(nullptr, close_button); |
+ |
+ // There should be 2 non-pinned notifications. |
+ EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ EXPECT_TRUE(close_button->enabled()); |
+ |
+ RemoveNotification(kNotificationId1, false); |
+ base::MessageLoop::current()->Run(); |
+ |
+ // There should be 1 non-pinned notification. |
+ EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ EXPECT_TRUE(close_button->enabled()); |
+ |
+ RemoveNotification(kNotificationId2, false); |
+ base::MessageLoop::current()->Run(); |
+ |
+ // There should be no notification. |
+ EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ EXPECT_FALSE(close_button->enabled()); |
+ |
+ 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); |
+ |
+#if defined(OS_CHROMEOS) |
+ Notification pinned_notification( |
+ NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), |
+ 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); |
+ pinned_notification.set_pinned(true); |
+ |
+ AddNotification( |
+ scoped_ptr<Notification>(new Notification(normal_notification))); |
+ |
+ // There should be 1 non-pinned notification. |
+ EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ EXPECT_TRUE(close_button->enabled()); |
+ |
+ AddNotification( |
+ scoped_ptr<Notification>(new Notification(pinned_notification))); |
+ |
+ // There should be 1 normal notification and 1 pinned notification. |
+ EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ EXPECT_TRUE(close_button->enabled()); |
+ |
+ RemoveNotification(kNotificationId1, false); |
+ |
+ // There should be 1 pinned notification. |
+ EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ EXPECT_FALSE(close_button->enabled()); |
+ |
+ RemoveNotification(kNotificationId2, false); |
+ |
+ // There should be no notification. |
+ EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ EXPECT_FALSE(close_button->enabled()); |
+ |
+ AddNotification( |
+ scoped_ptr<Notification>(new Notification(pinned_notification))); |
+ |
+ // There should be 1 pinned notification. |
+ EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ EXPECT_FALSE(close_button->enabled()); |
+#endif // defined(OS_CHROMEOS) |
+} |
+ |
} // namespace message_center |