| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
| 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
| 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 11 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" | 11 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" |
| 12 #include "content/browser/renderer_host/input/synthetic_pointer_gesture.h" | 12 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" |
| 13 #include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h" | 13 #include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h" |
| 14 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" | 14 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" |
| 15 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | 15 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" |
| 16 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" | 16 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
| 17 #include "content/browser/renderer_host/input/synthetic_touch_pointer.h" | 17 #include "content/browser/renderer_host/input/synthetic_touch_pointer.h" |
| 18 #include "content/browser/renderer_host/input/synthetic_touchpad_pinch_gesture.h
" | 18 #include "content/browser/renderer_host/input/synthetic_touchpad_pinch_gesture.h
" |
| 19 #include "content/browser/renderer_host/input/synthetic_touchscreen_pinch_gestur
e.h" | 19 #include "content/browser/renderer_host/input/synthetic_touchscreen_pinch_gestur
e.h" |
| 20 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 20 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 21 #include "content/common/input/synthetic_pinch_gesture_params.h" | 21 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 22 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 22 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); | 460 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); |
| 461 state_ = FINISHED; | 461 state_ = FINISHED; |
| 462 break; | 462 break; |
| 463 case FINISHED: | 463 case FINISHED: |
| 464 EXPECT_FALSE(true); | 464 EXPECT_FALSE(true); |
| 465 break; | 465 break; |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 }; | 468 }; |
| 469 | 469 |
| 470 class MockSyntheticPointerGestureTarget : public MockSyntheticGestureTarget { | 470 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { |
| 471 public: | 471 public: |
| 472 MockSyntheticPointerGestureTarget() {} | 472 MockSyntheticPointerActionTarget() {} |
| 473 ~MockSyntheticPointerGestureTarget() override {} | 473 ~MockSyntheticPointerActionTarget() override {} |
| 474 | 474 |
| 475 gfx::PointF positions(int index) const { return positions_[index]; } | 475 gfx::PointF positions(int index) const { return positions_[index]; } |
| 476 int indexes(int index) const { return indexes_[index]; } | 476 int indexes(int index) const { return indexes_[index]; } |
| 477 WebTouchPoint::State states(int index) { return states_[index]; } | 477 WebTouchPoint::State states(int index) { return states_[index]; } |
| 478 unsigned touch_length() const { return touch_length_; } | 478 unsigned touch_length() const { return touch_length_; } |
| 479 WebInputEvent::Type type() const { return type_; } | 479 WebInputEvent::Type type() const { return type_; } |
| 480 | 480 |
| 481 protected: | 481 protected: |
| 482 gfx::PointF positions_[kTouchPointersLength]; | 482 gfx::PointF positions_[kTouchPointersLength]; |
| 483 unsigned touch_length_; | 483 unsigned touch_length_; |
| 484 int indexes_[kTouchPointersLength]; | 484 int indexes_[kTouchPointersLength]; |
| 485 WebTouchPoint::State states_[kTouchPointersLength]; | 485 WebTouchPoint::State states_[kTouchPointersLength]; |
| 486 WebInputEvent::Type type_; | 486 WebInputEvent::Type type_; |
| 487 }; | 487 }; |
| 488 | 488 |
| 489 class MockSyntheticPointerTouchTarget | 489 class MockSyntheticPointerTouchActionTarget |
| 490 : public MockSyntheticPointerGestureTarget { | 490 : public MockSyntheticPointerActionTarget { |
| 491 public: | 491 public: |
| 492 MockSyntheticPointerTouchTarget() {} | 492 MockSyntheticPointerTouchActionTarget() {} |
| 493 ~MockSyntheticPointerTouchTarget() override {} | 493 ~MockSyntheticPointerTouchActionTarget() override {} |
| 494 | 494 |
| 495 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 495 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| 496 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 496 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
| 497 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 497 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
| 498 type_ = touch_event.type; | 498 type_ = touch_event.type; |
| 499 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 499 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
| 500 indexes_[i] = touch_event.touches[i].id; | 500 indexes_[i] = touch_event.touches[i].id; |
| 501 positions_[i] = gfx::PointF(touch_event.touches[i].position); | 501 positions_[i] = gfx::PointF(touch_event.touches[i].position); |
| 502 states_[i] = touch_event.touches[i].state; | 502 states_[i] = touch_event.touches[i].state; |
| 503 } | 503 } |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 static_cast<MockSyntheticTapMouseTarget*>(target_); | 1455 static_cast<MockSyntheticTapMouseTarget*>(target_); |
| 1456 EXPECT_EQ(1, num_success_); | 1456 EXPECT_EQ(1, num_success_); |
| 1457 EXPECT_EQ(0, num_failure_); | 1457 EXPECT_EQ(0, num_failure_); |
| 1458 EXPECT_TRUE(tap_target->GestureFinished()); | 1458 EXPECT_TRUE(tap_target->GestureFinished()); |
| 1459 EXPECT_EQ(tap_target->position(), params.position); | 1459 EXPECT_EQ(tap_target->position(), params.position); |
| 1460 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1460 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
| 1461 EXPECT_GE(GetTotalTime(), | 1461 EXPECT_GE(GetTotalTime(), |
| 1462 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1462 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
| 1463 } | 1463 } |
| 1464 | 1464 |
| 1465 TEST_F(SyntheticGestureControllerTest, PointerGestureTouch) { | 1465 TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { |
| 1466 CreateControllerAndTarget<MockSyntheticPointerTouchTarget>(); | 1466 CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>(); |
| 1467 | 1467 |
| 1468 SyntheticTouchPointer synthetic_pointer; | 1468 SyntheticTouchPointer synthetic_pointer; |
| 1469 | 1469 |
| 1470 gfx::PointF position(54, 89); | 1470 gfx::PointF position(54, 89); |
| 1471 scoped_ptr<SyntheticPointerGesture> gesture(new SyntheticPointerGesture( | 1471 scoped_ptr<SyntheticPointerAction> gesture(new SyntheticPointerAction( |
| 1472 SyntheticGestureParams::TOUCH_INPUT, SyntheticGesture::PRESS, | 1472 SyntheticGestureParams::TOUCH_INPUT, SyntheticGesture::PRESS, |
| 1473 &synthetic_pointer, position)); | 1473 &synthetic_pointer, position)); |
| 1474 QueueSyntheticGesture(gesture.Pass()); | 1474 QueueSyntheticGesture(gesture.Pass()); |
| 1475 FlushInputUntilComplete(); | 1475 FlushInputUntilComplete(); |
| 1476 | 1476 |
| 1477 MockSyntheticPointerTouchTarget* pointer_touch_target = | 1477 MockSyntheticPointerTouchActionTarget* pointer_touch_target = |
| 1478 static_cast<MockSyntheticPointerTouchTarget*>(target_); | 1478 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
| 1479 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); | 1479 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
| 1480 EXPECT_EQ(pointer_touch_target->positions(0), position); | 1480 EXPECT_EQ(pointer_touch_target->positions(0), position); |
| 1481 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); | 1481 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); |
| 1482 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); | 1482 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); |
| 1483 | 1483 |
| 1484 position.SetPoint(79, 132); | 1484 position.SetPoint(79, 132); |
| 1485 gesture.reset(new SyntheticPointerGesture(SyntheticGestureParams::TOUCH_INPUT, | 1485 gesture.reset(new SyntheticPointerAction(SyntheticGestureParams::TOUCH_INPUT, |
| 1486 SyntheticGesture::PRESS, | 1486 SyntheticGesture::PRESS, |
| 1487 &synthetic_pointer, position)); | 1487 &synthetic_pointer, position)); |
| 1488 QueueSyntheticGesture(gesture.Pass()); | 1488 QueueSyntheticGesture(gesture.Pass()); |
| 1489 FlushInputUntilComplete(); | 1489 FlushInputUntilComplete(); |
| 1490 | 1490 |
| 1491 pointer_touch_target = static_cast<MockSyntheticPointerTouchTarget*>(target_); | 1491 pointer_touch_target = |
| 1492 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
| 1492 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); | 1493 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
| 1493 EXPECT_EQ(pointer_touch_target->indexes(1), 1); | 1494 EXPECT_EQ(pointer_touch_target->indexes(1), 1); |
| 1494 EXPECT_EQ(pointer_touch_target->positions(1), position); | 1495 EXPECT_EQ(pointer_touch_target->positions(1), position); |
| 1495 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); | 1496 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); |
| 1496 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); | 1497 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); |
| 1497 | 1498 |
| 1498 int index = 1; | 1499 int index = 1; |
| 1499 position.SetPoint(133, 156); | 1500 position.SetPoint(133, 156); |
| 1500 gesture.reset(new SyntheticPointerGesture( | 1501 gesture.reset(new SyntheticPointerAction( |
| 1501 SyntheticGestureParams::TOUCH_INPUT, SyntheticGesture::MOVE, | 1502 SyntheticGestureParams::TOUCH_INPUT, SyntheticGesture::MOVE, |
| 1502 &synthetic_pointer, position, index)); | 1503 &synthetic_pointer, position, index)); |
| 1503 QueueSyntheticGesture(gesture.Pass()); | 1504 QueueSyntheticGesture(gesture.Pass()); |
| 1504 FlushInputUntilComplete(); | 1505 FlushInputUntilComplete(); |
| 1505 | 1506 |
| 1506 pointer_touch_target = static_cast<MockSyntheticPointerTouchTarget*>(target_); | 1507 pointer_touch_target = |
| 1508 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
| 1507 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove); | 1509 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove); |
| 1508 EXPECT_EQ(pointer_touch_target->positions(1), position); | 1510 EXPECT_EQ(pointer_touch_target->positions(1), position); |
| 1509 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); | 1511 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); |
| 1510 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); | 1512 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); |
| 1511 | 1513 |
| 1512 gesture.reset(new SyntheticPointerGesture( | 1514 gesture.reset(new SyntheticPointerAction( |
| 1513 SyntheticGestureParams::TOUCH_INPUT, SyntheticGesture::RELEASE, | 1515 SyntheticGestureParams::TOUCH_INPUT, SyntheticGesture::RELEASE, |
| 1514 &synthetic_pointer, position, index)); | 1516 &synthetic_pointer, position, index)); |
| 1515 QueueSyntheticGesture(gesture.Pass()); | 1517 QueueSyntheticGesture(gesture.Pass()); |
| 1516 FlushInputUntilComplete(); | 1518 FlushInputUntilComplete(); |
| 1517 | 1519 |
| 1518 pointer_touch_target = static_cast<MockSyntheticPointerTouchTarget*>(target_); | 1520 pointer_touch_target = |
| 1521 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
| 1519 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); | 1522 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); |
| 1520 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); | 1523 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); |
| 1521 } | 1524 } |
| 1522 | 1525 |
| 1523 } // namespace | 1526 } // namespace |
| 1524 | 1527 |
| 1525 } // namespace content | 1528 } // namespace content |
| OLD | NEW |