Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc

Issue 2336803003: Make SyntheticPointerAction to flush the pointer action sequence (Closed)
Patch Set: return invaid when index is out bound Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_;
tdresser 2016/12/13 14:37:43 Be more specific in the variable name here.
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
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 SyntheticPointerActionParams param1 = SyntheticPointerActionParams(
1516 SyntheticPointerActionParams::PointerActionType::PRESS,
1517 SyntheticGestureParams::TOUCH_INPUT);
1518 param0.set_position(gfx::PointF(54, 89));
1519 param0.set_index(0);
1520 param1.set_position(gfx::PointF(79, 132));
1521 param1.set_index(1);
1522 param_list.push_back(param0);
1523 param_list.push_back(param1);
1524 SyntheticPointerActionListParams params(param_list);
1525 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
1526 std::unique_ptr<SyntheticPointerAction> gesture(
1527 new SyntheticPointerAction(params));
1528 QueueSyntheticGesture(std::move(gesture));
1529 FlushInputUntilComplete();
1530
1531 MockSyntheticPointerTouchActionTarget* pointer_touch_target =
1532 static_cast<MockSyntheticPointerTouchActionTarget*>(target_);
1533 EXPECT_EQ(1, num_success_);
1534 EXPECT_EQ(0, num_failure_);
1535 EXPECT_EQ(pointer_touch_target->count(), 1);
1536 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchStart);
1537 EXPECT_EQ(pointer_touch_target->touch_length(), 2u);
1538 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
1539 EXPECT_EQ(pointer_touch_target->positions(0), gfx::PointF(54, 89));
1540 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed);
tdresser 2016/12/13 14:37:43 Can we add a helper to shorten this up? Maybe som
1541 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
1542 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(79, 132));
1543 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed);
1544
1545 // Second, send a touch release for finger 0, a touch move for finger 1.
1546 param0.set_pointer_action_type(
1547 SyntheticPointerActionParams::PointerActionType::RELEASE);
1548 param1.set_pointer_action_type(
1549 SyntheticPointerActionParams::PointerActionType::MOVE);
1550 param1.set_position(gfx::PointF(183, 239));
1551 param_list.clear();
1552 param_list.push_back(param0);
1553 param_list.push_back(param1);
1554 params.PushPointerActionParamsList(param_list);
1555 gesture.reset(new SyntheticPointerAction(params));
1556 QueueSyntheticGesture(std::move(gesture));
1557 pointer_touch_target->reset_count();
1558 FlushInputUntilComplete();
1559
1560 EXPECT_EQ(2, num_success_);
1561 EXPECT_EQ(0, num_failure_);
1562 EXPECT_EQ(pointer_touch_target->count(), 2);
1563 EXPECT_EQ(pointer_touch_target->type(), WebInputEvent::TouchMove);
1564 EXPECT_EQ(pointer_touch_target->touch_length(), 2u);
1565 EXPECT_EQ(pointer_touch_target->indexes(0), 0);
1566 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased);
1567 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
1568 EXPECT_EQ(pointer_touch_target->positions(1), gfx::PointF(183, 239));
1569 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved);
1570
1571 // Third, send a touch release for finger 1.
1572 param1.set_pointer_action_type(
1573 SyntheticPointerActionParams::PointerActionType::RELEASE);
1574 params.PushPointerActionParams(param1);
1575 gesture.reset(new SyntheticPointerAction(params));
1576 QueueSyntheticGesture(std::move(gesture));
1577 pointer_touch_target->reset_count();
1578 FlushInputUntilComplete();
1579
1580 EXPECT_EQ(3, num_success_);
1581 EXPECT_EQ(0, num_failure_);
1582 EXPECT_EQ(pointer_touch_target->count(), 3);
1583 EXPECT_EQ(pointer_touch_target->type(),
1584 WebInputEvent::WebInputEvent::TouchEnd);
1585 EXPECT_EQ(pointer_touch_target->touch_length(), 2u);
1586 EXPECT_EQ(pointer_touch_target->indexes(1), 1);
1587 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased);
1588 }
1589
1590 TEST_F(SyntheticGestureControllerTest, PointerMouseAction) {
1591 CreateControllerAndTarget<MockSyntheticPointerMouseActionTarget>();
1592
1593 // First, send a mouse move.
1594 SyntheticPointerActionListParams::ParamList param_list;
1595 SyntheticPointerActionParams param = SyntheticPointerActionParams(
1596 SyntheticPointerActionParams::PointerActionType::MOVE,
1597 SyntheticGestureParams::MOUSE_INPUT);
1598
1599 param.set_position(gfx::PointF(54, 89));
1600 SyntheticPointerActionListParams params;
1601 params.PushPointerActionParams(param);
1602 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
1603 std::unique_ptr<SyntheticPointerAction> gesture(
1604 new SyntheticPointerAction(params));
1605 QueueSyntheticGesture(std::move(gesture));
1606 FlushInputUntilComplete();
1607
1608 MockSyntheticPointerMouseActionTarget* pointer_mouse_target =
1609 static_cast<MockSyntheticPointerMouseActionTarget*>(target_);
1610 EXPECT_EQ(1, num_success_);
1611 EXPECT_EQ(0, num_failure_);
1612 EXPECT_EQ(pointer_mouse_target->count(), 1);
1613 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
1614 EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(54, 89));
1615 EXPECT_EQ(pointer_mouse_target->clickCount(), 0);
1616 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton);
1617
1618 // Second, send a mouse press.
1619 param.set_pointer_action_type(
1620 SyntheticPointerActionParams::PointerActionType::PRESS);
1621 param.set_position(gfx::PointF(183, 239));
1622 params.PushPointerActionParams(param);
1623 gesture.reset(new SyntheticPointerAction(params));
1624 QueueSyntheticGesture(std::move(gesture));
1625 pointer_mouse_target->reset_count();
1626 FlushInputUntilComplete();
1627
1628 EXPECT_EQ(2, num_success_);
1629 EXPECT_EQ(0, num_failure_);
1630 EXPECT_EQ(pointer_mouse_target->count(), 2);
1631 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown);
1632 EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(183, 239));
1633 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
1634 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left);
1635
1636 // Third, send a mouse move.
1637 param.set_pointer_action_type(
1638 SyntheticPointerActionParams::PointerActionType::MOVE);
1639 param.set_position(gfx::PointF(254, 279));
1640 params.PushPointerActionParams(param);
1641 gesture.reset(new SyntheticPointerAction(params));
1642 QueueSyntheticGesture(std::move(gesture));
1643 pointer_mouse_target->reset_count();
1644 FlushInputUntilComplete();
1645
1646 EXPECT_EQ(3, num_success_);
1647 EXPECT_EQ(0, num_failure_);
1648 EXPECT_EQ(pointer_mouse_target->count(), 3);
1649 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove);
1650 EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(254, 279));
1651 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
1652 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left);
1653
1654 // Fourth, send a mouse release.
1655 param.set_pointer_action_type(
1656 SyntheticPointerActionParams::PointerActionType::RELEASE);
1657 params.PushPointerActionParams(param);
1658 gesture.reset(new SyntheticPointerAction(params));
1659 QueueSyntheticGesture(std::move(gesture));
1660 pointer_mouse_target->reset_count();
1661 FlushInputUntilComplete();
1662
1663 EXPECT_EQ(4, num_success_);
1664 EXPECT_EQ(0, num_failure_);
1665 EXPECT_EQ(pointer_mouse_target->count(), 4);
1666 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp);
1667 EXPECT_EQ(pointer_mouse_target->clickCount(), 1);
1668 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left);
1669 }
1670
1474 } // namespace 1671 } // namespace
1475 1672
1476 } // namespace content 1673 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698