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

Unified Diff: ui/message_center/views/custom_notification_view_unittest.cc

Issue 2873553002: [Notifications] Fix swipe to close for ARC notifications. (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 side-by-side diff with in-line comments
Download patch
Index: ui/message_center/views/custom_notification_view_unittest.cc
diff --git a/ui/message_center/views/custom_notification_view_unittest.cc b/ui/message_center/views/custom_notification_view_unittest.cc
index 158e010c9dc6edc0567c3b039faa558600423884..c9cf8065db79dbc2787f5a53541126f597557836 100644
--- a/ui/message_center/views/custom_notification_view_unittest.cc
+++ b/ui/message_center/views/custom_notification_view_unittest.cc
@@ -29,6 +29,21 @@ namespace {
const SkColor kBackgroundColor = SK_ColorGREEN;
+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> GenerateGestureHorizontalScrollUpdateEvent(
+ 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;
+}
+
class TestCustomView : public views::View {
public:
TestCustomView() {
@@ -232,6 +247,13 @@ class CustomNotificationViewTest : public views::ViewsTestBase {
notification_view()->UpdateWithNotification(*notification());
}
+ float GetNotificationSlideAmount() const {
+ return notification_view_->GetSlideOutLayer()
+ ->transform()
+ .To2dTranslation()
+ .x();
+ }
+
TestMessageCenterController* controller() { return &controller_; }
Notification* notification() { return notification_.get(); }
TestCustomView* custom_view() {
@@ -275,6 +297,53 @@ TEST_F(CustomNotificationViewTest, Events) {
EXPECT_EQ(1, custom_view()->keyboard_event_count());
}
+TEST_F(CustomNotificationViewTest, SlideOut) {
+ UpdateNotificationViews();
+ std::string notification_id = notification()->id();
+
+ auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
+ auto event_scroll10 = GenerateGestureHorizontalScrollUpdateEvent(-10);
+ auto event_scroll500 = GenerateGestureHorizontalScrollUpdateEvent(-500);
+ auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
+
+ notification_view()->OnGestureEvent(event_begin.get());
+ notification_view()->OnGestureEvent(event_scroll10.get());
+ EXPECT_FALSE(controller()->IsRemoved(notification_id));
+ EXPECT_EQ(-10.f, GetNotificationSlideAmount());
+ notification_view()->OnGestureEvent(event_end.get());
+ EXPECT_FALSE(controller()->IsRemoved(notification_id));
+ EXPECT_EQ(0.f, GetNotificationSlideAmount());
+
+ notification_view()->OnGestureEvent(event_begin.get());
+ notification_view()->OnGestureEvent(event_scroll500.get());
+ EXPECT_FALSE(controller()->IsRemoved(notification_id));
+ EXPECT_EQ(-500.f, GetNotificationSlideAmount());
+ notification_view()->OnGestureEvent(event_end.get());
+ EXPECT_TRUE(controller()->IsRemoved(notification_id));
+}
+
+// Pinning notification is ChromeOS only feature.
+#if defined(OS_CHROMEOS)
+
+TEST_F(CustomNotificationViewTest, SlideOutPinned) {
+ notification()->set_pinned(true);
+ UpdateNotificationViews();
+ std::string notification_id = notification()->id();
+
+ auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
+ auto event_scroll500 = GenerateGestureHorizontalScrollUpdateEvent(-500);
+ auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
+
+ notification_view()->OnGestureEvent(event_begin.get());
+ notification_view()->OnGestureEvent(event_scroll500.get());
+ EXPECT_FALSE(controller()->IsRemoved(notification_id));
+ EXPECT_LT(-500.f, GetNotificationSlideAmount());
+ notification_view()->OnGestureEvent(event_end.get());
+ EXPECT_FALSE(controller()->IsRemoved(notification_id));
+}
+
+#endif // defined(OS_CHROMEOS)
+
TEST_F(CustomNotificationViewTest, PressBackspaceKey) {
std::string notification_id = notification()->id();
custom_view()->RequestFocus();
« no previous file with comments | « no previous file | ui/message_center/views/message_view.cc » ('j') | ui/message_center/views/slide_out_controller.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698