From 0f939daffbdbf70a3e1ec0ef61160761caa26d26 Mon Sep 17 00:00:00 2001 From: "dewittj@chromium.org" Date: Mon, 2 Jun 2014 22:25:36 +0000 Subject: Puts notification buttons back below the image A regression caused buttons to be rendered above the image. This fixes the problem by forcing the image to be the first child of the bottom view (image is together with the buttons in the bottom view). BUG=378077,368025 Review URL: https://codereview.chromium.org/305633004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274353 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/message_center/views/notification_view.cc | 2 +- ui/message_center/views/notification_view.h | 2 + .../views/notification_view_unittest.cc | 43 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) (limited to 'ui/message_center') diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc index 3dc31bf..be77657 100644 --- a/ui/message_center/views/notification_view.cc +++ b/ui/message_center/views/notification_view.cc @@ -695,7 +695,7 @@ void NotificationView::CreateOrUpdateImageView( gfx::Size image_size(kNotificationPreferredImageWidth, kNotificationPreferredImageHeight); image_view_ = MakeNotificationImage(notification.image(), image_size); - bottom_view_->AddChildView(image_view_); + bottom_view_->AddChildViewAt(image_view_, 0); } } diff --git a/ui/message_center/views/notification_view.h b/ui/message_center/views/notification_view.h index 3e009d7..2d69131 100644 --- a/ui/message_center/views/notification_view.h +++ b/ui/message_center/views/notification_view.h @@ -76,6 +76,8 @@ class MESSAGE_CENTER_EXPORT NotificationView : public MessageView, FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, UpdateButtonsStateTest); FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, UpdateButtonCountTest); + friend class NotificationViewTest; + void CreateOrUpdateViews(const Notification& notification); void SetAccessibleName(const Notification& notification); diff --git a/ui/message_center/views/notification_view_unittest.cc b/ui/message_center/views/notification_view_unittest.cc index 596e9ae..b6d6752 100644 --- a/ui/message_center/views/notification_view_unittest.cc +++ b/ui/message_center/views/notification_view_unittest.cc @@ -66,6 +66,34 @@ class NotificationViewTest : public views::ViewsTestBase, return std::vector(number, info); } + void CheckVerticalOrderInNotification() { + std::vector vertical_order; + vertical_order.push_back(notification_view()->top_view_); + vertical_order.push_back(notification_view()->image_view_); + std::copy(notification_view()->action_buttons_.begin(), + notification_view()->action_buttons_.end(), + std::back_inserter(vertical_order)); + std::vector::iterator current = vertical_order.begin(); + std::vector::iterator last = current++; + while (current != vertical_order.end()) { + gfx::Point last_point = (*last)->bounds().origin(); + views::View::ConvertPointToTarget( + (*last), notification_view(), &last_point); + + gfx::Point current_point = (*current)->bounds().origin(); + views::View::ConvertPointToTarget( + (*current), notification_view(), ¤t_point); + + EXPECT_LT(last_point.y(), current_point.y()); + last = current++; + } + } + + void UpdateNotificationViews() { + notification_view()->CreateOrUpdateViews(*notification()); + notification_view()->Layout(); + } + private: scoped_ptr data_; scoped_ptr notification_; @@ -277,4 +305,19 @@ TEST_F(NotificationViewTest, UpdateButtonCountTest) { EXPECT_TRUE(NULL == notification_view()->action_buttons_[0]->background()); } +TEST_F(NotificationViewTest, ViewOrderingTest) { + // Tests that views are created in the correct vertical order. + notification()->set_buttons(CreateButtons(2)); + + // Layout the initial views. + UpdateNotificationViews(); + + // Double-check that vertical order is correct. + CheckVerticalOrderInNotification(); + + // Tests that views remain in that order even after an update. + UpdateNotificationViews(); + CheckVerticalOrderInNotification(); +} + } // namespace message_center -- cgit v1.1