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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE {} | 164 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE {} |
165 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE { | 165 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE { |
166 NOTREACHED(); | 166 NOTREACHED(); |
167 return NULL; | 167 return NULL; |
168 } | 168 } |
169 virtual bool ShouldForwardTouchEvent() const OVERRIDE { return true; } | 169 virtual bool ShouldForwardTouchEvent() const OVERRIDE { return true; } |
170 virtual bool ShouldForwardGestureEvent( | 170 virtual bool ShouldForwardGestureEvent( |
171 const GestureEventWithLatencyInfo& gesture_event) const OVERRIDE { | 171 const GestureEventWithLatencyInfo& gesture_event) const OVERRIDE { |
172 return true; | 172 return true; |
173 } | 173 } |
174 virtual bool HasQueuedGestureEvents() const OVERRIDE { return true; } | |
175 | 174 |
176 // IPC::Listener | 175 // IPC::Listener |
177 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 176 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
178 message_received_ = true; | 177 message_received_ = true; |
179 return false; | 178 return false; |
180 } | 179 } |
181 | 180 |
182 bool flush_called_; | 181 bool flush_called_; |
183 bool send_event_called_; | 182 bool send_event_called_; |
184 bool sent_mouse_event_; | 183 bool sent_mouse_event_; |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode()); | 1377 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode()); |
1379 EXPECT_EQ(-81.f, host_->overscroll_delta_x()); | 1378 EXPECT_EQ(-81.f, host_->overscroll_delta_x()); |
1380 EXPECT_EQ(-31.f, host_->overscroll_delegate()->delta_x()); | 1379 EXPECT_EQ(-31.f, host_->overscroll_delegate()->delta_x()); |
1381 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y()); | 1380 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y()); |
1382 EXPECT_EQ(0U, process_->sink().message_count()); | 1381 EXPECT_EQ(0U, process_->sink().message_count()); |
1383 | 1382 |
1384 // Send a mouse-move event. This should cancel the overscroll navigation. | 1383 // Send a mouse-move event. This should cancel the overscroll navigation. |
1385 SimulateMouseMove(5, 10, 0); | 1384 SimulateMouseMove(5, 10, 0); |
1386 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); | 1385 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); |
1387 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); | 1386 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); |
| 1387 EXPECT_EQ(1U, process_->sink().message_count()); |
1388 } | 1388 } |
1389 | 1389 |
1390 // Tests that if some scroll events are consumed towards the start, then | 1390 // Tests that if some scroll events are consumed towards the start, then |
1391 // subsequent scrolls do not horizontal overscroll. | 1391 // subsequent scrolls do not horizontal overscroll. |
1392 TEST_F(RenderWidgetHostTest, WheelScrollConsumedDoNotHorizOverscroll) { | 1392 TEST_F(RenderWidgetHostTest, WheelScrollConsumedDoNotHorizOverscroll) { |
1393 host_->SetupForOverscrollControllerTest(); | 1393 host_->SetupForOverscrollControllerTest(); |
1394 process_->sink().ClearMessages(); | 1394 process_->sink().ClearMessages(); |
1395 | 1395 |
1396 // Simulate wheel events. | 1396 // Simulate wheel events. |
1397 SimulateWheelEvent(-5, 0, 0, true); // sent directly | 1397 SimulateWheelEvent(-5, 0, 0, true); // sent directly |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); | 1599 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); |
1600 EXPECT_EQ(60.f, host_->overscroll_delta_x()); | 1600 EXPECT_EQ(60.f, host_->overscroll_delta_x()); |
1601 EXPECT_EQ(10.f, host_->overscroll_delegate()->delta_x()); | 1601 EXPECT_EQ(10.f, host_->overscroll_delegate()->delta_x()); |
1602 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y()); | 1602 EXPECT_EQ(0.f, host_->overscroll_delegate()->delta_y()); |
1603 process_->sink().ClearMessages(); | 1603 process_->sink().ClearMessages(); |
1604 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); | 1604 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); |
1605 | 1605 |
1606 // Send a fling start, but with a small velocity, so that the overscroll is | 1606 // Send a fling start, but with a small velocity, so that the overscroll is |
1607 // aborted. The fling should proceed to the renderer, through the gesture | 1607 // aborted. The fling should proceed to the renderer, through the gesture |
1608 // event filter. | 1608 // event filter. |
1609 SimulateGestureFlingStartEvent(0.f, 0.f, WebGestureEvent::Touchpad); | 1609 SimulateGestureFlingStartEvent(10.f, 0.f, WebGestureEvent::Touchpad); |
1610 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); | 1610 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); |
1611 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); | 1611 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize()); |
1612 EXPECT_EQ(0U, process_->sink().message_count()); | 1612 EXPECT_EQ(1U, process_->sink().message_count()); |
1613 } | 1613 } |
1614 | 1614 |
1615 // Tests that a fling in the opposite direction of the overscroll cancels the | 1615 // Tests that a fling in the opposite direction of the overscroll cancels the |
1616 // overscroll nav instead of completing it. | 1616 // overscroll nav instead of completing it. |
1617 TEST_F(RenderWidgetHostTest, ReverseFlingCancelsOverscroll) { | 1617 TEST_F(RenderWidgetHostTest, ReverseFlingCancelsOverscroll) { |
1618 host_->SetupForOverscrollControllerTest(); | 1618 host_->SetupForOverscrollControllerTest(); |
1619 host_->set_debounce_interval_time_ms(0); | 1619 host_->set_debounce_interval_time_ms(0); |
1620 process_->sink().ClearMessages(); | 1620 process_->sink().ClearMessages(); |
1621 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); | 1621 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); |
1622 view_->Show(); | 1622 view_->Show(); |
1623 | 1623 |
1624 { | 1624 { |
1625 // Start and end a gesture in the same direction without processing the | 1625 // Start and end a gesture in the same direction without processing the |
1626 // gesture events in the renderer. This should initiate and complete an | 1626 // gesture events in the renderer. This should initiate and complete an |
1627 // overscroll navigation. | 1627 // overscroll navigation. |
1628 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1628 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1629 WebGestureEvent::Touchscreen); | 1629 WebGestureEvent::Touchscreen); |
1630 SimulateGestureScrollUpdateEvent(300, -5, 0); | 1630 SimulateGestureScrollUpdateEvent(300, -5, 0); |
1631 SendInputEventACK(WebInputEvent::GestureScrollBegin, | 1631 SendInputEventACK(WebInputEvent::GestureScrollBegin, |
1632 INPUT_EVENT_ACK_STATE_CONSUMED); | 1632 INPUT_EVENT_ACK_STATE_CONSUMED); |
1633 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1633 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
1634 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1634 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1635 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode()); | 1635 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode()); |
1636 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); | 1636 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); |
| 1637 process_->sink().ClearMessages(); |
1637 | 1638 |
1638 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1639 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
1639 WebGestureEvent::Touchscreen); | 1640 WebGestureEvent::Touchscreen); |
1640 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); | 1641 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); |
1641 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); | 1642 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); |
| 1643 EXPECT_EQ(1U, process_->sink().message_count()); |
1642 SendInputEventACK(WebInputEvent::GestureScrollEnd, | 1644 SendInputEventACK(WebInputEvent::GestureScrollEnd, |
1643 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1645 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1644 } | 1646 } |
1645 | 1647 |
1646 { | 1648 { |
1647 // Start over, except instead of ending the gesture with ScrollEnd, end it | 1649 // Start over, except instead of ending the gesture with ScrollEnd, end it |
1648 // with a FlingStart, with velocity in the reverse direction. This should | 1650 // with a FlingStart, with velocity in the reverse direction. This should |
1649 // initiate an overscroll navigation, but it should be cancelled because of | 1651 // initiate an overscroll navigation, but it should be cancelled because of |
1650 // the fling in the opposite direction. | 1652 // the fling in the opposite direction. |
1651 host_->overscroll_delegate()->Reset(); | 1653 host_->overscroll_delegate()->Reset(); |
1652 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1654 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1653 WebGestureEvent::Touchscreen); | 1655 WebGestureEvent::Touchscreen); |
1654 SimulateGestureScrollUpdateEvent(-300, -5, 0); | 1656 SimulateGestureScrollUpdateEvent(-300, -5, 0); |
1655 SendInputEventACK(WebInputEvent::GestureScrollBegin, | 1657 SendInputEventACK(WebInputEvent::GestureScrollBegin, |
1656 INPUT_EVENT_ACK_STATE_CONSUMED); | 1658 INPUT_EVENT_ACK_STATE_CONSUMED); |
1657 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1659 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
1658 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1660 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1659 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode()); | 1661 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_mode()); |
1660 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode()); | 1662 EXPECT_EQ(OVERSCROLL_WEST, host_->overscroll_delegate()->current_mode()); |
| 1663 process_->sink().ClearMessages(); |
| 1664 |
1661 SimulateGestureFlingStartEvent(100, 0, WebGestureEvent::Touchscreen); | 1665 SimulateGestureFlingStartEvent(100, 0, WebGestureEvent::Touchscreen); |
1662 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode()); | 1666 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode()); |
1663 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); | 1667 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); |
| 1668 EXPECT_EQ(1U, process_->sink().message_count()); |
1664 } | 1669 } |
1665 } | 1670 } |
1666 | 1671 |
1667 // Tests that touch-scroll events are handled correctly by the overscroll | 1672 // Tests that touch-scroll events are handled correctly by the overscroll |
1668 // controller. This also tests that the overscroll controller and the | 1673 // controller. This also tests that the overscroll controller and the |
1669 // gesture-event filter play nice with each other. | 1674 // gesture-event filter play nice with each other. |
1670 TEST_F(RenderWidgetHostTest, GestureScrollOverscrolls) { | 1675 TEST_F(RenderWidgetHostTest, GestureScrollOverscrolls) { |
1671 // Turn off debounce handling for test isolation. | 1676 // Turn off debounce handling for test isolation. |
1672 host_->SetupForOverscrollControllerTest(); | 1677 host_->SetupForOverscrollControllerTest(); |
1673 host_->set_debounce_interval_time_ms(0); | 1678 host_->set_debounce_interval_time_ms(0); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 WebGestureEvent::Touchscreen); | 1736 WebGestureEvent::Touchscreen); |
1732 SimulateGestureScrollUpdateEvent(10, 0, 0); | 1737 SimulateGestureScrollUpdateEvent(10, 0, 0); |
1733 | 1738 |
1734 // Start scrolling on content. ACK both events as being processed. | 1739 // Start scrolling on content. ACK both events as being processed. |
1735 SendInputEventACK(WebInputEvent::GestureScrollBegin, | 1740 SendInputEventACK(WebInputEvent::GestureScrollBegin, |
1736 INPUT_EVENT_ACK_STATE_CONSUMED); | 1741 INPUT_EVENT_ACK_STATE_CONSUMED); |
1737 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1742 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
1738 INPUT_EVENT_ACK_STATE_CONSUMED); | 1743 INPUT_EVENT_ACK_STATE_CONSUMED); |
1739 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); | 1744 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); |
1740 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); | 1745 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); |
| 1746 process_->sink().ClearMessages(); |
1741 | 1747 |
1742 // Send another gesture event and ACK as not being processed. This should | 1748 // Send another gesture event and ACK as not being processed. This should |
1743 // not initiate overscroll because the beginning of the scroll event did | 1749 // not initiate overscroll because the beginning of the scroll event did |
1744 // scroll some content on the page. | 1750 // scroll some content on the page. Since there was no overscroll, the event |
| 1751 // should reach the renderer. |
1745 SimulateGestureScrollUpdateEvent(55, 0, 0); | 1752 SimulateGestureScrollUpdateEvent(55, 0, 0); |
| 1753 EXPECT_EQ(1U, process_->sink().message_count()); |
1746 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1754 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
1747 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1755 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1748 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); | 1756 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); |
1749 } | 1757 } |
1750 | 1758 |
1751 // Tests that if the page is scrolled because of a scroll-gesture, then that | 1759 // Tests that if the page is scrolled because of a scroll-gesture, then that |
1752 // particular scroll sequence never generates overscroll if the scroll direction | 1760 // particular scroll sequence never generates overscroll if the scroll direction |
1753 // is vertical. | 1761 // is vertical. |
1754 TEST_F(RenderWidgetHostTest, GestureScrollConsumedVertical) { | 1762 TEST_F(RenderWidgetHostTest, GestureScrollConsumedVertical) { |
1755 // Turn off debounce handling for test isolation. | 1763 // Turn off debounce handling for test isolation. |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 SendInputEventACK(WebInputEvent::GestureScrollBegin, | 2290 SendInputEventACK(WebInputEvent::GestureScrollBegin, |
2283 INPUT_EVENT_ACK_STATE_CONSUMED); | 2291 INPUT_EVENT_ACK_STATE_CONSUMED); |
2284 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 2292 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
2285 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2293 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2286 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode()); | 2294 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_mode()); |
2287 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); | 2295 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); |
2288 process_->sink().ClearMessages(); | 2296 process_->sink().ClearMessages(); |
2289 | 2297 |
2290 // Overscroll gesture is in progress. Send a mouse-move now. This should | 2298 // Overscroll gesture is in progress. Send a mouse-move now. This should |
2291 // complete the gesture (because the amount overscrolled is above the | 2299 // complete the gesture (because the amount overscrolled is above the |
2292 // threshold), and consume the event. | 2300 // threshold). |
2293 SimulateMouseMove(5, 10, 0); | 2301 SimulateMouseMove(5, 10, 0); |
2294 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); | 2302 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); |
2295 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); | 2303 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_mode()); |
2296 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); | 2304 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); |
2297 EXPECT_EQ(0U, process_->sink().message_count()); | 2305 EXPECT_EQ(1U, process_->sink().message_count()); |
| 2306 process_->sink().ClearMessages(); |
| 2307 SendInputEventACK(WebInputEvent::MouseMove, |
| 2308 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2298 | 2309 |
2299 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 2310 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
2300 WebGestureEvent::Touchscreen); | 2311 WebGestureEvent::Touchscreen); |
2301 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); | 2312 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); |
2302 EXPECT_EQ(1U, process_->sink().message_count()); | 2313 EXPECT_EQ(1U, process_->sink().message_count()); |
2303 process_->sink().ClearMessages(); | 2314 process_->sink().ClearMessages(); |
2304 SendInputEventACK(WebInputEvent::GestureScrollEnd, | 2315 SendInputEventACK(WebInputEvent::GestureScrollEnd, |
2305 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2316 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2306 | 2317 |
2307 // Move mouse some more. The mouse-move events should reach the renderer. | 2318 // Move mouse some more. The mouse-move events should reach the renderer. |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2570 | 2581 |
2571 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) { | 2582 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) { |
2572 host_->SetupForInputRouterTest(); | 2583 host_->SetupForInputRouterTest(); |
2573 | 2584 |
2574 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 2585 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
2575 | 2586 |
2576 EXPECT_TRUE(host_->mock_input_router()->message_received_); | 2587 EXPECT_TRUE(host_->mock_input_router()->message_received_); |
2577 } | 2588 } |
2578 | 2589 |
2579 } // namespace content | 2590 } // namespace content |
OLD | NEW |