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

Unified Diff: ui/views/widget/widget_unittest.cc

Issue 408713002: Enhance test WidgetTest.GestureHandlerNotSetOnGestureEnd (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clarified this was for a single touch point only Created 6 years, 5 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/widget_unittest.cc
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
index 00413e242552530501953cfff965babd1bf70d50..36a83f1a82b6d3bf19e2c9ff5e5538c1744c91a7 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -1944,31 +1944,68 @@ TEST_F(WidgetTest, MAYBE_DisableTestRootViewHandlersWhenHidden) {
widget->Close();
}
-class GestureEndConsumerView : public View {
- private:
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
- if (event->type() == ui::ET_GESTURE_END)
- event->SetHandled();
- }
+// Convenience to make constructing a GestureEvent simpler.
+class GestureEventForTest : public ui::GestureEvent {
+ public:
+ GestureEventForTest(ui::EventType type, int x, int y)
+ : GestureEvent(x,
+ y,
+ 0,
+ base::TimeDelta(),
+ ui::GestureEventDetails(type, 0.0f, 0.0f)) {}
};
+// Tests that the |gesture_handler_| member in RootView is always NULL
+// after the dispatch of a ui::ET_GESTURE_END event corresponding to
+// the release of the final touch point on the screen.
TEST_F(WidgetTest, GestureHandlerNotSetOnGestureEnd) {
Widget* widget = CreateTopLevelNativeWidget();
widget->SetBounds(gfx::Rect(0, 0, 300, 300));
- View* view = new GestureEndConsumerView();
+ EventCountView* view = new EventCountView();
view->SetBounds(0, 0, 300, 300);
internal::RootView* root_view =
static_cast<internal::RootView*>(widget->GetRootView());
root_view->AddChildView(view);
-
widget->Show();
+
+ // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END
+ // event should not set the gesture handler if the event remains unhandled.
EXPECT_EQ(NULL, GetGestureHandler(root_view));
- ui::GestureEvent end(15,
- 15,
- 0,
- base::TimeDelta(),
- ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0));
+ GestureEventForTest end(ui::ET_GESTURE_END, 15, 15);
+ widget->OnGestureEvent(&end);
+ EXPECT_FALSE(end.handled());
+ EXPECT_EQ(NULL, GetGestureHandler(root_view));
+
+ // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END
+ // event should not set the gesture handler event if the event is handled.
+ view->set_handle_mode(EventCountView::CONSUME_EVENTS);
+ end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
widget->OnGestureEvent(&end);
+ EXPECT_TRUE(end.handled());
+ EXPECT_EQ(NULL, GetGestureHandler(root_view));
+
+ // If the gesture handler has been set by a previous gesture, then
+ // it should be reset to NULL by a ui::ET_GESTURE_END.
+ GestureEventForTest tap(ui::ET_GESTURE_TAP, 15, 15);
+ widget->OnGestureEvent(&tap);
+ EXPECT_TRUE(tap.handled());
+ EXPECT_EQ(view, GetGestureHandler(root_view));
+ end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
+ widget->OnGestureEvent(&end);
+ EXPECT_TRUE(end.handled());
+ EXPECT_EQ(NULL, GetGestureHandler(root_view));
+
+ // If the gesture handler has been set by a previous gesture, then
+ // it should be reset to NULL by a ui::ET_GESTURE_END, even when
+ // the gesture handler does not actually handle the end event.
+ tap = GestureEventForTest(ui::ET_GESTURE_TAP, 15, 15);
+ widget->OnGestureEvent(&tap);
+ EXPECT_TRUE(tap.handled());
+ EXPECT_EQ(view, GetGestureHandler(root_view));
+ end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
+ view->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
+ widget->OnGestureEvent(&end);
+ EXPECT_FALSE(end.handled());
EXPECT_EQ(NULL, GetGestureHandler(root_view));
widget->Close();
@@ -2448,20 +2485,6 @@ class FullscreenAwareFrame : public views::NonClientFrameView {
DISALLOW_COPY_AND_ASSIGN(FullscreenAwareFrame);
};
-// Convenience to make constructing a GestureEvent simpler.
-class GestureEventForTest : public ui::GestureEvent {
- public:
- GestureEventForTest(ui::EventType type, int x, int y)
- : GestureEvent(x,
- y,
- 0,
- base::TimeDelta(),
- ui::GestureEventDetails(type, 0.0f, 0.0f)) {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(GestureEventForTest);
-};
-
} // namespace
// Tests that frame Layout is called when a widget goes fullscreen without
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698