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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 break; | 471 break; |
472 } | 472 } |
473 } | 473 } |
474 }; | 474 }; |
475 | 475 |
476 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { | 476 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { |
477 public: | 477 public: |
478 MockSyntheticPointerActionTarget() {} | 478 MockSyntheticPointerActionTarget() {} |
479 ~MockSyntheticPointerActionTarget() override {} | 479 ~MockSyntheticPointerActionTarget() override {} |
480 | 480 |
481 gfx::PointF positions(int index) const { return positions_[index]; } | |
482 int indexes(int index) const { return indexes_[index]; } | |
483 WebTouchPoint::State states(int index) { return states_[index]; } | |
484 unsigned touch_length() const { return touch_length_; } | |
485 WebInputEvent::Type type() const { return type_; } | 481 WebInputEvent::Type type() const { return type_; } |
486 | 482 |
487 protected: | 483 protected: |
488 gfx::PointF positions_[kTouchPointersLength]; | |
489 unsigned touch_length_; | |
490 int indexes_[kTouchPointersLength]; | |
491 WebTouchPoint::State states_[kTouchPointersLength]; | |
492 WebInputEvent::Type type_; | 484 WebInputEvent::Type type_; |
493 }; | 485 }; |
494 | 486 |
495 class MockSyntheticPointerTouchActionTarget | 487 class MockSyntheticPointerTouchActionTarget |
496 : public MockSyntheticPointerActionTarget { | 488 : public MockSyntheticPointerActionTarget { |
497 public: | 489 public: |
498 MockSyntheticPointerTouchActionTarget() {} | 490 MockSyntheticPointerTouchActionTarget() {} |
499 ~MockSyntheticPointerTouchActionTarget() override {} | 491 ~MockSyntheticPointerTouchActionTarget() override {} |
500 | 492 |
501 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 493 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
502 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 494 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
503 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 495 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
504 type_ = touch_event.type; | 496 type_ = touch_event.type; |
505 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 497 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
506 indexes_[i] = touch_event.touches[i].id; | 498 indexes_[i] = touch_event.touches[i].id; |
507 positions_[i] = gfx::PointF(touch_event.touches[i].position); | 499 positions_[i] = gfx::PointF(touch_event.touches[i].position); |
508 states_[i] = touch_event.touches[i].state; | 500 states_[i] = touch_event.touches[i].state; |
509 } | 501 } |
510 touch_length_ = touch_event.touchesLength; | 502 touch_length_ = touch_event.touchesLength; |
511 } | 503 } |
| 504 |
| 505 gfx::PointF positions(int index) const { return positions_[index]; } |
| 506 int indexes(int index) const { return indexes_[index]; } |
| 507 WebTouchPoint::State states(int index) { return states_[index]; } |
| 508 unsigned touch_length() const { return touch_length_; } |
| 509 |
| 510 private: |
| 511 gfx::PointF positions_[kTouchPointersLength]; |
| 512 unsigned touch_length_; |
| 513 int indexes_[kTouchPointersLength]; |
| 514 WebTouchPoint::State states_[kTouchPointersLength]; |
| 515 }; |
| 516 |
| 517 class MockSyntheticPointerMouseActionTarget |
| 518 : public MockSyntheticPointerActionTarget { |
| 519 public: |
| 520 MockSyntheticPointerMouseActionTarget() {} |
| 521 ~MockSyntheticPointerMouseActionTarget() override {} |
| 522 |
| 523 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| 524 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); |
| 525 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
| 526 type_ = mouse_event.type; |
| 527 position_ = gfx::PointF(mouse_event.x, mouse_event.y); |
| 528 clickCount_ = mouse_event.clickCount; |
| 529 button_ = mouse_event.button; |
| 530 } |
| 531 |
| 532 gfx::PointF position() const { return position_; } |
| 533 int clickCount() const { return clickCount_; } |
| 534 WebMouseEvent::Button button() const { return button_; } |
| 535 |
| 536 private: |
| 537 gfx::PointF position_; |
| 538 int clickCount_; |
| 539 WebMouseEvent::Button button_; |
512 }; | 540 }; |
513 | 541 |
514 class SyntheticGestureControllerTestBase { | 542 class SyntheticGestureControllerTestBase { |
515 public: | 543 public: |
516 SyntheticGestureControllerTestBase() {} | 544 SyntheticGestureControllerTestBase() {} |
517 ~SyntheticGestureControllerTestBase() {} | 545 ~SyntheticGestureControllerTestBase() {} |
518 | 546 |
519 protected: | 547 protected: |
520 template<typename MockGestureTarget> | 548 template<typename MockGestureTarget> |
521 void CreateControllerAndTarget() { | 549 void CreateControllerAndTarget() { |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 static_cast<MockSyntheticTapMouseTarget*>(target_); | 1493 static_cast<MockSyntheticTapMouseTarget*>(target_); |
1466 EXPECT_EQ(1, num_success_); | 1494 EXPECT_EQ(1, num_success_); |
1467 EXPECT_EQ(0, num_failure_); | 1495 EXPECT_EQ(0, num_failure_); |
1468 EXPECT_TRUE(tap_target->GestureFinished()); | 1496 EXPECT_TRUE(tap_target->GestureFinished()); |
1469 EXPECT_EQ(tap_target->position(), params.position); | 1497 EXPECT_EQ(tap_target->position(), params.position); |
1470 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1498 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
1471 EXPECT_GE(GetTotalTime(), | 1499 EXPECT_GE(GetTotalTime(), |
1472 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1500 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
1473 } | 1501 } |
1474 | 1502 |
| 1503 TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { |
| 1504 CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>(); |
| 1505 std::unique_ptr<SyntheticPointer> synthetic_pointer = |
| 1506 SyntheticPointer::Create(SyntheticGestureParams::TOUCH_INPUT); |
| 1507 SyntheticPointerAction::IndexMap index_map; |
| 1508 std::fill(index_map.begin(), index_map.end(), -1); |
| 1509 std::vector<SyntheticPointerActionParams> action_param_list; |
| 1510 |
| 1511 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( |
| 1512 SyntheticGestureParams::TOUCH_INPUT, |
| 1513 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 1514 SyntheticPointerActionParams params1 = SyntheticPointerActionParams( |
| 1515 SyntheticGestureParams::TOUCH_INPUT, |
| 1516 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 1517 params0.set_index(0); |
| 1518 params0.set_position(gfx::PointF(54, 89)); |
| 1519 params1.set_index(1); |
| 1520 params1.set_position(gfx::PointF(79, 132)); |
| 1521 action_param_list.push_back(params0); |
| 1522 action_param_list.push_back(params1); |
| 1523 std::unique_ptr<SyntheticPointerAction> gesture(new SyntheticPointerAction( |
| 1524 action_param_list, synthetic_pointer.get(), &index_map)); |
| 1525 QueueSyntheticGesture(std::move(gesture)); |
| 1526 FlushInputUntilComplete(); |
| 1527 |
| 1528 MockSyntheticPointerTouchActionTarget* pointer_touch_target = |
| 1529 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
| 1530 ASSERT_EQ(pointer_touch_target->touch_length(), 2u); |
| 1531 EXPECT_EQ(pointer_touch_target->indexes(0), params0.index()); |
| 1532 EXPECT_EQ(pointer_touch_target->positions(0), params0.position()); |
| 1533 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); |
| 1534 EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); |
| 1535 EXPECT_EQ(pointer_touch_target->positions(1), params1.position()); |
| 1536 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); |
| 1537 |
| 1538 action_param_list.clear(); |
| 1539 params0.set_pointer_action_type( |
| 1540 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 1541 params1.set_pointer_action_type( |
| 1542 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 1543 params1.set_position(gfx::PointF(183, 239)); |
| 1544 action_param_list.push_back(params0); |
| 1545 action_param_list.push_back(params1); |
| 1546 gesture.reset(new SyntheticPointerAction( |
| 1547 action_param_list, synthetic_pointer.get(), &index_map)); |
| 1548 QueueSyntheticGesture(std::move(gesture)); |
| 1549 FlushInputUntilComplete(); |
| 1550 |
| 1551 ASSERT_EQ(pointer_touch_target->touch_length(), 2u); |
| 1552 EXPECT_EQ(pointer_touch_target->indexes(0), params0.index()); |
| 1553 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased); |
| 1554 EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); |
| 1555 EXPECT_EQ(pointer_touch_target->positions(1), params1.position()); |
| 1556 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); |
| 1557 |
| 1558 action_param_list.clear(); |
| 1559 params1.set_pointer_action_type( |
| 1560 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 1561 action_param_list.push_back(params1); |
| 1562 gesture.reset(new SyntheticPointerAction( |
| 1563 action_param_list, synthetic_pointer.get(), &index_map)); |
| 1564 QueueSyntheticGesture(std::move(gesture)); |
| 1565 FlushInputUntilComplete(); |
| 1566 |
| 1567 ASSERT_EQ(pointer_touch_target->touch_length(), 2u); |
| 1568 EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); |
| 1569 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); |
| 1570 } |
| 1571 |
| 1572 TEST_F(SyntheticGestureControllerTest, PointerMouseAction) { |
| 1573 CreateControllerAndTarget<MockSyntheticPointerMouseActionTarget>(); |
| 1574 std::unique_ptr<SyntheticPointer> synthetic_pointer = |
| 1575 SyntheticPointer::Create(SyntheticGestureParams::MOUSE_INPUT); |
| 1576 SyntheticPointerAction::IndexMap index_map; |
| 1577 std::fill(index_map.begin(), index_map.end(), -1); |
| 1578 std::vector<SyntheticPointerActionParams> action_param_list; |
| 1579 |
| 1580 SyntheticPointerActionParams params = SyntheticPointerActionParams( |
| 1581 SyntheticGestureParams::MOUSE_INPUT, |
| 1582 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 1583 params.set_index(0); |
| 1584 params.set_position(gfx::PointF(54, 89)); |
| 1585 action_param_list.push_back(params); |
| 1586 std::unique_ptr<SyntheticPointerAction> gesture(new SyntheticPointerAction( |
| 1587 action_param_list, synthetic_pointer.get(), &index_map)); |
| 1588 QueueSyntheticGesture(std::move(gesture)); |
| 1589 FlushInputUntilComplete(); |
| 1590 |
| 1591 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = |
| 1592 static_cast<MockSyntheticPointerMouseActionTarget*>(target_); |
| 1593 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| 1594 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 1595 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); |
| 1596 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); |
| 1597 |
| 1598 action_param_list.clear(); |
| 1599 params.set_pointer_action_type( |
| 1600 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 1601 params.set_position(gfx::PointF(183, 239)); |
| 1602 action_param_list.push_back(params); |
| 1603 gesture.reset(new SyntheticPointerAction( |
| 1604 action_param_list, synthetic_pointer.get(), &index_map)); |
| 1605 QueueSyntheticGesture(std::move(gesture)); |
| 1606 FlushInputUntilComplete(); |
| 1607 |
| 1608 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); |
| 1609 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 1610 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 1611 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 1612 |
| 1613 action_param_list.clear(); |
| 1614 params.set_pointer_action_type( |
| 1615 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 1616 params.set_position(gfx::PointF(254, 279)); |
| 1617 action_param_list.push_back(params); |
| 1618 gesture.reset(new SyntheticPointerAction( |
| 1619 action_param_list, synthetic_pointer.get(), &index_map)); |
| 1620 QueueSyntheticGesture(std::move(gesture)); |
| 1621 FlushInputUntilComplete(); |
| 1622 |
| 1623 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); |
| 1624 EXPECT_EQ(pointer_mouse_target->position(), params.position()); |
| 1625 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 1626 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 1627 |
| 1628 action_param_list.clear(); |
| 1629 params.set_pointer_action_type( |
| 1630 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 1631 action_param_list.push_back(params); |
| 1632 gesture.reset(new SyntheticPointerAction( |
| 1633 action_param_list, synthetic_pointer.get(), &index_map)); |
| 1634 QueueSyntheticGesture(std::move(gesture)); |
| 1635 FlushInputUntilComplete(); |
| 1636 |
| 1637 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); |
| 1638 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
| 1639 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); |
| 1640 } |
| 1641 |
1475 } // namespace | 1642 } // namespace |
1476 | 1643 |
1477 } // namespace content | 1644 } // namespace content |
OLD | NEW |