This source file includes following definitions.
- DefaultTouchTimeoutDelay
- touch_scrolling_mode_
- SetUp
- SetTouchScrollingMode
- TearDown
- SendTouchEventImmediately
- OnTouchEventAck
- SetUpForTimeoutTesting
- SetUpForTouchMoveSlopTesting
- SendTouchEvent
- SendGestureEvent
- SendTouchEventAck
- SendGestureEventAck
- SetFollowupEvent
- SetFollowupEvent
- SetSyncAckResult
- PressTouchPoint
- MoveTouchPoint
- MoveTouchPoints
- ReleaseTouchPoint
- CancelTouchPoint
- GetAndResetAckedEventCount
- GetAndResetSentEventCount
- IsPendingAckTouchStart
- OnHasTouchEventHandlers
- SetAckTimeoutDisabled
- IsTimeoutEnabled
- IsTimeoutRunning
- queued_event_count
- latest_event
- acked_event
- sent_event
- acked_event_state
- RunTasksAndWait
- SendTouchEvent
- ResetQueueWithParameters
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "content/browser/renderer_host/input/timeout_monitor.h"
#include "content/browser/renderer_host/input/touch_event_queue.h"
#include "content/common/input/synthetic_web_input_event_builders.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
using blink::WebGestureEvent;
using blink::WebInputEvent;
using blink::WebTouchEvent;
using blink::WebTouchPoint;
namespace content {
namespace {
base::TimeDelta DefaultTouchTimeoutDelay() {
return base::TimeDelta::FromMilliseconds(1);
}
}
class TouchEventQueueTest : public testing::Test,
public TouchEventQueueClient {
public:
TouchEventQueueTest()
: sent_event_count_(0),
acked_event_count_(0),
last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN),
slop_length_dips_(0),
touch_scrolling_mode_(TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT) {}
virtual ~TouchEventQueueTest() {}
virtual void SetUp() OVERRIDE {
ResetQueueWithParameters(touch_scrolling_mode_, slop_length_dips_);
}
virtual void SetTouchScrollingMode(TouchEventQueue::TouchScrollingMode mode) {
touch_scrolling_mode_ = mode;
ResetQueueWithParameters(touch_scrolling_mode_, slop_length_dips_);
}
virtual void TearDown() OVERRIDE {
queue_.reset();
}
virtual void SendTouchEventImmediately(
const TouchEventWithLatencyInfo& event) OVERRIDE {
++sent_event_count_;
last_sent_event_ = event.event;
if (sync_ack_result_)
SendTouchEventAck(*sync_ack_result_.Pass());
}
virtual void OnTouchEventAck(
const TouchEventWithLatencyInfo& event,
InputEventAckState ack_result) OVERRIDE {
++acked_event_count_;
last_acked_event_ = event.event;
last_acked_event_state_ = ack_result;
if (followup_touch_event_) {
scoped_ptr<WebTouchEvent> followup_touch_event =
followup_touch_event_.Pass();
SendTouchEvent(*followup_touch_event);
}
if (followup_gesture_event_) {
scoped_ptr<WebGestureEvent> followup_gesture_event =
followup_gesture_event_.Pass();
queue_->OnGestureScrollEvent(
GestureEventWithLatencyInfo(*followup_gesture_event,
ui::LatencyInfo()));
}
}
protected:
void SetUpForTimeoutTesting(base::TimeDelta timeout_delay) {
queue_->SetAckTimeoutEnabled(true, timeout_delay);
}
void SetUpForTouchMoveSlopTesting(double slop_length_dips) {
slop_length_dips_ = slop_length_dips;
ResetQueueWithParameters(touch_scrolling_mode_, slop_length_dips_);
}
void SendTouchEvent(const WebTouchEvent& event) {
queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo()));
}
void SendGestureEvent(WebInputEvent::Type type) {
WebGestureEvent event;
event.type = type;
queue_->OnGestureScrollEvent(
GestureEventWithLatencyInfo(event, ui::LatencyInfo()));
}
void SendTouchEventAck(InputEventAckState ack_result) {
queue_->ProcessTouchAck(ack_result, ui::LatencyInfo());
}
void SendGestureEventAck(WebInputEvent::Type type,
InputEventAckState ack_result) {
blink::WebGestureEvent gesture_event;
gesture_event.type = type;
GestureEventWithLatencyInfo event(gesture_event, ui::LatencyInfo());
queue_->OnGestureEventAck(event, ack_result);
}
void SetFollowupEvent(const WebTouchEvent& event) {
followup_touch_event_.reset(new WebTouchEvent(event));
}
void SetFollowupEvent(const WebGestureEvent& event) {
followup_gesture_event_.reset(new WebGestureEvent(event));
}
void SetSyncAckResult(InputEventAckState sync_ack_result) {
sync_ack_result_.reset(new InputEventAckState(sync_ack_result));
}
void PressTouchPoint(float x, float y) {
touch_event_.PressPoint(x, y);
SendTouchEvent();
}
void MoveTouchPoint(int index, float x, float y) {
touch_event_.MovePoint(index, x, y);
SendTouchEvent();
}
void MoveTouchPoints(int index0,
float x0,
float y0,
int index1,
float x1,
float y1) {
touch_event_.MovePoint(index0, x0, y0);
touch_event_.MovePoint(index1, x1, y1);
SendTouchEvent();
}
void ReleaseTouchPoint(int index) {
touch_event_.ReleasePoint(index);
SendTouchEvent();
}
void CancelTouchPoint(int index) {
touch_event_.CancelPoint(index);
SendTouchEvent();
}
size_t GetAndResetAckedEventCount() {
size_t count = acked_event_count_;
acked_event_count_ = 0;
return count;
}
size_t GetAndResetSentEventCount() {
size_t count = sent_event_count_;
sent_event_count_ = 0;
return count;
}
bool IsPendingAckTouchStart() const {
return queue_->IsPendingAckTouchStart();
}
void OnHasTouchEventHandlers(bool has_handlers) {
queue_->OnHasTouchEventHandlers(has_handlers);
}
void SetAckTimeoutDisabled() {
queue_->SetAckTimeoutEnabled(false, base::TimeDelta());
}
bool IsTimeoutEnabled() {
return queue_->ack_timeout_enabled();
}
bool IsTimeoutRunning() {
return queue_->IsTimeoutRunningForTesting();
}
size_t queued_event_count() const {
return queue_->size();
}
const WebTouchEvent& latest_event() const {
return queue_->GetLatestEventForTesting().event;
}
const WebTouchEvent& acked_event() const {
return last_acked_event_;
}
const WebTouchEvent& sent_event() const {
return last_sent_event_;
}
InputEventAckState acked_event_state() const {
return last_acked_event_state_;
}
static void RunTasksAndWait(base::TimeDelta delay) {
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitClosure(), delay);
base::MessageLoop::current()->Run();
}
private:
void SendTouchEvent() {
SendTouchEvent(touch_event_);
touch_event_.ResetPoints();
}
void ResetQueueWithParameters(TouchEventQueue::TouchScrollingMode mode,
double slop_length_dips) {
queue_.reset(new TouchEventQueue(this, mode, slop_length_dips));
queue_->OnHasTouchEventHandlers(true);
}
scoped_ptr<TouchEventQueue> queue_;
size_t sent_event_count_;
size_t acked_event_count_;
WebTouchEvent last_sent_event_;
WebTouchEvent last_acked_event_;
InputEventAckState last_acked_event_state_;
SyntheticWebTouchEvent touch_event_;
scoped_ptr<WebTouchEvent> followup_touch_event_;
scoped_ptr<WebGestureEvent> followup_gesture_event_;
scoped_ptr<InputEventAckState> sync_ack_result_;
double slop_length_dips_;
TouchEventQueue::TouchScrollingMode touch_scrolling_mode_;
base::MessageLoopForUI message_loop_;
};
TEST_F(TouchEventQueueTest, Basic) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
MoveTouchPoint(0, 5, 5);
EXPECT_EQ(2U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
}
TEST_F(TouchEventQueueTest, QueueFlushedWhenHandlersRemoved) {
OnHasTouchEventHandlers(true);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
ReleaseTouchPoint(0);
for (int i = 5; i < 15; ++i) {
PressTouchPoint(1, 1);
MoveTouchPoint(0, i, i);
ReleaseTouchPoint(0);
}
EXPECT_EQ(32U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(31U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
OnHasTouchEventHandlers(false);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(31U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) {
OnHasTouchEventHandlers(false);
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
OnHasTouchEventHandlers(true);
MoveTouchPoint(0, 5, 5);
ReleaseTouchPoint(0);
EXPECT_EQ(2U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
PressTouchPoint(1, 1);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
}
TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
MoveTouchPoint(0, 5, 5);
EXPECT_EQ(2U, queued_event_count());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
OnHasTouchEventHandlers(false);
EXPECT_EQ(2U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_EQ(0U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, queued_event_count());
MoveTouchPoint(0, 10, 10);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
OnHasTouchEventHandlers(true);
ReleaseTouchPoint(0);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
PressTouchPoint(1, 1);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
}
TEST_F(TouchEventQueueTest, Coalesce) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
for (int i = 5; i < 15; ++i)
MoveTouchPoint(0, i, i);
EXPECT_EQ(0U, GetAndResetSentEventCount());
ReleaseTouchPoint(0);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(3U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(2U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(10U, GetAndResetAckedEventCount());
EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
}
TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
for (int i = 5; i < 15; ++i)
MoveTouchPoint(0, i, i);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(2U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
MoveTouchPoint(0, 5, 5);
EXPECT_EQ(2U, queued_event_count());
MoveTouchPoint(0, 7, 7);
EXPECT_EQ(2U, queued_event_count());
}
TEST_F(TouchEventQueueTest, MultiTouch) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
MoveTouchPoint(0, 5, 5);
EXPECT_EQ(2U, queued_event_count());
PressTouchPoint(2, 2);
EXPECT_EQ(3U, queued_event_count());
MoveTouchPoints(0, 10, 10, 1, 20, 20);
MoveTouchPoint(1, 20, 20);
EXPECT_EQ(4U, queued_event_count());
MoveTouchPoint(0, 15, 15);
EXPECT_EQ(4U, queued_event_count());
MoveTouchPoint(1, 25, 25);
EXPECT_EQ(4U, queued_event_count());
const WebTouchEvent& event = latest_event();
EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state);
EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state);
}
TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
MoveTouchPoint(0, 10, 10);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(2U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
OnHasTouchEventHandlers(false);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
}
TEST_F(TouchEventQueueTest, NoConsumer) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
MoveTouchPoint(0, 5, 5);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(2U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
EXPECT_EQ(2U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
ReleaseTouchPoint(0);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
PressTouchPoint(10, 10);
EXPECT_EQ(1U, GetAndResetSentEventCount());
MoveTouchPoint(0, 5, 5);
MoveTouchPoint(0, 6, 5);
ReleaseTouchPoint(0);
PressTouchPoint(6, 5);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(4U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
EXPECT_EQ(4U, GetAndResetAckedEventCount());
EXPECT_EQ(1U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, queued_event_count());
PressTouchPoint(1, 1);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, queued_event_count());
}
TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
MoveTouchPoint(0, 5, 5);
PressTouchPoint(10, 10);
MoveTouchPoint(0, 2, 2);
MoveTouchPoint(1, 4, 10);
MoveTouchPoints(0, 10, 10, 1, 20, 20);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(4U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(3U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(2U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
MoveTouchPoint(1, 30, 30);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
MoveTouchPoint(0, 10, 10);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
MoveTouchPoints(0, 15, 15, 1, 25, 25);
EXPECT_EQ(0U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
ReleaseTouchPoint(0);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, queued_event_count());
MoveTouchPoint(1, 40, 40);
MoveTouchPoint(1, 50, 50);
PressTouchPoint(1, 1);
MoveTouchPoint(1, 30, 30);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(4U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(2U, queued_event_count());
EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
ReleaseTouchPoint(2);
ReleaseTouchPoint(1);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, queued_event_count());
}
TEST_F(TouchEventQueueTest, AckWithFollowupEvents) {
PressTouchPoint(1, 1);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
WebTouchEvent followup_event;
followup_event.type = WebInputEvent::TouchStart;
followup_event.touchesLength = 1;
followup_event.touches[0].id = 1;
followup_event.touches[0].state = WebTouchPoint::StatePressed;
SetFollowupEvent(followup_event);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
MoveTouchPoint(0, 2, 2);
EXPECT_EQ(2U, queued_event_count());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, SynchronousAcks) {
SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
PressTouchPoint(1, 1);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
MoveTouchPoint(0, 2, 2);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
ReleaseTouchPoint(0);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
PressTouchPoint(1, 1);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
CancelTouchPoint(0);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) {
WebTouchEvent followup_event;
followup_event.type = WebInputEvent::TouchStart;
followup_event.touchesLength = 1;
followup_event.touches[0].id = 1;
followup_event.touches[0].state = WebTouchPoint::StatePressed;
SetFollowupEvent(followup_event);
WebTouchEvent stationary_event;
stationary_event.touchesLength = 1;
stationary_event.type = WebInputEvent::TouchMove;
stationary_event.touches[0].id = 1;
stationary_event.touches[0].state = WebTouchPoint::StateStationary;
SendTouchEvent(stationary_event);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
}
TEST_F(TouchEventQueueTest, NoTouchBasic) {
OnHasTouchEventHandlers(false);
PressTouchPoint(30, 5);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 65, 10);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
ReleaseTouchPoint(0);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
OnHasTouchEventHandlers(true);
PressTouchPoint(80, 10);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 80, 20);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
ReleaseTouchPoint(0);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, TouchCancelOnScroll) {
SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL);
PressTouchPoint(0, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 20, 5);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
PressTouchPoint(20, 20);
EXPECT_EQ(2U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type);
WebGestureEvent followup_scroll;
followup_scroll.type = WebInputEvent::GestureScrollBegin;
SetFollowupEvent(followup_scroll);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(2U, queued_event_count());
EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
MoveTouchPoint(0, 30, 5);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
SendGestureEvent(WebInputEvent::GestureScrollUpdate);
ReleaseTouchPoint(0);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
ReleaseTouchPoint(0);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
PressTouchPoint(80, 10);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 80, 20);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
ReleaseTouchPoint(0);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, NoTouchCancelOnScrollIfNoConsumer) {
SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL);
PressTouchPoint(0, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
WebGestureEvent followup_scroll;
followup_scroll.type = WebInputEvent::GestureScrollBegin;
SetFollowupEvent(followup_scroll);
MoveTouchPoint(0, 20, 5);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
MoveTouchPoint(0, 30, 5);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
ReleaseTouchPoint(0);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
PressTouchPoint(80, 10);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, PendingStart) {
EXPECT_FALSE(IsPendingAckTouchStart());
PressTouchPoint(1, 1);
EXPECT_EQ(1U, queued_event_count());
EXPECT_TRUE(IsPendingAckTouchStart());
MoveTouchPoint(0, 5, 5);
EXPECT_EQ(2U, queued_event_count());
EXPECT_TRUE(IsPendingAckTouchStart());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, queued_event_count());
EXPECT_FALSE(IsPendingAckTouchStart());
PressTouchPoint(10, 10);
EXPECT_EQ(2U, queued_event_count());
EXPECT_FALSE(IsPendingAckTouchStart());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, queued_event_count());
EXPECT_TRUE(IsPendingAckTouchStart());
PressTouchPoint(15, 15);
EXPECT_EQ(2U, queued_event_count());
EXPECT_TRUE(IsPendingAckTouchStart());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, queued_event_count());
EXPECT_TRUE(IsPendingAckTouchStart());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_FALSE(IsPendingAckTouchStart());
}
TEST_F(TouchEventQueueTest, TouchTimeoutTypes) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
PressTouchPoint(0, 1);
EXPECT_TRUE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
MoveTouchPoint(0, 5, 5);
EXPECT_TRUE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
ReleaseTouchPoint(0);
EXPECT_FALSE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
PressTouchPoint(0, 1);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
ASSERT_FALSE(IsTimeoutRunning());
CancelTouchPoint(0);
EXPECT_FALSE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
}
TEST_F(TouchEventQueueTest, TouchTimeoutBasic) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
GetAndResetSentEventCount();
GetAndResetAckedEventCount();
PressTouchPoint(0, 1);
ASSERT_EQ(1U, GetAndResetSentEventCount());
ASSERT_EQ(0U, GetAndResetAckedEventCount());
EXPECT_TRUE(IsTimeoutRunning());
RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
EXPECT_EQ(1U, GetAndResetSentEventCount());
MoveTouchPoint(0, 1, 1);
ASSERT_EQ(0U, GetAndResetSentEventCount());
ASSERT_EQ(1U, GetAndResetAckedEventCount());
ReleaseTouchPoint(0);
ASSERT_EQ(0U, GetAndResetSentEventCount());
ASSERT_EQ(1U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
PressTouchPoint(0, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
PressTouchPoint(0, 1);
ASSERT_TRUE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
MoveTouchPoint(0, 5, 5);
EXPECT_FALSE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
PressTouchPoint(1, 0);
EXPECT_FALSE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
ReleaseTouchPoint(1);
EXPECT_FALSE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
CancelTouchPoint(0);
EXPECT_FALSE(IsTimeoutRunning());
}
TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
PressTouchPoint(0, 1);
ASSERT_TRUE(IsTimeoutRunning());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_TRUE(IsTimeoutEnabled());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
SetAckTimeoutDisabled();
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_FALSE(IsTimeoutEnabled());
MoveTouchPoint(0, 5, 5);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(1U, GetAndResetSentEventCount());
RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
EXPECT_EQ(0U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
ASSERT_FALSE(IsTimeoutRunning());
PressTouchPoint(0, 1);
EXPECT_FALSE(IsTimeoutRunning());
}
TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTouchHandlerRemoved) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
PressTouchPoint(0, 1);
ASSERT_TRUE(IsTimeoutRunning());
OnHasTouchEventHandlers(false);
EXPECT_FALSE(IsTimeoutRunning());
}
TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
PressTouchPoint(0, 1);
ASSERT_TRUE(IsTimeoutRunning());
SetAckTimeoutDisabled();
EXPECT_FALSE(IsTimeoutRunning());
RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
EXPECT_EQ(0U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
PressTouchPoint(0, 1);
EXPECT_TRUE(IsTimeoutRunning());
EXPECT_EQ(1U, GetAndResetSentEventCount());
WebGestureEvent followup_scroll;
followup_scroll.type = WebInputEvent::GestureScrollBegin;
SetFollowupEvent(followup_scroll);
RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
GetAndResetSentEventCount();
GetAndResetAckedEventCount();
MoveTouchPoint(0, 1, 1);
ReleaseTouchPoint(0);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(2U, GetAndResetAckedEventCount());
SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
PressTouchPoint(0, 1);
EXPECT_TRUE(IsTimeoutRunning());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
PressTouchPoint(0, 1);
EXPECT_TRUE(IsTimeoutRunning());
EXPECT_EQ(1U, GetAndResetSentEventCount());
WebGestureEvent followup_scroll;
followup_scroll.type = WebInputEvent::GestureScrollBegin;
SetFollowupEvent(followup_scroll);
RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
GetAndResetSentEventCount();
GetAndResetAckedEventCount();
MoveTouchPoint(0, 1, 1);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
MoveTouchPoint(0, 2, 2);
ReleaseTouchPoint(0);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(2U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
PressTouchPoint(0, 1);
EXPECT_TRUE(IsTimeoutRunning());
EXPECT_EQ(1U, GetAndResetSentEventCount());
}
TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) {
SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
PressTouchPoint(0, 1);
ASSERT_EQ(1U, GetAndResetSentEventCount());
ASSERT_EQ(0U, GetAndResetAckedEventCount());
EXPECT_TRUE(IsTimeoutRunning());
RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 1, 1);
ReleaseTouchPoint(0);
ASSERT_EQ(0U, GetAndResetSentEventCount());
ASSERT_EQ(2U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, GetAndResetSentEventCount());
PressTouchPoint(0, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, TouchMoveSuppressionWithinSlopRegion) {
const double kSlopLengthDips = 10.;
const double kHalfSlopLengthDips = kSlopLengthDips / 2;
SetUpForTouchMoveSlopTesting(kSlopLengthDips);
PressTouchPoint(0, 0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
ASSERT_EQ(1U, GetAndResetSentEventCount());
ASSERT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, kHalfSlopLengthDips);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
MoveTouchPoint(0, kHalfSlopLengthDips, 0);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
MoveTouchPoint(0, -kHalfSlopLengthDips, 0);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
const double kFortyFiveDegreeSlopLengthXY =
kSlopLengthDips * std::sqrt(2.) / 2.;
MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2,
kFortyFiveDegreeSlopLengthXY + .2);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, 0);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
ReleaseTouchPoint(0);
PressTouchPoint(0, 0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
ASSERT_EQ(2U, GetAndResetSentEventCount());
ASSERT_EQ(2U, GetAndResetAckedEventCount());
ASSERT_EQ(0U, queued_event_count());
MoveTouchPoint(0, kSlopLengthDips - 1., 0);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, kSlopLengthDips, 0);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) {
const double kSlopLengthDips = 10.;
const double kHalfSlopLengthDips = kSlopLengthDips / 2;
SetUpForTouchMoveSlopTesting(kSlopLengthDips);
PressTouchPoint(0, 0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
ASSERT_EQ(1U, GetAndResetSentEventCount());
ASSERT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, kHalfSlopLengthDips);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, TouchMoveSuppressionWithDIPScaling) {
const float kSlopLengthPixels = 7.f;
const float kDPIScale = 3.f;
SetUpForTouchMoveSlopTesting(kSlopLengthPixels / kDPIScale);
PressTouchPoint(0, 0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
ASSERT_EQ(1U, GetAndResetSentEventCount());
ASSERT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, kSlopLengthPixels / kDPIScale);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
ReleaseTouchPoint(0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
GetAndResetSentEventCount();
GetAndResetAckedEventCount();
PressTouchPoint(0, 0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
ASSERT_EQ(1U, GetAndResetSentEventCount());
ASSERT_EQ(1U, GetAndResetAckedEventCount());
const float kPixelCoordOutsideSlopRegion = kSlopLengthPixels + 0.5f;
MoveTouchPoint(0, 0, kPixelCoordOutsideSlopRegion / kDPIScale);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) {
const double kSlopLengthDips = 10.;
const double kHalfSlopLengthDips = kSlopLengthDips / 2;
SetUpForTouchMoveSlopTesting(kSlopLengthDips);
PressTouchPoint(0, 0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
ASSERT_EQ(1U, GetAndResetSentEventCount());
ASSERT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, kHalfSlopLengthDips);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
PressTouchPoint(kSlopLengthDips, 0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(1, kSlopLengthDips, 0);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
ReleaseTouchPoint(0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, 0);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(0U, GetAndResetAckedEventCount());
}
TEST_F(TouchEventQueueTest, SyncTouchMoveDoesntCancelTouchOnScroll) {
SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE);
PressTouchPoint(0, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 20, 5);
EXPECT_EQ(1U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
WebGestureEvent followup_scroll;
followup_scroll.type = WebInputEvent::GestureScrollBegin;
SetFollowupEvent(followup_scroll);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(0U, queued_event_count());
}
TEST_F(TouchEventQueueTest, TouchAbsorption) {
SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE);
PressTouchPoint(0, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
for (int i = 0; i < 3; ++i) {
SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
MoveTouchPoint(0, 20, 5);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
MoveTouchPoint(0, 20, 5);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
}
}
TEST_F(TouchEventQueueTest, TouchAbsorptionNoTouchAfterScroll) {
SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE);
PressTouchPoint(0, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, 5);
WebGestureEvent followup_scroll;
followup_scroll.type = WebInputEvent::GestureScrollBegin;
SetFollowupEvent(followup_scroll);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, 10);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
ReleaseTouchPoint(0);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
SendGestureEventAck(WebInputEvent::GestureScrollBegin,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
PressTouchPoint(0, 1);
EXPECT_EQ(1U, GetAndResetSentEventCount());
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, 5);
SetFollowupEvent(followup_scroll);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetSentEventCount());
EXPECT_EQ(1U, GetAndResetAckedEventCount());
MoveTouchPoint(0, 0, 10);
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
}
}