Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: ui/message_center/views/message_center_view_unittest.cc

Issue 2696523002: Stop notifications from being clipped on resize. (Closed)
Patch Set: Add additional comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void RemoveAllNotifications(bool by_user, RemoveType type) override { 108 void RemoveAllNotifications(bool by_user, RemoveType type) override {
109 if (type == RemoveType::NON_PINNED) 109 if (type == RemoveType::NON_PINNED)
110 remove_all_closable_notification_called_ = true; 110 remove_all_closable_notification_called_ = true;
111 } 111 }
112 bool IsLockedState() const override { return locked_; } 112 bool IsLockedState() const override { return locked_; }
113 bool remove_all_closable_notification_called_ = false; 113 bool remove_all_closable_notification_called_ = false;
114 NotificationList::Notifications visible_notifications_; 114 NotificationList::Notifications visible_notifications_;
115 bool locked_ = false; 115 bool locked_ = false;
116 }; 116 };
117 117
118 // This is the class we are testing, but we need to override some functions
119 // in it, hence MockMessageCenterView.
120 class MockMessageCenterView : public MessageCenterView {
121 public:
122 MockMessageCenterView(MessageCenter* message_center,
123 MessageCenterTray* tray,
124 int max_height,
125 bool initially_settings_visible);
126
127 bool SetRepositionTarget() override;
128
129 private:
130 DISALLOW_COPY_AND_ASSIGN(MockMessageCenterView);
131 };
132
133 MockMessageCenterView::MockMessageCenterView(MessageCenter* message_center,
134 MessageCenterTray* tray,
135 int max_height,
136 bool initially_settings_visible)
137 : MessageCenterView(message_center,
138 tray,
139 max_height,
140 initially_settings_visible) {}
141
142 // Always say that the current reposition session is still active, by
143 // returning true. Normally the reposition session is set based on where the
144 // mouse is hovering.
145 bool MockMessageCenterView::SetRepositionTarget() {
146 return true;
147 }
148
118 /* Test fixture ***************************************************************/ 149 /* Test fixture ***************************************************************/
119 150
120 class MessageCenterViewTest : public views::ViewsTestBase, 151 class MessageCenterViewTest : public views::ViewsTestBase,
121 public MockNotificationView::Test, 152 public MockNotificationView::Test,
122 public MessageCenterController { 153 public MessageCenterController {
123 public: 154 public:
124 // Expose the private enum class MessageCenter::Mode for this test. 155 // Expose the private enum class MessageCenter::Mode for this test.
125 using Mode = MessageCenterView::Mode; 156 using Mode = MessageCenterView::Mode;
126 157
127 MessageCenterViewTest(); 158 MessageCenterViewTest();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 MessageCenterButtonBar* GetButtonBar() const; 199 MessageCenterButtonBar* GetButtonBar() const;
169 200
170 void RemoveDefaultNotifications(); 201 void RemoveDefaultNotifications();
171 202
172 private: 203 private:
173 views::View* MakeParent(views::View* child1, views::View* child2); 204 views::View* MakeParent(views::View* child1, views::View* child2);
174 205
175 // The ownership map of notifications; the key is the id. 206 // The ownership map of notifications; the key is the id.
176 std::map<std::string, std::unique_ptr<Notification>> notifications_; 207 std::map<std::string, std::unique_ptr<Notification>> notifications_;
177 std::unique_ptr<views::Widget> widget_; 208 std::unique_ptr<views::Widget> widget_;
178 std::unique_ptr<MessageCenterView> message_center_view_; 209 std::unique_ptr<MockMessageCenterView> message_center_view_;
179 std::unique_ptr<FakeMessageCenterImpl> message_center_; 210 std::unique_ptr<FakeMessageCenterImpl> message_center_;
180 std::map<CallType,int> callCounts_; 211 std::map<CallType,int> callCounts_;
181 212
182 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest); 213 DISALLOW_COPY_AND_ASSIGN(MessageCenterViewTest);
183 }; 214 };
184 215
185 MessageCenterViewTest::MessageCenterViewTest() { 216 MessageCenterViewTest::MessageCenterViewTest() {
186 } 217 }
187 218
188 MessageCenterViewTest::~MessageCenterViewTest() { 219 MessageCenterViewTest::~MessageCenterViewTest() {
(...skipping 18 matching lines...) Expand all
207 base::UTF8ToUTF16("display source"), GURL(), 238 base::UTF8ToUTF16("display source"), GURL(),
208 NotifierId(NotifierId::APPLICATION, "extension_id"), 239 NotifierId(NotifierId::APPLICATION, "extension_id"),
209 message_center::RichNotificationData(), nullptr); 240 message_center::RichNotificationData(), nullptr);
210 241
211 // ...and a list for it. 242 // ...and a list for it.
212 notifications_[std::string(kNotificationId1)] = std::move(notification1); 243 notifications_[std::string(kNotificationId1)] = std::move(notification1);
213 notifications_[std::string(kNotificationId2)] = std::move(notification2); 244 notifications_[std::string(kNotificationId2)] = std::move(notification2);
214 NotificationList::Notifications notifications = Notifications(); 245 NotificationList::Notifications notifications = Notifications();
215 message_center_->SetVisibleNotifications(notifications); 246 message_center_->SetVisibleNotifications(notifications);
216 247
217 // Then create a new MessageCenterView with that single notification. 248 // Then create a new MockMessageCenterView with that single notification.
218 message_center_view_.reset(new MessageCenterView( 249 message_center_view_.reset(
219 message_center_.get(), NULL, 100, false)); 250 new MockMessageCenterView(message_center_.get(), NULL, 100, false));
220 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true; 251 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true;
221 GetMessageCenterView()->SetBounds(0, 0, 380, 600); 252 GetMessageCenterView()->SetBounds(0, 0, 380, 600);
222 message_center_view_->SetNotifications(notifications); 253 message_center_view_->SetNotifications(notifications);
223 message_center_view_->set_owned_by_client(); 254 message_center_view_->set_owned_by_client();
224 255
225 widget_.reset(new views::Widget()); 256 widget_.reset(new views::Widget());
226 views::Widget::InitParams params = 257 views::Widget::InitParams params =
227 CreateParams(views::Widget::InitParams::TYPE_POPUP); 258 CreateParams(views::Widget::InitParams::TYPE_POPUP);
228 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 259 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
229 params.bounds = gfx::Rect(50, 50, 650, 650); 260 params.bounds = gfx::Rect(50, 50, 650, 650);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 EXPECT_NE(previous_height, GetMessageListView()->height()); 488 EXPECT_NE(previous_height, GetMessageListView()->height());
458 489
459 EXPECT_EQ( 490 EXPECT_EQ(
460 GetMessageListView()->height(), 491 GetMessageListView()->height(),
461 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) + 492 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) +
462 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + 493 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) +
463 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + 494 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
464 GetMessageListView()->GetInsets().height()); 495 GetMessageListView()->GetInsets().height());
465 } 496 }
466 497
498 TEST_F(MessageCenterViewTest, SizeAfterUpdateBelowWithRepositionTarget) {
499 EXPECT_EQ(2, GetMessageListView()->child_count());
500 // Make sure that notification 2 is placed above notification 1.
501 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(),
502 GetNotificationView(kNotificationId1)->bounds().y());
503
504 GetMessageListView()->SetRepositionTargetForTest(
505 GetNotificationView(kNotificationId1)->bounds());
506
507 std::unique_ptr<Notification> notification = base::MakeUnique<Notification>(
508 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2),
509 base::UTF8ToUTF16("title2"),
510 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
511 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
512 NotifierId(NotifierId::APPLICATION, "extension_id"),
513 message_center::RichNotificationData(), nullptr);
514 UpdateNotification(kNotificationId2, std::move(notification));
515
516 // Wait until the animation finishes if available.
517 if (GetAnimator()->IsAnimating())
518 base::RunLoop().Run();
519
520 int width =
521 GetMessageListView()->width() - GetMessageListView()->GetInsets().width();
522 EXPECT_EQ(
523 GetMessageListView()->height(),
524 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) +
525 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) +
526 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
527 GetMessageListView()->GetInsets().height());
528 }
529
530 TEST_F(MessageCenterViewTest, SizeAfterUpdateOfRepositionTarget) {
531 EXPECT_EQ(2, GetMessageListView()->child_count());
532 // Make sure that notification 2 is placed above notification 1.
533 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(),
534 GetNotificationView(kNotificationId1)->bounds().y());
535
536 GetMessageListView()->SetRepositionTargetForTest(
537 GetNotificationView(kNotificationId1)->bounds());
538
539 std::unique_ptr<Notification> notification = base::MakeUnique<Notification>(
540 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
541 base::UTF8ToUTF16("title2"),
542 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
543 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
544 NotifierId(NotifierId::APPLICATION, "extension_id"),
545 message_center::RichNotificationData(), nullptr);
546 UpdateNotification(kNotificationId1, std::move(notification));
547
548 // Wait until the animation finishes if available.
549 if (GetAnimator()->IsAnimating())
550 base::RunLoop().Run();
551
552 int width =
553 GetMessageListView()->width() - GetMessageListView()->GetInsets().width();
554 EXPECT_EQ(
555 GetMessageListView()->height(),
556 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) +
557 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) +
558 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
559 GetMessageListView()->GetInsets().height());
560 }
561
467 TEST_F(MessageCenterViewTest, SizeAfterRemove) { 562 TEST_F(MessageCenterViewTest, SizeAfterRemove) {
468 EXPECT_EQ(2, GetMessageListView()->child_count()); 563 EXPECT_EQ(2, GetMessageListView()->child_count());
469 RemoveNotification(kNotificationId1, false); 564 RemoveNotification(kNotificationId1, false);
470 565
471 // Wait until the animation finishes if available. 566 // Wait until the animation finishes if available.
472 if (GetAnimator()->IsAnimating()) 567 if (GetAnimator()->IsAnimating())
473 base::RunLoop().Run(); 568 base::RunLoop().Run();
474 569
475 EXPECT_EQ(1, GetMessageListView()->child_count()); 570 EXPECT_EQ(1, GetMessageListView()->child_count());
476 571
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 base::UTF8ToUTF16("title1"), base::UTF8ToUTF16("message"), gfx::Image(), 945 base::UTF8ToUTF16("title1"), base::UTF8ToUTF16("message"), gfx::Image(),
851 base::UTF8ToUTF16("display source"), GURL(), 946 base::UTF8ToUTF16("display source"), GURL(),
852 NotifierId(NotifierId::APPLICATION, "extension_id"), 947 NotifierId(NotifierId::APPLICATION, "extension_id"),
853 message_center::RichNotificationData(), nullptr)); 948 message_center::RichNotificationData(), nullptr));
854 949
855 GetMessageCenterView()->SizeToPreferredSize(); 950 GetMessageCenterView()->SizeToPreferredSize();
856 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); 951 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height());
857 } 952 }
858 953
859 } // namespace message_center 954 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/message_center_view.cc ('k') | ui/message_center/views/message_list_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698