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 28 matching lines...) Expand all Loading... | |
39 #include "ui/gfx/geometry/vector2d_f.h" | 39 #include "ui/gfx/geometry/vector2d_f.h" |
40 | 40 |
41 using blink::WebInputEvent; | 41 using blink::WebInputEvent; |
42 using blink::WebMouseEvent; | 42 using blink::WebMouseEvent; |
43 using blink::WebMouseWheelEvent; | 43 using blink::WebMouseWheelEvent; |
44 using blink::WebTouchEvent; | 44 using blink::WebTouchEvent; |
45 using blink::WebTouchPoint; | 45 using blink::WebTouchPoint; |
46 | 46 |
47 namespace content { | 47 namespace content { |
48 | 48 |
49 class TestSyntheticGestureController : public SyntheticGestureController { | |
50 public: | |
51 TestSyntheticGestureController( | |
52 std::unique_ptr<SyntheticGestureTarget> gesture_target) | |
53 : SyntheticGestureController(std::move(gesture_target)) {} | |
54 ~TestSyntheticGestureController() override {} | |
55 | |
56 int PointerIndex(int index) const { | |
57 CHECK_GE(index, 0); | |
58 CHECK_LT(index, WebTouchEvent::touchesLengthCap); | |
59 return pointer_action_controller_.index_map_[index]; | |
60 } | |
61 }; | |
62 | |
49 namespace { | 63 namespace { |
50 | 64 |
51 const int kFlushInputRateInMs = 16; | 65 const int kFlushInputRateInMs = 16; |
52 const int kPointerAssumedStoppedTimeMs = 43; | 66 const int kPointerAssumedStoppedTimeMs = 43; |
53 const float kTouchSlopInDips = 7.0f; | 67 const float kTouchSlopInDips = 7.0f; |
54 const float kMinScalingSpanInDips = 27.5f; | 68 const float kMinScalingSpanInDips = 27.5f; |
55 const int kTouchPointersLength = 16; | 69 const int kTouchPointersLength = 16; |
56 | 70 |
57 enum TouchGestureType { TOUCH_SCROLL, TOUCH_DRAG }; | 71 enum TouchGestureType { TOUCH_SCROLL, TOUCH_DRAG }; |
58 | 72 |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 break; | 485 break; |
472 } | 486 } |
473 } | 487 } |
474 }; | 488 }; |
475 | 489 |
476 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { | 490 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { |
477 public: | 491 public: |
478 MockSyntheticPointerActionTarget() {} | 492 MockSyntheticPointerActionTarget() {} |
479 ~MockSyntheticPointerActionTarget() override {} | 493 ~MockSyntheticPointerActionTarget() override {} |
480 | 494 |
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_; } | 495 WebInputEvent::Type type() const { return type_; } |
486 | 496 |
487 protected: | 497 protected: |
488 gfx::PointF positions_[kTouchPointersLength]; | |
489 unsigned touch_length_; | |
490 int indexes_[kTouchPointersLength]; | |
491 WebTouchPoint::State states_[kTouchPointersLength]; | |
492 WebInputEvent::Type type_; | 498 WebInputEvent::Type type_; |
493 }; | 499 }; |
494 | 500 |
495 class MockSyntheticPointerTouchActionTarget | 501 class MockSyntheticPointerTouchActionTarget |
496 : public MockSyntheticPointerActionTarget { | 502 : public MockSyntheticPointerActionTarget { |
497 public: | 503 public: |
498 MockSyntheticPointerTouchActionTarget() {} | 504 MockSyntheticPointerTouchActionTarget() {} |
499 ~MockSyntheticPointerTouchActionTarget() override {} | 505 ~MockSyntheticPointerTouchActionTarget() override {} |
500 | 506 |
501 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 507 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
502 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 508 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
503 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 509 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
504 type_ = touch_event.type; | 510 type_ = touch_event.type; |
505 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 511 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
506 indexes_[i] = touch_event.touches[i].id; | 512 indexes_[i] = touch_event.touches[i].id; |
507 positions_[i] = gfx::PointF(touch_event.touches[i].position); | 513 positions_[i] = gfx::PointF(touch_event.touches[i].position); |
508 states_[i] = touch_event.touches[i].state; | 514 states_[i] = touch_event.touches[i].state; |
509 } | 515 } |
510 touch_length_ = touch_event.touchesLength; | 516 touch_length_ = touch_event.touchesLength; |
511 } | 517 } |
518 | |
519 gfx::PointF positions(int index) const { return positions_[index]; } | |
520 int indexes(int index) const { return indexes_[index]; } | |
521 WebTouchPoint::State states(int index) { return states_[index]; } | |
522 unsigned touch_length() const { return touch_length_; } | |
523 | |
524 private: | |
525 gfx::PointF positions_[kTouchPointersLength]; | |
526 unsigned touch_length_; | |
527 int indexes_[kTouchPointersLength]; | |
528 WebTouchPoint::State states_[kTouchPointersLength]; | |
529 }; | |
530 | |
531 class MockSyntheticPointerMouseActionTarget | |
532 : public MockSyntheticPointerActionTarget { | |
533 public: | |
534 MockSyntheticPointerMouseActionTarget() {} | |
535 ~MockSyntheticPointerMouseActionTarget() override {} | |
536 | |
537 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | |
538 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); | |
539 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | |
540 type_ = mouse_event.type; | |
541 position_ = gfx::PointF(mouse_event.x, mouse_event.y); | |
542 clickCount_ = mouse_event.clickCount; | |
543 button_ = mouse_event.button; | |
544 } | |
545 | |
546 gfx::PointF position() const { return position_; } | |
547 int clickCount() const { return clickCount_; } | |
548 WebMouseEvent::Button button() const { return button_; } | |
549 | |
550 private: | |
551 gfx::PointF position_; | |
552 int clickCount_; | |
553 WebMouseEvent::Button button_; | |
512 }; | 554 }; |
513 | 555 |
514 class SyntheticGestureControllerTestBase { | 556 class SyntheticGestureControllerTestBase { |
515 public: | 557 public: |
516 SyntheticGestureControllerTestBase() {} | 558 SyntheticGestureControllerTestBase() {} |
517 ~SyntheticGestureControllerTestBase() {} | 559 ~SyntheticGestureControllerTestBase() {} |
518 | 560 |
519 protected: | 561 protected: |
520 template<typename MockGestureTarget> | 562 template<typename MockGestureTarget> |
521 void CreateControllerAndTarget() { | 563 void CreateControllerAndTarget() { |
522 target_ = new MockGestureTarget(); | 564 target_ = new MockGestureTarget(); |
523 controller_.reset(new SyntheticGestureController( | 565 controller_.reset(new TestSyntheticGestureController( |
524 std::unique_ptr<SyntheticGestureTarget>(target_))); | 566 std::unique_ptr<SyntheticGestureTarget>(target_))); |
525 } | 567 } |
526 | 568 |
527 void QueueSyntheticGesture(std::unique_ptr<SyntheticGesture> gesture) { | 569 void QueueSyntheticGesture(std::unique_ptr<SyntheticGesture> gesture) { |
528 controller_->QueueSyntheticGesture( | 570 controller_->QueueSyntheticGesture( |
529 std::move(gesture), | 571 std::move(gesture), |
530 base::Bind( | 572 base::Bind( |
531 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted, | 573 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted, |
532 base::Unretained(this))); | 574 base::Unretained(this))); |
533 } | 575 } |
534 | 576 |
577 void QueueSyntheticPointerAction( | |
578 const SyntheticPointerActionParams& gesture_params) { | |
579 controller_->QueueSyntheticPointerAction( | |
580 gesture_params, base::Bind(&SyntheticGestureControllerTestBase:: | |
581 OnSyntheticPointerActionCompleted, | |
582 base::Unretained(this))); | |
583 } | |
584 | |
535 void FlushInputUntilComplete() { | 585 void FlushInputUntilComplete() { |
536 while (target_->flush_requested()) { | 586 while (target_->flush_requested()) { |
537 while (target_->flush_requested()) { | 587 while (target_->flush_requested()) { |
538 target_->ClearFlushRequest(); | 588 target_->ClearFlushRequest(); |
539 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | 589 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); |
540 controller_->Flush(time_); | 590 controller_->Flush(time_); |
541 } | 591 } |
542 controller_->OnDidFlushInput(); | 592 controller_->OnDidFlushInput(); |
543 } | 593 } |
544 } | 594 } |
545 | 595 |
546 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { | 596 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { |
547 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); | 597 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); |
548 if (result == SyntheticGesture::GESTURE_FINISHED) | 598 if (result == SyntheticGesture::GESTURE_FINISHED) |
549 num_success_++; | 599 num_success_++; |
550 else | 600 else |
551 num_failure_++; | 601 num_failure_++; |
552 } | 602 } |
553 | 603 |
604 void OnSyntheticPointerActionCompleted(SyntheticGesture::Result result) { | |
605 if (result == SyntheticGesture::POINTER_ACTION_PROCESSED) { | |
606 num_success_++; | |
607 action_state_ = PROCESSED; | |
608 } else if (result == SyntheticGesture::POINTER_ACTION_FINISHED) { | |
609 num_success_++; | |
610 action_state_ = FINISHED; | |
611 } else { | |
612 num_failure_++; | |
613 action_state_ = OTHER; | |
614 } | |
615 } | |
616 | |
554 base::TimeDelta GetTotalTime() const { return time_ - start_time_; } | 617 base::TimeDelta GetTotalTime() const { return time_ - start_time_; } |
555 | 618 |
619 int PointerIndex(int index) const { return controller_->PointerIndex(index); } | |
620 | |
621 enum PointerActionState { PROCESSED, FINISHED, OTHER }; | |
622 | |
556 MockSyntheticGestureTarget* target_; | 623 MockSyntheticGestureTarget* target_; |
557 std::unique_ptr<SyntheticGestureController> controller_; | 624 std::unique_ptr<TestSyntheticGestureController> controller_; |
558 base::TimeTicks start_time_; | 625 base::TimeTicks start_time_; |
559 base::TimeTicks time_; | 626 base::TimeTicks time_; |
560 int num_success_; | 627 int num_success_; |
561 int num_failure_; | 628 int num_failure_; |
629 PointerActionState action_state_; | |
562 }; | 630 }; |
563 | 631 |
564 class SyntheticGestureControllerTest | 632 class SyntheticGestureControllerTest |
565 : public SyntheticGestureControllerTestBase, | 633 : public SyntheticGestureControllerTestBase, |
566 public testing::Test { | 634 public testing::Test { |
567 protected: | 635 protected: |
568 void SetUp() override { | 636 void SetUp() override { |
569 start_time_ = base::TimeTicks::Now(); | 637 start_time_ = base::TimeTicks::Now(); |
570 time_ = start_time_; | 638 time_ = start_time_; |
571 num_success_ = 0; | 639 num_success_ = 0; |
572 num_failure_ = 0; | 640 num_failure_ = 0; |
641 action_state_ = OTHER; | |
573 } | 642 } |
574 | 643 |
575 void TearDown() override { | 644 void TearDown() override { |
576 controller_.reset(); | 645 controller_.reset(); |
577 target_ = nullptr; | 646 target_ = nullptr; |
578 time_ = base::TimeTicks(); | 647 time_ = base::TimeTicks(); |
579 } | 648 } |
580 }; | 649 }; |
581 | 650 |
582 class SyntheticGestureControllerTestWithParam | 651 class SyntheticGestureControllerTestWithParam |
583 : public SyntheticGestureControllerTestBase, | 652 : public SyntheticGestureControllerTestBase, |
584 public testing::TestWithParam<bool> { | 653 public testing::TestWithParam<bool> { |
585 protected: | 654 protected: |
586 void SetUp() override { | 655 void SetUp() override { |
587 start_time_ = base::TimeTicks::Now(); | 656 start_time_ = base::TimeTicks::Now(); |
588 time_ = start_time_; | 657 time_ = start_time_; |
589 num_success_ = 0; | 658 num_success_ = 0; |
590 num_failure_ = 0; | 659 num_failure_ = 0; |
660 action_state_ = OTHER; | |
591 } | 661 } |
592 | 662 |
593 void TearDown() override { | 663 void TearDown() override { |
594 controller_.reset(); | 664 controller_.reset(); |
595 target_ = nullptr; | 665 target_ = nullptr; |
596 time_ = base::TimeTicks(); | 666 time_ = base::TimeTicks(); |
597 } | 667 } |
598 }; | 668 }; |
599 | 669 |
600 TEST_F(SyntheticGestureControllerTest, SingleGesture) { | 670 TEST_F(SyntheticGestureControllerTest, SingleGesture) { |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1468 EXPECT_TRUE(tap_target->GestureFinished()); | 1538 EXPECT_TRUE(tap_target->GestureFinished()); |
1469 EXPECT_EQ(tap_target->position(), params.position); | 1539 EXPECT_EQ(tap_target->position(), params.position); |
1470 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1540 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
1471 EXPECT_GE(GetTotalTime(), | 1541 EXPECT_GE(GetTotalTime(), |
1472 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1542 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
1473 } | 1543 } |
1474 | 1544 |
1475 TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { | 1545 TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { |
1476 CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>(); | 1546 CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>(); |
1477 | 1547 |
1478 SyntheticPointerActionParams params = SyntheticPointerActionParams( | 1548 SyntheticPointerActionParams params1 = SyntheticPointerActionParams( |
1479 SyntheticPointerActionParams::PointerActionType::PRESS); | 1549 SyntheticPointerActionParams::PointerActionType::PRESS); |
1480 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1550 params1.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
1481 params.set_index(0); | 1551 params1.set_index(0); |
1482 params.set_position(gfx::PointF(54, 89)); | 1552 params1.set_position(gfx::PointF(54, 89)); |
1483 SyntheticTouchPointer synthetic_pointer; | |
1484 | 1553 |
1485 std::unique_ptr<SyntheticPointerAction> gesture( | 1554 // Send a touch press for one finger. |
1486 new SyntheticPointerAction(params, &synthetic_pointer)); | 1555 SyntheticPointerActionParams process_params = SyntheticPointerActionParams( |
1487 QueueSyntheticGesture(std::move(gesture)); | 1556 SyntheticPointerActionParams::PointerActionType::PROCESS); |
1557 process_params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
1558 QueueSyntheticPointerAction(params1); | |
1559 QueueSyntheticPointerAction(process_params); | |
1488 FlushInputUntilComplete(); | 1560 FlushInputUntilComplete(); |
1489 | 1561 |
1490 MockSyntheticPointerTouchActionTarget* pointer_touch_target = | 1562 MockSyntheticPointerTouchActionTarget* pointer_touch_target = |
1491 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); | 1563 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
1564 EXPECT_EQ(1, num_success_); | |
1565 EXPECT_EQ(0, num_failure_); | |
1492 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); | 1566 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
1493 EXPECT_EQ(pointer_touch_target->positions(0), params.position()); | 1567 EXPECT_EQ(pointer_touch_target->indexes(0), PointerIndex(0)); |
1568 EXPECT_EQ(pointer_touch_target->positions(0), params1.position()); | |
1494 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); | 1569 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); |
1495 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); | 1570 ASSERT_EQ(pointer_touch_target->touch_length(), 1U); |
1571 EXPECT_EQ(PROCESSED, action_state_); | |
1496 | 1572 |
1497 params.set_index(1); | 1573 // Send a touch move for the first finger and a touch press for the second |
1498 params.set_position(gfx::PointF(79, 132)); | 1574 // finger. |
1499 gesture.reset(new SyntheticPointerAction(params, &synthetic_pointer)); | 1575 params1.set_pointer_action_type( |
1500 QueueSyntheticGesture(std::move(gesture)); | 1576 SyntheticPointerActionParams::PointerActionType::MOVE); |
1577 params1.set_position(gfx::PointF(133, 156)); | |
1578 QueueSyntheticPointerAction(params1); | |
1579 SyntheticPointerActionParams params2 = SyntheticPointerActionParams( | |
1580 SyntheticPointerActionParams::PointerActionType::PRESS); | |
1581 params2.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
1582 params2.set_index(1); | |
1583 params2.set_position(gfx::PointF(79, 132)); | |
1584 QueueSyntheticPointerAction(params2); | |
1585 QueueSyntheticPointerAction(process_params); | |
1501 FlushInputUntilComplete(); | 1586 FlushInputUntilComplete(); |
1502 | 1587 |
1503 pointer_touch_target = | 1588 pointer_touch_target = |
1504 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); | 1589 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); |
1590 EXPECT_EQ(2, num_success_); | |
1591 EXPECT_EQ(0, num_failure_); | |
1592 // The type of the SyntheticWebTouchEvent is the action of the last finger. | |
1505 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); | 1593 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart); |
1506 EXPECT_EQ(pointer_touch_target->indexes(1), params.index()); | 1594 EXPECT_EQ(pointer_touch_target->indexes(0), PointerIndex(0)); |
1507 EXPECT_EQ(pointer_touch_target->positions(1), params.position()); | 1595 EXPECT_EQ(pointer_touch_target->positions(0), params1.position()); |
1596 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateMoved); | |
1597 EXPECT_EQ(pointer_touch_target->indexes(1), PointerIndex(1)); | |
1598 EXPECT_EQ(pointer_touch_target->positions(1), params2.position()); | |
1508 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); | 1599 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); |
1509 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); | 1600 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); |
1601 EXPECT_EQ(PROCESSED, action_state_); | |
1510 | 1602 |
1511 params.set_pointer_action_type( | 1603 // Send touch releases for both fingers. |
1512 SyntheticPointerActionParams::PointerActionType::MOVE); | 1604 params1.set_pointer_action_type( |
1513 params.set_position(gfx::PointF(133, 156)); | 1605 SyntheticPointerActionParams::PointerActionType::RELEASE); |
1514 gesture.reset(new SyntheticPointerAction(params, &synthetic_pointer)); | 1606 QueueSyntheticPointerAction(params1); |
1515 QueueSyntheticGesture(std::move(gesture)); | 1607 params2.set_pointer_action_type( |
1608 SyntheticPointerActionParams::PointerActionType::RELEASE); | |
1609 QueueSyntheticPointerAction(params2); | |
1610 QueueSyntheticPointerAction(process_params); | |
1516 FlushInputUntilComplete(); | 1611 FlushInputUntilComplete(); |
1517 | 1612 |
1518 pointer_touch_target = | 1613 EXPECT_EQ(3, num_success_); |
1519 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); | 1614 EXPECT_EQ(0, num_failure_); |
1520 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove); | 1615 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); |
1521 EXPECT_EQ(pointer_touch_target->positions(1), params.position()); | 1616 EXPECT_EQ(pointer_touch_target->indexes(0), PointerIndex(0)); |
1522 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); | 1617 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased); |
1618 EXPECT_EQ(pointer_touch_target->indexes(1), PointerIndex(1)); | |
1619 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); | |
1523 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); | 1620 ASSERT_EQ(pointer_touch_target->touch_length(), 2U); |
1621 EXPECT_EQ(PROCESSED, action_state_); | |
1524 | 1622 |
1623 // Send a finish action to notify synthetic gesture controller the whole | |
1624 // pointer action sequence has been handled. | |
1625 SyntheticPointerActionParams finish_params = SyntheticPointerActionParams( | |
1626 SyntheticPointerActionParams::PointerActionType::FINISH); | |
1627 finish_params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
1628 QueueSyntheticPointerAction(finish_params); | |
1629 FlushInputUntilComplete(); | |
1630 | |
1631 EXPECT_EQ(4, num_success_); | |
1632 EXPECT_EQ(0, num_failure_); | |
1633 EXPECT_EQ(FINISHED, action_state_); | |
1634 } | |
1635 | |
1636 TEST_F(SyntheticGestureControllerTest, PointerMouseAction) { | |
1637 CreateControllerAndTarget<MockSyntheticPointerMouseActionTarget>(); | |
1638 | |
1639 SyntheticPointerActionParams params = SyntheticPointerActionParams( | |
1640 SyntheticPointerActionParams::PointerActionType::MOVE); | |
1641 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
1642 params.set_index(0); | |
1643 params.set_position(gfx::PointF(189, 62)); | |
1644 | |
1645 // Send a mouse move. | |
1646 SyntheticPointerActionParams process_params = SyntheticPointerActionParams( | |
1647 SyntheticPointerActionParams::PointerActionType::PROCESS); | |
1648 process_params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
1649 QueueSyntheticPointerAction(params); | |
1650 QueueSyntheticPointerAction(process_params); | |
1651 FlushInputUntilComplete(); | |
1652 | |
1653 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = | |
1654 static_cast<MockSyntheticPointerMouseActionTarget*>(target_); | |
1655 EXPECT_EQ(1, num_success_); | |
1656 EXPECT_EQ(0, num_failure_); | |
tdresser
2016/05/31 13:44:26
Should we test a case that does cause a failure?
| |
1657 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | |
1658 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | |
1659 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); | |
1660 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); | |
1661 EXPECT_EQ(PROCESSED, action_state_); | |
1662 | |
1663 // Send a mouse press. | |
1664 params.set_position(gfx::PointF(326, 298)); | |
1665 params.set_pointer_action_type( | |
1666 SyntheticPointerActionParams::PointerActionType::PRESS); | |
1667 QueueSyntheticPointerAction(params); | |
1668 QueueSyntheticPointerAction(process_params); | |
1669 FlushInputUntilComplete(); | |
1670 | |
1671 EXPECT_EQ(2, num_success_); | |
1672 EXPECT_EQ(0, num_failure_); | |
1673 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); | |
1674 EXPECT_EQ(pointer_mouse_target->position(), params.position()); | |
1675 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | |
1676 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); | |
1677 EXPECT_EQ(PROCESSED, action_state_); | |
1678 | |
1679 // Send a mouse release. | |
1525 params.set_pointer_action_type( | 1680 params.set_pointer_action_type( |
1526 SyntheticPointerActionParams::PointerActionType::RELEASE); | 1681 SyntheticPointerActionParams::PointerActionType::RELEASE); |
1527 gesture.reset(new SyntheticPointerAction(params, &synthetic_pointer)); | 1682 QueueSyntheticPointerAction(params); |
1528 QueueSyntheticGesture(std::move(gesture)); | 1683 QueueSyntheticPointerAction(process_params); |
1529 FlushInputUntilComplete(); | 1684 FlushInputUntilComplete(); |
1530 | 1685 |
1531 pointer_touch_target = | 1686 EXPECT_EQ(3, num_success_); |
1532 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); | 1687 EXPECT_EQ(0, num_failure_); |
1533 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchEnd); | 1688 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); |
1534 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); | 1689 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); |
1690 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::ButtonLeft); | |
1691 EXPECT_EQ(PROCESSED, action_state_); | |
1692 | |
1693 // Send a finish action to notify synthetic gesture controller the whole | |
1694 // pointer action sequence has been handled. | |
1695 SyntheticPointerActionParams finish_params = SyntheticPointerActionParams( | |
1696 SyntheticPointerActionParams::PointerActionType::FINISH); | |
1697 finish_params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
1698 QueueSyntheticPointerAction(finish_params); | |
1699 FlushInputUntilComplete(); | |
1700 | |
1701 EXPECT_EQ(4, num_success_); | |
1702 EXPECT_EQ(0, num_failure_); | |
1703 EXPECT_EQ(FINISHED, action_state_); | |
1535 } | 1704 } |
1536 | 1705 |
1537 } // namespace | 1706 } // namespace |
1538 | 1707 |
1539 } // namespace content | 1708 } // namespace content |
OLD | NEW |