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 <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/message_center/fake_message_center.h" | 15 #include "ui/message_center/fake_message_center.h" |
16 #include "ui/message_center/message_center_style.h" | 16 #include "ui/message_center/message_center_style.h" |
17 #include "ui/message_center/notification.h" | 17 #include "ui/message_center/notification.h" |
18 #include "ui/message_center/notification_list.h" | 18 #include "ui/message_center/notification_list.h" |
19 #include "ui/message_center/notification_types.h" | 19 #include "ui/message_center/notification_types.h" |
20 #include "ui/message_center/views/message_center_button_bar.h" | 20 #include "ui/message_center/views/message_center_button_bar.h" |
21 #include "ui/message_center/views/message_center_controller.h" | 21 #include "ui/message_center/views/message_center_controller.h" |
22 #include "ui/message_center/views/message_list_view.h" | 22 #include "ui/message_center/views/message_list_view.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void TearDown() override; | 123 void TearDown() override; |
124 | 124 |
125 MessageCenterView* GetMessageCenterView(); | 125 MessageCenterView* GetMessageCenterView(); |
126 MessageListView* GetMessageListView(); | 126 MessageListView* GetMessageListView(); |
127 FakeMessageCenterImpl* GetMessageCenter() const; | 127 FakeMessageCenterImpl* GetMessageCenter() const; |
128 NotificationView* GetNotificationView(const std::string& id); | 128 NotificationView* GetNotificationView(const std::string& id); |
129 views::BoundsAnimator* GetAnimator(); | 129 views::BoundsAnimator* GetAnimator(); |
130 int GetNotificationCount(); | 130 int GetNotificationCount(); |
131 int GetCallCount(CallType type); | 131 int GetCallCount(CallType type); |
132 int GetCalculatedMessageListViewHeight(); | 132 int GetCalculatedMessageListViewHeight(); |
133 void AddNotification(scoped_ptr<Notification> notification); | 133 void AddNotification(std::unique_ptr<Notification> notification); |
134 void UpdateNotification(const std::string& notification_id, | 134 void UpdateNotification(const std::string& notification_id, |
135 scoped_ptr<Notification> notification); | 135 std::unique_ptr<Notification> notification); |
136 | 136 |
137 // Overridden from MessageCenterController: | 137 // Overridden from MessageCenterController: |
138 void ClickOnNotification(const std::string& notification_id) override; | 138 void ClickOnNotification(const std::string& notification_id) override; |
139 void RemoveNotification(const std::string& notification_id, | 139 void RemoveNotification(const std::string& notification_id, |
140 bool by_user) override; | 140 bool by_user) override; |
141 scoped_ptr<ui::MenuModel> CreateMenuModel( | 141 std::unique_ptr<ui::MenuModel> CreateMenuModel( |
142 const NotifierId& notifier_id, | 142 const NotifierId& notifier_id, |
143 const base::string16& display_source) override; | 143 const base::string16& display_source) override; |
144 bool HasClickedListener(const std::string& notification_id) override; | 144 bool HasClickedListener(const std::string& notification_id) override; |
145 void ClickOnNotificationButton(const std::string& notification_id, | 145 void ClickOnNotificationButton(const std::string& notification_id, |
146 int button_index) override; | 146 int button_index) override; |
147 void ClickOnSettingsButton(const std::string& notification_id) override; | 147 void ClickOnSettingsButton(const std::string& notification_id) override; |
148 | 148 |
149 // Overridden from MockNotificationView::Test | 149 // Overridden from MockNotificationView::Test |
150 void RegisterCall(CallType type) override; | 150 void RegisterCall(CallType type) override; |
151 | 151 |
152 void FireOnMouseExitedEvent(); | 152 void FireOnMouseExitedEvent(); |
153 | 153 |
154 void LogBounds(int depth, views::View* view); | 154 void LogBounds(int depth, views::View* view); |
155 | 155 |
156 MessageCenterButtonBar* GetButtonBar() const; | 156 MessageCenterButtonBar* GetButtonBar() const; |
157 | 157 |
158 private: | 158 private: |
159 views::View* MakeParent(views::View* child1, views::View* child2); | 159 views::View* MakeParent(views::View* child1, views::View* child2); |
160 | 160 |
161 base::MessageLoopForUI message_loop_; | 161 base::MessageLoopForUI message_loop_; |
162 | 162 |
163 NotificationList::Notifications notifications_; | 163 NotificationList::Notifications notifications_; |
164 scoped_ptr<MessageCenterView> message_center_view_; | 164 std::unique_ptr<MessageCenterView> message_center_view_; |
165 scoped_ptr<FakeMessageCenterImpl> message_center_; | 165 std::unique_ptr<FakeMessageCenterImpl> message_center_; |
166 std::map<CallType,int> callCounts_; | 166 std::map<CallType,int> callCounts_; |
167 | 167 |
168 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); | 168 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); |
169 }; | 169 }; |
170 | 170 |
171 MessageCenterViewTest::MessageCenterViewTest() { | 171 MessageCenterViewTest::MessageCenterViewTest() { |
172 } | 172 } |
173 | 173 |
174 MessageCenterViewTest::~MessageCenterViewTest() { | 174 MessageCenterViewTest::~MessageCenterViewTest() { |
175 } | 175 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 return callCounts_[type]; | 248 return callCounts_[type]; |
249 } | 249 } |
250 | 250 |
251 void MessageCenterViewTest::ClickOnNotification( | 251 void MessageCenterViewTest::ClickOnNotification( |
252 const std::string& notification_id) { | 252 const std::string& notification_id) { |
253 // For this test, this method should not be invoked. | 253 // For this test, this method should not be invoked. |
254 NOTREACHED(); | 254 NOTREACHED(); |
255 } | 255 } |
256 | 256 |
257 void MessageCenterViewTest::AddNotification( | 257 void MessageCenterViewTest::AddNotification( |
258 scoped_ptr<Notification> notification) { | 258 std::unique_ptr<Notification> notification) { |
259 std::string notification_id = notification->id(); | 259 std::string notification_id = notification->id(); |
260 notifications_.insert(notification.release()); | 260 notifications_.insert(notification.release()); |
261 message_center_->SetVisibleNotifications(notifications_); | 261 message_center_->SetVisibleNotifications(notifications_); |
262 message_center_view_->OnNotificationAdded(notification_id); | 262 message_center_view_->OnNotificationAdded(notification_id); |
263 } | 263 } |
264 | 264 |
265 void MessageCenterViewTest::UpdateNotification( | 265 void MessageCenterViewTest::UpdateNotification( |
266 const std::string& notification_id, | 266 const std::string& notification_id, |
267 scoped_ptr<Notification> notification) { | 267 std::unique_ptr<Notification> notification) { |
268 for (auto it = notifications_.begin(); it != notifications_.end(); it++) { | 268 for (auto it = notifications_.begin(); it != notifications_.end(); it++) { |
269 if ((*it)->id() == notification_id) { | 269 if ((*it)->id() == notification_id) { |
270 delete *it; | 270 delete *it; |
271 notifications_.erase(it); | 271 notifications_.erase(it); |
272 break; | 272 break; |
273 } | 273 } |
274 } | 274 } |
275 // |notifications| is a "set" container so we don't need to be aware the | 275 // |notifications| is a "set" container so we don't need to be aware the |
276 // order. | 276 // order. |
277 notifications_.insert(notification.release()); | 277 notifications_.insert(notification.release()); |
278 message_center_->SetVisibleNotifications(notifications_); | 278 message_center_->SetVisibleNotifications(notifications_); |
279 message_center_view_->OnNotificationUpdated(notification_id); | 279 message_center_view_->OnNotificationUpdated(notification_id); |
280 } | 280 } |
281 | 281 |
282 void MessageCenterViewTest::RemoveNotification( | 282 void MessageCenterViewTest::RemoveNotification( |
283 const std::string& notification_id, | 283 const std::string& notification_id, |
284 bool by_user) { | 284 bool by_user) { |
285 for (auto it = notifications_.begin(); it != notifications_.end(); it++) { | 285 for (auto it = notifications_.begin(); it != notifications_.end(); it++) { |
286 if ((*it)->id() == notification_id) { | 286 if ((*it)->id() == notification_id) { |
287 delete *it; | 287 delete *it; |
288 notifications_.erase(it); | 288 notifications_.erase(it); |
289 break; | 289 break; |
290 } | 290 } |
291 } | 291 } |
292 message_center_->SetVisibleNotifications(notifications_); | 292 message_center_->SetVisibleNotifications(notifications_); |
293 message_center_view_->OnNotificationRemoved(notification_id, by_user); | 293 message_center_view_->OnNotificationRemoved(notification_id, by_user); |
294 } | 294 } |
295 | 295 |
296 scoped_ptr<ui::MenuModel> MessageCenterViewTest::CreateMenuModel( | 296 std::unique_ptr<ui::MenuModel> MessageCenterViewTest::CreateMenuModel( |
297 const NotifierId& notifier_id, | 297 const NotifierId& notifier_id, |
298 const base::string16& display_source) { | 298 const base::string16& display_source) { |
299 // For this test, this method should not be invoked. | 299 // For this test, this method should not be invoked. |
300 NOTREACHED(); | 300 NOTREACHED(); |
301 return nullptr; | 301 return nullptr; |
302 } | 302 } |
303 | 303 |
304 bool MessageCenterViewTest::HasClickedListener( | 304 bool MessageCenterViewTest::HasClickedListener( |
305 const std::string& notification_id) { | 305 const std::string& notification_id) { |
306 return true; | 306 return true; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + | 375 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + |
376 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + | 376 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + |
377 GetMessageListView()->GetInsets().height()); | 377 GetMessageListView()->GetInsets().height()); |
378 } | 378 } |
379 | 379 |
380 TEST_F(MessageCenterViewTest, SizeAfterUpdate) { | 380 TEST_F(MessageCenterViewTest, SizeAfterUpdate) { |
381 EXPECT_EQ(2, GetMessageListView()->child_count()); | 381 EXPECT_EQ(2, GetMessageListView()->child_count()); |
382 int width = | 382 int width = |
383 GetMessageListView()->width() - GetMessageListView()->GetInsets().width(); | 383 GetMessageListView()->width() - GetMessageListView()->GetInsets().width(); |
384 | 384 |
385 scoped_ptr<Notification> notification(new Notification( | 385 std::unique_ptr<Notification> notification(new Notification( |
386 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), | 386 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), |
387 base::UTF8ToUTF16("title2"), | 387 base::UTF8ToUTF16("title2"), |
388 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), | 388 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), |
389 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), | 389 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
390 NotifierId(NotifierId::APPLICATION, "extension_id"), | 390 NotifierId(NotifierId::APPLICATION, "extension_id"), |
391 message_center::RichNotificationData(), NULL)); | 391 message_center::RichNotificationData(), NULL)); |
392 | 392 |
393 EXPECT_EQ( | 393 EXPECT_EQ( |
394 GetMessageListView()->height(), | 394 GetMessageListView()->height(), |
395 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) + | 395 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) + |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 // Make sure that the notification 2 is placed above the notification 1. | 443 // Make sure that the notification 2 is placed above the notification 1. |
444 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(), | 444 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(), |
445 GetNotificationView(kNotificationId1)->bounds().y()); | 445 GetNotificationView(kNotificationId1)->bounds().y()); |
446 | 446 |
447 int previous_vertical_pos_from_bottom = | 447 int previous_vertical_pos_from_bottom = |
448 GetMessageListView()->height() - | 448 GetMessageListView()->height() - |
449 GetNotificationView(kNotificationId1)->bounds().y(); | 449 GetNotificationView(kNotificationId1)->bounds().y(); |
450 GetMessageListView()->SetRepositionTargetForTest( | 450 GetMessageListView()->SetRepositionTargetForTest( |
451 GetNotificationView(kNotificationId1)->bounds()); | 451 GetNotificationView(kNotificationId1)->bounds()); |
452 | 452 |
453 scoped_ptr<Notification> notification(new Notification( | 453 std::unique_ptr<Notification> notification(new Notification( |
454 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), | 454 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), |
455 base::UTF8ToUTF16("title2"), | 455 base::UTF8ToUTF16("title2"), |
456 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), | 456 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), |
457 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), | 457 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
458 NotifierId(NotifierId::APPLICATION, "extension_id"), | 458 NotifierId(NotifierId::APPLICATION, "extension_id"), |
459 message_center::RichNotificationData(), NULL)); | 459 message_center::RichNotificationData(), NULL)); |
460 UpdateNotification(kNotificationId2, std::move(notification)); | 460 UpdateNotification(kNotificationId2, std::move(notification)); |
461 | 461 |
462 // Wait until the animation finishes if available. | 462 // Wait until the animation finishes if available. |
463 if (GetAnimator()->IsAnimating()) | 463 if (GetAnimator()->IsAnimating()) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 Notification pinned_notification( | 558 Notification pinned_notification( |
559 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), | 559 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), |
560 base::UTF8ToUTF16("title2"), | 560 base::UTF8ToUTF16("title2"), |
561 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), | 561 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), |
562 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), | 562 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
563 NotifierId(NotifierId::APPLICATION, "extension_id"), | 563 NotifierId(NotifierId::APPLICATION, "extension_id"), |
564 message_center::RichNotificationData(), NULL); | 564 message_center::RichNotificationData(), NULL); |
565 pinned_notification.set_pinned(true); | 565 pinned_notification.set_pinned(true); |
566 | 566 |
567 AddNotification( | 567 AddNotification( |
568 scoped_ptr<Notification>(new Notification(normal_notification))); | 568 std::unique_ptr<Notification>(new Notification(normal_notification))); |
569 | 569 |
570 // There should be 1 non-pinned notification. | 570 // There should be 1 non-pinned notification. |
571 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); | 571 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
572 EXPECT_TRUE(close_button->enabled()); | 572 EXPECT_TRUE(close_button->enabled()); |
573 | 573 |
574 AddNotification( | 574 AddNotification( |
575 scoped_ptr<Notification>(new Notification(pinned_notification))); | 575 std::unique_ptr<Notification>(new Notification(pinned_notification))); |
576 | 576 |
577 // There should be 1 normal notification and 1 pinned notification. | 577 // There should be 1 normal notification and 1 pinned notification. |
578 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size()); | 578 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size()); |
579 EXPECT_TRUE(close_button->enabled()); | 579 EXPECT_TRUE(close_button->enabled()); |
580 | 580 |
581 RemoveNotification(kNotificationId1, false); | 581 RemoveNotification(kNotificationId1, false); |
582 | 582 |
583 // There should be 1 pinned notification. | 583 // There should be 1 pinned notification. |
584 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); | 584 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
585 EXPECT_FALSE(close_button->enabled()); | 585 EXPECT_FALSE(close_button->enabled()); |
586 | 586 |
587 RemoveNotification(kNotificationId2, false); | 587 RemoveNotification(kNotificationId2, false); |
588 | 588 |
589 // There should be no notification. | 589 // There should be no notification. |
590 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); | 590 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); |
591 EXPECT_FALSE(close_button->enabled()); | 591 EXPECT_FALSE(close_button->enabled()); |
592 | 592 |
593 AddNotification( | 593 AddNotification( |
594 scoped_ptr<Notification>(new Notification(pinned_notification))); | 594 std::unique_ptr<Notification>(new Notification(pinned_notification))); |
595 | 595 |
596 // There should be 1 pinned notification. | 596 // There should be 1 pinned notification. |
597 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); | 597 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
598 EXPECT_FALSE(close_button->enabled()); | 598 EXPECT_FALSE(close_button->enabled()); |
599 #endif // defined(OS_CHROMEOS) | 599 #endif // defined(OS_CHROMEOS) |
600 } | 600 } |
601 | 601 |
602 } // namespace message_center | 602 } // namespace message_center |
OLD | NEW |