| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 const NotificationList::Notifications& GetVisibleNotifications() override { | 100 const NotificationList::Notifications& GetVisibleNotifications() override { |
| 101 return visible_notifications_; | 101 return visible_notifications_; |
| 102 } | 102 } |
| 103 void SetVisibleNotifications(NotificationList::Notifications notifications) { | 103 void SetVisibleNotifications(NotificationList::Notifications notifications) { |
| 104 visible_notifications_ = notifications; | 104 visible_notifications_ = notifications; |
| 105 } | 105 } |
| 106 void RemoveAllNotifications(bool by_user, RemoveType type) override { | 106 void RemoveAllNotifications(bool by_user, RemoveType type) override { |
| 107 if (type == RemoveType::NON_PINNED) | 107 if (type == RemoveType::NON_PINNED) |
| 108 remove_all_closable_notification_called_ = true; | 108 remove_all_closable_notification_called_ = true; |
| 109 } | 109 } |
| 110 bool IsLockedState() const override { return locked_; } |
| 110 bool remove_all_closable_notification_called_ = false; | 111 bool remove_all_closable_notification_called_ = false; |
| 111 NotificationList::Notifications visible_notifications_; | 112 NotificationList::Notifications visible_notifications_; |
| 113 bool locked_ = false; |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 /* Test fixture ***************************************************************/ | 116 /* Test fixture ***************************************************************/ |
| 115 | 117 |
| 116 class MessageCenterViewTest : public views::ViewsTestBase, | 118 class MessageCenterViewTest : public views::ViewsTestBase, |
| 117 public MockNotificationView::Test, | 119 public MockNotificationView::Test, |
| 118 public MessageCenterController { | 120 public MessageCenterController { |
| 119 public: | 121 public: |
| 120 // Expose the private enum class MessageCenter::Mode for this test. | 122 // Expose the private enum class MessageCenter::Mode for this test. |
| 121 typedef MessageCenterView::Mode Mode; | 123 typedef MessageCenterView::Mode Mode; |
| 122 | 124 |
| 123 MessageCenterViewTest(); | 125 MessageCenterViewTest(); |
| 124 ~MessageCenterViewTest() override; | 126 ~MessageCenterViewTest() override; |
| 125 | 127 |
| 126 void SetUp() override; | 128 void SetUp() override; |
| 127 void TearDown() override; | 129 void TearDown() override; |
| 128 | 130 |
| 129 MessageCenterView* GetMessageCenterView(); | 131 MessageCenterView* GetMessageCenterView(); |
| 130 MessageListView* GetMessageListView(); | 132 MessageListView* GetMessageListView(); |
| 131 FakeMessageCenterImpl* GetMessageCenter() const; | 133 FakeMessageCenterImpl* GetMessageCenter() const; |
| 132 MessageView* GetNotificationView(const std::string& id); | 134 MessageView* GetNotificationView(const std::string& id); |
| 133 views::BoundsAnimator* GetAnimator(); | 135 views::BoundsAnimator* GetAnimator(); |
| 134 int GetNotificationCount(); | 136 int GetNotificationCount(); |
| 135 int GetCallCount(CallType type); | 137 int GetCallCount(CallType type); |
| 136 int GetCalculatedMessageListViewHeight(); | 138 int GetCalculatedMessageListViewHeight(); |
| 139 void SetLockedState(bool locked); |
| 137 Mode GetMessageCenterViewInternalMode(); | 140 Mode GetMessageCenterViewInternalMode(); |
| 138 void AddNotification(std::unique_ptr<Notification> notification); | 141 void AddNotification(std::unique_ptr<Notification> notification); |
| 139 void UpdateNotification(const std::string& notification_id, | 142 void UpdateNotification(const std::string& notification_id, |
| 140 std::unique_ptr<Notification> notification); | 143 std::unique_ptr<Notification> notification); |
| 141 | 144 |
| 142 // Overridden from MessageCenterController: | 145 // Overridden from MessageCenterController: |
| 143 void ClickOnNotification(const std::string& notification_id) override; | 146 void ClickOnNotification(const std::string& notification_id) override; |
| 144 void RemoveNotification(const std::string& notification_id, | 147 void RemoveNotification(const std::string& notification_id, |
| 145 bool by_user) override; | 148 bool by_user) override; |
| 146 std::unique_ptr<ui::MenuModel> CreateMenuModel( | 149 std::unique_ptr<ui::MenuModel> CreateMenuModel( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 159 void LogBounds(int depth, views::View* view); | 162 void LogBounds(int depth, views::View* view); |
| 160 | 163 |
| 161 MessageCenterButtonBar* GetButtonBar() const; | 164 MessageCenterButtonBar* GetButtonBar() const; |
| 162 | 165 |
| 163 void RemoveDefaultNotifications(); | 166 void RemoveDefaultNotifications(); |
| 164 | 167 |
| 165 private: | 168 private: |
| 166 views::View* MakeParent(views::View* child1, views::View* child2); | 169 views::View* MakeParent(views::View* child1, views::View* child2); |
| 167 | 170 |
| 168 NotificationList::Notifications notifications_; | 171 NotificationList::Notifications notifications_; |
| 172 std::unique_ptr<views::Widget> widget_; |
| 169 std::unique_ptr<MessageCenterView> message_center_view_; | 173 std::unique_ptr<MessageCenterView> message_center_view_; |
| 170 std::unique_ptr<FakeMessageCenterImpl> message_center_; | 174 std::unique_ptr<FakeMessageCenterImpl> message_center_; |
| 171 std::map<CallType,int> callCounts_; | 175 std::map<CallType,int> callCounts_; |
| 172 | 176 |
| 173 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); | 177 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); |
| 174 }; | 178 }; |
| 175 | 179 |
| 176 MessageCenterViewTest::MessageCenterViewTest() { | 180 MessageCenterViewTest::MessageCenterViewTest() { |
| 177 } | 181 } |
| 178 | 182 |
| 179 MessageCenterViewTest::~MessageCenterViewTest() { | 183 MessageCenterViewTest::~MessageCenterViewTest() { |
| 180 } | 184 } |
| 181 | 185 |
| 182 void MessageCenterViewTest::SetUp() { | 186 void MessageCenterViewTest::SetUp() { |
| 183 views::ViewsTestBase::SetUp(); | 187 views::ViewsTestBase::SetUp(); |
| 188 MessageCenterView::disable_animation_for_testing = true; |
| 184 message_center_.reset(new FakeMessageCenterImpl()); | 189 message_center_.reset(new FakeMessageCenterImpl()); |
| 185 | 190 |
| 186 // Create a dummy notification. | 191 // Create a dummy notification. |
| 187 Notification* notification1 = new Notification( | 192 Notification* notification1 = new Notification( |
| 188 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), | 193 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), |
| 189 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message1"), gfx::Image(), | 194 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message1"), gfx::Image(), |
| 190 base::UTF8ToUTF16("display source"), GURL(), | 195 base::UTF8ToUTF16("display source"), GURL(), |
| 191 NotifierId(NotifierId::APPLICATION, "extension_id"), | 196 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 192 message_center::RichNotificationData(), NULL); | 197 message_center::RichNotificationData(), NULL); |
| 193 | 198 |
| 194 Notification* notification2 = new Notification( | 199 Notification* notification2 = new Notification( |
| 195 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), | 200 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), |
| 196 base::UTF8ToUTF16("title2"), base::UTF8ToUTF16("message2"), gfx::Image(), | 201 base::UTF8ToUTF16("title2"), base::UTF8ToUTF16("message2"), gfx::Image(), |
| 197 base::UTF8ToUTF16("display source"), GURL(), | 202 base::UTF8ToUTF16("display source"), GURL(), |
| 198 NotifierId(NotifierId::APPLICATION, "extension_id"), | 203 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 199 message_center::RichNotificationData(), NULL); | 204 message_center::RichNotificationData(), NULL); |
| 200 | 205 |
| 201 // ...and a list for it. | 206 // ...and a list for it. |
| 202 notifications_.insert(notification1); | 207 notifications_.insert(notification1); |
| 203 notifications_.insert(notification2); | 208 notifications_.insert(notification2); |
| 204 message_center_->SetVisibleNotifications(notifications_); | 209 message_center_->SetVisibleNotifications(notifications_); |
| 205 | 210 |
| 206 // Then create a new MessageCenterView with that single notification. | 211 // Then create a new MessageCenterView with that single notification. |
| 207 message_center_view_.reset(new MessageCenterView( | 212 message_center_view_.reset(new MessageCenterView( |
| 208 message_center_.get(), NULL, 100, false, /*top_down =*/false)); | 213 message_center_.get(), NULL, 100, false, /*top_down =*/false)); |
| 209 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true; | 214 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true; |
| 210 GetMessageCenterView()->SetBounds(0, 0, 380, 600); | 215 GetMessageCenterView()->SetBounds(0, 0, 380, 600); |
| 211 message_center_view_->SetNotifications(notifications_); | 216 message_center_view_->SetNotifications(notifications_); |
| 217 message_center_view_->set_owned_by_client(); |
| 218 |
| 219 widget_.reset(new views::Widget()); |
| 220 views::Widget::InitParams params = |
| 221 CreateParams(views::Widget::InitParams::TYPE_POPUP); |
| 222 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 223 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 224 widget_->Init(params); |
| 225 views::View* root = widget_->GetRootView(); |
| 226 root->AddChildView(message_center_view_.get()); |
| 227 widget_->Show(); |
| 228 widget_->Activate(); |
| 212 | 229 |
| 213 // Wait until the animation finishes if available. | 230 // Wait until the animation finishes if available. |
| 214 if (GetAnimator()->IsAnimating()) | 231 if (GetAnimator()->IsAnimating()) |
| 215 base::MessageLoop::current()->Run(); | 232 base::MessageLoop::current()->Run(); |
| 216 } | 233 } |
| 217 | 234 |
| 218 void MessageCenterViewTest::TearDown() { | 235 void MessageCenterViewTest::TearDown() { |
| 236 widget_->CloseNow(); |
| 237 widget_.reset(); |
| 219 message_center_view_.reset(); | 238 message_center_view_.reset(); |
| 220 STLDeleteElements(¬ifications_); | 239 STLDeleteElements(¬ifications_); |
| 221 views::ViewsTestBase::TearDown(); | 240 views::ViewsTestBase::TearDown(); |
| 222 } | 241 } |
| 223 | 242 |
| 224 MessageCenterView* MessageCenterViewTest::GetMessageCenterView() { | 243 MessageCenterView* MessageCenterViewTest::GetMessageCenterView() { |
| 225 return message_center_view_.get(); | 244 return message_center_view_.get(); |
| 226 } | 245 } |
| 227 | 246 |
| 228 MessageListView* MessageCenterViewTest::GetMessageListView() { | 247 MessageListView* MessageCenterViewTest::GetMessageListView() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 251 } | 270 } |
| 252 | 271 |
| 253 int MessageCenterViewTest::GetNotificationCount() { | 272 int MessageCenterViewTest::GetNotificationCount() { |
| 254 return 2; | 273 return 2; |
| 255 } | 274 } |
| 256 | 275 |
| 257 int MessageCenterViewTest::GetCallCount(CallType type) { | 276 int MessageCenterViewTest::GetCallCount(CallType type) { |
| 258 return callCounts_[type]; | 277 return callCounts_[type]; |
| 259 } | 278 } |
| 260 | 279 |
| 280 void MessageCenterViewTest::SetLockedState(bool locked) { |
| 281 GetMessageCenterView()->OnLockedStateChanged(locked); |
| 282 } |
| 283 |
| 261 void MessageCenterViewTest::ClickOnNotification( | 284 void MessageCenterViewTest::ClickOnNotification( |
| 262 const std::string& notification_id) { | 285 const std::string& notification_id) { |
| 263 // For this test, this method should not be invoked. | 286 // For this test, this method should not be invoked. |
| 264 NOTREACHED(); | 287 NOTREACHED(); |
| 265 } | 288 } |
| 266 | 289 |
| 267 void MessageCenterViewTest::AddNotification( | 290 void MessageCenterViewTest::AddNotification( |
| 268 std::unique_ptr<Notification> notification) { | 291 std::unique_ptr<Notification> notification) { |
| 269 std::string notification_id = notification->id(); | 292 std::string notification_id = notification->id(); |
| 270 notifications_.insert(notification.release()); | 293 notifications_.insert(notification.release()); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 message_center::RichNotificationData(), NULL); | 723 message_center::RichNotificationData(), NULL); |
| 701 AddNotification( | 724 AddNotification( |
| 702 std::unique_ptr<Notification>(new Notification(normal_notification))); | 725 std::unique_ptr<Notification>(new Notification(normal_notification))); |
| 703 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); | 726 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); |
| 704 | 727 |
| 705 // Hide the settings. | 728 // Hide the settings. |
| 706 GetMessageCenterView()->SetSettingsVisible(false); | 729 GetMessageCenterView()->SetSettingsVisible(false); |
| 707 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); | 730 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); |
| 708 } | 731 } |
| 709 | 732 |
| 733 TEST_F(MessageCenterViewTest, LockScreen) { |
| 734 const int kLockedMessageCenterViewHeight = 50; |
| 735 |
| 736 EXPECT_TRUE(GetNotificationView(kNotificationId1)->IsDrawn()); |
| 737 EXPECT_TRUE(GetNotificationView(kNotificationId2)->IsDrawn()); |
| 738 |
| 739 // Lock! |
| 740 SetLockedState(true); |
| 741 |
| 742 EXPECT_FALSE(GetNotificationView(kNotificationId1)->IsDrawn()); |
| 743 EXPECT_FALSE(GetNotificationView(kNotificationId2)->IsDrawn()); |
| 744 |
| 745 GetMessageCenterView()->SizeToPreferredSize(); |
| 746 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 747 |
| 748 RemoveNotification(kNotificationId1, false); |
| 749 |
| 750 GetMessageCenterView()->SizeToPreferredSize(); |
| 751 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 752 |
| 753 RemoveNotification(kNotificationId2, false); |
| 754 |
| 755 GetMessageCenterView()->SizeToPreferredSize(); |
| 756 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 757 |
| 758 AddNotification(std::unique_ptr<Notification>(new Notification( |
| 759 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), |
| 760 base::UTF8ToUTF16("title1"), |
| 761 base::UTF8ToUTF16("message"), |
| 762 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
| 763 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 764 message_center::RichNotificationData(), NULL))); |
| 765 EXPECT_FALSE(GetNotificationView(kNotificationId1)->IsDrawn()); |
| 766 |
| 767 GetMessageCenterView()->SizeToPreferredSize(); |
| 768 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 769 |
| 770 // Unlock! |
| 771 SetLockedState(false); |
| 772 |
| 773 EXPECT_TRUE(GetNotificationView(kNotificationId1)->IsDrawn()); |
| 774 |
| 775 GetMessageCenterView()->SizeToPreferredSize(); |
| 776 EXPECT_NE(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 777 |
| 778 // Lock! |
| 779 SetLockedState(true); |
| 780 |
| 781 EXPECT_FALSE(GetNotificationView(kNotificationId1)->IsDrawn()); |
| 782 |
| 783 GetMessageCenterView()->SizeToPreferredSize(); |
| 784 EXPECT_EQ(kLockedMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 785 } |
| 786 |
| 787 TEST_F(MessageCenterViewTest, NoNotification) { |
| 788 const int kEmptyMessageCenterViewHeight = 50; |
| 789 |
| 790 GetMessageCenterView()->SizeToPreferredSize(); |
| 791 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 792 RemoveNotification(kNotificationId1, false); |
| 793 GetMessageCenterView()->SizeToPreferredSize(); |
| 794 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 795 RemoveNotification(kNotificationId2, false); |
| 796 GetMessageCenterView()->SizeToPreferredSize(); |
| 797 EXPECT_EQ(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 798 |
| 799 AddNotification(std::unique_ptr<Notification>(new Notification( |
| 800 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), |
| 801 base::UTF8ToUTF16("title1"), |
| 802 base::UTF8ToUTF16("message"), |
| 803 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
| 804 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 805 message_center::RichNotificationData(), NULL))); |
| 806 |
| 807 GetMessageCenterView()->SizeToPreferredSize(); |
| 808 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 809 } |
| 810 |
| 710 } // namespace message_center | 811 } // namespace message_center |
| OLD | NEW |