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/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
14 #include "ui/events/event_processor.h" | 15 #include "ui/events/event_processor.h" |
15 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
16 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
18 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
19 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
20 #include "ui/message_center/message_center_style.h" | 21 #include "ui/message_center/message_center_style.h" |
21 #include "ui/message_center/notification.h" | 22 #include "ui/message_center/notification.h" |
22 #include "ui/message_center/notification_list.h" | 23 #include "ui/message_center/notification_list.h" |
23 #include "ui/message_center/notification_types.h" | 24 #include "ui/message_center/notification_types.h" |
24 #include "ui/message_center/views/constants.h" | 25 #include "ui/message_center/views/constants.h" |
25 #include "ui/message_center/views/message_center_controller.h" | 26 #include "ui/message_center/views/message_center_controller.h" |
26 #include "ui/message_center/views/notification_button.h" | 27 #include "ui/message_center/views/notification_button.h" |
27 #include "ui/message_center/views/proportional_image_view.h" | 28 #include "ui/message_center/views/proportional_image_view.h" |
28 #include "ui/views/controls/button/image_button.h" | 29 #include "ui/views/controls/button/image_button.h" |
29 #include "ui/views/layout/fill_layout.h" | 30 #include "ui/views/layout/fill_layout.h" |
30 #include "ui/views/test/views_test_base.h" | 31 #include "ui/views/test/views_test_base.h" |
31 #include "ui/views/test/widget_test.h" | 32 #include "ui/views/test/widget_test.h" |
32 #include "ui/views/widget/widget_delegate.h" | 33 #include "ui/views/widget/widget_delegate.h" |
33 | 34 |
| 35 namespace { |
| 36 |
| 37 scoped_ptr<ui::GestureEvent> GenerateGestureEvent(ui::EventType type) { |
| 38 ui::GestureEventDetails detail(type); |
| 39 scoped_ptr<ui::GestureEvent> event( |
| 40 new ui::GestureEvent(0, 0, 0, base::TimeDelta(), detail)); |
| 41 return event; |
| 42 } |
| 43 |
| 44 scoped_ptr<ui::GestureEvent> GenerateGestureVerticalScrollUpdateEvent(int dx) { |
| 45 ui::GestureEventDetails detail(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0); |
| 46 scoped_ptr<ui::GestureEvent> event( |
| 47 new ui::GestureEvent(0, 0, 0, base::TimeDelta(), detail)); |
| 48 return event; |
| 49 } |
| 50 |
| 51 } // anonymouse namespace |
| 52 |
34 namespace message_center { | 53 namespace message_center { |
35 | 54 |
36 // A test delegate used for tests that deal with the notification settings | 55 // A test delegate used for tests that deal with the notification settings |
37 // button. | 56 // button. |
38 class NotificationSettingsDelegate : public NotificationDelegate { | 57 class NotificationSettingsDelegate : public NotificationDelegate { |
39 bool ShouldDisplaySettingsButton() override { return true; } | 58 bool ShouldDisplaySettingsButton() override { return true; } |
40 | 59 |
41 private: | 60 private: |
42 ~NotificationSettingsDelegate() override {} | 61 ~NotificationSettingsDelegate() override {} |
43 }; | 62 }; |
44 | 63 |
45 /* Test fixture ***************************************************************/ | 64 /* Test fixture ***************************************************************/ |
46 | 65 |
47 class NotificationViewTest : public views::ViewsTestBase, | 66 class NotificationViewTest : public views::ViewsTestBase, |
48 public MessageCenterController { | 67 public MessageCenterController { |
49 public: | 68 public: |
50 NotificationViewTest(); | 69 NotificationViewTest(); |
51 ~NotificationViewTest() override; | 70 ~NotificationViewTest() override; |
52 | 71 |
53 void SetUp() override; | 72 void SetUp() override; |
54 void TearDown() override; | 73 void TearDown() override; |
55 | 74 |
56 views::Widget* widget() { return notification_view_->GetWidget(); } | 75 views::Widget* widget() { return notification_view_->GetWidget(); } |
57 NotificationView* notification_view() { return notification_view_.get(); } | 76 NotificationView* notification_view() const { |
| 77 return notification_view_.get(); |
| 78 } |
58 Notification* notification() { return notification_.get(); } | 79 Notification* notification() { return notification_.get(); } |
59 RichNotificationData* data() { return data_.get(); } | 80 RichNotificationData* data() { return data_.get(); } |
60 | 81 |
61 // Overridden from MessageCenterController: | 82 // Overridden from MessageCenterController: |
62 void ClickOnNotification(const std::string& notification_id) override; | 83 void ClickOnNotification(const std::string& notification_id) override; |
63 void RemoveNotification(const std::string& notification_id, | 84 void RemoveNotification(const std::string& notification_id, |
64 bool by_user) override; | 85 bool by_user) override; |
65 scoped_ptr<ui::MenuModel> CreateMenuModel( | 86 scoped_ptr<ui::MenuModel> CreateMenuModel( |
66 const NotifierId& notifier_id, | 87 const NotifierId& notifier_id, |
67 const base::string16& display_source) override; | 88 const base::string16& display_source) override; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 169 |
149 gfx::Point current_point = (*current)->bounds().origin(); | 170 gfx::Point current_point = (*current)->bounds().origin(); |
150 views::View::ConvertPointToTarget( | 171 views::View::ConvertPointToTarget( |
151 (*current), notification_view(), ¤t_point); | 172 (*current), notification_view(), ¤t_point); |
152 | 173 |
153 EXPECT_LT(last_point.y(), current_point.y()); | 174 EXPECT_LT(last_point.y(), current_point.y()); |
154 last = current++; | 175 last = current++; |
155 } | 176 } |
156 } | 177 } |
157 | 178 |
| 179 views::ImageButton* GetCloseButton() { |
| 180 return notification_view()->close_button_.get(); |
| 181 } |
| 182 |
158 void UpdateNotificationViews() { | 183 void UpdateNotificationViews() { |
159 notification_view()->CreateOrUpdateViews(*notification()); | 184 notification_view()->CreateOrUpdateViews(*notification()); |
160 notification_view()->Layout(); | 185 notification_view()->Layout(); |
161 } | 186 } |
162 | 187 |
| 188 float GetNotificationScrollAmount() const { |
| 189 return notification_view()->GetTransform().To2dTranslation().x(); |
| 190 } |
| 191 |
| 192 bool IsRemoved(const std::string& notification_id) const { |
| 193 return (removed_ids_.find(notification_id) != removed_ids_.end()); |
| 194 } |
| 195 |
| 196 void RemoveNotificationView() { notification_view_.reset(); } |
| 197 |
163 private: | 198 private: |
| 199 std::set<std::string> removed_ids_; |
| 200 |
164 scoped_ptr<RichNotificationData> data_; | 201 scoped_ptr<RichNotificationData> data_; |
165 scoped_ptr<Notification> notification_; | 202 scoped_ptr<Notification> notification_; |
166 scoped_ptr<NotificationView> notification_view_; | 203 scoped_ptr<NotificationView> notification_view_; |
167 | 204 |
168 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); | 205 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); |
169 }; | 206 }; |
170 | 207 |
171 NotificationViewTest::NotificationViewTest() { | 208 NotificationViewTest::NotificationViewTest() { |
172 } | 209 } |
173 | 210 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 246 |
210 void NotificationViewTest::ClickOnNotification( | 247 void NotificationViewTest::ClickOnNotification( |
211 const std::string& notification_id) { | 248 const std::string& notification_id) { |
212 // For this test, this method should not be invoked. | 249 // For this test, this method should not be invoked. |
213 NOTREACHED(); | 250 NOTREACHED(); |
214 } | 251 } |
215 | 252 |
216 void NotificationViewTest::RemoveNotification( | 253 void NotificationViewTest::RemoveNotification( |
217 const std::string& notification_id, | 254 const std::string& notification_id, |
218 bool by_user) { | 255 bool by_user) { |
219 // For this test, this method should not be invoked. | 256 removed_ids_.insert(notification_id); |
220 NOTREACHED(); | |
221 } | 257 } |
222 | 258 |
223 scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel( | 259 scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel( |
224 const NotifierId& notifier_id, | 260 const NotifierId& notifier_id, |
225 const base::string16& display_source) { | 261 const base::string16& display_source) { |
226 // For this test, this method should not be invoked. | 262 // For this test, this method should not be invoked. |
227 NOTREACHED(); | 263 NOTREACHED(); |
228 return nullptr; | 264 return nullptr; |
229 } | 265 } |
230 | 266 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 // some generic checking here. | 647 // some generic checking here. |
612 // The url has been elided (it starts with an ellipsis) | 648 // The url has been elided (it starts with an ellipsis) |
613 // The end of the domainsuffix is shown | 649 // The end of the domainsuffix is shown |
614 // the url piece is not shown | 650 // the url piece is not shown |
615 EXPECT_TRUE(base::UTF16ToUTF8(result).find( | 651 EXPECT_TRUE(base::UTF16ToUTF8(result).find( |
616 ".veryveryveyrylong.chromium.org") != std::string::npos); | 652 ".veryveryveyrylong.chromium.org") != std::string::npos); |
617 EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0); | 653 EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0); |
618 EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos); | 654 EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos); |
619 } | 655 } |
620 | 656 |
| 657 TEST_F(NotificationViewTest, SlideOut) { |
| 658 ui::ScopedAnimationDurationScaleMode zero_duration_scope( |
| 659 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 660 |
| 661 UpdateNotificationViews(); |
| 662 std::string notification_id = notification()->id(); |
| 663 |
| 664 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN); |
| 665 auto event_scroll10 = GenerateGestureVerticalScrollUpdateEvent(-10); |
| 666 auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500); |
| 667 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END); |
| 668 |
| 669 notification_view()->OnGestureEvent(event_begin.get()); |
| 670 notification_view()->OnGestureEvent(event_scroll10.get()); |
| 671 EXPECT_FALSE(IsRemoved(notification_id)); |
| 672 EXPECT_EQ(-10.f, GetNotificationScrollAmount()); |
| 673 notification_view()->OnGestureEvent(event_end.get()); |
| 674 EXPECT_FALSE(IsRemoved(notification_id)); |
| 675 EXPECT_EQ(0.f, GetNotificationScrollAmount()); |
| 676 |
| 677 notification_view()->OnGestureEvent(event_begin.get()); |
| 678 notification_view()->OnGestureEvent(event_scroll500.get()); |
| 679 EXPECT_FALSE(IsRemoved(notification_id)); |
| 680 EXPECT_EQ(-500.f, GetNotificationScrollAmount()); |
| 681 notification_view()->OnGestureEvent(event_end.get()); |
| 682 EXPECT_TRUE(IsRemoved(notification_id)); |
| 683 } |
| 684 |
| 685 // Pinning notification is ChromeOS only feature. |
| 686 #if defined(OS_CHROMEOS) |
| 687 |
| 688 TEST_F(NotificationViewTest, SlideOutPinned) { |
| 689 ui::ScopedAnimationDurationScaleMode zero_duration_scope( |
| 690 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 691 |
| 692 notification()->set_pinned(true); |
| 693 UpdateNotificationViews(); |
| 694 std::string notification_id = notification()->id(); |
| 695 |
| 696 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN); |
| 697 auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500); |
| 698 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END); |
| 699 |
| 700 notification_view()->OnGestureEvent(event_begin.get()); |
| 701 notification_view()->OnGestureEvent(event_scroll500.get()); |
| 702 EXPECT_FALSE(IsRemoved(notification_id)); |
| 703 EXPECT_LT(-500.f, GetNotificationScrollAmount()); |
| 704 notification_view()->OnGestureEvent(event_end.get()); |
| 705 EXPECT_FALSE(IsRemoved(notification_id)); |
| 706 } |
| 707 |
| 708 TEST_F(NotificationViewTest, Pinned) { |
| 709 notification()->set_pinned(true); |
| 710 |
| 711 UpdateNotificationViews(); |
| 712 EXPECT_EQ(NULL, GetCloseButton()); |
| 713 } |
| 714 |
| 715 #endif // defined(OS_CHROMEOS) |
| 716 |
621 } // namespace message_center | 717 } // namespace message_center |
OLD | NEW |