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 "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 break; | 467 break; |
468 case FINISHED: | 468 case FINISHED: |
469 EXPECT_FALSE(true); | 469 EXPECT_FALSE(true); |
470 break; | 470 break; |
471 } | 471 } |
472 } | 472 } |
473 }; | 473 }; |
474 | 474 |
475 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { | 475 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { |
476 public: | 476 public: |
477 MockSyntheticPointerActionTarget() {} | 477 MockSyntheticPointerActionTarget() : count_(0) {} |
478 ~MockSyntheticPointerActionTarget() override {} | 478 ~MockSyntheticPointerActionTarget() override {} |
479 | 479 |
480 gfx::PointF positions(int index) const { return positions_[index]; } | |
481 int indexes(int index) const { return indexes_[index]; } | |
482 WebTouchPoint::State states(int index) { return states_[index]; } | |
483 unsigned touch_length() const { return touch_length_; } | |
484 WebInputEvent::Type type() const { return type_; } | 480 WebInputEvent::Type type() const { return type_; } |
| 481 int count() const { return count_; } |
| 482 void reset_count() { count_ = 0; } |
485 | 483 |
486 protected: | 484 protected: |
487 gfx::PointF positions_[kTouchPointersLength]; | |
488 unsigned touch_length_; | |
489 int indexes_[kTouchPointersLength]; | |
490 WebTouchPoint::State states_[kTouchPointersLength]; | |
491 WebInputEvent::Type type_; | 485 WebInputEvent::Type type_; |
| 486 int count_; |
492 }; | 487 }; |
493 | 488 |
494 class MockSyntheticPointerTouchActionTarget | 489 class MockSyntheticPointerTouchActionTarget |
495 : public MockSyntheticPointerActionTarget { | 490 : public MockSyntheticPointerActionTarget { |
496 public: | 491 public: |
497 MockSyntheticPointerTouchActionTarget() {} | 492 MockSyntheticPointerTouchActionTarget() {} |
498 ~MockSyntheticPointerTouchActionTarget() override {} | 493 ~MockSyntheticPointerTouchActionTarget() override {} |
499 | 494 |
500 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 495 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
501 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 496 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
502 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 497 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
503 type_ = touch_event.type; | 498 type_ = touch_event.type; |
504 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 499 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
505 indexes_[i] = touch_event.touches[i].id; | 500 indexes_[i] = touch_event.touches[i].id; |
506 positions_[i] = gfx::PointF(touch_event.touches[i].position); | 501 positions_[i] = gfx::PointF(touch_event.touches[i].position); |
507 states_[i] = touch_event.touches[i].state; | 502 states_[i] = touch_event.touches[i].state; |
508 } | 503 } |
509 touch_length_ = touch_event.touchesLength; | 504 touch_length_ = touch_event.touchesLength; |
| 505 count_++; |
510 } | 506 } |
| 507 |
| 508 gfx::PointF positions(int index) const { return positions_[index]; } |
| 509 int indexes(int index) const { return indexes_[index]; } |
| 510 WebTouchPoint::State states(int index) { return states_[index]; } |
| 511 unsigned touch_length() const { return touch_length_; } |
| 512 |
| 513 private: |
| 514 gfx::PointF positions_[kTouchPointersLength]; |
| 515 unsigned touch_length_; |
| 516 int indexes_[kTouchPointersLength]; |
| 517 WebTouchPoint::State states_[kTouchPointersLength]; |
| 518 }; |
| 519 |
| 520 class MockSyntheticPointerMouseActionTarget |
| 521 : public MockSyntheticPointerActionTarget { |
| 522 public: |
| 523 MockSyntheticPointerMouseActionTarget() {} |
| 524 ~MockSyntheticPointerMouseActionTarget() override {} |
| 525 |
| 526 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| 527 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); |
| 528 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
| 529 type_ = mouse_event.type; |
| 530 position_ = gfx::PointF(mouse_event.x, mouse_event.y); |
| 531 clickCount_ = mouse_event.clickCount; |
| 532 button_ = mouse_event.button; |
| 533 count_++; |
| 534 } |
| 535 |
| 536 gfx::PointF position() const { return position_; } |
| 537 int clickCount() const { return clickCount_; } |
| 538 WebMouseEvent::Button button() const { return button_; } |
| 539 |
| 540 private: |
| 541 gfx::PointF position_; |
| 542 int clickCount_; |
| 543 WebMouseEvent::Button button_; |
511 }; | 544 }; |
512 | 545 |
513 class SyntheticGestureControllerTestBase { | 546 class SyntheticGestureControllerTestBase { |
514 public: | 547 public: |
515 SyntheticGestureControllerTestBase() {} | 548 SyntheticGestureControllerTestBase() {} |
516 ~SyntheticGestureControllerTestBase() {} | 549 ~SyntheticGestureControllerTestBase() {} |
517 | 550 |
518 protected: | 551 protected: |
519 template<typename MockGestureTarget> | 552 template<typename MockGestureTarget> |
520 void CreateControllerAndTarget() { | 553 void CreateControllerAndTarget() { |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 static_cast<MockSyntheticTapMouseTarget*>(target_); | 1497 static_cast<MockSyntheticTapMouseTarget*>(target_); |
1465 EXPECT_EQ(1, num_success_); | 1498 EXPECT_EQ(1, num_success_); |
1466 EXPECT_EQ(0, num_failure_); | 1499 EXPECT_EQ(0, num_failure_); |
1467 EXPECT_TRUE(tap_target->GestureFinished()); | 1500 EXPECT_TRUE(tap_target->GestureFinished()); |
1468 EXPECT_EQ(tap_target->position(), params.position); | 1501 EXPECT_EQ(tap_target->position(), params.position); |
1469 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1502 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
1470 EXPECT_GE(GetTotalTime(), | 1503 EXPECT_GE(GetTotalTime(), |
1471 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1504 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
1472 } | 1505 } |
1473 | 1506 |
| 1507 TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { |
| 1508 CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>(); |
| 1509 |
| 1510 // First, send two touch presses for finger 0 and finger 1. |
| 1511 SyntheticPointerActionListParams::ParamList param_list; |
| 1512 SyntheticPointerActionParams param0 = SyntheticPointerActionParams( |
| 1513 SyntheticPointerActionParams::PointerActionType::PRESS, |
| 1514 SyntheticGestureParams::TOUCH_INPUT); |
| 1515 |
| 1516 SyntheticPointerActionParams param1 = SyntheticPointerActionParams( |
| 1517 SyntheticPointerActionParams::PointerActionType::PRESS, |
| 1518 SyntheticGestureParams::TOUCH_INPUT); |
| 1519 param0.set_position(gfx::PointF(54, 89)); |
| 1520 param0.set_index(0); |
| 1521 param1.set_position(gfx::PointF(79, 132)); |
| 1522 param1.set_index(1); |
| 1523 SyntheticPointerActionListParams params; |
| 1524 params.PushPointerActionParams(0, param0); |
| 1525 params.PushPointerActionParams(0, param1); |
| 1526 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 1527 std::unique_ptr<SyntheticPointerAction> gesture( |
| 1528 new SyntheticPointerAction(params)); |
| 1529 QueueSyntheticGesture(std::move(gesture)); |
| 1530 FlushInputUntilComplete(); |
| 1531 |
| 1532 MockSyntheticPointerTouchActionTarget* pointer_touch_target = |
| 1533 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
| 1534 EXPECT_EQ(1, num_success_); |
| 1535 EXPECT_EQ(0, num_failure_); |
| 1536 EXPECT_EQ(pointer_touch_target->count(), 1); |
| 1537 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
| 1538 EXPECT_EQ(pointer_touch_target->touch_length(), 2u); |
| 1539 EXPECT_EQ(pointer_touch_target->indexes(0), 0); |
| 1540 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89)); |
| 1541 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); |
| 1542 EXPECT_EQ(pointer_touch_target->indexes(1), 1); |
| 1543 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(79, 132)); |
| 1544 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); |
| 1545 |
| 1546 // Second, send a touch release for finger 0, a touch move for finger 1. |
| 1547 param0.set_pointer_action_type( |
| 1548 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 1549 param1.set_pointer_action_type( |
| 1550 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 1551 param1.set_position(gfx::PointF(183, 239)); |
| 1552 params.PushPointerActionParams(1, param0); |
| 1553 params.PushPointerActionParams(1, param1); |
| 1554 gesture.reset(new SyntheticPointerAction(params)); |
| 1555 QueueSyntheticGesture(std::move(gesture)); |
| 1556 pointer_touch_target->reset_count(); |
| 1557 FlushInputUntilComplete(); |
| 1558 |
| 1559 EXPECT_EQ(2, num_success_); |
| 1560 EXPECT_EQ(0, num_failure_); |
| 1561 EXPECT_EQ(pointer_touch_target->count(), 2); |
| 1562 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove); |
| 1563 EXPECT_EQ(pointer_touch_target->touch_length(), 2u); |
| 1564 EXPECT_EQ(pointer_touch_target->indexes(0), 0); |
| 1565 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased); |
| 1566 EXPECT_EQ(pointer_touch_target->indexes(1), 1); |
| 1567 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(183, 239)); |
| 1568 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); |
| 1569 |
| 1570 // Third, send a touch release for finger 1. |
| 1571 param1.set_pointer_action_type( |
| 1572 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 1573 params.PushPointerActionParams(2, param1); |
| 1574 gesture.reset(new SyntheticPointerAction(params)); |
| 1575 QueueSyntheticGesture(std::move(gesture)); |
| 1576 pointer_touch_target->reset_count(); |
| 1577 FlushInputUntilComplete(); |
| 1578 |
| 1579 EXPECT_EQ(3, num_success_); |
| 1580 EXPECT_EQ(0, num_failure_); |
| 1581 EXPECT_EQ(pointer_touch_target->count(), 3); |
| 1582 EXPECT_EQ(pointer_touch_target->type(), |
| 1583 WebInputEvent::WebInputEvent::TouchEnd); |
| 1584 EXPECT_EQ(pointer_touch_target->touch_length(), 2u); |
| 1585 EXPECT_EQ(pointer_touch_target->indexes(1), 1); |
| 1586 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); |
| 1587 } |
| 1588 |
| 1589 TEST_F(SyntheticGestureControllerTest, PointerMouseAction) { |
| 1590 CreateControllerAndTarget<MockSyntheticPointerMouseActionTarget>(); |
| 1591 |
| 1592 // First, send a mouse move. |
| 1593 SyntheticPointerActionListParams::ParamList param_list; |
| 1594 SyntheticPointerActionParams param = SyntheticPointerActionParams( |
| 1595 SyntheticPointerActionParams::PointerActionType::MOVE, |
| 1596 SyntheticGestureParams::MOUSE_INPUT); |
| 1597 |
| 1598 param.set_position(gfx::PointF(54, 89)); |
| 1599 SyntheticPointerActionListParams params; |
| 1600 params.PushPointerActionParams(param); |
| 1601 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
| 1602 std::unique_ptr<SyntheticPointerAction> gesture( |
| 1603 new SyntheticPointerAction(params)); |
| 1604 QueueSyntheticGesture(std::move(gesture)); |
| 1605 FlushInputUntilComplete(); |
| 1606 |
| 1607 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
| 1608 static_cast<MockSyntheticPointerMouseActionTarget*>(target_); |
| 1609 EXPECT_EQ(1, num_success_); |
| 1610 EXPECT_EQ(0, num_failure_); |
| 1611 EXPECT_EQ(pointer_mouse_target->count(), 1); |
| 1612 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| 1613 EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(54, 89)); |
| 1614 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); |
| 1615 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); |
| 1616 |
| 1617 // Second, send a mouse press. |
| 1618 param.set_pointer_action_type( |
| 1619 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 1620 param.set_position(gfx::PointF(183, 239)); |
| 1621 params.PushPointerActionParams(param); |
| 1622 gesture.reset(new SyntheticPointerAction(params)); |
| 1623 QueueSyntheticGesture(std::move(gesture)); |
| 1624 pointer_mouse_target->reset_count(); |
| 1625 FlushInputUntilComplete(); |
| 1626 |
| 1627 EXPECT_EQ(2, num_success_); |
| 1628 EXPECT_EQ(0, num_failure_); |
| 1629 EXPECT_EQ(pointer_mouse_target->count(), 2); |
| 1630 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
| 1631 EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(183, 239)); |
| 1632 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 1633 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 1634 |
| 1635 // Third, send a mouse move. |
| 1636 param.set_pointer_action_type( |
| 1637 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 1638 param.set_position(gfx::PointF(254, 279)); |
| 1639 params.PushPointerActionParams(param); |
| 1640 gesture.reset(new SyntheticPointerAction(params)); |
| 1641 QueueSyntheticGesture(std::move(gesture)); |
| 1642 pointer_mouse_target->reset_count(); |
| 1643 FlushInputUntilComplete(); |
| 1644 |
| 1645 EXPECT_EQ(3, num_success_); |
| 1646 EXPECT_EQ(0, num_failure_); |
| 1647 EXPECT_EQ(pointer_mouse_target->count(), 3); |
| 1648 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| 1649 EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(254, 279)); |
| 1650 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 1651 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 1652 |
| 1653 // Fourth, send a mouse release. |
| 1654 param.set_pointer_action_type( |
| 1655 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 1656 params.PushPointerActionParams(param); |
| 1657 gesture.reset(new SyntheticPointerAction(params)); |
| 1658 QueueSyntheticGesture(std::move(gesture)); |
| 1659 pointer_mouse_target->reset_count(); |
| 1660 FlushInputUntilComplete(); |
| 1661 |
| 1662 EXPECT_EQ(4, num_success_); |
| 1663 EXPECT_EQ(0, num_failure_); |
| 1664 EXPECT_EQ(pointer_mouse_target->count(), 4); |
| 1665 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); |
| 1666 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 1667 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 1668 } |
| 1669 |
1474 } // namespace | 1670 } // namespace |
1475 | 1671 |
1476 } // namespace content | 1672 } // namespace content |
OLD | NEW |