OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
11 #include "content/browser/browser_thread_impl.h" | 11 #include "content/browser/browser_thread_impl.h" |
12 #include "content/browser/renderer_host/input/gesture_event_queue.h" | 12 #include "content/browser/renderer_host/input/gesture_event_queue.h" |
13 #include "content/browser/renderer_host/input/input_router_impl.h" | 13 #include "content/browser/renderer_host/input/input_router_impl.h" |
14 #include "content/browser/renderer_host/input/tap_suppression_controller.h" | |
15 #include "content/browser/renderer_host/input/tap_suppression_controller_client.
h" | |
16 #include "content/browser/renderer_host/input/touch_event_queue.h" | 14 #include "content/browser/renderer_host/input/touch_event_queue.h" |
17 #include "content/browser/renderer_host/overscroll_controller.h" | 15 #include "content/browser/renderer_host/overscroll_controller.h" |
18 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 16 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
19 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 17 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
20 #include "content/common/input/synthetic_web_input_event_builders.h" | 18 #include "content/common/input/synthetic_web_input_event_builders.h" |
21 #include "content/common/input_messages.h" | 19 #include "content/common/input_messages.h" |
22 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
23 #include "content/port/browser/render_widget_host_view_port.h" | 21 #include "content/port/browser/render_widget_host_view_port.h" |
24 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
25 #include "content/public/test/mock_render_process_host.h" | 23 #include "content/public/test/mock_render_process_host.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // MockRenderWidgetHost ---------------------------------------------------- | 189 // MockRenderWidgetHost ---------------------------------------------------- |
192 | 190 |
193 class MockRenderWidgetHost : public RenderWidgetHostImpl { | 191 class MockRenderWidgetHost : public RenderWidgetHostImpl { |
194 public: | 192 public: |
195 MockRenderWidgetHost( | 193 MockRenderWidgetHost( |
196 RenderWidgetHostDelegate* delegate, | 194 RenderWidgetHostDelegate* delegate, |
197 RenderProcessHost* process, | 195 RenderProcessHost* process, |
198 int routing_id) | 196 int routing_id) |
199 : RenderWidgetHostImpl(delegate, process, routing_id, false), | 197 : RenderWidgetHostImpl(delegate, process, routing_id, false), |
200 unresponsive_timer_fired_(false) { | 198 unresponsive_timer_fired_(false) { |
201 input_router_impl_ = static_cast<InputRouterImpl*>(input_router_.get()); | |
202 acked_touch_event_type_ = blink::WebInputEvent::Undefined; | 199 acked_touch_event_type_ = blink::WebInputEvent::Undefined; |
203 } | 200 } |
204 | 201 |
205 // Allow poking at a few private members. | 202 // Allow poking at a few private members. |
206 using RenderWidgetHostImpl::OnUpdateRect; | 203 using RenderWidgetHostImpl::OnUpdateRect; |
207 using RenderWidgetHostImpl::RendererExited; | 204 using RenderWidgetHostImpl::RendererExited; |
208 using RenderWidgetHostImpl::last_requested_size_; | 205 using RenderWidgetHostImpl::last_requested_size_; |
209 using RenderWidgetHostImpl::is_hidden_; | 206 using RenderWidgetHostImpl::is_hidden_; |
210 using RenderWidgetHostImpl::resize_ack_pending_; | 207 using RenderWidgetHostImpl::resize_ack_pending_; |
211 using RenderWidgetHostImpl::input_router_; | 208 using RenderWidgetHostImpl::input_router_; |
(...skipping 30 matching lines...) Expand all Loading... |
242 bool ScrollingInProgress() const { | 239 bool ScrollingInProgress() const { |
243 return gesture_event_queue().scrolling_in_progress_; | 240 return gesture_event_queue().scrolling_in_progress_; |
244 } | 241 } |
245 | 242 |
246 void SetupForOverscrollControllerTest() { | 243 void SetupForOverscrollControllerTest() { |
247 SetOverscrollControllerEnabled(true); | 244 SetOverscrollControllerEnabled(true); |
248 overscroll_delegate_.reset(new TestOverscrollDelegate(GetView())); | 245 overscroll_delegate_.reset(new TestOverscrollDelegate(GetView())); |
249 overscroll_controller_->set_delegate(overscroll_delegate_.get()); | 246 overscroll_controller_->set_delegate(overscroll_delegate_.get()); |
250 } | 247 } |
251 | 248 |
| 249 void SetupForGestureDebouncing(int delay_ms) { |
| 250 gesture_event_queue().set_debounce_enabled_for_testing(true); |
| 251 gesture_event_queue().set_debounce_interval_time_ms_for_testing(delay_ms); |
| 252 } |
| 253 |
252 void DisableGestureDebounce() { | 254 void DisableGestureDebounce() { |
253 gesture_event_queue().set_debounce_enabled_for_testing(false); | 255 gesture_event_queue().set_debounce_enabled_for_testing(false); |
254 } | 256 } |
255 | 257 |
256 void set_debounce_interval_time_ms(int delay_ms) { | |
257 gesture_event_queue(). | |
258 set_debounce_interval_time_ms_for_testing(delay_ms); | |
259 } | |
260 | |
261 bool TouchEventQueueEmpty() const { | 258 bool TouchEventQueueEmpty() const { |
262 return touch_event_queue().empty(); | 259 return touch_event_queue().empty(); |
263 } | 260 } |
264 | 261 |
265 virtual void OnTouchEventAck( | 262 virtual void OnTouchEventAck( |
266 const TouchEventWithLatencyInfo& event, | 263 const TouchEventWithLatencyInfo& event, |
267 InputEventAckState ack_result) OVERRIDE { | 264 InputEventAckState ack_result) OVERRIDE { |
268 // Sniff touch acks. | 265 // Sniff touch acks. |
269 acked_touch_event_type_ = event.event.type; | 266 acked_touch_event_type_ = event.event.type; |
270 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); | 267 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); |
(...skipping 29 matching lines...) Expand all Loading... |
300 | 297 |
301 float overscroll_delta_y() const { | 298 float overscroll_delta_y() const { |
302 return overscroll_controller_->overscroll_delta_y_; | 299 return overscroll_controller_->overscroll_delta_y_; |
303 } | 300 } |
304 | 301 |
305 TestOverscrollDelegate* overscroll_delegate() { | 302 TestOverscrollDelegate* overscroll_delegate() { |
306 return overscroll_delegate_.get(); | 303 return overscroll_delegate_.get(); |
307 } | 304 } |
308 | 305 |
309 void SetupForInputRouterTest() { | 306 void SetupForInputRouterTest() { |
310 mock_input_router_ = new MockInputRouter(this); | 307 input_router_.reset(new MockInputRouter(this)); |
311 input_router_.reset(mock_input_router_); | |
312 } | 308 } |
313 | 309 |
314 MockInputRouter* mock_input_router() { | 310 MockInputRouter* mock_input_router() { |
315 return mock_input_router_; | 311 return static_cast<MockInputRouter*>(input_router_.get()); |
316 } | 312 } |
317 | 313 |
318 protected: | 314 protected: |
319 virtual void NotifyRendererUnresponsive() OVERRIDE { | 315 virtual void NotifyRendererUnresponsive() OVERRIDE { |
320 unresponsive_timer_fired_ = true; | 316 unresponsive_timer_fired_ = true; |
321 } | 317 } |
322 | 318 |
323 const TouchEventQueue& touch_event_queue() const { | 319 const TouchEventQueue& touch_event_queue() const { |
324 return input_router_impl_->touch_event_queue_; | 320 return input_router_impl()->touch_event_queue_; |
325 } | 321 } |
326 | 322 |
327 const GestureEventQueue& gesture_event_queue() const { | 323 const GestureEventQueue& gesture_event_queue() const { |
328 return input_router_impl_->gesture_event_queue_; | 324 return input_router_impl()->gesture_event_queue_; |
329 } | 325 } |
330 | 326 |
331 GestureEventQueue& gesture_event_queue() { | 327 GestureEventQueue& gesture_event_queue() { |
332 return input_router_impl_->gesture_event_queue_; | 328 return input_router_impl()->gesture_event_queue_; |
| 329 } |
| 330 |
| 331 const InputRouterImpl* input_router_impl() const { |
| 332 return static_cast<InputRouterImpl*>(input_router_.get()); |
| 333 } |
| 334 |
| 335 InputRouterImpl* input_router_impl() { |
| 336 return static_cast<InputRouterImpl*>(input_router_.get()); |
333 } | 337 } |
334 | 338 |
335 private: | 339 private: |
336 bool unresponsive_timer_fired_; | 340 bool unresponsive_timer_fired_; |
337 WebInputEvent::Type acked_touch_event_type_; | 341 WebInputEvent::Type acked_touch_event_type_; |
338 | 342 |
339 // |input_router_impl_| and |mock_input_router_| are owned by | |
340 // RenderWidgetHostImpl. The handles below are provided for convenience so | |
341 // that we don't have to reinterpret_cast it all the time. | |
342 InputRouterImpl* input_router_impl_; | |
343 MockInputRouter* mock_input_router_; | |
344 | |
345 scoped_ptr<TestOverscrollDelegate> overscroll_delegate_; | 343 scoped_ptr<TestOverscrollDelegate> overscroll_delegate_; |
346 | 344 |
347 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); | 345 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); |
348 }; | 346 }; |
349 | 347 |
350 namespace { | 348 namespace { |
351 | 349 |
352 // RenderWidgetHostProcess ----------------------------------------------------- | 350 // RenderWidgetHostProcess ----------------------------------------------------- |
353 | 351 |
354 class RenderWidgetHostProcess : public MockRenderProcessHost { | 352 class RenderWidgetHostProcess : public MockRenderProcessHost { |
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 EXPECT_EQ(1U, process_->sink().message_count()); | 1649 EXPECT_EQ(1U, process_->sink().message_count()); |
1652 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1650 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
1653 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1651 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1654 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); | 1652 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); |
1655 } | 1653 } |
1656 | 1654 |
1657 // Tests that the overscroll controller plays nice with touch-scrolls and the | 1655 // Tests that the overscroll controller plays nice with touch-scrolls and the |
1658 // gesture event filter with debounce filtering turned on. | 1656 // gesture event filter with debounce filtering turned on. |
1659 TEST_F(RenderWidgetHostTest, GestureScrollDebounceOverscrolls) { | 1657 TEST_F(RenderWidgetHostTest, GestureScrollDebounceOverscrolls) { |
1660 host_->SetupForOverscrollControllerTest(); | 1658 host_->SetupForOverscrollControllerTest(); |
1661 host_->set_debounce_interval_time_ms(100); | 1659 host_->SetupForGestureDebouncing(100); |
1662 process_->sink().ClearMessages(); | 1660 process_->sink().ClearMessages(); |
1663 | 1661 |
1664 // Start scrolling. Receive ACK as it being processed. | 1662 // Start scrolling. Receive ACK as it being processed. |
1665 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1663 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1666 WebGestureEvent::Touchscreen); | 1664 WebGestureEvent::Touchscreen); |
1667 EXPECT_EQ(1U, process_->sink().message_count()); | 1665 EXPECT_EQ(1U, process_->sink().message_count()); |
1668 process_->sink().ClearMessages(); | 1666 process_->sink().ClearMessages(); |
1669 | 1667 |
1670 // Send update events. | 1668 // Send update events. |
1671 SimulateGestureScrollUpdateEvent(25, 0, 0); | 1669 SimulateGestureScrollUpdateEvent(25, 0, 0); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y()); | 1727 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y()); |
1730 EXPECT_EQ(0U, process_->sink().message_count()); | 1728 EXPECT_EQ(0U, process_->sink().message_count()); |
1731 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); | 1729 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); |
1732 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); | 1730 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); |
1733 } | 1731 } |
1734 | 1732 |
1735 // Tests that the gesture debounce timer plays nice with the overscroll | 1733 // Tests that the gesture debounce timer plays nice with the overscroll |
1736 // controller. | 1734 // controller. |
1737 TEST_F(RenderWidgetHostTest, GestureScrollDebounceTimerOverscroll) { | 1735 TEST_F(RenderWidgetHostTest, GestureScrollDebounceTimerOverscroll) { |
1738 host_->SetupForOverscrollControllerTest(); | 1736 host_->SetupForOverscrollControllerTest(); |
1739 host_->set_debounce_interval_time_ms(10); | 1737 host_->SetupForGestureDebouncing(10); |
1740 process_->sink().ClearMessages(); | 1738 process_->sink().ClearMessages(); |
1741 | 1739 |
1742 // Start scrolling. Receive ACK as it being processed. | 1740 // Start scrolling. Receive ACK as it being processed. |
1743 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1741 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1744 WebGestureEvent::Touchscreen); | 1742 WebGestureEvent::Touchscreen); |
1745 EXPECT_EQ(1U, process_->sink().message_count()); | 1743 EXPECT_EQ(1U, process_->sink().message_count()); |
1746 process_->sink().ClearMessages(); | 1744 process_->sink().ClearMessages(); |
1747 | 1745 |
1748 // Send update events. | 1746 // Send update events. |
1749 SimulateGestureScrollUpdateEvent(55, 0, 0); | 1747 SimulateGestureScrollUpdateEvent(55, 0, 0); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 // router. | 1787 // router. |
1790 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); | 1788 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); |
1791 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); | 1789 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); |
1792 EXPECT_EQ(1U, process_->sink().message_count()); | 1790 EXPECT_EQ(1U, process_->sink().message_count()); |
1793 } | 1791 } |
1794 | 1792 |
1795 // Tests that when touch-events are dispatched to the renderer, the overscroll | 1793 // Tests that when touch-events are dispatched to the renderer, the overscroll |
1796 // gesture deals with them correctly. | 1794 // gesture deals with them correctly. |
1797 TEST_F(RenderWidgetHostTest, OverscrollWithTouchEvents) { | 1795 TEST_F(RenderWidgetHostTest, OverscrollWithTouchEvents) { |
1798 host_->SetupForOverscrollControllerTest(); | 1796 host_->SetupForOverscrollControllerTest(); |
1799 host_->set_debounce_interval_time_ms(10); | 1797 host_->SetupForGestureDebouncing(10); |
1800 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 1798 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
1801 process_->sink().ClearMessages(); | 1799 process_->sink().ClearMessages(); |
1802 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); | 1800 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); |
1803 view_->Show(); | 1801 view_->Show(); |
1804 | 1802 |
1805 // The test sends an intermingled sequence of touch and gesture events. | 1803 // The test sends an intermingled sequence of touch and gesture events. |
1806 | 1804 |
1807 PressTouchPoint(0, 1); | 1805 PressTouchPoint(0, 1); |
1808 SendTouchEvent(); | 1806 SendTouchEvent(); |
1809 EXPECT_EQ(1U, process_->sink().message_count()); | 1807 EXPECT_EQ(1U, process_->sink().message_count()); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1917 EXPECT_TRUE(host_->TouchEventQueueEmpty()); | 1915 EXPECT_TRUE(host_->TouchEventQueueEmpty()); |
1918 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); | 1916 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); |
1919 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); | 1917 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); |
1920 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); | 1918 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); |
1921 } | 1919 } |
1922 | 1920 |
1923 // Tests that touch-gesture end is dispatched to the renderer at the end of a | 1921 // Tests that touch-gesture end is dispatched to the renderer at the end of a |
1924 // touch-gesture initiated overscroll. | 1922 // touch-gesture initiated overscroll. |
1925 TEST_F(RenderWidgetHostTest, TouchGestureEndDispatchedAfterOverscrollComplete) { | 1923 TEST_F(RenderWidgetHostTest, TouchGestureEndDispatchedAfterOverscrollComplete) { |
1926 host_->SetupForOverscrollControllerTest(); | 1924 host_->SetupForOverscrollControllerTest(); |
1927 host_->set_debounce_interval_time_ms(10); | 1925 host_->SetupForGestureDebouncing(10); |
1928 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 1926 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
1929 process_->sink().ClearMessages(); | 1927 process_->sink().ClearMessages(); |
1930 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); | 1928 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); |
1931 view_->Show(); | 1929 view_->Show(); |
1932 | 1930 |
1933 // Start scrolling. Receive ACK as it being processed. | 1931 // Start scrolling. Receive ACK as it being processed. |
1934 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1932 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1935 WebGestureEvent::Touchscreen); | 1933 WebGestureEvent::Touchscreen); |
1936 EXPECT_EQ(1U, process_->sink().message_count()); | 1934 EXPECT_EQ(1U, process_->sink().message_count()); |
1937 // The scroll begin event will have received a synthetic ack from the input | 1935 // The scroll begin event will have received a synthetic ack from the input |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 process_->sink().ClearMessages(); | 2035 process_->sink().ClearMessages(); |
2038 // The scroll end event will have received a synthetic ack from the input | 2036 // The scroll end event will have received a synthetic ack from the input |
2039 // router. | 2037 // router. |
2040 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); | 2038 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); |
2041 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); | 2039 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); |
2042 EXPECT_EQ(0U, process_->sink().message_count()); | 2040 EXPECT_EQ(0U, process_->sink().message_count()); |
2043 } | 2041 } |
2044 | 2042 |
2045 TEST_F(RenderWidgetHostTest, OverscrollDirectionChange) { | 2043 TEST_F(RenderWidgetHostTest, OverscrollDirectionChange) { |
2046 host_->SetupForOverscrollControllerTest(); | 2044 host_->SetupForOverscrollControllerTest(); |
2047 host_->set_debounce_interval_time_ms(100); | 2045 host_->SetupForGestureDebouncing(100); |
2048 process_->sink().ClearMessages(); | 2046 process_->sink().ClearMessages(); |
2049 | 2047 |
2050 // Start scrolling. Receive ACK as it being processed. | 2048 // Start scrolling. Receive ACK as it being processed. |
2051 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 2049 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
2052 WebGestureEvent::Touchscreen); | 2050 WebGestureEvent::Touchscreen); |
2053 EXPECT_EQ(1U, process_->sink().message_count()); | 2051 EXPECT_EQ(1U, process_->sink().message_count()); |
2054 process_->sink().ClearMessages(); | 2052 process_->sink().ClearMessages(); |
2055 | 2053 |
2056 // Send update events and receive ack as not consumed. | 2054 // Send update events and receive ack as not consumed. |
2057 SimulateGestureScrollUpdateEvent(125, -5, 0); | 2055 SimulateGestureScrollUpdateEvent(125, -5, 0); |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2679 | 2677 |
2680 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). | 2678 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). |
2681 PressTouchPoint(0, 1); | 2679 PressTouchPoint(0, 1); |
2682 SendTouchEvent(); | 2680 SendTouchEvent(); |
2683 CheckLatencyInfoComponentInMessage( | 2681 CheckLatencyInfoComponentInMessage( |
2684 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); | 2682 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); |
2685 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 2683 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
2686 } | 2684 } |
2687 | 2685 |
2688 } // namespace content | 2686 } // namespace content |
OLD | NEW |