| 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..03ae24a71d0d6045581bf1cd5a6958c82492ad5e 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,10 @@ class FakeMessageCenterImpl : public FakeMessageCenter {
 | 
|    void SetVisibleNotifications(NotificationList::Notifications notifications) {
 | 
|      visible_notifications_ = notifications;
 | 
|    }
 | 
| +  void RemoveAllClosableNotifications(bool by_user) override {
 | 
| +    remove_all_closable_notification_called_ = true;
 | 
| +  }
 | 
| +  bool remove_all_closable_notification_called_ = false;
 | 
|    NotificationList::Notifications visible_notifications_;
 | 
|  };
 | 
|  
 | 
| @@ -111,6 +123,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 +152,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 +161,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 +174,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 +194,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 +222,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 +257,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 +274,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 +288,7 @@ void MessageCenterViewTest::RemoveNotification(
 | 
|        break;
 | 
|      }
 | 
|    }
 | 
| -  message_center_.SetVisibleNotifications(notifications_);
 | 
| +  message_center_->SetVisibleNotifications(notifications_);
 | 
|    message_center_view_->OnNotificationRemoved(notification_id, by_user);
 | 
|  }
 | 
|  
 | 
| @@ -322,6 +343,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 +513,86 @@ TEST_F(MessageCenterViewTest, PositionAfterRemove) {
 | 
|              GetMessageListView()->height());
 | 
|  }
 | 
|  
 | 
| +TEST_F(MessageCenterViewTest, CloseButton) {
 | 
| +  views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest();
 | 
| +  EXPECT_NE(nullptr, close_button);
 | 
| +
 | 
| +  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 closable notifications.
 | 
| +  EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size());
 | 
| +  EXPECT_TRUE(close_button->enabled());
 | 
| +
 | 
| +  RemoveNotification(kNotificationId1, false);
 | 
| +  base::MessageLoop::current()->Run();
 | 
| +
 | 
| +  // There should be 1 closable 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 closable_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);
 | 
| +
 | 
| +  Notification nonclosable_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);
 | 
| +  nonclosable_notification.set_closable(false);
 | 
| +
 | 
| +  AddNotification(scoped_ptr<Notification>(
 | 
| +        new Notification(closable_notification)));
 | 
| +
 | 
| +  // There should be 1 closable notification.
 | 
| +  EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
 | 
| +  EXPECT_TRUE(close_button->enabled());
 | 
| +
 | 
| +  AddNotification(scoped_ptr<Notification>(
 | 
| +        new Notification(nonclosable_notification)));
 | 
| +
 | 
| +  // There should be 1 closable notification and 1 nonclosable notification.
 | 
| +  EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size());
 | 
| +  EXPECT_TRUE(close_button->enabled());
 | 
| +
 | 
| +  RemoveNotification(kNotificationId1, false);
 | 
| +
 | 
| +  // There should be 1 nonclosable 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(nonclosable_notification)));
 | 
| +
 | 
| +  // There should be 1 nonclosable notification.
 | 
| +  EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
 | 
| +  EXPECT_FALSE(close_button->enabled());
 | 
| +}
 | 
| +
 | 
|  }  // namespace message_center
 | 
| 
 |