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

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

Issue 2805143002: Don't shrink the message center height while open (Closed)
Patch Set: Remove unnecessary include Created 3 years, 8 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // in it, hence MockMessageCenterView. 119 // in it, hence MockMessageCenterView.
120 class MockMessageCenterView : public MessageCenterView { 120 class MockMessageCenterView : public MessageCenterView {
121 public: 121 public:
122 MockMessageCenterView(MessageCenter* message_center, 122 MockMessageCenterView(MessageCenter* message_center,
123 MessageCenterTray* tray, 123 MessageCenterTray* tray,
124 int max_height, 124 int max_height,
125 bool initially_settings_visible); 125 bool initially_settings_visible);
126 126
127 bool SetRepositionTarget() override; 127 bool SetRepositionTarget() override;
128 128
129 void PreferredSizeChanged() override;
130
129 private: 131 private:
130 DISALLOW_COPY_AND_ASSIGN(MockMessageCenterView); 132 DISALLOW_COPY_AND_ASSIGN(MockMessageCenterView);
131 }; 133 };
132 134
133 MockMessageCenterView::MockMessageCenterView(MessageCenter* message_center, 135 MockMessageCenterView::MockMessageCenterView(MessageCenter* message_center,
134 MessageCenterTray* tray, 136 MessageCenterTray* tray,
135 int max_height, 137 int max_height,
136 bool initially_settings_visible) 138 bool initially_settings_visible)
137 : MessageCenterView(message_center, 139 : MessageCenterView(message_center,
138 tray, 140 tray,
139 max_height, 141 max_height,
140 initially_settings_visible) {} 142 initially_settings_visible) {}
141 143
142 // Always say that the current reposition session is still active, by 144 // Always say that the current reposition session is still active, by
143 // returning true. Normally the reposition session is set based on where the 145 // returning true. Normally the reposition session is set based on where the
144 // mouse is hovering. 146 // mouse is hovering.
145 bool MockMessageCenterView::SetRepositionTarget() { 147 bool MockMessageCenterView::SetRepositionTarget() {
146 return true; 148 return true;
147 } 149 }
148 150
151 void MockMessageCenterView::PreferredSizeChanged() {
152 SetSize(GetPreferredSize());
153 MessageCenterView::PreferredSizeChanged();
154 }
155
149 /* Test fixture ***************************************************************/ 156 /* Test fixture ***************************************************************/
150 157
151 class MessageCenterViewTest : public views::ViewsTestBase, 158 class MessageCenterViewTest : public views::ViewsTestBase,
152 public MockNotificationView::Test, 159 public MockNotificationView::Test,
153 public MessageCenterController { 160 public MessageCenterController {
154 public: 161 public:
155 // Expose the private enum class MessageCenter::Mode for this test. 162 // Expose the private enum class MessageCenter::Mode for this test.
156 using Mode = MessageCenterView::Mode; 163 using Mode = MessageCenterView::Mode;
157 164
158 MessageCenterViewTest(); 165 MessageCenterViewTest();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 message_center::RichNotificationData(), nullptr); 247 message_center::RichNotificationData(), nullptr);
241 248
242 // ...and a list for it. 249 // ...and a list for it.
243 notifications_[std::string(kNotificationId1)] = std::move(notification1); 250 notifications_[std::string(kNotificationId1)] = std::move(notification1);
244 notifications_[std::string(kNotificationId2)] = std::move(notification2); 251 notifications_[std::string(kNotificationId2)] = std::move(notification2);
245 NotificationList::Notifications notifications = Notifications(); 252 NotificationList::Notifications notifications = Notifications();
246 message_center_->SetVisibleNotifications(notifications); 253 message_center_->SetVisibleNotifications(notifications);
247 254
248 // Then create a new MockMessageCenterView with that single notification. 255 // Then create a new MockMessageCenterView with that single notification.
249 message_center_view_.reset( 256 message_center_view_.reset(
250 new MockMessageCenterView(message_center_.get(), NULL, 100, false)); 257 new MockMessageCenterView(message_center_.get(), NULL, 600, false));
251 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true; 258 GetMessageListView()->quit_message_loop_after_animation_for_test_ = true;
252 GetMessageCenterView()->SetBounds(0, 0, 380, 600); 259 GetMessageCenterView()->SetBounds(0, 0, 380, 100);
253 message_center_view_->SetNotifications(notifications); 260 message_center_view_->SetNotifications(notifications);
254 message_center_view_->set_owned_by_client(); 261 message_center_view_->set_owned_by_client();
255 262
256 widget_.reset(new views::Widget()); 263 widget_.reset(new views::Widget());
257 views::Widget::InitParams params = 264 views::Widget::InitParams params =
258 CreateParams(views::Widget::InitParams::TYPE_POPUP); 265 CreateParams(views::Widget::InitParams::TYPE_POPUP);
259 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 266 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
260 params.bounds = gfx::Rect(50, 50, 650, 650); 267 params.bounds = gfx::Rect(50, 50, 650, 650);
261 widget_->Init(params); 268 widget_->Init(params);
262 views::View* root = widget_->GetRootView(); 269 views::View* root = widget_->GetRootView();
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 GetMessageListView()->width() - GetMessageListView()->GetInsets().width(); 560 GetMessageListView()->width() - GetMessageListView()->GetInsets().width();
554 EXPECT_EQ( 561 EXPECT_EQ(
555 GetMessageListView()->height(), 562 GetMessageListView()->height(),
556 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) + 563 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) +
557 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + 564 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) +
558 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + 565 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
559 GetMessageListView()->GetInsets().height()); 566 GetMessageListView()->GetInsets().height());
560 } 567 }
561 568
562 TEST_F(MessageCenterViewTest, SizeAfterRemove) { 569 TEST_F(MessageCenterViewTest, SizeAfterRemove) {
570 int original_height = GetMessageListView()->height();
563 EXPECT_EQ(2, GetMessageListView()->child_count()); 571 EXPECT_EQ(2, GetMessageListView()->child_count());
564 RemoveNotification(kNotificationId1, false); 572 RemoveNotification(kNotificationId1, false);
565 573
566 // Wait until the animation finishes if available. 574 // Wait until the animation finishes if available.
567 if (GetAnimator()->IsAnimating()) 575 if (GetAnimator()->IsAnimating())
568 base::RunLoop().Run(); 576 base::RunLoop().Run();
569 577
570 EXPECT_EQ(1, GetMessageListView()->child_count()); 578 EXPECT_EQ(1, GetMessageListView()->child_count());
571 579
572 int width =
573 GetMessageListView()->width() - GetMessageListView()->GetInsets().width();
574 EXPECT_FALSE(GetNotificationView(kNotificationId1)); 580 EXPECT_FALSE(GetNotificationView(kNotificationId1));
575 EXPECT_TRUE(GetNotificationView(kNotificationId2)); 581 EXPECT_TRUE(GetNotificationView(kNotificationId2));
576 EXPECT_EQ(GetMessageListView()->height(), 582 EXPECT_EQ(GetMessageListView()->height(), original_height);
577 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
578 GetMessageListView()->GetInsets().height());
579 } 583 }
580 584
581 TEST_F(MessageCenterViewTest, PositionAfterUpdate) { 585 TEST_F(MessageCenterViewTest, PositionAfterUpdate) {
582 // Make sure that the notification 2 is placed above the notification 1. 586 // Make sure that the notification 2 is placed above the notification 1.
583 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(), 587 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(),
584 GetNotificationView(kNotificationId1)->bounds().y()); 588 GetNotificationView(kNotificationId1)->bounds().y());
585 589
586 int previous_vertical_pos_from_bottom = 590 int previous_vertical_pos_from_bottom =
587 GetMessageListView()->height() - 591 GetMessageListView()->height() -
588 GetNotificationView(kNotificationId1)->bounds().y(); 592 GetNotificationView(kNotificationId1)->bounds().y();
(...skipping 24 matching lines...) Expand all
613 TEST_F(MessageCenterViewTest, PositionAfterRemove) { 617 TEST_F(MessageCenterViewTest, PositionAfterRemove) {
614 // Make sure that the notification 2 is placed above the notification 1. 618 // Make sure that the notification 2 is placed above the notification 1.
615 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(), 619 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(),
616 GetNotificationView(kNotificationId1)->bounds().y()); 620 GetNotificationView(kNotificationId1)->bounds().y());
617 621
618 GetMessageListView()->SetRepositionTargetForTest( 622 GetMessageListView()->SetRepositionTargetForTest(
619 GetNotificationView(kNotificationId2)->bounds()); 623 GetNotificationView(kNotificationId2)->bounds());
620 int previous_height = GetMessageListView()->height(); 624 int previous_height = GetMessageListView()->height();
621 int previous_notification2_y = 625 int previous_notification2_y =
622 GetNotificationView(kNotificationId2)->bounds().y(); 626 GetNotificationView(kNotificationId2)->bounds().y();
623 int previous_notification2_height =
624 GetNotificationView(kNotificationId2)->bounds().height();
625 627
626 EXPECT_EQ(2, GetMessageListView()->child_count()); 628 EXPECT_EQ(2, GetMessageListView()->child_count());
627 RemoveNotification(kNotificationId2, false); 629 RemoveNotification(kNotificationId2, false);
628 630
629 // Wait until the animation finishes if available. 631 // Wait until the animation finishes if available.
630 if (GetAnimator()->IsAnimating()) 632 if (GetAnimator()->IsAnimating())
631 base::RunLoop().Run(); 633 base::RunLoop().Run();
632 634
633 EXPECT_EQ(1, GetMessageListView()->child_count()); 635 EXPECT_EQ(1, GetMessageListView()->child_count());
634 636
635 // Confirm that notification 1 is moved up to the place on which the 637 // Confirm that notification 1 is moved up to the place on which the
636 // notification 2 was. 638 // notification 2 was.
637 EXPECT_EQ(previous_notification2_y, 639 EXPECT_EQ(previous_notification2_y,
638 GetNotificationView(kNotificationId1)->bounds().y()); 640 GetNotificationView(kNotificationId1)->bounds().y());
639 // The size should be kept. 641 // The size should be kept.
640 EXPECT_EQ(previous_height, GetMessageListView()->height()); 642 EXPECT_EQ(previous_height, GetMessageListView()->height());
641 643
642 // Notification 2 is successfully removed. 644 // Notification 2 is successfully removed.
643 EXPECT_FALSE(GetNotificationView(kNotificationId2)); 645 EXPECT_FALSE(GetNotificationView(kNotificationId2));
644 EXPECT_TRUE(GetNotificationView(kNotificationId1)); 646 EXPECT_TRUE(GetNotificationView(kNotificationId1));
645 647
646 // Mouse cursor moves out of the message center. This resets the reposition 648 // Mouse cursor moves out of the message center. This resets the reposition
647 // target in the message list. 649 // target in the message list.
648 FireOnMouseExitedEvent(); 650 FireOnMouseExitedEvent();
649 651
650 // The height should shrink from the height of the removed notification 2. 652 // The height should be kept even after the cursor moved out.
651 EXPECT_EQ(previous_height - previous_notification2_height - 653 EXPECT_EQ(previous_height, GetMessageListView()->height());
652 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()),
653 GetMessageListView()->height());
654 } 654 }
655 655
656 TEST_F(MessageCenterViewTest, CloseButton) { 656 TEST_F(MessageCenterViewTest, CloseButton) {
657 views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest(); 657 views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest();
658 EXPECT_NE(nullptr, close_button); 658 EXPECT_NE(nullptr, close_button);
659 659
660 ((views::ButtonListener*)GetButtonBar()) 660 ((views::ButtonListener*)GetButtonBar())
661 ->ButtonPressed(close_button, DummyEvent()); 661 ->ButtonPressed(close_button, DummyEvent());
662 base::RunLoop().Run(); 662 base::RunLoop().Run();
663 EXPECT_TRUE(GetMessageCenter()->remove_all_closable_notification_called_); 663 EXPECT_TRUE(GetMessageCenter()->remove_all_closable_notification_called_);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 base::UTF8ToUTF16("title1"), base::UTF8ToUTF16("message"), gfx::Image(), 945 base::UTF8ToUTF16("title1"), base::UTF8ToUTF16("message"), gfx::Image(),
946 base::UTF8ToUTF16("display source"), GURL(), 946 base::UTF8ToUTF16("display source"), GURL(),
947 NotifierId(NotifierId::APPLICATION, "extension_id"), 947 NotifierId(NotifierId::APPLICATION, "extension_id"),
948 message_center::RichNotificationData(), nullptr)); 948 message_center::RichNotificationData(), nullptr));
949 949
950 GetMessageCenterView()->SizeToPreferredSize(); 950 GetMessageCenterView()->SizeToPreferredSize();
951 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); 951 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height());
952 } 952 }
953 953
954 } // 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