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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/views/message_center_view_unittest.cc
diff --git a/ui/message_center/views/message_center_view_unittest.cc b/ui/message_center/views/message_center_view_unittest.cc
index 36a8302487b8897d1f5ea7e8b3d74430308f474a..4f8a0a16942da1a7aa969c954353d83803182eaa 100644
--- a/ui/message_center/views/message_center_view_unittest.cc
+++ b/ui/message_center/views/message_center_view_unittest.cc
@@ -115,6 +115,37 @@ class FakeMessageCenterImpl : public FakeMessageCenter {
bool locked_ = false;
};
+// This is the class we are testing, but we need to override some functions
+// in it, hence MockMessageCenterView.
+class MockMessageCenterView : public MessageCenterView {
+ public:
+ MockMessageCenterView(MessageCenter* message_center,
+ MessageCenterTray* tray,
+ int max_height,
+ bool initially_settings_visible);
+
+ bool SetRepositionTarget() override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockMessageCenterView);
+};
+
+MockMessageCenterView::MockMessageCenterView(MessageCenter* message_center,
+ MessageCenterTray* tray,
+ int max_height,
+ bool initially_settings_visible)
+ : MessageCenterView(message_center,
+ tray,
+ max_height,
+ initially_settings_visible) {}
+
+// Always say that the current reposition session is still active, by
+// returning true. Normally the reposition session is set based on where the
+// mouse is hovering.
+bool MockMessageCenterView::SetRepositionTarget() {
+ return true;
+}
+
/* Test fixture ***************************************************************/
class MessageCenterViewTest : public views::ViewsTestBase,
@@ -175,7 +206,7 @@ class MessageCenterViewTest : public views::ViewsTestBase,
// The ownership map of notifications; the key is the id.
std::map<std::string, std::unique_ptr<Notification>> notifications_;
std::unique_ptr<views::Widget> widget_;
- std::unique_ptr<MessageCenterView> message_center_view_;
+ std::unique_ptr<MockMessageCenterView> message_center_view_;
std::unique_ptr<FakeMessageCenterImpl> message_center_;
std::map<CallType,int> callCounts_;
@@ -214,9 +245,9 @@ void MessageCenterViewTest::SetUp() {
NotificationList::Notifications notifications = Notifications();
message_center_->SetVisibleNotifications(notifications);
- // Then create a new MessageCenterView with that single notification.
- message_center_view_.reset(new MessageCenterView(
- message_center_.get(), NULL, 100, false));
+ // Then create a new MockMessageCenterView with that single notification.
+ message_center_view_.reset(
+ new MockMessageCenterView(message_center_.get(), NULL, 100, false));
GetMessageListView()->quit_message_loop_after_animation_for_test_ = true;
GetMessageCenterView()->SetBounds(0, 0, 380, 600);
message_center_view_->SetNotifications(notifications);
@@ -464,6 +495,70 @@ TEST_F(MessageCenterViewTest, SizeAfterUpdate) {
GetMessageListView()->GetInsets().height());
}
+TEST_F(MessageCenterViewTest, SizeAfterUpdateBelowWithRepositionTarget) {
+ EXPECT_EQ(2, GetMessageListView()->child_count());
+ // Make sure that notification 2 is placed above notification 1.
+ EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(),
+ GetNotificationView(kNotificationId1)->bounds().y());
+
+ GetMessageListView()->SetRepositionTargetForTest(
+ GetNotificationView(kNotificationId1)->bounds());
+
+ std::unique_ptr<Notification> notification = base::MakeUnique<Notification>(
+ NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2),
+ base::UTF8ToUTF16("title2"),
+ base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
+ gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
+ NotifierId(NotifierId::APPLICATION, "extension_id"),
+ message_center::RichNotificationData(), nullptr);
+ UpdateNotification(kNotificationId2, std::move(notification));
+
+ // Wait until the animation finishes if available.
+ if (GetAnimator()->IsAnimating())
+ base::RunLoop().Run();
+
+ int width =
+ GetMessageListView()->width() - GetMessageListView()->GetInsets().width();
+ EXPECT_EQ(
+ GetMessageListView()->height(),
+ GetNotificationView(kNotificationId1)->GetHeightForWidth(width) +
+ (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) +
+ GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
+ GetMessageListView()->GetInsets().height());
+}
+
+TEST_F(MessageCenterViewTest, SizeAfterUpdateOfRepositionTarget) {
+ EXPECT_EQ(2, GetMessageListView()->child_count());
+ // Make sure that notification 2 is placed above notification 1.
+ EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(),
+ GetNotificationView(kNotificationId1)->bounds().y());
+
+ GetMessageListView()->SetRepositionTargetForTest(
+ GetNotificationView(kNotificationId1)->bounds());
+
+ std::unique_ptr<Notification> notification = base::MakeUnique<Notification>(
+ NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1),
+ base::UTF8ToUTF16("title2"),
+ base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."),
+ gfx::Image(), base::UTF8ToUTF16("display source"), GURL(),
+ NotifierId(NotifierId::APPLICATION, "extension_id"),
+ message_center::RichNotificationData(), nullptr);
+ UpdateNotification(kNotificationId1, std::move(notification));
+
+ // Wait until the animation finishes if available.
+ if (GetAnimator()->IsAnimating())
+ base::RunLoop().Run();
+
+ int width =
+ GetMessageListView()->width() - GetMessageListView()->GetInsets().width();
+ EXPECT_EQ(
+ GetMessageListView()->height(),
+ GetNotificationView(kNotificationId1)->GetHeightForWidth(width) +
+ (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) +
+ GetNotificationView(kNotificationId2)->GetHeightForWidth(width) +
+ GetMessageListView()->GetInsets().height());
+}
+
TEST_F(MessageCenterViewTest, SizeAfterRemove) {
EXPECT_EQ(2, GetMessageListView()->child_count());
RemoveNotification(kNotificationId1, false);
« 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