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

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

Issue 2620133003: Set slide_out_enabled property for CustomNotification (Closed)
Patch Set: Fix the wrong term: vertical -> horizontal Created 3 years, 11 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
« no previous file with comments | « no previous file | ui/message_center/views/message_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e26c4b2f8a08d42ffef7f055b2582605c2cd1dce..1e5e2713d3d923d12893ca4d5338c778b708c9fc 100644
--- a/ui/message_center/views/custom_notification_view_unittest.cc
+++ b/ui/message_center/views/custom_notification_view_unittest.cc
@@ -26,6 +26,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() {
@@ -196,12 +211,23 @@ class CustomNotificationViewTest : public views::ViewsTestBase {
widget()->OnKeyEvent(&event);
}
+ void UpdateNotificationViews() {
+ notification_view()->UpdateWithNotification(*notification());
+ }
+
+ float GetNotificationScrollAmount() const {
+ return notification_view_->GetTransform().To2dTranslation().x();
+ }
+
TestMessageCenterController* controller() { return &controller_; }
Notification* notification() { return notification_.get(); }
TestCustomView* custom_view() {
return static_cast<TestCustomView*>(notification_view_->contents_view_);
}
views::Widget* widget() { return notification_view_->GetWidget(); }
+ CustomNotificationView* notification_view() {
+ return notification_view_.get();
+ }
private:
TestMessageCenterController controller_;
@@ -236,4 +262,51 @@ 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, GetNotificationScrollAmount());
+ notification_view()->OnGestureEvent(event_end.get());
+ EXPECT_FALSE(controller()->IsRemoved(notification_id));
+ EXPECT_EQ(0.f, GetNotificationScrollAmount());
+
+ notification_view()->OnGestureEvent(event_begin.get());
+ notification_view()->OnGestureEvent(event_scroll500.get());
+ EXPECT_FALSE(controller()->IsRemoved(notification_id));
+ EXPECT_EQ(-500.f, GetNotificationScrollAmount());
+ 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, GetNotificationScrollAmount());
+ notification_view()->OnGestureEvent(event_end.get());
+ EXPECT_FALSE(controller()->IsRemoved(notification_id));
+}
+
+#endif // defined(OS_CHROMEOS)
+
} // namespace message_center
« no previous file with comments | « no previous file | ui/message_center/views/message_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698