summaryrefslogtreecommitdiffstats
path: root/content/renderer/render_widget_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'content/renderer/render_widget_unittest.cc')
-rw-r--r--content/renderer/render_widget_unittest.cc83
1 files changed, 76 insertions, 7 deletions
diff --git a/content/renderer/render_widget_unittest.cc b/content/renderer/render_widget_unittest.cc
index d9b919a..508ebc1 100644
--- a/content/renderer/render_widget_unittest.cc
+++ b/content/renderer/render_widget_unittest.cc
@@ -29,14 +29,15 @@ class RenderWidgetUnittest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(RenderWidgetUnittest);
};
-class TouchableRenderWidget : public RenderWidget {
+class InteractiveRenderWidget : public RenderWidget {
public:
- TouchableRenderWidget()
+ InteractiveRenderWidget()
: RenderWidget(blink::WebPopupTypeNone,
blink::WebScreenInfo(),
false,
false,
- false) {}
+ false),
+ always_overscroll_(false) {}
void SetTouchRegion(const std::vector<gfx::Rect>& rects) {
rects_ = rects;
@@ -46,10 +47,14 @@ class TouchableRenderWidget : public RenderWidget {
OnHandleInputEvent(&event, ui::LatencyInfo(), false);
}
+ void set_always_overscroll(bool overscroll) {
+ always_overscroll_ = overscroll;
+ }
+
IPC::TestSink* sink() { return &sink_; }
protected:
- ~TouchableRenderWidget() override {}
+ ~InteractiveRenderWidget() override {}
// Overridden from RenderWidget:
bool HasTouchEventHandlersAt(const gfx::Point& point) const override {
@@ -61,6 +66,22 @@ class TouchableRenderWidget : public RenderWidget {
return false;
}
+ bool WillHandleGestureEvent(const blink::WebGestureEvent& event) override {
+ if (always_overscroll_ &&
+ event.type == blink::WebInputEvent::GestureScrollUpdate) {
+ didOverscroll(blink::WebFloatSize(event.data.scrollUpdate.deltaX,
+ event.data.scrollUpdate.deltaY),
+ blink::WebFloatSize(event.data.scrollUpdate.deltaX,
+ event.data.scrollUpdate.deltaY),
+ blink::WebFloatPoint(event.x, event.y),
+ blink::WebFloatSize(event.data.scrollUpdate.velocityX,
+ event.data.scrollUpdate.velocityY));
+ return true;
+ }
+
+ return false;
+ }
+
bool Send(IPC::Message* msg) override {
sink_.OnMessageReceived(*msg);
delete msg;
@@ -70,12 +91,13 @@ class TouchableRenderWidget : public RenderWidget {
private:
std::vector<gfx::Rect> rects_;
IPC::TestSink sink_;
+ bool always_overscroll_;
- DISALLOW_COPY_AND_ASSIGN(TouchableRenderWidget);
+ DISALLOW_COPY_AND_ASSIGN(InteractiveRenderWidget);
};
TEST_F(RenderWidgetUnittest, TouchHitTestSinglePoint) {
- scoped_refptr<TouchableRenderWidget> widget = new TouchableRenderWidget();
+ scoped_refptr<InteractiveRenderWidget> widget = new InteractiveRenderWidget();
SyntheticWebTouchEvent touch;
touch.PressPoint(10, 10);
@@ -109,7 +131,7 @@ TEST_F(RenderWidgetUnittest, TouchHitTestSinglePoint) {
}
TEST_F(RenderWidgetUnittest, TouchHitTestMultiplePoints) {
- scoped_refptr<TouchableRenderWidget> widget = new TouchableRenderWidget();
+ scoped_refptr<InteractiveRenderWidget> widget = new InteractiveRenderWidget();
std::vector<gfx::Rect> rects;
rects.push_back(gfx::Rect(0, 0, 20, 20));
rects.push_back(gfx::Rect(25, 0, 10, 10));
@@ -143,4 +165,51 @@ TEST_F(RenderWidgetUnittest, TouchHitTestMultiplePoints) {
widget->sink()->ClearMessages();
}
+TEST_F(RenderWidgetUnittest, EventOverscroll) {
+ scoped_refptr<InteractiveRenderWidget> widget = new InteractiveRenderWidget();
+ widget->set_always_overscroll(true);
+
+ blink::WebGestureEvent scroll;
+ scroll.type = blink::WebInputEvent::GestureScrollUpdate;
+ scroll.x = -10;
+ scroll.data.scrollUpdate.deltaY = 10;
+ widget->SendInputEvent(scroll);
+
+ // Overscroll notifications received while handling an input event should
+ // be bundled with the event ack IPC.
+ ASSERT_EQ(1u, widget->sink()->message_count());
+ const IPC::Message* message = widget->sink()->GetMessageAt(0);
+ ASSERT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type());
+ InputHostMsg_HandleInputEvent_ACK::Param params;
+ InputHostMsg_HandleInputEvent_ACK::Read(message, &params);
+ const InputEventAck& ack = base::get<0>(params);
+ ASSERT_EQ(ack.type, scroll.type);
+ ASSERT_TRUE(ack.overscroll);
+ EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->accumulated_overscroll);
+ EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->latest_overscroll_delta);
+ EXPECT_EQ(gfx::Vector2dF(), ack.overscroll->current_fling_velocity);
+ EXPECT_EQ(gfx::PointF(-10, 0), ack.overscroll->causal_event_viewport_point);
+ widget->sink()->ClearMessages();
+}
+
+TEST_F(RenderWidgetUnittest, FlingOverscroll) {
+ scoped_refptr<InteractiveRenderWidget> widget = new InteractiveRenderWidget();
+
+ // Overscroll notifications received outside of handling an input event should
+ // be sent as a separate IPC.
+ widget->didOverscroll(blink::WebFloatSize(10, 5), blink::WebFloatSize(5, 5),
+ blink::WebFloatPoint(1, 1), blink::WebFloatSize(10, 5));
+ ASSERT_EQ(1u, widget->sink()->message_count());
+ const IPC::Message* message = widget->sink()->GetMessageAt(0);
+ ASSERT_EQ(InputHostMsg_DidOverscroll::ID, message->type());
+ InputHostMsg_DidOverscroll::Param params;
+ InputHostMsg_DidOverscroll::Read(message, &params);
+ const DidOverscrollParams& overscroll = base::get<0>(params);
+ EXPECT_EQ(gfx::Vector2dF(10, 5), overscroll.latest_overscroll_delta);
+ EXPECT_EQ(gfx::Vector2dF(5, 5), overscroll.accumulated_overscroll);
+ EXPECT_EQ(gfx::PointF(1, 1), overscroll.causal_event_viewport_point);
+ EXPECT_EQ(gfx::Vector2dF(-10, -5), overscroll.current_fling_velocity);
+ widget->sink()->ClearMessages();
+}
+
} // namespace content