| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" | 
| 6 | 6 | 
| 7 #include <vector> | 7 #include <vector> | 
| 8 | 8 | 
| 9 #include "content/common/input/synthetic_web_input_event_builders.h" | 9 #include "content/common/input/synthetic_web_input_event_builders.h" | 
| 10 #include "content/common/input_messages.h" | 10 #include "content/common/input_messages.h" | 
| 11 #include "content/public/test/mock_render_thread.h" | 11 #include "content/public/test/mock_render_thread.h" | 
|  | 12 #include "content/test/fake_compositor_dependencies.h" | 
| 12 #include "content/test/mock_render_process.h" | 13 #include "content/test/mock_render_process.h" | 
| 13 #include "ipc/ipc_test_sink.h" | 14 #include "ipc/ipc_test_sink.h" | 
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" | 
| 15 #include "third_party/WebKit/public/web/WebInputEvent.h" | 16 #include "third_party/WebKit/public/web/WebInputEvent.h" | 
| 16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" | 
| 17 | 18 | 
| 18 namespace content { | 19 namespace content { | 
| 19 | 20 | 
| 20 class RenderWidgetUnittest : public testing::Test { |  | 
| 21  public: |  | 
| 22   RenderWidgetUnittest() {} |  | 
| 23   ~RenderWidgetUnittest() override {} |  | 
| 24 |  | 
| 25  private: |  | 
| 26   MockRenderProcess render_process_; |  | 
| 27   MockRenderThread render_thread_; |  | 
| 28 |  | 
| 29   DISALLOW_COPY_AND_ASSIGN(RenderWidgetUnittest); |  | 
| 30 }; |  | 
| 31 |  | 
| 32 class InteractiveRenderWidget : public RenderWidget { | 21 class InteractiveRenderWidget : public RenderWidget { | 
| 33  public: | 22  public: | 
| 34   InteractiveRenderWidget() | 23   explicit InteractiveRenderWidget(CompositorDependencies* compositor_deps) | 
| 35       : RenderWidget(blink::WebPopupTypeNone, | 24       : RenderWidget(compositor_deps, | 
|  | 25                      blink::WebPopupTypeNone, | 
| 36                      blink::WebScreenInfo(), | 26                      blink::WebScreenInfo(), | 
| 37                      false, | 27                      false, | 
| 38                      false, | 28                      false, | 
| 39                      false), | 29                      false), | 
| 40         always_overscroll_(false) {} | 30         always_overscroll_(false) {} | 
| 41 | 31 | 
| 42   void SetTouchRegion(const std::vector<gfx::Rect>& rects) { | 32   void SetTouchRegion(const std::vector<gfx::Rect>& rects) { | 
| 43     rects_ = rects; | 33     rects_ = rects; | 
| 44   } | 34   } | 
| 45 | 35 | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 89   } | 79   } | 
| 90 | 80 | 
| 91  private: | 81  private: | 
| 92   std::vector<gfx::Rect> rects_; | 82   std::vector<gfx::Rect> rects_; | 
| 93   IPC::TestSink sink_; | 83   IPC::TestSink sink_; | 
| 94   bool always_overscroll_; | 84   bool always_overscroll_; | 
| 95 | 85 | 
| 96   DISALLOW_COPY_AND_ASSIGN(InteractiveRenderWidget); | 86   DISALLOW_COPY_AND_ASSIGN(InteractiveRenderWidget); | 
| 97 }; | 87 }; | 
| 98 | 88 | 
|  | 89 class RenderWidgetUnittest : public testing::Test { | 
|  | 90  public: | 
|  | 91   RenderWidgetUnittest() | 
|  | 92       : widget_(new InteractiveRenderWidget(&compositor_deps_)) {} | 
|  | 93   ~RenderWidgetUnittest() override {} | 
|  | 94 | 
|  | 95   InteractiveRenderWidget* widget() const { return widget_.get(); } | 
|  | 96 | 
|  | 97  private: | 
|  | 98   MockRenderProcess render_process_; | 
|  | 99   MockRenderThread render_thread_; | 
|  | 100   FakeCompositorDependencies compositor_deps_; | 
|  | 101   scoped_refptr<InteractiveRenderWidget> widget_; | 
|  | 102 | 
|  | 103   DISALLOW_COPY_AND_ASSIGN(RenderWidgetUnittest); | 
|  | 104 }; | 
|  | 105 | 
| 99 TEST_F(RenderWidgetUnittest, TouchHitTestSinglePoint) { | 106 TEST_F(RenderWidgetUnittest, TouchHitTestSinglePoint) { | 
| 100   scoped_refptr<InteractiveRenderWidget> widget = new InteractiveRenderWidget(); |  | 
| 101 |  | 
| 102   SyntheticWebTouchEvent touch; | 107   SyntheticWebTouchEvent touch; | 
| 103   touch.PressPoint(10, 10); | 108   touch.PressPoint(10, 10); | 
| 104 | 109 | 
| 105   widget->SendInputEvent(touch); | 110   widget()->SendInputEvent(touch); | 
| 106   ASSERT_EQ(1u, widget->sink()->message_count()); | 111   ASSERT_EQ(1u, widget()->sink()->message_count()); | 
| 107 | 112 | 
| 108   // Since there's currently no touch-event handling region, the response should | 113   // Since there's currently no touch-event handling region, the response should | 
| 109   // be 'no consumer exists'. | 114   // be 'no consumer exists'. | 
| 110   const IPC::Message* message = widget->sink()->GetMessageAt(0); | 115   const IPC::Message* message = widget()->sink()->GetMessageAt(0); | 
| 111   EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 116   EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 
| 112   InputHostMsg_HandleInputEvent_ACK::Param params; | 117   InputHostMsg_HandleInputEvent_ACK::Param params; | 
| 113   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 118   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 
| 114   InputEventAckState ack_state = base::get<0>(params).state; | 119   InputEventAckState ack_state = base::get<0>(params).state; | 
| 115   EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state); | 120   EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state); | 
| 116   widget->sink()->ClearMessages(); | 121   widget()->sink()->ClearMessages(); | 
| 117 | 122 | 
| 118   std::vector<gfx::Rect> rects; | 123   std::vector<gfx::Rect> rects; | 
| 119   rects.push_back(gfx::Rect(0, 0, 20, 20)); | 124   rects.push_back(gfx::Rect(0, 0, 20, 20)); | 
| 120   rects.push_back(gfx::Rect(25, 0, 10, 10)); | 125   rects.push_back(gfx::Rect(25, 0, 10, 10)); | 
| 121   widget->SetTouchRegion(rects); | 126   widget()->SetTouchRegion(rects); | 
| 122 | 127 | 
| 123   widget->SendInputEvent(touch); | 128   widget()->SendInputEvent(touch); | 
| 124   ASSERT_EQ(1u, widget->sink()->message_count()); | 129   ASSERT_EQ(1u, widget()->sink()->message_count()); | 
| 125   message = widget->sink()->GetMessageAt(0); | 130   message = widget()->sink()->GetMessageAt(0); | 
| 126   EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 131   EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 
| 127   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 132   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 
| 128   ack_state = base::get<0>(params).state; | 133   ack_state = base::get<0>(params).state; | 
| 129   EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state); | 134   EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state); | 
| 130   widget->sink()->ClearMessages(); | 135   widget()->sink()->ClearMessages(); | 
| 131 } | 136 } | 
| 132 | 137 | 
| 133 TEST_F(RenderWidgetUnittest, TouchHitTestMultiplePoints) { | 138 TEST_F(RenderWidgetUnittest, TouchHitTestMultiplePoints) { | 
| 134   scoped_refptr<InteractiveRenderWidget> widget = new InteractiveRenderWidget(); |  | 
| 135   std::vector<gfx::Rect> rects; | 139   std::vector<gfx::Rect> rects; | 
| 136   rects.push_back(gfx::Rect(0, 0, 20, 20)); | 140   rects.push_back(gfx::Rect(0, 0, 20, 20)); | 
| 137   rects.push_back(gfx::Rect(25, 0, 10, 10)); | 141   rects.push_back(gfx::Rect(25, 0, 10, 10)); | 
| 138   widget->SetTouchRegion(rects); | 142   widget()->SetTouchRegion(rects); | 
| 139 | 143 | 
| 140   SyntheticWebTouchEvent touch; | 144   SyntheticWebTouchEvent touch; | 
| 141   touch.PressPoint(25, 25); | 145   touch.PressPoint(25, 25); | 
| 142 | 146 | 
| 143   widget->SendInputEvent(touch); | 147   widget()->SendInputEvent(touch); | 
| 144   ASSERT_EQ(1u, widget->sink()->message_count()); | 148   ASSERT_EQ(1u, widget()->sink()->message_count()); | 
| 145 | 149 | 
| 146   // Since there's currently no touch-event handling region, the response should | 150   // Since there's currently no touch-event handling region, the response should | 
| 147   // be 'no consumer exists'. | 151   // be 'no consumer exists'. | 
| 148   const IPC::Message* message = widget->sink()->GetMessageAt(0); | 152   const IPC::Message* message = widget()->sink()->GetMessageAt(0); | 
| 149   EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 153   EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 
| 150   InputHostMsg_HandleInputEvent_ACK::Param params; | 154   InputHostMsg_HandleInputEvent_ACK::Param params; | 
| 151   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 155   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 
| 152   InputEventAckState ack_state = base::get<0>(params).state; | 156   InputEventAckState ack_state = base::get<0>(params).state; | 
| 153   EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state); | 157   EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state); | 
| 154   widget->sink()->ClearMessages(); | 158   widget()->sink()->ClearMessages(); | 
| 155 | 159 | 
| 156   // Press a second touch point. This time, on a touch-handling region. | 160   // Press a second touch point. This time, on a touch-handling region. | 
| 157   touch.PressPoint(10, 10); | 161   touch.PressPoint(10, 10); | 
| 158   widget->SendInputEvent(touch); | 162   widget()->SendInputEvent(touch); | 
| 159   ASSERT_EQ(1u, widget->sink()->message_count()); | 163   ASSERT_EQ(1u, widget()->sink()->message_count()); | 
| 160   message = widget->sink()->GetMessageAt(0); | 164   message = widget()->sink()->GetMessageAt(0); | 
| 161   EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 165   EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 
| 162   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 166   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 
| 163   ack_state = base::get<0>(params).state; | 167   ack_state = base::get<0>(params).state; | 
| 164   EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state); | 168   EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state); | 
| 165   widget->sink()->ClearMessages(); | 169   widget()->sink()->ClearMessages(); | 
| 166 } | 170 } | 
| 167 | 171 | 
| 168 TEST_F(RenderWidgetUnittest, EventOverscroll) { | 172 TEST_F(RenderWidgetUnittest, EventOverscroll) { | 
| 169   scoped_refptr<InteractiveRenderWidget> widget = new InteractiveRenderWidget(); | 173   widget()->set_always_overscroll(true); | 
| 170   widget->set_always_overscroll(true); |  | 
| 171 | 174 | 
| 172   blink::WebGestureEvent scroll; | 175   blink::WebGestureEvent scroll; | 
| 173   scroll.type = blink::WebInputEvent::GestureScrollUpdate; | 176   scroll.type = blink::WebInputEvent::GestureScrollUpdate; | 
| 174   scroll.x = -10; | 177   scroll.x = -10; | 
| 175   scroll.data.scrollUpdate.deltaY = 10; | 178   scroll.data.scrollUpdate.deltaY = 10; | 
| 176   widget->SendInputEvent(scroll); | 179   widget()->SendInputEvent(scroll); | 
| 177 | 180 | 
| 178   // Overscroll notifications received while handling an input event should | 181   // Overscroll notifications received while handling an input event should | 
| 179   // be bundled with the event ack IPC. | 182   // be bundled with the event ack IPC. | 
| 180   ASSERT_EQ(1u, widget->sink()->message_count()); | 183   ASSERT_EQ(1u, widget()->sink()->message_count()); | 
| 181   const IPC::Message* message = widget->sink()->GetMessageAt(0); | 184   const IPC::Message* message = widget()->sink()->GetMessageAt(0); | 
| 182   ASSERT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 185   ASSERT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); | 
| 183   InputHostMsg_HandleInputEvent_ACK::Param params; | 186   InputHostMsg_HandleInputEvent_ACK::Param params; | 
| 184   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 187   InputHostMsg_HandleInputEvent_ACK::Read(message, ¶ms); | 
| 185   const InputEventAck& ack = base::get<0>(params); | 188   const InputEventAck& ack = base::get<0>(params); | 
| 186   ASSERT_EQ(ack.type, scroll.type); | 189   ASSERT_EQ(ack.type, scroll.type); | 
| 187   ASSERT_TRUE(ack.overscroll); | 190   ASSERT_TRUE(ack.overscroll); | 
| 188   EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->accumulated_overscroll); | 191   EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->accumulated_overscroll); | 
| 189   EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->latest_overscroll_delta); | 192   EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->latest_overscroll_delta); | 
| 190   EXPECT_EQ(gfx::Vector2dF(), ack.overscroll->current_fling_velocity); | 193   EXPECT_EQ(gfx::Vector2dF(), ack.overscroll->current_fling_velocity); | 
| 191   EXPECT_EQ(gfx::PointF(-10, 0), ack.overscroll->causal_event_viewport_point); | 194   EXPECT_EQ(gfx::PointF(-10, 0), ack.overscroll->causal_event_viewport_point); | 
| 192   widget->sink()->ClearMessages(); | 195   widget()->sink()->ClearMessages(); | 
| 193 } | 196 } | 
| 194 | 197 | 
| 195 TEST_F(RenderWidgetUnittest, FlingOverscroll) { | 198 TEST_F(RenderWidgetUnittest, FlingOverscroll) { | 
| 196   scoped_refptr<InteractiveRenderWidget> widget = new InteractiveRenderWidget(); |  | 
| 197 |  | 
| 198   // Overscroll notifications received outside of handling an input event should | 199   // Overscroll notifications received outside of handling an input event should | 
| 199   // be sent as a separate IPC. | 200   // be sent as a separate IPC. | 
| 200   widget->didOverscroll(blink::WebFloatSize(10, 5), blink::WebFloatSize(5, 5), | 201   widget()->didOverscroll(blink::WebFloatSize(10, 5), blink::WebFloatSize(5, 5), | 
| 201                         blink::WebFloatPoint(1, 1), blink::WebFloatSize(10, 5)); | 202                           blink::WebFloatPoint(1, 1), | 
| 202   ASSERT_EQ(1u, widget->sink()->message_count()); | 203                           blink::WebFloatSize(10, 5)); | 
| 203   const IPC::Message* message = widget->sink()->GetMessageAt(0); | 204   ASSERT_EQ(1u, widget()->sink()->message_count()); | 
|  | 205   const IPC::Message* message = widget()->sink()->GetMessageAt(0); | 
| 204   ASSERT_EQ(InputHostMsg_DidOverscroll::ID, message->type()); | 206   ASSERT_EQ(InputHostMsg_DidOverscroll::ID, message->type()); | 
| 205   InputHostMsg_DidOverscroll::Param params; | 207   InputHostMsg_DidOverscroll::Param params; | 
| 206   InputHostMsg_DidOverscroll::Read(message, ¶ms); | 208   InputHostMsg_DidOverscroll::Read(message, ¶ms); | 
| 207   const DidOverscrollParams& overscroll = base::get<0>(params); | 209   const DidOverscrollParams& overscroll = base::get<0>(params); | 
| 208   EXPECT_EQ(gfx::Vector2dF(10, 5), overscroll.latest_overscroll_delta); | 210   EXPECT_EQ(gfx::Vector2dF(10, 5), overscroll.latest_overscroll_delta); | 
| 209   EXPECT_EQ(gfx::Vector2dF(5, 5), overscroll.accumulated_overscroll); | 211   EXPECT_EQ(gfx::Vector2dF(5, 5), overscroll.accumulated_overscroll); | 
| 210   EXPECT_EQ(gfx::PointF(1, 1), overscroll.causal_event_viewport_point); | 212   EXPECT_EQ(gfx::PointF(1, 1), overscroll.causal_event_viewport_point); | 
| 211   EXPECT_EQ(gfx::Vector2dF(-10, -5), overscroll.current_fling_velocity); | 213   EXPECT_EQ(gfx::Vector2dF(-10, -5), overscroll.current_fling_velocity); | 
| 212   widget->sink()->ClearMessages(); | 214   widget()->sink()->ClearMessages(); | 
| 213 } | 215 } | 
| 214 | 216 | 
| 215 }  // namespace content | 217 }  // namespace content | 
| OLD | NEW | 
|---|