Index: ui/message_center/views/notification_view_unittest.cc |
diff --git a/ui/message_center/views/notification_view_unittest.cc b/ui/message_center/views/notification_view_unittest.cc |
index 5528ef1f6c9e6046ee882da6105947958338d65c..4f9413daeabfbf1d7b9d84df08ea67d5c448f8ab 100644 |
--- a/ui/message_center/views/notification_view_unittest.cc |
+++ b/ui/message_center/views/notification_view_unittest.cc |
@@ -16,7 +16,6 @@ |
#include "ui/compositor/scoped_animation_duration_scale_mode.h" |
#include "ui/events/event_processor.h" |
#include "ui/events/event_utils.h" |
-#include "ui/events/test/event_generator.h" |
#include "ui/gfx/canvas.h" |
#include "ui/gfx/geometry/rect.h" |
#include "ui/gfx/geometry/size.h" |
@@ -35,6 +34,25 @@ |
#include "ui/views/test/views_test_base.h" |
#include "ui/views/test/widget_test.h" |
#include "ui/views/widget/widget_delegate.h" |
+ |
+namespace { |
+ |
+std::unique_ptr<ui::GestureEvent> GenerateGestureEvent(ui::EventType type) { |
+ ui::GestureEventDetails detail(type); |
+ std::unique_ptr<ui::GestureEvent> event( |
+ new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail)); |
+ return event; |
+} |
+ |
+std::unique_ptr<ui::GestureEvent> GenerateGestureVerticalScrollUpdateEvent( |
+ int dx) { |
+ ui::GestureEventDetails detail(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0); |
+ std::unique_ptr<ui::GestureEvent> event( |
+ new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail)); |
+ return event; |
+} |
+ |
+} // anonymouse namespace |
namespace message_center { |
@@ -168,11 +186,8 @@ |
notification_view()->UpdateWithNotification(*notification()); |
} |
- float GetNotificationSlideAmount() const { |
- return notification_view_->GetSlideOutLayer() |
- ->transform() |
- .To2dTranslation() |
- .x(); |
+ float GetNotificationScrollAmount() const { |
+ return notification_view()->GetTransform().To2dTranslation().x(); |
} |
bool IsRemoved(const std::string& notification_id) const { |
@@ -180,28 +195,6 @@ |
} |
void RemoveNotificationView() { notification_view_.reset(); } |
- |
- void DispatchGesture(const ui::GestureEventDetails& details) { |
- ui::test::EventGenerator generator( |
- notification_view()->GetWidget()->GetNativeWindow()); |
- gfx::Point center = notification_view()->GetBoundsInScreen().CenterPoint(); |
- ui::GestureEvent event(center.x(), center.y(), 0, ui::EventTimeForNow(), |
- details); |
- generator.Dispatch(&event); |
- } |
- |
- void BeginScroll() { |
- DispatchGesture(ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); |
- } |
- |
- void EndScroll() { |
- DispatchGesture(ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); |
- } |
- |
- void ScrollBy(int dx) { |
- DispatchGesture( |
- ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0)); |
- } |
private: |
std::set<std::string> removed_ids_; |
@@ -244,7 +237,6 @@ |
widget->Init(init_params); |
widget->SetContentsView(notification_view_.get()); |
widget->SetSize(notification_view_->GetPreferredSize()); |
- widget->Show(); |
} |
void NotificationViewTest::TearDown() { |
@@ -667,43 +659,24 @@ |
UpdateNotificationViews(); |
std::string notification_id = notification()->id(); |
- BeginScroll(); |
- ScrollBy(-10); |
+ auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN); |
+ auto event_scroll10 = GenerateGestureVerticalScrollUpdateEvent(-10); |
+ auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500); |
+ auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END); |
+ |
+ notification_view()->OnGestureEvent(event_begin.get()); |
+ notification_view()->OnGestureEvent(event_scroll10.get()); |
EXPECT_FALSE(IsRemoved(notification_id)); |
- EXPECT_EQ(-10.f, GetNotificationSlideAmount()); |
- EndScroll(); |
+ EXPECT_EQ(-10.f, GetNotificationScrollAmount()); |
+ notification_view()->OnGestureEvent(event_end.get()); |
EXPECT_FALSE(IsRemoved(notification_id)); |
- EXPECT_EQ(0.f, GetNotificationSlideAmount()); |
- |
- BeginScroll(); |
- ScrollBy(-180); |
+ EXPECT_EQ(0.f, GetNotificationScrollAmount()); |
+ |
+ notification_view()->OnGestureEvent(event_begin.get()); |
+ notification_view()->OnGestureEvent(event_scroll500.get()); |
EXPECT_FALSE(IsRemoved(notification_id)); |
- EXPECT_EQ(-180.f, GetNotificationSlideAmount()); |
- EndScroll(); |
- EXPECT_TRUE(IsRemoved(notification_id)); |
-} |
- |
-TEST_F(NotificationViewTest, SlideOutNested) { |
- ui::ScopedAnimationDurationScaleMode zero_duration_scope( |
- ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
- |
- UpdateNotificationViews(); |
- notification_view()->SetIsNested(); |
- std::string notification_id = notification()->id(); |
- |
- BeginScroll(); |
- ScrollBy(-10); |
- EXPECT_FALSE(IsRemoved(notification_id)); |
- EXPECT_EQ(-10.f, GetNotificationSlideAmount()); |
- EndScroll(); |
- EXPECT_FALSE(IsRemoved(notification_id)); |
- EXPECT_EQ(0.f, GetNotificationSlideAmount()); |
- |
- BeginScroll(); |
- ScrollBy(-180); |
- EXPECT_FALSE(IsRemoved(notification_id)); |
- EXPECT_EQ(-180.f, GetNotificationSlideAmount()); |
- EndScroll(); |
+ EXPECT_EQ(-500.f, GetNotificationScrollAmount()); |
+ notification_view()->OnGestureEvent(event_end.get()); |
EXPECT_TRUE(IsRemoved(notification_id)); |
} |
@@ -718,11 +691,15 @@ |
UpdateNotificationViews(); |
std::string notification_id = notification()->id(); |
- BeginScroll(); |
- ScrollBy(-180); |
+ auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN); |
+ auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500); |
+ auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END); |
+ |
+ notification_view()->OnGestureEvent(event_begin.get()); |
+ notification_view()->OnGestureEvent(event_scroll500.get()); |
EXPECT_FALSE(IsRemoved(notification_id)); |
- EXPECT_LT(-180.f, GetNotificationSlideAmount()); |
- EndScroll(); |
+ EXPECT_LT(-500.f, GetNotificationScrollAmount()); |
+ notification_view()->OnGestureEvent(event_end.get()); |
EXPECT_FALSE(IsRemoved(notification_id)); |
} |