| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() { | 140 void EnableNoTouchToRendererWhileScrolling() { |
| 141 input_router()->enable_no_touch_to_renderer_while_scrolling_ = true; | 141 input_router()->enable_no_touch_to_renderer_while_scrolling_ = true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool no_touch_move_to_renderer() { | 144 bool no_touch_to_renderer() { |
| 145 return input_router()->touch_event_queue()->no_touch_move_to_renderer(); | 145 return input_router()->touch_event_queue()->no_touch_to_renderer(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool TouchEventQueueEmpty() const { | 148 bool TouchEventQueueEmpty() const { |
| 149 return input_router()->touch_event_queue()->empty(); | 149 return input_router()->touch_event_queue()->empty(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 unsigned GestureEventLastQueueEventSize() { | 152 unsigned GestureEventLastQueueEventSize() { |
| 153 return gesture_event_filter()->coalesced_gesture_events_.size(); | 153 return gesture_event_filter()->coalesced_gesture_events_.size(); |
| 154 } | 154 } |
| 155 | 155 |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 // Check that the second event was sent. | 1307 // Check that the second event was sent. |
| 1308 EXPECT_EQ(1U, process_->sink().message_count()); | 1308 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1309 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 1309 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 1310 InputMsg_HandleInputEvent::ID)); | 1310 InputMsg_HandleInputEvent::ID)); |
| 1311 process_->sink().ClearMessages(); | 1311 process_->sink().ClearMessages(); |
| 1312 | 1312 |
| 1313 // Check that the correct unhandled wheel event was received. | 1313 // Check that the correct unhandled wheel event was received. |
| 1314 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); | 1314 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 // Tests that no touch move events are sent to renderer during scrolling. | 1317 // Tests that no touch events are sent to renderer during scrolling. |
| 1318 TEST_F(ImmediateInputRouterTest, NoTouchMoveWhileScroll) { | 1318 TEST_F(ImmediateInputRouterTest, NoTouchWhileScroll) { |
| 1319 EnableNoTouchToRendererWhileScrolling(); | 1319 EnableNoTouchToRendererWhileScrolling(); |
| 1320 set_debounce_interval_time_ms(0); | 1320 set_debounce_interval_time_ms(0); |
| 1321 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 1321 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
| 1322 process_->sink().ClearMessages(); | 1322 process_->sink().ClearMessages(); |
| 1323 | 1323 |
| 1324 // First touch press. | 1324 // First touch press. |
| 1325 PressTouchPoint(0, 1); | 1325 PressTouchPoint(0, 1); |
| 1326 SendTouchEvent(); | 1326 SendTouchEvent(); |
| 1327 EXPECT_EQ(1U, process_->sink().message_count()); | 1327 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1328 process_->sink().ClearMessages(); | 1328 process_->sink().ClearMessages(); |
| 1329 SendInputEventACK(WebInputEvent::TouchStart, | 1329 SendInputEventACK(WebInputEvent::TouchStart, |
| 1330 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1330 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1331 ack_handler_->ExpectAckCalled(1); |
| 1331 | 1332 |
| 1332 // Touch move will trigger scroll. | 1333 // Touch move will trigger scroll. |
| 1333 MoveTouchPoint(0, 20, 5); | 1334 MoveTouchPoint(0, 20, 5); |
| 1334 SendTouchEvent(); | 1335 SendTouchEvent(); |
| 1335 EXPECT_EQ(1U, process_->sink().message_count()); | 1336 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1336 process_->sink().ClearMessages(); | 1337 process_->sink().ClearMessages(); |
| 1338 |
| 1339 // A second touch press. |
| 1340 PressTouchPoint(20, 20); |
| 1341 SendTouchEvent(); |
| 1342 // This TouchStart is queued. |
| 1343 EXPECT_EQ(0U, process_->sink().message_count()); |
| 1344 process_->sink().ClearMessages(); |
| 1345 |
| 1346 WebGestureEvent followup_scroll; |
| 1347 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1348 ack_handler_->set_followup_touch_event(make_scoped_ptr( |
| 1349 new GestureEventWithLatencyInfo(followup_scroll, ui::LatencyInfo()))); |
| 1350 |
| 1337 SendInputEventACK(WebInputEvent::TouchMove, | 1351 SendInputEventACK(WebInputEvent::TouchMove, |
| 1338 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1352 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1353 ack_handler_->ExpectAckCalled(1); |
| 1354 // GestureScroll inserts touch cancel into the queue before the touch start. |
| 1355 // ScrollBegin is sent first, then the TouchCancel. |
| 1356 EXPECT_EQ(2U, process_->sink().message_count()); |
| 1357 const WebInputEvent* input_event = |
| 1358 GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); |
| 1359 EXPECT_EQ(WebInputEvent::GestureScrollBegin, input_event->type); |
| 1360 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(1)); |
| 1361 EXPECT_EQ(WebInputEvent::TouchCancel, input_event->type); |
| 1362 EXPECT_TRUE(no_touch_to_renderer()); |
| 1363 process_->sink().ClearMessages(); |
| 1339 | 1364 |
| 1340 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1365 // Clear the followup events since now the touch events are directly |
| 1341 WebGestureEvent::Touchscreen); | 1366 // sent to client, instead of being sent to renderer and waiting for |
| 1342 EXPECT_EQ(1U, process_->sink().message_count()); | 1367 // ack. So we should use SimulateGestureScrollUpdateEvent() instead of |
| 1343 EXPECT_TRUE(no_touch_move_to_renderer()); | 1368 // followup gesture events. |
| 1369 ack_handler_->set_followup_touch_event(make_scoped_ptr( |
| 1370 static_cast<GestureEventWithLatencyInfo*>(NULL))); |
| 1371 |
| 1372 // Ack the TouchCancel will result in the next TouchStart to be dispatched |
| 1373 // to client. |
| 1374 SendInputEventACK(WebInputEvent::TouchCancel, |
| 1375 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1376 // The touch cancel does not reach client, only the touch start. |
| 1377 ack_handler_->ExpectAckCalled(1); |
| 1378 EXPECT_EQ(WebInputEvent::TouchStart, |
| 1379 ack_handler_->acked_touch_event().event.type); |
| 1380 // No touch to renderer. |
| 1381 EXPECT_EQ(0U, process_->sink().message_count()); |
| 1344 process_->sink().ClearMessages(); | 1382 process_->sink().ClearMessages(); |
| 1383 |
| 1345 SendInputEventACK(WebInputEvent::GestureScrollBegin, | 1384 SendInputEventACK(WebInputEvent::GestureScrollBegin, |
| 1346 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1385 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1386 ack_handler_->ExpectAckCalled(1); |
| 1387 EXPECT_EQ(0U, process_->sink().message_count()); |
| 1388 process_->sink().ClearMessages(); |
| 1347 | 1389 |
| 1348 // Touch move should not be sent to renderer. | 1390 // Touch move should not be sent to renderer. |
| 1349 MoveTouchPoint(0, 30, 5); | 1391 MoveTouchPoint(0, 30, 5); |
| 1350 SendTouchEvent(); | 1392 SendTouchEvent(); |
| 1351 EXPECT_EQ(0U, process_->sink().message_count()); | 1393 EXPECT_EQ(0U, process_->sink().message_count()); |
| 1352 process_->sink().ClearMessages(); | 1394 process_->sink().ClearMessages(); |
| 1353 | 1395 |
| 1354 // Touch moves become ScrollUpdate. | 1396 // Touch moves become ScrollUpdate. |
| 1355 SimulateGestureScrollUpdateEvent(20, 4, 0); | 1397 SimulateGestureScrollUpdateEvent(20, 4, 0); |
| 1356 EXPECT_TRUE(no_touch_move_to_renderer()); | |
| 1357 process_->sink().ClearMessages(); | 1398 process_->sink().ClearMessages(); |
| 1358 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1399 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 1359 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1400 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1360 | 1401 |
| 1361 // Touch move should not be sent to renderer. | 1402 // Touch end should not be sent to renderer. |
| 1362 MoveTouchPoint(0, 65, 10); | 1403 ReleaseTouchPoint(0); |
| 1363 SendTouchEvent(); | 1404 SendTouchEvent(); |
| 1364 EXPECT_EQ(0U, process_->sink().message_count()); | 1405 EXPECT_EQ(0U, process_->sink().message_count()); |
| 1365 process_->sink().ClearMessages(); | 1406 process_->sink().ClearMessages(); |
| 1366 | 1407 |
| 1367 // Touch end should still be sent to renderer. | |
| 1368 ReleaseTouchPoint(0); | |
| 1369 SendTouchEvent(); | |
| 1370 EXPECT_EQ(1U, process_->sink().message_count()); | |
| 1371 process_->sink().ClearMessages(); | |
| 1372 SendInputEventACK(WebInputEvent::TouchEnd, | |
| 1373 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1374 | |
| 1375 // On GestureScrollEnd, resume sending touch moves to renderer. | 1408 // On GestureScrollEnd, resume sending touch moves to renderer. |
| 1376 SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd, | 1409 SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd, |
| 1377 WebGestureEvent::Touchscreen); | 1410 WebGestureEvent::Touchscreen); |
| 1378 EXPECT_EQ(1U, process_->sink().message_count()); | 1411 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1379 EXPECT_FALSE(no_touch_move_to_renderer()); | 1412 EXPECT_FALSE(no_touch_to_renderer()); |
| 1380 process_->sink().ClearMessages(); | 1413 process_->sink().ClearMessages(); |
| 1381 SendInputEventACK(WebInputEvent::GestureScrollEnd, | 1414 SendInputEventACK(WebInputEvent::GestureScrollEnd, |
| 1382 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1415 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1383 | 1416 |
| 1384 // Now touch events should come through to renderer. | 1417 // Now touch events should come through to renderer. |
| 1385 PressTouchPoint(80, 10); | 1418 PressTouchPoint(80, 10); |
| 1386 SendTouchEvent(); | 1419 SendTouchEvent(); |
| 1387 EXPECT_EQ(1U, process_->sink().message_count()); | 1420 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1388 process_->sink().ClearMessages(); | 1421 process_->sink().ClearMessages(); |
| 1389 SendInputEventACK(WebInputEvent::TouchStart, | 1422 SendInputEventACK(WebInputEvent::TouchStart, |
| 1390 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1423 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1391 | 1424 |
| 1392 MoveTouchPoint(0, 80, 20); | 1425 MoveTouchPoint(0, 80, 20); |
| 1393 SendTouchEvent(); | 1426 SendTouchEvent(); |
| 1394 EXPECT_EQ(1U, process_->sink().message_count()); | 1427 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1395 process_->sink().ClearMessages(); | 1428 process_->sink().ClearMessages(); |
| 1396 SendInputEventACK(WebInputEvent::TouchMove, | 1429 SendInputEventACK(WebInputEvent::TouchMove, |
| 1397 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1430 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1398 | 1431 |
| 1399 ReleaseTouchPoint(0); | 1432 ReleaseTouchPoint(0); |
| 1400 SendTouchEvent(); | 1433 SendTouchEvent(); |
| 1401 EXPECT_EQ(1U, process_->sink().message_count()); | 1434 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1402 process_->sink().ClearMessages(); | 1435 process_->sink().ClearMessages(); |
| 1403 SendInputEventACK(WebInputEvent::TouchEnd, | 1436 SendInputEventACK(WebInputEvent::TouchEnd, |
| 1404 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1437 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1405 } | 1438 } |
| 1406 } // namespace content | 1439 } // namespace content |
| OLD | NEW |