| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/renderer_host/input/gesture_event_filter.h" | 8 #include "content/browser/renderer_host/input/gesture_event_filter.h" |
| 9 #include "content/browser/renderer_host/input/immediate_input_router.h" | 9 #include "content/browser/renderer_host/input/immediate_input_router.h" |
| 10 #include "content/browser/renderer_host/input/input_router_client.h" | 10 #include "content/browser/renderer_host/input/input_router_client.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 130 } |
| 131 | 131 |
| 132 void set_debounce_interval_time_ms(int ms) { | 132 void set_debounce_interval_time_ms(int ms) { |
| 133 input_router()->gesture_event_filter()->debounce_interval_time_ms_ = ms; | 133 input_router()->gesture_event_filter()->debounce_interval_time_ms_ = ms; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void set_maximum_tap_gap_time_ms(int delay_ms) { | 136 void set_maximum_tap_gap_time_ms(int delay_ms) { |
| 137 input_router()->gesture_event_filter()->maximum_tap_gap_time_ms_ = delay_ms; | 137 input_router()->gesture_event_filter()->maximum_tap_gap_time_ms_ = delay_ms; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void EnableNoTouchToRendererWhileScrolling() { | |
| 141 input_router()->enable_no_touch_to_renderer_while_scrolling_ = true; | |
| 142 } | |
| 143 | |
| 144 bool no_touch_to_renderer() { | 140 bool no_touch_to_renderer() { |
| 145 return input_router()->touch_event_queue()->no_touch_to_renderer(); | 141 return input_router()->touch_event_queue()->no_touch_to_renderer(); |
| 146 } | 142 } |
| 147 | 143 |
| 148 bool TouchEventQueueEmpty() const { | 144 bool TouchEventQueueEmpty() const { |
| 149 return input_router()->touch_event_queue()->empty(); | 145 return input_router()->touch_event_queue()->empty(); |
| 150 } | 146 } |
| 151 | 147 |
| 152 unsigned GestureEventLastQueueEventSize() { | 148 unsigned GestureEventLastQueueEventSize() { |
| 153 return gesture_event_filter()->coalesced_gesture_events_.size(); | 149 return gesture_event_filter()->coalesced_gesture_events_.size(); |
| (...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 // Check that the second event was sent. | 1406 // Check that the second event was sent. |
| 1411 EXPECT_EQ(1U, process_->sink().message_count()); | 1407 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1412 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 1408 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 1413 InputMsg_HandleInputEvent::ID)); | 1409 InputMsg_HandleInputEvent::ID)); |
| 1414 process_->sink().ClearMessages(); | 1410 process_->sink().ClearMessages(); |
| 1415 | 1411 |
| 1416 // Check that the correct unhandled wheel event was received. | 1412 // Check that the correct unhandled wheel event was received. |
| 1417 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); | 1413 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); |
| 1418 } | 1414 } |
| 1419 | 1415 |
| 1420 // Tests that no touch events are sent to renderer during scrolling. | |
| 1421 TEST_F(ImmediateInputRouterTest, NoTouchWhileScroll) { | |
| 1422 EnableNoTouchToRendererWhileScrolling(); | |
| 1423 set_debounce_interval_time_ms(0); | |
| 1424 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | |
| 1425 process_->sink().ClearMessages(); | |
| 1426 | |
| 1427 // First touch press. | |
| 1428 PressTouchPoint(0, 1); | |
| 1429 SendTouchEvent(); | |
| 1430 EXPECT_EQ(1U, process_->sink().message_count()); | |
| 1431 process_->sink().ClearMessages(); | |
| 1432 SendInputEventACK(WebInputEvent::TouchStart, | |
| 1433 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1434 ack_handler_->ExpectAckCalled(1); | |
| 1435 | |
| 1436 // Touch move will trigger scroll. | |
| 1437 MoveTouchPoint(0, 20, 5); | |
| 1438 SendTouchEvent(); | |
| 1439 EXPECT_EQ(1U, process_->sink().message_count()); | |
| 1440 process_->sink().ClearMessages(); | |
| 1441 | |
| 1442 // A second touch press. | |
| 1443 PressTouchPoint(20, 20); | |
| 1444 SendTouchEvent(); | |
| 1445 // This TouchStart is queued. | |
| 1446 EXPECT_EQ(0U, process_->sink().message_count()); | |
| 1447 process_->sink().ClearMessages(); | |
| 1448 | |
| 1449 WebGestureEvent followup_scroll; | |
| 1450 followup_scroll.type = WebInputEvent::GestureScrollBegin; | |
| 1451 ack_handler_->set_followup_touch_event(make_scoped_ptr( | |
| 1452 new GestureEventWithLatencyInfo(followup_scroll, ui::LatencyInfo()))); | |
| 1453 | |
| 1454 SendInputEventACK(WebInputEvent::TouchMove, | |
| 1455 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1456 ack_handler_->ExpectAckCalled(1); | |
| 1457 // GestureScroll inserts touch cancel into the queue before the touch start. | |
| 1458 // ScrollBegin is sent first, then the TouchCancel. | |
| 1459 EXPECT_EQ(2U, process_->sink().message_count()); | |
| 1460 const WebInputEvent* input_event = | |
| 1461 GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 1462 EXPECT_EQ(WebInputEvent::GestureScrollBegin, input_event->type); | |
| 1463 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(1)); | |
| 1464 EXPECT_EQ(WebInputEvent::TouchCancel, input_event->type); | |
| 1465 EXPECT_TRUE(no_touch_to_renderer()); | |
| 1466 process_->sink().ClearMessages(); | |
| 1467 | |
| 1468 // Clear the followup events since now the touch events are directly | |
| 1469 // sent to client, instead of being sent to renderer and waiting for | |
| 1470 // ack. So we should use SimulateGestureScrollUpdateEvent() instead of | |
| 1471 // followup gesture events. | |
| 1472 ack_handler_->set_followup_touch_event(make_scoped_ptr( | |
| 1473 static_cast<GestureEventWithLatencyInfo*>(NULL))); | |
| 1474 | |
| 1475 // Ack the TouchCancel will result in the next TouchStart to be dispatched | |
| 1476 // to client. | |
| 1477 SendInputEventACK(WebInputEvent::TouchCancel, | |
| 1478 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1479 // The touch cancel does not reach client, only the touch start. | |
| 1480 ack_handler_->ExpectAckCalled(1); | |
| 1481 EXPECT_EQ(WebInputEvent::TouchStart, | |
| 1482 ack_handler_->acked_touch_event().event.type); | |
| 1483 // No touch to renderer. | |
| 1484 EXPECT_EQ(0U, process_->sink().message_count()); | |
| 1485 process_->sink().ClearMessages(); | |
| 1486 | |
| 1487 SendInputEventACK(WebInputEvent::GestureScrollBegin, | |
| 1488 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1489 ack_handler_->ExpectAckCalled(1); | |
| 1490 EXPECT_EQ(0U, process_->sink().message_count()); | |
| 1491 process_->sink().ClearMessages(); | |
| 1492 | |
| 1493 // Touch move should not be sent to renderer. | |
| 1494 MoveTouchPoint(0, 30, 5); | |
| 1495 SendTouchEvent(); | |
| 1496 EXPECT_EQ(0U, process_->sink().message_count()); | |
| 1497 process_->sink().ClearMessages(); | |
| 1498 | |
| 1499 // Touch moves become ScrollUpdate. | |
| 1500 SimulateGestureScrollUpdateEvent(20, 4, 0); | |
| 1501 process_->sink().ClearMessages(); | |
| 1502 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | |
| 1503 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1504 | |
| 1505 // Touch end should not be sent to renderer. | |
| 1506 ReleaseTouchPoint(0); | |
| 1507 SendTouchEvent(); | |
| 1508 EXPECT_EQ(0U, process_->sink().message_count()); | |
| 1509 process_->sink().ClearMessages(); | |
| 1510 | |
| 1511 // On GestureScrollEnd, resume sending touch moves to renderer. | |
| 1512 SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd, | |
| 1513 WebGestureEvent::Touchscreen); | |
| 1514 EXPECT_EQ(1U, process_->sink().message_count()); | |
| 1515 EXPECT_FALSE(no_touch_to_renderer()); | |
| 1516 process_->sink().ClearMessages(); | |
| 1517 SendInputEventACK(WebInputEvent::GestureScrollEnd, | |
| 1518 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1519 | |
| 1520 // Now touch events should come through to renderer. | |
| 1521 PressTouchPoint(80, 10); | |
| 1522 SendTouchEvent(); | |
| 1523 EXPECT_EQ(1U, process_->sink().message_count()); | |
| 1524 process_->sink().ClearMessages(); | |
| 1525 SendInputEventACK(WebInputEvent::TouchStart, | |
| 1526 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1527 | |
| 1528 MoveTouchPoint(0, 80, 20); | |
| 1529 SendTouchEvent(); | |
| 1530 EXPECT_EQ(1U, process_->sink().message_count()); | |
| 1531 process_->sink().ClearMessages(); | |
| 1532 SendInputEventACK(WebInputEvent::TouchMove, | |
| 1533 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1534 | |
| 1535 ReleaseTouchPoint(0); | |
| 1536 SendTouchEvent(); | |
| 1537 EXPECT_EQ(1U, process_->sink().message_count()); | |
| 1538 process_->sink().ClearMessages(); | |
| 1539 SendInputEventACK(WebInputEvent::TouchEnd, | |
| 1540 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1541 } | |
| 1542 } // namespace content | 1416 } // namespace content |
| OLD | NEW |