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