Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 bitmap.eraseRGB(0, 255, 0); | 59 bitmap.eraseRGB(0, 255, 0); |
| 60 return bitmap; | 60 return bitmap; |
| 61 } | 61 } |
| 62 | 62 |
| 63 std::vector<ButtonInfo> CreateButtons(int number) { | 63 std::vector<ButtonInfo> CreateButtons(int number) { |
| 64 ButtonInfo info(base::ASCIIToUTF16("Test button title.")); | 64 ButtonInfo info(base::ASCIIToUTF16("Test button title.")); |
| 65 info.icon = CreateTestImage(4, 4); | 65 info.icon = CreateTestImage(4, 4); |
| 66 return std::vector<ButtonInfo>(number, info); | 66 return std::vector<ButtonInfo>(number, info); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void CheckVerticalOrderInNotification() { | |
| 70 std::vector<views::View*> vertical_order; | |
| 71 vertical_order.push_back(notification_view()->top_view_); | |
| 72 vertical_order.push_back(notification_view()->image_view_); | |
| 73 std::copy(notification_view()->action_buttons_.begin(), | |
| 74 notification_view()->action_buttons_.end(), | |
| 75 std::back_inserter(vertical_order)); | |
| 76 std::vector<views::View*>::iterator current = vertical_order.begin(); | |
| 77 std::vector<views::View*>::iterator last = current++; | |
| 78 while (current != vertical_order.end()) { | |
| 79 gfx::Point last_point = (*last)->bounds().origin(); | |
| 80 views::View::ConvertPointToTarget( | |
| 81 (*last), notification_view(), &last_point); | |
| 82 | |
| 83 gfx::Point current_point = (*current)->bounds().origin(); | |
|
robliao
2014/05/30 01:19:33
This was CenterPoint before. Is origin a better me
dewittj
2014/06/02 18:00:05
It was easier for me to verify that they were in r
| |
| 84 views::View::ConvertPointToTarget( | |
| 85 (*current), notification_view(), ¤t_point); | |
| 86 | |
| 87 EXPECT_LT(last_point.y(), current_point.y()); | |
| 88 last = current++; | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 void UpdateNotificationViews() { | |
| 93 notification_view()->CreateOrUpdateViews(*notification()); | |
| 94 notification_view()->Layout(); | |
| 95 } | |
| 96 | |
| 69 private: | 97 private: |
| 70 scoped_ptr<RichNotificationData> data_; | 98 scoped_ptr<RichNotificationData> data_; |
| 71 scoped_ptr<Notification> notification_; | 99 scoped_ptr<Notification> notification_; |
| 72 scoped_ptr<NotificationView> notification_view_; | 100 scoped_ptr<NotificationView> notification_view_; |
| 73 | 101 |
| 74 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); | 102 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); |
| 75 }; | 103 }; |
| 76 | 104 |
| 77 NotificationViewTest::NotificationViewTest() { | 105 NotificationViewTest::NotificationViewTest() { |
| 78 } | 106 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 move = ui::MouseEvent(ui::ET_MOUSE_MOVED, | 298 move = ui::MouseEvent(ui::ET_MOUSE_MOVED, |
| 271 cursor_location, | 299 cursor_location, |
| 272 cursor_location, | 300 cursor_location, |
| 273 ui::EF_NONE, | 301 ui::EF_NONE, |
| 274 ui::EF_NONE); | 302 ui::EF_NONE); |
| 275 widget()->OnMouseEvent(&move); | 303 widget()->OnMouseEvent(&move); |
| 276 | 304 |
| 277 EXPECT_TRUE(NULL == notification_view()->action_buttons_[0]->background()); | 305 EXPECT_TRUE(NULL == notification_view()->action_buttons_[0]->background()); |
| 278 } | 306 } |
| 279 | 307 |
| 308 TEST_F(NotificationViewTest, ViewOrderingTest) { | |
| 309 // Tests that views are created in the correct vertical order. | |
| 310 notification()->set_buttons(CreateButtons(2)); | |
| 311 | |
| 312 // Layout the initial views. | |
| 313 UpdateNotificationViews(); | |
| 314 | |
| 315 // Double-check that vertical order is correct. | |
| 316 CheckVerticalOrderInNotification(); | |
| 317 | |
| 318 // Tests that views remain in that order even after an update. | |
| 319 UpdateNotificationViews(); | |
| 320 CheckVerticalOrderInNotification(); | |
| 321 } | |
| 322 | |
| 280 } // namespace message_center | 323 } // namespace message_center |
| OLD | NEW |