Enhance test WidgetTest.GestureHandlerNotSetOnGestureEnd

Enhance the coverage of this unit test to verify that
the gesture handler tracked by RootView is always NULL
after a ui::ET_GESTURE_END event corresponding to the 
release of the final touch point has been dispatched.

BUG=395397
TEST=WidgetTest.GestureHandlerNotSetOnGestureEnd

Review URL: https://codereview.chromium.org/408713002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284478 0039d316-1c4b-4281-b951-d872f2087c98
parent 18359a3a
...@@ -1944,31 +1944,68 @@ TEST_F(WidgetTest, MAYBE_DisableTestRootViewHandlersWhenHidden) { ...@@ -1944,31 +1944,68 @@ TEST_F(WidgetTest, MAYBE_DisableTestRootViewHandlersWhenHidden) {
widget->Close(); widget->Close();
} }
class GestureEndConsumerView : public View { // Convenience to make constructing a GestureEvent simpler.
private: class GestureEventForTest : public ui::GestureEvent {
virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { public:
if (event->type() == ui::ET_GESTURE_END) GestureEventForTest(ui::EventType type, int x, int y)
event->SetHandled(); : 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) { TEST_F(WidgetTest, GestureHandlerNotSetOnGestureEnd) {
Widget* widget = CreateTopLevelNativeWidget(); Widget* widget = CreateTopLevelNativeWidget();
widget->SetBounds(gfx::Rect(0, 0, 300, 300)); widget->SetBounds(gfx::Rect(0, 0, 300, 300));
View* view = new GestureEndConsumerView(); EventCountView* view = new EventCountView();
view->SetBounds(0, 0, 300, 300); view->SetBounds(0, 0, 300, 300);
internal::RootView* root_view = internal::RootView* root_view =
static_cast<internal::RootView*>(widget->GetRootView()); static_cast<internal::RootView*>(widget->GetRootView());
root_view->AddChildView(view); root_view->AddChildView(view);
widget->Show(); 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)); EXPECT_EQ(NULL, GetGestureHandler(root_view));
ui::GestureEvent end(15, GestureEventForTest end(ui::ET_GESTURE_END, 15, 15);
15, widget->OnGestureEvent(&end);
0, EXPECT_FALSE(end.handled());
base::TimeDelta(), EXPECT_EQ(NULL, GetGestureHandler(root_view));
ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0));
// 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); 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)); EXPECT_EQ(NULL, GetGestureHandler(root_view));
widget->Close(); widget->Close();
...@@ -2448,20 +2485,6 @@ class FullscreenAwareFrame : public views::NonClientFrameView { ...@@ -2448,20 +2485,6 @@ class FullscreenAwareFrame : public views::NonClientFrameView {
DISALLOW_COPY_AND_ASSIGN(FullscreenAwareFrame); 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 } // namespace
// Tests that frame Layout is called when a widget goes fullscreen without // Tests that frame Layout is called when a widget goes fullscreen without
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment