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

Side by Side Diff: ui/message_center/views/notification_view_unittest.cc

Issue 2850153003: Revert of CrOS: Fix appearance of notification toasts when sliding out via gesture (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "third_party/skia/include/core/SkCanvas.h" 14 #include "third_party/skia/include/core/SkCanvas.h"
15 #include "third_party/skia/include/core/SkColor.h" 15 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 16 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
17 #include "ui/events/event_processor.h" 17 #include "ui/events/event_processor.h"
18 #include "ui/events/event_utils.h" 18 #include "ui/events/event_utils.h"
19 #include "ui/events/test/event_generator.h"
20 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/geometry/size.h" 21 #include "ui/gfx/geometry/size.h"
23 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
24 #include "ui/message_center/message_center_style.h" 23 #include "ui/message_center/message_center_style.h"
25 #include "ui/message_center/notification.h" 24 #include "ui/message_center/notification.h"
26 #include "ui/message_center/notification_list.h" 25 #include "ui/message_center/notification_list.h"
27 #include "ui/message_center/notification_types.h" 26 #include "ui/message_center/notification_types.h"
28 #include "ui/message_center/views/constants.h" 27 #include "ui/message_center/views/constants.h"
29 #include "ui/message_center/views/message_center_controller.h" 28 #include "ui/message_center/views/message_center_controller.h"
30 #include "ui/message_center/views/message_view_factory.h" 29 #include "ui/message_center/views/message_view_factory.h"
31 #include "ui/message_center/views/notification_button.h" 30 #include "ui/message_center/views/notification_button.h"
32 #include "ui/message_center/views/proportional_image_view.h" 31 #include "ui/message_center/views/proportional_image_view.h"
33 #include "ui/views/controls/button/image_button.h" 32 #include "ui/views/controls/button/image_button.h"
34 #include "ui/views/layout/fill_layout.h" 33 #include "ui/views/layout/fill_layout.h"
35 #include "ui/views/test/views_test_base.h" 34 #include "ui/views/test/views_test_base.h"
36 #include "ui/views/test/widget_test.h" 35 #include "ui/views/test/widget_test.h"
37 #include "ui/views/widget/widget_delegate.h" 36 #include "ui/views/widget/widget_delegate.h"
38 37
38 namespace {
39
40 std::unique_ptr<ui::GestureEvent> GenerateGestureEvent(ui::EventType type) {
41 ui::GestureEventDetails detail(type);
42 std::unique_ptr<ui::GestureEvent> event(
43 new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail));
44 return event;
45 }
46
47 std::unique_ptr<ui::GestureEvent> GenerateGestureVerticalScrollUpdateEvent(
48 int dx) {
49 ui::GestureEventDetails detail(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0);
50 std::unique_ptr<ui::GestureEvent> event(
51 new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail));
52 return event;
53 }
54
55 } // anonymouse namespace
56
39 namespace message_center { 57 namespace message_center {
40 58
41 // A test delegate used for tests that deal with the notification settings 59 // A test delegate used for tests that deal with the notification settings
42 // button. 60 // button.
43 class NotificationSettingsDelegate : public NotificationDelegate { 61 class NotificationSettingsDelegate : public NotificationDelegate {
44 bool ShouldDisplaySettingsButton() override { return true; } 62 bool ShouldDisplaySettingsButton() override { return true; }
45 63
46 private: 64 private:
47 ~NotificationSettingsDelegate() override {} 65 ~NotificationSettingsDelegate() override {}
48 }; 66 };
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 179 }
162 180
163 views::ImageButton* GetCloseButton() { 181 views::ImageButton* GetCloseButton() {
164 return notification_view()->close_button(); 182 return notification_view()->close_button();
165 } 183 }
166 184
167 void UpdateNotificationViews() { 185 void UpdateNotificationViews() {
168 notification_view()->UpdateWithNotification(*notification()); 186 notification_view()->UpdateWithNotification(*notification());
169 } 187 }
170 188
171 float GetNotificationSlideAmount() const { 189 float GetNotificationScrollAmount() const {
172 return notification_view_->GetSlideOutLayer() 190 return notification_view()->GetTransform().To2dTranslation().x();
173 ->transform()
174 .To2dTranslation()
175 .x();
176 } 191 }
177 192
178 bool IsRemoved(const std::string& notification_id) const { 193 bool IsRemoved(const std::string& notification_id) const {
179 return (removed_ids_.find(notification_id) != removed_ids_.end()); 194 return (removed_ids_.find(notification_id) != removed_ids_.end());
180 } 195 }
181 196
182 void RemoveNotificationView() { notification_view_.reset(); } 197 void RemoveNotificationView() { notification_view_.reset(); }
183 198
184 void DispatchGesture(const ui::GestureEventDetails& details) {
185 ui::test::EventGenerator generator(
186 notification_view()->GetWidget()->GetNativeWindow());
187 gfx::Point center = notification_view()->GetBoundsInScreen().CenterPoint();
188 ui::GestureEvent event(center.x(), center.y(), 0, ui::EventTimeForNow(),
189 details);
190 generator.Dispatch(&event);
191 }
192
193 void BeginScroll() {
194 DispatchGesture(ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN));
195 }
196
197 void EndScroll() {
198 DispatchGesture(ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END));
199 }
200
201 void ScrollBy(int dx) {
202 DispatchGesture(
203 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0));
204 }
205
206 private: 199 private:
207 std::set<std::string> removed_ids_; 200 std::set<std::string> removed_ids_;
208 201
209 std::unique_ptr<RichNotificationData> data_; 202 std::unique_ptr<RichNotificationData> data_;
210 std::unique_ptr<Notification> notification_; 203 std::unique_ptr<Notification> notification_;
211 std::unique_ptr<NotificationView> notification_view_; 204 std::unique_ptr<NotificationView> notification_view_;
212 205
213 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); 206 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest);
214 }; 207 };
215 208
(...skipping 21 matching lines...) Expand all
237 notification_view_.reset(static_cast<NotificationView*>( 230 notification_view_.reset(static_cast<NotificationView*>(
238 MessageViewFactory::Create(this, *notification_, true))); 231 MessageViewFactory::Create(this, *notification_, true)));
239 notification_view_->set_owned_by_client(); 232 notification_view_->set_owned_by_client();
240 233
241 views::Widget::InitParams init_params( 234 views::Widget::InitParams init_params(
242 CreateParams(views::Widget::InitParams::TYPE_POPUP)); 235 CreateParams(views::Widget::InitParams::TYPE_POPUP));
243 views::Widget* widget = new views::Widget(); 236 views::Widget* widget = new views::Widget();
244 widget->Init(init_params); 237 widget->Init(init_params);
245 widget->SetContentsView(notification_view_.get()); 238 widget->SetContentsView(notification_view_.get());
246 widget->SetSize(notification_view_->GetPreferredSize()); 239 widget->SetSize(notification_view_->GetPreferredSize());
247 widget->Show();
248 } 240 }
249 241
250 void NotificationViewTest::TearDown() { 242 void NotificationViewTest::TearDown() {
251 widget()->Close(); 243 widget()->Close();
252 notification_view_.reset(); 244 notification_view_.reset();
253 views::ViewsTestBase::TearDown(); 245 views::ViewsTestBase::TearDown();
254 } 246 }
255 247
256 void NotificationViewTest::ClickOnNotification( 248 void NotificationViewTest::ClickOnNotification(
257 const std::string& notification_id) { 249 const std::string& notification_id) {
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 EXPECT_TRUE(result_utf8.find("hello") == std::string::npos); 652 EXPECT_TRUE(result_utf8.find("hello") == std::string::npos);
661 } 653 }
662 654
663 TEST_F(NotificationViewTest, SlideOut) { 655 TEST_F(NotificationViewTest, SlideOut) {
664 ui::ScopedAnimationDurationScaleMode zero_duration_scope( 656 ui::ScopedAnimationDurationScaleMode zero_duration_scope(
665 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 657 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
666 658
667 UpdateNotificationViews(); 659 UpdateNotificationViews();
668 std::string notification_id = notification()->id(); 660 std::string notification_id = notification()->id();
669 661
670 BeginScroll(); 662 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
671 ScrollBy(-10); 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());
672 EXPECT_FALSE(IsRemoved(notification_id)); 669 EXPECT_FALSE(IsRemoved(notification_id));
673 EXPECT_EQ(-10.f, GetNotificationSlideAmount()); 670 EXPECT_EQ(-10.f, GetNotificationScrollAmount());
674 EndScroll(); 671 notification_view()->OnGestureEvent(event_end.get());
675 EXPECT_FALSE(IsRemoved(notification_id)); 672 EXPECT_FALSE(IsRemoved(notification_id));
676 EXPECT_EQ(0.f, GetNotificationSlideAmount()); 673 EXPECT_EQ(0.f, GetNotificationScrollAmount());
677 674
678 BeginScroll(); 675 notification_view()->OnGestureEvent(event_begin.get());
679 ScrollBy(-180); 676 notification_view()->OnGestureEvent(event_scroll500.get());
680 EXPECT_FALSE(IsRemoved(notification_id)); 677 EXPECT_FALSE(IsRemoved(notification_id));
681 EXPECT_EQ(-180.f, GetNotificationSlideAmount()); 678 EXPECT_EQ(-500.f, GetNotificationScrollAmount());
682 EndScroll(); 679 notification_view()->OnGestureEvent(event_end.get());
683 EXPECT_TRUE(IsRemoved(notification_id)); 680 EXPECT_TRUE(IsRemoved(notification_id));
684 } 681 }
685 682
686 TEST_F(NotificationViewTest, SlideOutNested) {
687 ui::ScopedAnimationDurationScaleMode zero_duration_scope(
688 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
689
690 UpdateNotificationViews();
691 notification_view()->SetIsNested();
692 std::string notification_id = notification()->id();
693
694 BeginScroll();
695 ScrollBy(-10);
696 EXPECT_FALSE(IsRemoved(notification_id));
697 EXPECT_EQ(-10.f, GetNotificationSlideAmount());
698 EndScroll();
699 EXPECT_FALSE(IsRemoved(notification_id));
700 EXPECT_EQ(0.f, GetNotificationSlideAmount());
701
702 BeginScroll();
703 ScrollBy(-180);
704 EXPECT_FALSE(IsRemoved(notification_id));
705 EXPECT_EQ(-180.f, GetNotificationSlideAmount());
706 EndScroll();
707 EXPECT_TRUE(IsRemoved(notification_id));
708 }
709
710 // Pinning notification is ChromeOS only feature. 683 // Pinning notification is ChromeOS only feature.
711 #if defined(OS_CHROMEOS) 684 #if defined(OS_CHROMEOS)
712 685
713 TEST_F(NotificationViewTest, SlideOutPinned) { 686 TEST_F(NotificationViewTest, SlideOutPinned) {
714 ui::ScopedAnimationDurationScaleMode zero_duration_scope( 687 ui::ScopedAnimationDurationScaleMode zero_duration_scope(
715 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 688 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
716 689
717 notification()->set_pinned(true); 690 notification()->set_pinned(true);
718 UpdateNotificationViews(); 691 UpdateNotificationViews();
719 std::string notification_id = notification()->id(); 692 std::string notification_id = notification()->id();
720 693
721 BeginScroll(); 694 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
722 ScrollBy(-180); 695 auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500);
696 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
697
698 notification_view()->OnGestureEvent(event_begin.get());
699 notification_view()->OnGestureEvent(event_scroll500.get());
723 EXPECT_FALSE(IsRemoved(notification_id)); 700 EXPECT_FALSE(IsRemoved(notification_id));
724 EXPECT_LT(-180.f, GetNotificationSlideAmount()); 701 EXPECT_LT(-500.f, GetNotificationScrollAmount());
725 EndScroll(); 702 notification_view()->OnGestureEvent(event_end.get());
726 EXPECT_FALSE(IsRemoved(notification_id)); 703 EXPECT_FALSE(IsRemoved(notification_id));
727 } 704 }
728 705
729 TEST_F(NotificationViewTest, Pinned) { 706 TEST_F(NotificationViewTest, Pinned) {
730 notification()->set_pinned(true); 707 notification()->set_pinned(true);
731 708
732 UpdateNotificationViews(); 709 UpdateNotificationViews();
733 EXPECT_EQ(NULL, GetCloseButton()); 710 EXPECT_EQ(NULL, GetCloseButton());
734 } 711 }
735 712
736 #endif // defined(OS_CHROMEOS) 713 #endif // defined(OS_CHROMEOS)
737 714
738 } // namespace message_center 715 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/message_view_factory.cc ('k') | ui/message_center/views/slide_out_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698