| 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_; } | |
| 111 bool remove_all_closable_notification_called_ = false; | 110 bool remove_all_closable_notification_called_ = false; |
| 112 NotificationList::Notifications visible_notifications_; | 111 NotificationList::Notifications visible_notifications_; |
| 113 bool locked_ = false; | |
| 114 }; | 112 }; |
| 115 | 113 |
| 116 /* Test fixture ***************************************************************/ | 114 /* Test fixture ***************************************************************/ |
| 117 | 115 |
| 118 class MessageCenterViewTest : public views::ViewsTestBase, | 116 class MessageCenterViewTest : public views::ViewsTestBase, |
| 119 public MockNotificationView::Test, | 117 public MockNotificationView::Test, |
| 120 public MessageCenterController { | 118 public MessageCenterController { |
| 121 public: | 119 public: |
| 122 // Expose the private enum class MessageCenter::Mode for this test. | 120 // Expose the private enum class MessageCenter::Mode for this test. |
| 123 typedef MessageCenterView::Mode Mode; | 121 typedef MessageCenterView::Mode Mode; |
| 124 | 122 |
| 125 MessageCenterViewTest(); | 123 MessageCenterViewTest(); |
| 126 ~MessageCenterViewTest() override; | 124 ~MessageCenterViewTest() override; |
| 127 | 125 |
| 128 void SetUp() override; | 126 void SetUp() override; |
| 129 void TearDown() override; | 127 void TearDown() override; |
| 130 | 128 |
| 131 MessageCenterView* GetMessageCenterView(); | 129 MessageCenterView* GetMessageCenterView(); |
| 132 MessageListView* GetMessageListView(); | 130 MessageListView* GetMessageListView(); |
| 133 FakeMessageCenterImpl* GetMessageCenter() const; | 131 FakeMessageCenterImpl* GetMessageCenter() const; |
| 134 MessageView* GetNotificationView(const std::string& id); | 132 MessageView* GetNotificationView(const std::string& id); |
| 135 views::BoundsAnimator* GetAnimator(); | 133 views::BoundsAnimator* GetAnimator(); |
| 136 int GetNotificationCount(); | 134 int GetNotificationCount(); |
| 137 int GetCallCount(CallType type); | 135 int GetCallCount(CallType type); |
| 138 int GetCalculatedMessageListViewHeight(); | 136 int GetCalculatedMessageListViewHeight(); |
| 139 void SetLockedState(bool locked); | |
| 140 Mode GetMessageCenterViewInternalMode(); | 137 Mode GetMessageCenterViewInternalMode(); |
| 141 void AddNotification(std::unique_ptr<Notification> notification); | 138 void AddNotification(std::unique_ptr<Notification> notification); |
| 142 void UpdateNotification(const std::string& notification_id, | 139 void UpdateNotification(const std::string& notification_id, |
| 143 std::unique_ptr<Notification> notification); | 140 std::unique_ptr<Notification> notification); |
| 144 | 141 |
| 145 // Overridden from MessageCenterController: | 142 // Overridden from MessageCenterController: |
| 146 void ClickOnNotification(const std::string& notification_id) override; | 143 void ClickOnNotification(const std::string& notification_id) override; |
| 147 void RemoveNotification(const std::string& notification_id, | 144 void RemoveNotification(const std::string& notification_id, |
| 148 bool by_user) override; | 145 bool by_user) override; |
| 149 std::unique_ptr<ui::MenuModel> CreateMenuModel( | 146 std::unique_ptr<ui::MenuModel> CreateMenuModel( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 162 void LogBounds(int depth, views::View* view); | 159 void LogBounds(int depth, views::View* view); |
| 163 | 160 |
| 164 MessageCenterButtonBar* GetButtonBar() const; | 161 MessageCenterButtonBar* GetButtonBar() const; |
| 165 | 162 |
| 166 void RemoveDefaultNotifications(); | 163 void RemoveDefaultNotifications(); |
| 167 | 164 |
| 168 private: | 165 private: |
| 169 views::View* MakeParent(views::View* child1, views::View* child2); | 166 views::View* MakeParent(views::View* child1, views::View* child2); |
| 170 | 167 |
| 171 NotificationList::Notifications notifications_; | 168 NotificationList::Notifications notifications_; |
| 172 std::unique_ptr<views::Widget> widget_; | |
| 173 std::unique_ptr<MessageCenterView> message_center_view_; | 169 std::unique_ptr<MessageCenterView> message_center_view_; |
| 174 std::unique_ptr<FakeMessageCenterImpl> message_center_; | 170 std::unique_ptr<FakeMessageCenterImpl> message_center_; |
| 175 std::map<CallType,int> callCounts_; | 171 std::map<CallType,int> callCounts_; |
| 176 | 172 |
| 177 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); | 173 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); |
| 178 }; | 174 }; |
| 179 | 175 |
| 180 MessageCenterViewTest::MessageCenterViewTest() { | 176 MessageCenterViewTest::MessageCenterViewTest() { |
| 181 } | 177 } |
| 182 | 178 |
| 183 MessageCenterViewTest::~MessageCenterViewTest() { | 179 MessageCenterViewTest::~MessageCenterViewTest() { |
| 184 } | 180 } |
| 185 | 181 |
| 186 void MessageCenterViewTest::SetUp() { | 182 void MessageCenterViewTest::SetUp() { |
| 187 views::ViewsTestBase::SetUp(); | 183 views::ViewsTestBase::SetUp(); |
| 188 MessageCenterView::disable_animation_for_testing = true; | |
| 189 message_center_.reset(new FakeMessageCenterImpl()); | 184 message_center_.reset(new FakeMessageCenterImpl()); |
| 190 | 185 |
| 191 // Create a dummy notification. | 186 // Create a dummy notification. |
| 192 Notification* notification1 = new Notification( | 187 Notification* notification1 = new Notification( |
| 193 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), | 188 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), |
| 194 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message1"), gfx::Image(), | 189 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message1"), gfx::Image(), |
| 195 base::UTF8ToUTF16("display source"), GURL(), | 190 base::UTF8ToUTF16("display source"), GURL(), |
| 196 NotifierId(NotifierId::APPLICATION, "extension_id"), | 191 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 197 message_center::RichNotificationData(), NULL); | 192 message_center::RichNotificationData(), NULL); |
| 198 | 193 |
| 199 Notification* notification2 = new Notification( | 194 Notification* notification2 = new Notification( |
| 200 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), | 195 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), |
| 201 base::UTF8ToUTF16("title2"), base::UTF8ToUTF16("message2"), gfx::Image(), | 196 base::UTF8ToUTF16("title2"), base::UTF8ToUTF16("message2"), gfx::Image(), |
| 202 base::UTF8ToUTF16("display source"), GURL(), | 197 base::UTF8ToUTF16("display source"), GURL(), |
| 203 NotifierId(NotifierId::APPLICATION, "extension_id"), | 198 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 204 message_center::RichNotificationData(), NULL); | 199 message_center::RichNotificationData(), NULL); |
| 205 | 200 |
| 206 // ...and a list for it. | 201 // ...and a list for it. |
| 207 notifications_.insert(notification1); | 202 notifications_.insert(notification1); |
| 208 notifications_.insert(notification2); | 203 notifications_.insert(notification2); |
| 209 message_center_->SetVisibleNotifications(notifications_); | 204 message_center_->SetVisibleNotifications(notifications_); |
| 210 | 205 |
| 211 // Then create a new MessageCenterView with that single notification. | 206 // Then create a new MessageCenterView with that single notification. |
| 212 message_center_view_.reset(new MessageCenterView( | 207 message_center_view_.reset(new MessageCenterView( |
| 213 message_center_.get(), NULL, 100, false, /*top_down =*/false)); | 208 message_center_.get(), NULL, 100, false, /*top_down =*/false)); |
| 214 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true; | 209 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true; |
| 215 GetMessageCenterView()->SetBounds(0, 0, 380, 600); | 210 GetMessageCenterView()->SetBounds(0, 0, 380, 600); |
| 216 message_center_view_->SetNotifications(notifications_); | 211 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(); | |
| 229 | 212 |
| 230 // Wait until the animation finishes if available. | 213 // Wait until the animation finishes if available. |
| 231 if (GetAnimator()->IsAnimating()) | 214 if (GetAnimator()->IsAnimating()) |
| 232 base::MessageLoop::current()->Run(); | 215 base::MessageLoop::current()->Run(); |
| 233 } | 216 } |
| 234 | 217 |
| 235 void MessageCenterViewTest::TearDown() { | 218 void MessageCenterViewTest::TearDown() { |
| 236 widget_->CloseNow(); | |
| 237 widget_.reset(); | |
| 238 message_center_view_.reset(); | 219 message_center_view_.reset(); |
| 239 STLDeleteElements(¬ifications_); | 220 STLDeleteElements(¬ifications_); |
| 240 views::ViewsTestBase::TearDown(); | 221 views::ViewsTestBase::TearDown(); |
| 241 } | 222 } |
| 242 | 223 |
| 243 MessageCenterView* MessageCenterViewTest::GetMessageCenterView() { | 224 MessageCenterView* MessageCenterViewTest::GetMessageCenterView() { |
| 244 return message_center_view_.get(); | 225 return message_center_view_.get(); |
| 245 } | 226 } |
| 246 | 227 |
| 247 MessageListView* MessageCenterViewTest::GetMessageListView() { | 228 MessageListView* MessageCenterViewTest::GetMessageListView() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 270 } | 251 } |
| 271 | 252 |
| 272 int MessageCenterViewTest::GetNotificationCount() { | 253 int MessageCenterViewTest::GetNotificationCount() { |
| 273 return 2; | 254 return 2; |
| 274 } | 255 } |
| 275 | 256 |
| 276 int MessageCenterViewTest::GetCallCount(CallType type) { | 257 int MessageCenterViewTest::GetCallCount(CallType type) { |
| 277 return callCounts_[type]; | 258 return callCounts_[type]; |
| 278 } | 259 } |
| 279 | 260 |
| 280 void MessageCenterViewTest::SetLockedState(bool locked) { | |
| 281 GetMessageCenterView()->OnLockedStateChanged(locked); | |
| 282 } | |
| 283 | |
| 284 void MessageCenterViewTest::ClickOnNotification( | 261 void MessageCenterViewTest::ClickOnNotification( |
| 285 const std::string& notification_id) { | 262 const std::string& notification_id) { |
| 286 // For this test, this method should not be invoked. | 263 // For this test, this method should not be invoked. |
| 287 NOTREACHED(); | 264 NOTREACHED(); |
| 288 } | 265 } |
| 289 | 266 |
| 290 void MessageCenterViewTest::AddNotification( | 267 void MessageCenterViewTest::AddNotification( |
| 291 std::unique_ptr<Notification> notification) { | 268 std::unique_ptr<Notification> notification) { |
| 292 std::string notification_id = notification->id(); | 269 std::string notification_id = notification->id(); |
| 293 notifications_.insert(notification.release()); | 270 notifications_.insert(notification.release()); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 message_center::RichNotificationData(), NULL); | 700 message_center::RichNotificationData(), NULL); |
| 724 AddNotification( | 701 AddNotification( |
| 725 std::unique_ptr<Notification>(new Notification(normal_notification))); | 702 std::unique_ptr<Notification>(new Notification(normal_notification))); |
| 726 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); | 703 EXPECT_EQ(Mode::SETTINGS, GetMessageCenterViewInternalMode()); |
| 727 | 704 |
| 728 // Hide the settings. | 705 // Hide the settings. |
| 729 GetMessageCenterView()->SetSettingsVisible(false); | 706 GetMessageCenterView()->SetSettingsVisible(false); |
| 730 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); | 707 EXPECT_EQ(Mode::NOTIFICATIONS, GetMessageCenterViewInternalMode()); |
| 731 } | 708 } |
| 732 | 709 |
| 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 | |
| 811 } // namespace message_center | 710 } // namespace message_center |
| OLD | NEW |